akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;


int main()
{


int n,m;
cin >> n >> m;

vector <vector <int>> g(n,vector <int>(m));

char c;
for (int i=0; i<n; i++)
for (int j=0; j<m; j++)
{     cin >> c;
    if (c=='#') g[i][j] = -1; else g[i][j] = 0;
}










    int maxALL = 0;

for (int i=0; i<n; i++)
    for (int j=0; j<m; j++)
    {
        if (g[i][j]==-1) continue;
        int maxV = 0;
        auto xg = g;

        /*for (int i=0; i<n; i++)
        for (int j=0; j<m; j++) cout << xg[i][j] <<"\n"[j!=m-1]; */


        queue <pair<int,int>> q;

        pair <int,int> now = {i,j};
        q.push(now);
        xg[i][j] = 1;

        while (!q.empty())
        {
            now = q.front();
            q.pop();
            if (now.first>0 && xg[now.first-1][now.second]==0){  xg[now.first-1][now.second]=xg[now.first][now.second]+1; now.first--; q.push(now); now.first++;}
            if (now.second>0 && xg[now.first][now.second-1]==0){  xg[now.first][now.second-1]=xg[now.first][now.second]+1; now.second--; q.push(now); now.second++;}
            if (now.first<n-1 && xg[now.first+1][now.second]==0){  xg[now.first+1][now.second]=xg[now.first][now.second]+1; now.first++; q.push(now); now.first--;}
            if (now.second<m-1 && xg[now.first][now.second+1]==0){  xg[now.first][now.second+1]=xg[now.first][now.second]+1; now.second++; q.push(now); now.second--;}
            maxV = max(maxV,xg[now.first][now.second]);

//            cout << now.first << " " << now.second << "\n";
        }
        //cout << "\n";
        maxALL = max(maxALL,maxV);
    }

cout << maxALL -1;





}

/*
5 6
......
#.##.#
#.##.#
#.##..
##....
*/









Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int f(char *S,int N){
  for(int i=0;i<N/2;i++){
    if(S[i]!=S[N-1-i]) return 0;
  }
  return 1;
}

int main(){
  char S[101],T[101],U[101];
  int N;
  scanf("%s",S);
  N=strlen(S);
  for(int i=0;i<(N-1)/2;i++) T[i]=S[i];
  for(int i=(N+3)/2-1;i<N;i++) U[i-(N+3)/2+1]=S[i];
  if(f(S,N)*f(T,(N-1)/2)*f(U,(N-1)/2)==1) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	int n;
	cin >> n;
	
	vector<int> stone;
	rep(i, n){
		int a;
		cin >> a;
		stone.push_back(a);
	}

	int ans = -1;
	int crash = 0;
	int node = 1; // 欲しい石

	rep(i, n)
	{
		if(stone[i] == node){
			if(ans == -1) ans = crash;
			else ans += crash;

			node++;
			crash = 0;
		}
		else {
			crash++;
		}
	}

	if(ans != -1) ans += crash;

	cout << ans;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define int long long

int i, j, n, dp[202][202], mod = 1e9+7;
char c[202];

signed main() {
	cin >> n;
	for(i=0; i<n; i++) {
		cin >> c[i];
		if (c[i]=='-') i--, n--;
	}
	dp[0][0] = 1;
	for(i=0; i<n; i++) for(j=0; j<n; j++) {
		if (c[i]=='D') {
			if (j) (dp[i+1][j-1] += dp[i][j]*j %mod *j) %= mod;
			(dp[i+1][j] += dp[i][j]*j) %= mod;
		}
		else {
			(dp[i+1][j] += dp[i][j]*j) %= mod;
			(dp[i+1][j+1] += dp[i][j]) %= mod;
		}
	}
	cout << dp[n][0] << endl;
}


Measured memory_bytes: 3392
#include <cstdio>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int Ans[100016];
int Now[100016];

int main() {
    int N;
    scanf("%d", &N);
    vector<pair<int, int> > A, B;
    for(int n=0; n<N; ++n) {
        int a;
        scanf("%d", &a);
        A.emplace_back(a, n);
    }
    for(int n=0; n<N; ++n) {
        int b;
        scanf("%d", &b);
        B.emplace_back(b, n);
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    for(int n=0; n<N; ++n) {
        if(B[n].first<A[n].first) {
            printf("No\n");
            return 0;
        }
    }
    for(int n=1; n<N; ++n) {
        if(A[n].first<=B[n-1].first) {
            printf("Yes\n");
            return 0;
        }
    }
    for(int n=0; n<N; ++n) {
        Now[n] = n;
        Ans[B[n].second] = A[n].second;
    }
    for(int n=0; n<N-1; ++n) {
        if(Now[n]==Ans[n]) {
            printf("Yes\n");
            return 0;
        }
        int ans = Ans[n];
        for(int i=N-1; n+1<=i; --i) {
            if(ans==Now[i]) {
                Now[i] = Now[n];
                break;
            }
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2676
n,m=map(int,input().split())
g=[list(map(int,input().split())) for i in range(m)]
lis=[]
for i in range(m):
  if g[i][0]==1:
    lis.append(g[i][1])
  if g[i][1]==n:
    lis.append(g[i][0])
lis.sort()
if len(lis)<2:
  print('IMPOSSIBLE')
else:
  for i in range(len(lis)-1):
    if lis[i]==lis[i+1]:
      print('POSSIBLE')
      exit()
  print('IMPOSSIBLE')

Measured memory_bytes: 51740
#include <iostream>

using namespace std;

const int MAX_H = 50, MAX_W = 50;

int main(int argc, char const *argv[]) {
  int h, w;
  cin >> h >> w;
  char s[MAX_H][MAX_W];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) cin >> s[i][j];
  }

  bool tf = true;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i == 0 and j == 0 and s[i][j] == '#') {
        if (s[i+1][j] == '#' or s[i][j+1] == '#') continue;
        else {
          tf = false;
          break;
        }
      } else if (i == h-1 and j == w-1 and s[i][j] == '#') {
        if (s[i-1][j] == '#' or s[i][j-1] == '#') continue;
        else {
          tf = false;
          break;
        }
      } else if (i == 0 and j == w-1 and s[i][j] == '#') {
        if (s[i+1][j] == '#' or s[i][j-1] == '#') continue;
        else {
          tf = false;
          break;
        }
      } else if (i == h-1 and j == 0 and s[i][j] == '#') {
        if (s[i-1][j] == '#' or s[i][j+1] == '#') continue;
        else {
          tf = false;
          break;
        }
      } else if (i == 0 and s[i][j] == '#') {
        if (s[i+1][j] == '#' or s[i][j-1] == '#' or s[i][j+1] == '#') continue;
        else {
          tf = false;
          break;
        }
      } else if (i == h-1 and s[i][j] == '#') {
        if (s[i-1][j] == '#' or s[i][j-1] == '#' or s[i][j+1] == '#') continue;
        else {
          tf = false;
          break;
        }
      } else if (j == 0 and s[i][j] == '#') {
        if (s[i][j+1] == '#' or s[i-1][j] == '#' or s[i+1][j] == '#') continue;
        else {
          tf = false;
          break;
        }
      } else if (j == w-1 and s[i][j] == '#') {
        if (s[i][j-1] == '#' or s[i-1][j] == '#' or s[i+1][j] == '#') continue;
        else {
          tf = false;
          break;
        }
      } else if(s[i][j] == '#'){
        if (s[i][j-1] == '#' or s[i][j+1] == '#' or s[i-1][j] == '#' or s[i+1][j] == '#') continue;
        else {
          tf = false;
          break;
        }
      }
    }
  }

  if (tf) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=1e6+100;
struct poi
{
    double x,y;
};

int main()
{
    int n;
    scanf("%d",&n);
    cout<<n*n<<endl;
    return 0;
}


Measured memory_bytes: 256
//754

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    string S;cin >> S;
    ll Ans = 99999999999;
    rep(i,0,S.size()){
        Ans=min(abs(stoll(S.substr(i,3))-753),Ans);
    } 
    cout << Ans << endl;
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
	ll N;
	cin >> N;
	ll A[N][N];
	ll B[N][N];
	REP(i, N) REP(j, N) cin >> A[i][j];
	REP(i, N) REP(j, N) B[i][j] = A[i][j];
	bool flag = true;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			for (int k=0;k<N;k++){
				if (i!=k && j!=k){
					if(A[i][j] > A[i][k]+A[j][k]){
						flag = false;
					}
					if(A[i][j] == A[i][k] + A[j][k]){
						B[i][j] = 0;
					}
				}
			}
		}
	}
	ll res = 0;
	for(int i=0;i<N;i++){
		for (int j=i+1;j<N;j++){
			res += B[i][j];
		}
	}
	if(!flag){
		cout << -1 << endl;
	}else{
		cout << res << endl;
	}
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
using namespace std;
int main ()
{   int k;
    cin>>k;
    if(k%2==0) cout<<"-1"<<endl;
    else
    {  int ans=7;
        int i;
       for(i=1;;i++)
       {  if(ans%k==0) {cout<<i<<endl;break;}
          else   ans=(ans%k)*10+7;
          if(i==5000000) {cout<<-1<<endl;break;}
	   }
	}
}

Measured memory_bytes: 3612
n = gets.to_i
w = gets.chomp.split.map(&:to_i)
 
before = 0
after = w.inject(&:+)
score = after+1
 
n.times do |i|
  before += w[i]
  after -= w[i]
  tmp = (after - before).abs
  if tmp < score
    score = tmp
  else
    break
  end
end
 
print score

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

using namespace std;

#define ff(i, a, b) for(int i = (a); (i <= (b)); ++i)
#define FF(i, a, b) for(int i = (a); (i >= (b)); --i)
#define ll long long

const int M = 1000000000 + 7;

struct re {
    int x, y;
//    const bool operator < (const re &a) const {
//        if (x != a.x) return x < a.x;
//        return y < a.y;
//    }
};

int n, m, f[1<<12];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("", "r" , stdin);
    //freopen("", "w", stdout);
    cin >> n >> m;
    ff(i, 1, (1 << n) - 1) f[i] = M;
    ff(i, 1, m) {
        int c, l, sum = 0;
        cin >> c >> l;
        ff(j, 1, l) {
            int x;
            cin >> x;
            sum += (1 << (x - 1));
        }
        f[sum] = min(f[sum], c);
    }

    ff(i, 1, (1 << n) - 1)
    if (f[i] < M) {
        ff(j, 1, i - 1) {
            f[i | j] = min(f[i | j], f[i] + f[j]);
        }
    }

    if (f[(1 << n) - 1] == M) cout << -1; else
    cout << f[(1 << n) - 1];
}
//This code belongs to s34vv1nd


Measured memory_bytes: 256
//
//  main.cpp
//  130-A Rounding
//
//  Created by 李罗罗 on 2019/8/24.
//  Copyright © 2019 李罗罗. All rights reserved.
//

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    int a,b;
    cin>>a>>b;
    if(a<b) cout<<"0";
    else cout<<"10";
    
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN,"%d",$N);

$a_list = array();
for($i=0;$i<$N;$i++){
    $a_list[] = trim(fgets(STDIN));
}

$sort_a_list = $a_list;
rsort($sort_a_list);

for($j=0;$j<$N;$j++){
   if($a_list[$j] == $sort_a_list[0]){
       echo $sort_a_list[1]."\n";
   }else{
       echo $sort_a_list[0]."\n";
   }
}


Measured memory_bytes: 28528
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define rg register
#define il inline
#define ll long long
using namespace std;
il ll gi() {
    ll res=0,flg=1; char ch=0;
    while((ch<'0'|| ch>'9')&&(ch!='-')){ ch=getchar(); }
    if(ch=='-')flg=-1,ch=getchar();
    while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar();
    return res*flg;
}
il void we(ll x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) we(x/10);
    putchar(x%10+'0');
}
int LNum=0,RNum=0;
ll xl[1000008],xr[1000008];
ll l(ll t){
    return -xl[LNum-t];
}
ll r(ll t){
    return xr[t-1];
}
int main(){
    ll n,k;    
    n=gi();
    k=gi();
    int flg=0;
    for(ll i=0;i<n;i++){
        ll tmp=gi();
        if(tmp<0){
            xl[LNum]=tmp;
            LNum++;
        }
        else{
            xr[RNum]=tmp;
            RNum++;
        }
    }
    ll ans=l(LNum)*2+r(RNum)*2;
    if(LNum>=k)ans=min(ans,l(k));
    if(RNum>=k)ans=min(ans,r(k));
    for(int i=1;i<=LNum;i++)
            if((k-i<=RNum)&&(k-i>0)){
                ans=min(ans,min(l(i),r(k-i))*2+max(l(i),r(k-i)));
            }
    we(ans);
    return 0;
}

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

int main()
{
    int a;
    cin>>a;
    if(a>=0&&a<1200)
        cout<<"ABC";
        else if(a>=1200&&a<2800)
            cout<<"ARC";
            else
                cout<<"AGC";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//縦H,横Wの＃でできた長方形を作成する
		//HとWがともに0の場合に終了
		Scanner sc=new Scanner(System.in);
		while(true){
			int H=sc.nextInt();
			int W=sc.nextInt();
			if(H==0 && W==0){
				break;
			}
			for(int i=1;i<=H;i++){
				for(int j=1;j<=W;j++){
					System.out.print("#");
					if(j==W){
						System.out.println();
					}
				}
				if(i==H){
					System.out.println();
				}
			}
		}
	}

}



Measured memory_bytes: 35640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll, ll> pii;
 
int main() {
    ll n; 
    cin>>n;
    ll a[n+1];
    ll cnt[n+1];
    memset(cnt,0,sizeof(cnt));
    for(ll i=1;i<=n;i++){
        cin>>a[i];
        cnt[a[i]]++;
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ans+= cnt[i]*(cnt[i]-1)/2;
    }
    for(ll i=1;i<=n;i++){
        cout<<ans-cnt[a[i]]+1<<endl;
    }
    
	return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;
  
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;
  
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>
  
const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};
  
int main(){
    while(1){
        int n,m,s;
        scanf("%d%d%d",&n,&m,&s); if(n == 0 && m == 0 && s == 0)break;
          
        static int dp[2002][3002] = {};
        rep(i,2002){
            rep(j,3002){
                if(j == 0)dp[i][j] = 1;
                else dp[i][j] = 0;
            }
        }
    	
    	int l = 0,r;
          
        rep1(i,n*n){
        	l += i;
        	r = s;
        	for(int j = i+1;j <= n*n; j++){
        		r -= j;
        	}
        	for(int j = r;j >= l;j --){
                rep1(k,min(m,j)){
                    dp[k][j] = dp[k-1][j-k];
                    if(dp[k][j] >= 100000)dp[k][j] %= 100000;
                }
        		for(int k = min (m,j)+1;k <= m ; k ++){
        			dp[k][j] = 0;
        		}
                dp[0][j] = 0;
            }
        	for(int j = l-i;j < l;j ++){
        		rep1(k,m){
        			dp[k][j] = 0;
        		}
        		dp[0][j] = 0;
        	}
        	for(int j = l;j <= r;j ++){
        		for(int k = i;k <= m && k*(n*n-i) <= s;k++){
               // rep1(k,m){
                    dp[k][j] += dp[k-1][j];
                    if(dp[k][j] >= 100000)dp[k][j] %= 100000;
                }
            }
        }
          
        printf("%d\n",dp[m][s]);
    }
}

Measured memory_bytes: 24664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    if (h1 > h2) h2 += 24;
    else if (h1 == h2 && m1 >= m2) h2 += 24;
    int m = 60 - m1;
    h1++;
    m += (h2 - h1) * 60;
    m += m2;
    int ans = max(0, m-k);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
 
using namespace std;
 
#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238
 
typedef pair<int, int> P;
  
signed main(){
    deque<char> d;
    string s; cin>>s;
    REP(i,s.length()){
        d.push_back(s[i]);
    }
    int n; cin>>n;
    bool flag = true;
    REP(i,n){
        int t; cin>>t;
        if(t==1){
            if(flag) flag =false;
            else flag = true;
        }
        else{
            int f; cin>>f;
            char c; cin>>c;
            if(flag){
                if(f==1) d.push_front(c);
                else d.push_back(c);
            } else {
                if(f==2) d.push_front(c);
                else d.push_back(c);
            }
        }
    }
    int m = d.size();
    if(!flag){
        REP(i,m){
            cout<<d.back();
            d.pop_back();
        }
        cout<<endl;
    } else {
        REP(i,m){
            cout<<d.front();
            d.pop_front();
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 896
N = int(input())
A = [int(input()) for _ in range(N)]
B = {}
for i in A:
    if i not in B:
        B[i] = 1
    else:
        if B[i] == 1:
            B[i] -= 1
        else:
            B[i] += 1
cnt = 0
for j in B.keys():
    if B[j] == 1:
        cnt += 1
print(cnt)


Measured memory_bytes: 16268
a, b, h, m = map(int, input().split())

theta = abs(30*h+0.5*m - 6*m)

theta = min(theta, 360 - theta)

import math

x_2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(theta))

print(x_2**0.5)

Measured memory_bytes: 62408
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <set>
#include <algorithm>
#include <cassert>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
using namespace std;

int N;
//int d[110];

int main()
{
  cin >> N;
  set<int> st;
  REP(i,0,N) {
    int d;
    cin >> d;
    st.insert(d);
  }

  // dの相異なる要素数
  // これを下から大きい順に並べれば良い
  cout << st.size() << endl;

  return 0;
}


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

vector<int> z_algorithm(string s) {
  vector<int> ret(s.size());  // 結果を入れるvector
  ret[0] = s.size();
  int i = 1, j = 0;
  while (i < s.size()) {
    while (i + j < s.size() && s[j] == s[i + j]) ++j;  // 右向きにjを伸ばしていく
    ret[i] = j;
    if (j == 0) {
      ++i;
      continue;
    }
    int k = 1;
    while (i + k < s.size() && k + ret[k] < j) ret[i + k] = ret[k], ++k;  // i~j間にkを走らせる
    i += k;
    j -= k;
  }
  return ret;
}

// ====================================================================

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

  int ans = 0;
  while (s.size()) {
    vector<int> v = z_algorithm(s);
    for (int i = 0; i < v.size(); i++) 
      if (i >= v[i]) ans = max(ans, v[i]);
    s.erase(s.begin());
  }
  cout << ans << endl;
}


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

CSF = []

for n in range(N-1):
    CSF.append(list(map(int, input().split())))

ans = []

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        t = max(math.ceil(t / CSF[j][2]) * CSF[j][2], CSF[j][1]) + CSF[j][0]
    ans.append(t)
ans.append(0)

print(*ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long a, b, minn=9223372036854775800;
	cin >> a >> b;
	long long x=b-a+1;
	if (x>=2019)
	{
		cout << 0 << endl;
		return 0;
	}
	for (long long i=a; i<b; i++)
		for (long long j=i+1; j<=b; j++) minn=min(minn, ((i*j)%2019));
	cout << minn << endl;
	return 0;
}

Measured memory_bytes: 256
N,K,Q = map(int ,input().split())

point = [K-Q for i in range(N)]

minus = [0]*N

for i in range(Q):
    num = int(input())-1
    minus[num] += 1
    
point = ["Yes"  if (point[i]+ minus[i])>0 else "No" for i in range(N)]

point = "\n".join(point)

print(point)

Measured memory_bytes: 8624
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let l = read::<usize>();

    let length = l as f64 / 3. ;

    println!("{}", length.powf(3.));
}

Measured memory_bytes: 4352
var  a,b,c,d:longint;
     s:string;
begin
  readln(s);
  a:=ord(s[1])-ord('0');
  b:=ord(s[2])-ord('0');
  c:=ord(s[3])-ord('0');
  d:=ord(s[4])-ord('0');
  if  a+b+c+d=7  then
    begin  writeln(a,'+',b,'+',c,'+',d,'=7');  exit;  end;
  if  a+b+c-d=7  then
    begin  writeln(a,'+',b,'+',c,'-',d,'=7');  exit;  end;
  if  a+b-c+d=7  then
    begin  writeln(a,'+',b,'-',c,'+',d,'=7');  exit;  end;
  if  a-b+c+d=7  then
    begin  writeln(a,'-',b,'+',c,'+',d,'=7');  exit;  end;
  if  a-b-c+d=7  then
    begin  writeln(a,'-',b,'-',c,'+',d,'=7');  exit;  end;
  if  a-b+c-d=7  then
    begin  writeln(a,'-',b,'+',c,'-',d,'=7');  exit;  end;
  if  a+b-c-d=7  then
    begin  writeln(a,'+',b,'-',c,'-',d,'=7');  exit;  end;
  if  a-b-c-d=7  then
    begin  writeln(a,'-',b,'-',c,'-',d,'=7');  exit;  end;
end.

Measured memory_bytes: 128
#include <stdio.h>

#define H 251

int A[H];

int main(){

int i,n;

scanf("%d",&n);
//for(i = 0 ; i < n+1 ; i++)A[i] = -1;//?????????

for(i = 1 ; i <= n ; i++)scanf("%d",&A[i]);

for(i = 1 ; i <= n ; i++){
printf("node %d: key = %d, ",i,A[i]);
if(i == 1);
 else if(i/2 <= n)printf("parent key = %d, ",A[i/2]);
if(2*i<= n)printf("left key = %d, ",A[2*i]);
if(2*i+1<= n)printf("right key = %d, ",A[2*i+1]);
printf("\n");

}

return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int k, a, b;
  cin >> k >> a >> b;
  bool ans = false;
  for (int i = a; i <= b; ++i) {
    if (i % k == 0) {
      ans = true;
      break;
    }
  }

  cout << (ans ? "OK" : "NG") << '\n';
  return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string> 
#include <sstream>  
#include <vector> 
using namespace std;
  
int main(){

    int m,n;
    while(cin >> m >> n){
        if(m == 0 and n == 0){break;}
        int player[m + 1],speaker = 1,nokori = m;
        string kotaetayatu,kotaerubekimono;
        for(int i = 1;m >= i;i++){player[i] = 1;}
            for(int number = 1;n >= number;number++){
                for(int NxstSpeaker = speaker;true;NxstSpeaker++){
                    if(NxstSpeaker > m){NxstSpeaker = 1;}
                    
                    if(player[NxstSpeaker] == 1){
                        stringstream ss;ss << number;
                        kotaerubekimono  = ss.str(); 
                        if(number % 3 == 0){kotaerubekimono = "Fizz";}
                        if(number % 5 == 0){kotaerubekimono = "Buzz";}
                        if(number % 3 == 0 and number % 5 == 0){kotaerubekimono = "FizzBuzz";}
                        cin >> kotaetayatu;
                        if(nokori > 1){
                            if(kotaetayatu != kotaerubekimono){player[NxstSpeaker] = 0;nokori--;}
                            speaker = NxstSpeaker + 1;
                        }
                        break;
                    }
                }
            }
        int hatena = 1;
        for(int ii = 1;m >= ii;ii++){if(player[ii] == 1){if(hatena == 1){cout << ii;hatena = 0;}else{cout << " " << ii;}}}
        cout << endl;
    } 
}

Measured memory_bytes: 1228
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=sorted(p)
c=0
z=0
a=[]
for i in range(n):
    a.append(p[i]-x)
for i in range(100):
    if a.count(-i)==0:
        z=-c
        break
    elif a.count(i)==0:
        z=c
        break
    else:
        c+=1
print(x+z)     

Measured memory_bytes: 9204
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
void solve(std::string S, std::string T){
  cout<<T<<S<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


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

using namespace std;

typedef long long ll;

int a[105];
ll dp[105][200050];

int mod = (int)1e9 + 7;


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

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

    dp[0][k] = 1;
    for(int i = 1 ; i <= n ;i++){
        for(int j = 0 ; j <= k ;j++){
            //if(j < a[i])    continue;

            int dele = 0;
            if(j)   dele = dp[i-1][j - 1];

            dp[i][j] += dp[i-1][min( k , j + a[i])] - dele;
            if(j) dp[i][j] += dp[i][j-1];
            dp[i][j] =  (dp[i][j] + mod) % mod;
            //printf("%d %d %d\n",i,j,dp[i][j]);
        }
    }

    cout << dp[n][0];


    return 0;
}


Measured memory_bytes: 156416
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, T = sc.nextInt()
  val min = List
    .fill(N)(sc.nextInt() -> sc.nextInt())
    .filter(_._2 <= T)
    .minByOption(_._1)
  println(min.map(_._1).getOrElse("TLE"))
}


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

using namespace std;

#define ll long long
#define mod 1e9 + 7
#define mx 1000000000
#define endl '\n'

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll l,r;
    cin>>l>>r;
    ll ans = 2019;
    int d = (r-l);
    if(d >= 2019){
        cout<<0;
    }else{
        for(ll i = l;i<=r;i++){
            for(ll j = i+1;j<=r;j++){
                ans = min(ans,(i*j)%2019);
            }
        }
        cout<<ans;
    }

    return 0;
}



Measured memory_bytes: 256
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        for (int i = 1; i < n; i++) a[i] = a[i - 1] + a[i];
        Console.WriteLine(getAns(a, n));
    }
    static int getAns(int[] a, int n)
    {
        var ans = int.MaxValue;
        for (int i = 0; i < n; i++)
            ans = Min(ans, a[i] / (i + 1));
        return ans;
    }
}



Measured memory_bytes: 15968
import math
X = int(input())
f = True
if X == 2:
    print(X)
else:
    while f:
        for n in range(2, int(math.sqrt(X)) + 1):
            if X % n == 0:
                X += 1
                break
            if n == int(math.sqrt(X)): 
                print(X)
                f = False
                break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/
template<class T> class Dijkstra {
public:
    int N;
    T inf;
    vector<T> cost;
    vector<vector<pair<T, int>>> edge;
 
    Dijkstra(const int N, T inf) : N(N), inf(inf),cost(N), edge(N) {
    }
 
    void make_edge(int from, int to, T w) {
        edge[from].push_back({ w,to });
    }
 
    void solve(int start) {
        for(int i = 0; i < N; ++i) cost[i] = inf;
 
        priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
        cost[start] = 0;
        pq.push({ 0,start });
 
        while (!pq.empty()) {
            T v = pq.top().first;
            int from = pq.top().second;
            pq.pop();
            for (auto u : edge[from]) {
                T w = v + u.first;
                int to = u.second;
                if (w < cost[to]) {
                    cost[to] = w;
                    pq.push({ w,to });
                }
            }
        }
        return;
    }
};

/*
使い方
1. まずインスタンス生成
重みの型、頂点の数、距離の無限大のINFLL
Dijkstra<ll> d(N, INFLL);

2. 辺を貼る
iからjに重みwの辺を貼る場合
d.make_edge(i,j,w);

3. 頂点sから解く
d.solve(s);

4. sからgの距離
d.cost[g]

GigaCode2019 E - 車の乗り継ぎ
https://atcoder.jp/contests/gigacode-2019/submissions/8651446

*/
/*------------------------------------*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N,M;
    cin>>N>>M;
    Dijkstra<ll> G(N,INFLL);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G.make_edge(a,b,1);
    }
    G.solve(0);
    cout<<((G.cost[N-1] <= 2) ? "POSSIBLE" : "IMPOSSIBLE")<<endl;
}

Measured memory_bytes: 14320
def solv():
    n = int(input())
    a = list(map(int,input().split()))
    _ = int(input())
    m = list(map(int,input().split()))
    h = {}
    for v in m:
        h[v] = 0
    c = 0
    while c < (1 << n):
        check = 0
        for i in range(n):
            if c & (1 << i):
                check += a[i]
        if check in h:
            h[check] = 1
        c += 1
    for v in m:
        if h[v]:print("yes")
        else:print("no")

if __name__ == "__main__":
    solv()


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

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> V(N);
	for (auto &x : V) {
		cin >> x;
	}

	int ans = 0;
	int C = min(N, K);

	for (int A = 0; A <= C; ++A) {
		for (int B = 0; A + B <= C; ++B) {
			int sum = 0;
			vector<int> a;
			for (int i = 0; i < A; ++i) {
				sum += V[i];
				if (V[i] < 0) {
					a.push_back(V[i]);
				}
			}
			for (int i = 0; i < B; ++i) {
				int j = N - 1 - i;
				sum += V[j];
				if (V[j] < 0) {
					a.push_back(V[j]);
				}
			}
			sort(a.begin(), a.end());
			for (int i = 0; i < a.size() && i < K - (A + B); ++i) {
				sum -= a[i];
			}
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin, s;
    if (s.back() == 's') {
        s += "es";
    } else {
        s += "s";
    }
    print(s);
    return 0;
}


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

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >>n ;

  ll a[10001]={};
  for(int i=1;i<100;i++){
    for(int j=1;j<100;j++){
      for(int k=1;k<100;k++){
        if(i*i+j*j+k*k+i*j+j*k+k*i<=10000)a[i*i+j*j+k*k+i*j+j*k+k*i]++;
      }
    }
  }
  for(int i=1;i<=n;i++){
    cout << a[i] << endl;
  }

}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<double> v(n);
  rep(i, 0, n) cin >> v[i];
  sort(v.begin(), v.end());
  rep(i, 0, n-1) {
    v[i+1] = (v[i]+v[i+1])/2.0;
  }
  cout << v[n-1];
}
  

Measured memory_bytes: 256
a,b,c = map(int, input().split())
count = 0
while True:
    if a == b == c and a % 2 == 0:
        count = -1
        break
    elif a%2 == 0 and b%2 == 0 and c%2 == 0:
        a,b,c = (b+c)//2, (c+a)//2, (a+b)//2
        count += 1
    else:
        break


print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

constexpr auto INF = INT_MAX/2;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	vi L(3);
	cin >> n >> L[0] >> L[1] >> L[2];
	vi l(n);
	rep(i, n)cin >> l[i];
	sort(all(l));
	rep(i, 3)l.push_back(INF);

	int ans = INF;

	do {
		vvi leng(3, vi(0));
		int k = 0;

		rep(i, 3) {
			while (k<n+3) {
				if (l[k] != INF)leng[i].push_back(l[k]);
				k++;
				if (l[k - 1] == INF)break;
			}
		}

		if (leng[0].size() * leng[1].size() * leng[2].size() == 0)continue;

		vi sum(3,0);
		rep(i, 3)rep(j, leng[i].size()) sum[i]+= leng[i][j];

		int mp = 0;
		rep(i, 3)mp += 10 * leng[i].size() - 10 + abs(sum[i] - L[i]);
		
		ans = min(ans, mp);

	} while (next_permutation(all(l)));

	cout << ans << endl;
}

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

int main(){
  int a,b[10000],c,d[500],e[500]={},f=0;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b[i];
}
  cin>>c;
  for(int i=0;i<c;i++){
    cin>>d[i];
  }
  for(int i=0;i<a;i++){
    for(int j=0;j<c;j++){
      if(b[i]==d[j]){
	e[j]=1;
      }
    }
  }
  for(int i=0;i<c;i++){
    f+=e[i];
  }
  cout <<f<<endl;
}

Measured memory_bytes: 3136
/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int XMAX=1e5;
ll a,b,c,x,y;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> a >> b >> c >> x >> y;
	
	
	if(x>y){
		swap(x,y);
		swap(a,b);
	}
	
	ll minimum=min(x*a+y*b,c*2*y);
	minimum=min(minimum,c*2*x+b*(y-x));
	
	cout << minimum << '\n';
	
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[100010],ab[100010],ac[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc[1000][1000],cd[1000][1000];
vector<ll> va,vb,vc;

int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>aa[i];
    cin>>m;
    for(int i=0;i<m;i++)cin>>ab[i]>>ac[i];
    
    for(int i=0;i<m;i++){
        y=0;
        for(int j=0;j<n;j++){
            if(ab[i]==j+1)y+=ac[i];
            else y+=aa[j];
        }
        C y E;
    }
    
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> Pi;
typedef unsigned long long ULL;
int gcd(int a,int b){if (b == 0) return a; return gcd(b , a%b);}
int lcm(int a, int b){ return a/gcd(a,b)*b;}
inline int read(){
    int f = 1, x = 0;char ch = getchar();
    while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
    while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
    return x * f;
}
const int maxn = 1e5 + 10;
int a[maxn],b[maxn];
int main(){
    //freopen("/Users/chutong/data.txt", "r", stdin);
    int n = read(),m = read(),c = read();
    for(int i=1; i<=m; i++)
        b[i] = read();
    int ans = 0;
    for (int i=1; i<=n; i++) {
        int sum = c;
        for (int j=1; j<=m; j++) {
            a[j] = read();
            sum += a[j]*b[j];
        }
        if (sum > 0) ans++;
    }
    printf("%d\n",ans);
    return 0;
}


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


int main(){

string s;
cin>>s;
string day[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};

rep(i,7){
    bool match=true;
    rep(k,3){
        
        if(s[k]!=day[i][k]){
            match=false;
            break;
        }
    }
    if(match){
        cout<<7-i;
        break;
    }
}


 return 0;
}
/*
SAT

1

SUN

7

*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()

using namespace std;

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

const ll mx = 105;
const ll maxn = 1000001;
const ll mod = 1000000007;

vector<vector<int>> adj;
vector<ll> lis;
bool vis[maxn];
bool pos;

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

  ll t = 1;

  //cin>>t;

  while(t--){
    
     ll n, i, j, k, m, s = 0;

     cin>>n>>m;

     ll a[m];
     
     for(i =0 ;i < m;i++){
         cin>>a[i];
         s += a[i];
     }
     if(s > n){
         cout<<"-1\n";
     }
     else{
         cout<<n-s<<"\n";
     }
  }     
        
}


Measured memory_bytes: 3736
from heapq import heappush, heappop

N, D, A, *XH = map(int, open(0).read().split())

XH = sorted(zip(*[iter(XH)] * 2))

ans = 0
Q = []
damage = 0
for x, h in XH:

    while Q:
        v, d = Q[0]
        if v >= x:
            break
        v, d = heappop(Q)
        damage -= d

    h -= damage
    if h <= 0:
        continue

    n = -(-h // A)

    damage += A * n
    ans += n

    heappush(Q, (x + 2 * D, A * n))

print(ans)


Measured memory_bytes: 49684
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define loopj(n) for(int j=0;j<n;j++)
#define loopi(a,b,k) for(int i=a;i<b;i=i+k)
#define  deb(x) cout<<#x<<"  "<<x<<endl
#define sync std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int main()
{
	int x;
	cin>>x;
	if(x)
	cout<<"0";
	else
	cout<<"1";
}

Measured memory_bytes: 3628
#include <stdio.h>

int main (void){
  
  int N,K;
  scanf("%d %d",&N,&K);
  int n = 0,a = 1,ans;
  
  while(1){
    if(a <= N){
      a *= K;
      n++;
    }
    if(a >  N){
      ans = n;
      break;
    }
  }
  
  printf("%d\n",ans);
  return 0;
}
    


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,cnt[15],x[15][15],y[15][15],ans;
void check(int w)
{
	int num=0;
	for(int i=0;i<n;++i)
		if(w>>i&1)
		{
			++num;
			for(int j=0;j<cnt[i];++j)
				if((w>>x[i][j]&1)!=y[i][j])return;
		}
	ans=max(ans,num);
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	{
		scanf("%d",&cnt[i]);
		for(int j=0;j<cnt[i];++j)scanf("%d %d",&x[i][j],&y[i][j]),--x[i][j];
	}
	for(int i=1;i<1<<n;++i)check(i);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
 
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <random>
#include <cassert>
 
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define RANDOM srand(94385)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)]);
 
template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
 
signed main() {
    FAST; FIXED; RANDOM;
    int m, d;
    cin >> m >> d;
    int ans = 0;
    for (int i = 1; i <= m; ++i)
        for (int j = 10; j <= d; ++j)
            if (j % 10 >= 2 && j / 10 >= 2 && i == (j % 10) * (j / 10)) 
                ++ans;
    cout << ans;
    return 0;
}

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

int main(){
  int64_t N,K,first=0,roop=0,next=0;
  cin >> N >> K;
  vector<int64_t> A(N),B(N+1);
  for(int64_t i=0;i<N;i++){
    cin >> A.at(i);
    A.at(i)--;
  }
  B.at(0)=0;
  for(int64_t i=0;i<N;i++){
    B.at(i+1)=A.at(B.at(i));
  }
  int64_t i=0;
  while(true){
    if(B.at(i)==B.at(N)){
      first=i;
      break;
    }
    i++;
  }
  i=0;
  while(true){
    if(B.at(first-i)!=B.at(N-i)){
      first-=i-1;
      break;
    }
    if(i==first){
      first=0;
      break;
    }
    i++;
  }
  next=B.at(first);
  while(true){
    roop++;
    next=A.at(next);
    if(next==B.at(first)){
      break;
    }
  }
  if(K>first){
    K-=first;
    K%=roop;
  }else{
    next=0;
  }
  while(true){
    if(K==0){
      cout << next+1 << endl;
      return 0;
    }
    K--;
    next=A.at(next);
  }
}
    

Measured memory_bytes: 6388
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
  char c[4];
  int i,n=0;
  int a[3]={0};
  scanf("%s",c);
  for(i=0;i<3;i++){
    if(c[i]=='R')
      a[i]=1;
  }
  if(a[1]==1){
    if(a[0]==1){
     if(a[2]==1){
      n=3; 
     }else{
      n=2;
     }
    }else{
     if(a[2]==1){
      n=2; 
     }else{
      n=1;
     }
    }
  }else{
   if(a[0]==1)
     n=1;
   if(a[2]==1)
     n=1;
  }
  printf("%d",n);
  return 0;
}

Measured memory_bytes: 1720
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int F[N][10] = {};
    for(int i = 0;i < N;i++){
        for(int j = 0;j < 10;j++){
            cin >> F[i][j];
        }
    }
    int P[N][11] = {};
    for(int i = 0;i < N;i++){
        for(int j = 0;j <= 10;j++){
            cin >> P[i][j];
        }
    }
    
    int maxi = -INF;
    for(int i = 1;i < (1 << 10);i++){
        int sum = 0;
        for(int j = 0;j < N;j++){
            int cnt = 0;
            for(int k = 0;k < 10;k++){
                cnt += (i & (1 << k)) && F[j][k];
            }
            sum += P[j][cnt];
        }
        maxi = max(maxi, sum);
    }
    cout << maxi << endl;
}

Measured memory_bytes: 256
mondaisu,kaitosu=map(int, input().split())
kuroji=[0]*mondaisu
akaji=[0]*mondaisu
for i in range(kaitosu):
    a,kekka = input().strip().split()
    a=int(a)
    if kuroji[a-1]==1:
        pass
    elif kuroji[a-1]==0:
        if kekka=="WA":
            akaji[a-1]+=1
        else:
            kuroji[a-1]=1
for i in range(mondaisu):
    if kuroji[i]==0:
        akaji[i]=0
kurojisum=sum(kuroji)
akajisum=sum(akaji)
print(kurojisum,akajisum)

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vec A(n),num(200001,0);
    rep(i,n) cin>>A[i],num[A[i]]++;
    ll ans=0;
    rep1(i,200000) ans+=num[i]*(num[i]-1)/2;
    rep(i,n){
        cout<<ans-(num[A[i]]-1)<<"\n";
    }
}

Measured memory_bytes: 6344