akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
long long l[10000],r[10000],x1,x2,y1,y2,m,n,t,p,d[10000],c[10000],a[300][300],b[300][300],x,y;
int main()
{
while (1)
{
    scanf("%lld%lld%lld%lld",&n,&m,&t,&p);
    if (n==0&&m==0&&t==0&&p==0) break;
    x1=32; y1=32; x2=31+m; y2=31+n;
    memset(a,0,sizeof(a));
    for (int i=32;i<=m+31;i++)
        for (int j=32;j<=n+31;j++)
        a[i][j]=1;
    for (int k=1;k<=t;k++)
    {
        scanf("%lld%lld",&d[k],&c[k]);
        if (d[k]==2)
        {
          for (int i=x2-c[k]+1;i<=x2;i++)
          for (int j=32;j<=y2;j++)
          {
              a[2*(x2-c[k])+1-i][j]+=a[i][j];
              a[i][j]=0;
          }
          x1=min(x1,x2-2*c[k]+1);
          x2=x2-c[k];
          x=31;
          for (int i=x1;i<=x2;i++)
          {
              x++;
              y=31;
              for (int j=y1;j<=y2;j++)
              b[x][++y]=a[i][j];
          }
          memset(a,0,sizeof(a));
          for (int i=32;i<=x;i++)
          for (int j=32;j<=y;j++)
            a[i][j]=b[i][j];
          x1=32; y1=32;
          x2=x; y2=y;
        } else
        if (d[k]==1)
        {
          c[k]+=31;
          for (int i=32;i<=x2;i++)
          for (int j=32;j<=c[k];j++)
          {
              a[i][2*c[k]+1-j]+=a[i][j];
              a[i][j]=0;
          }
          y2=max(y2,2*c[k]-31);
          y1=c[k]+1;
          x=31;
          for (int i=x1;i<=x2;i++)
          {
              x++;
              y=31;
              for (int j=y1;j<=y2;j++)
              b[x][++y]=a[i][j];
          }
          memset(a,0,sizeof(a));
          for (int i=32;i<=x;i++)
          for (int j=32;j<=y;j++)
            a[i][j]=b[i][j];
          x1=32; y1=32;
          x2=x; y2=y;
        }
    }
   for (int k=1;k<=p;k++)
   {
       scanf("%lld%lld",&l[k],&r[k]);
       l[k]+=32;
       printf("%lld\n",a[x2-r[k]][l[k]]);
   }
}
    return(0);
}



Measured memory_bytes: 3984
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()



int main() {
	float a,b;
	cin >> a >> b;
	cout << fixed << a / b << endl;
}

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

using namespace std;

int main(){
  double a, b, x, tan, rad, ans;
  cin >> a >> b >> x;
  if(x <= a * a * b / 2){
    tan = a * b * b / (2 * x);
  }
  else{
    tan = 2 * (a * a * b - x) / (a * a * a);
  }
  rad = atan(tan);
  ans = 180 * rad / 3.14159265358979;
  cout << fixed << setprecision(10);
  cout << ans << endl;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= int(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(c) begin(c), end(c)
#define MSG(a) cout << a << endl;

template <typename T>
using vec = std::vector<T>;
using vi = vec<int>;
using vvi = vec<vi>;
using pii = std::pair<int, int>;
using ll = long long;
using ld = long double;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  pii a, b, c, d;
  cin >> a.first >> a.second >> b.first >> b.second;
  int x = b.first - a.first;
  int y = b.second - a.second;
  c = make_pair(b.first - y, b.second + x);
  d = make_pair(a.first - y, a.second + x);

  cout << c.first << " " << c.second << " " << d.first << " " << d.second
       << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;

int main()
{
    /*
    freopen(filename".in","r",stdin);
    freopen(filename".out","w",stdout);
    */
    /*
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    */
    int n,a,b;
    cin>>n>>a>>b;
    if ((b-a)%2)
    {
        cout<<"Borys\n";
    }
    else
    {
        cout<<"Alice\n";
    }
    re 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int prex, prey, pret;
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int t, x, y;
		scanf("%d%d%d", &t, &x, &y);
		int dis = abs(x-prex) + abs(y-prey);
		if (dis <= t-pret && (dis-(t-pret)) % 2 == 0)
		{
			pret = t;
			prex = x;
			prey = y;
		}
		else
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
}

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

int main() {
  int p,q,r;
  cin >> p >> q >> r;
  int sum = p+q+r;
  int p1 = sum - p;
  int p2 = sum - q;
  int p3 = sum - r;
  cout << min(p1,min(p2,p3));
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
#define MAX 100000
using namespace std;
typedef long long ll;
int dp[50];
int main()
{	
	int n;
	cin>>n;
	dp[0]=dp[1]=1;
	for(int i=2;i<=n;i++) dp[i]=dp[i-1]+dp[i-2];
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
 
using namespace std;
 
#define MAX 100000
 
struct TRAMP{
    char mark;
    int number,inputed_order;
};
 
TRAMP cards[MAX];
 
int n;
 
int Partition(int left,int right){
    int i = left-1,pivot = cards[right].number;
    for(int start = left; start < right; start++){
        if(cards[start].number <= pivot){
                i++;
                std::swap(cards[i],cards[start]);
        }
    }
 
    std::swap(cards[i+1],cards[right]);
 
    return i+1;
}
 
void quickSort(int left,int right){
    if(left < right){
        int q = Partition(left,right);
        quickSort(left,q-1);
        quickSort(q+1,right);
    }
}
 
 
int main(){
 
    bool stableFLG = true;
    scanf("%d",&n);
 
    for(int i = 0; i < n; i++){
        scanf("%s %d",&cards[i].mark,&cards[i].number);
        cards[i].inputed_order = i;
    }
 
    quickSort(0,n-1);
 


    for(int i = 1; i < n; i++){
        if(cards[i].number == cards[i-1].number && cards[i].inputed_order < cards[i-1].inputed_order){
            stableFLG = false;
            break;
        }
    }
 
    if(stableFLG){
        printf("Stable\n");
    }else{
        printf("Not stable\n");
    }
 
    for(int i = 0; i < n; i++)   printf("%c %d\n",cards[i].mark,cards[i].number);
}


Measured memory_bytes: 4324
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
  int n,m,c,a[22],b[22],ans=0,i,j;
  scanf("%d%d%d",&n,&m,&c);
  for(i=0;i<m;i++) scanf("%d",&b[i]);
  for(i=0;i<n;i++){
    int t=c;
    for(j=0;j<m;j++){
      scanf("%d",&a[j]);
      t+=a[j]*b[j];
    }
    if(t>0) ans++;
  }
  printf("%d",ans);
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

int x,y,z,n;

ll sq(ll a){return a*a;}

void solve()
{
	ll a[3] = {x,y,z};
	sort(a,a+3);
	ll r2 = sq(a[0]) + sq(a[1]);
	cin>>n;
	for (int i = 0; i < n; i++){
		ll b; cin>>b;
		puts((r2 >= 4*b*b) ? "NA" : "OK");
	}
}

int main(){
	while(cin>>x>>y>>z,(x||y||z)){
		solve();
	}

    return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



def main():
    A = input()
    B = input()

    A = A.zfill(len(B))
    B = B.zfill(len(A))

    if A > B:
        print("GREATER")
    elif A < B:
        print("LESS")
    else:
        print("EQUAL")

if __name__ == "__main__": main()


Measured memory_bytes: 4084
n=int(input())
S=input()

def caesar(s, n):
	ns = []
	for ch in s:
		if ('A' <= ch and ch <= 'Z'):
			ns.append(chr((ord(ch) - ord('A') - n) % 26 + ord('A')))
		elif ('a' <= ch and ch <= 'z'):
			ns.append(chr((ord(ch) - ord('a') - n) % 26 + ord('a')))
		elif ('0' <= ch and ch <= '9'):
			ns.append(chr((ord(ch) - ord('0') - n) % 10 + ord('0')))
		else:
			ns.append(ch)
	return "".join(ns)

result = caesar(S, -n)
print(result)

Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
char a[100001];
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",a);
	int len=strlen(a);
	int ans=0; 
	for(int i=1;i<len;i++)
	{
		if(a[i]!=a[i-1])
		ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	char A[3][31];
	char B[11];
	char C[11];
	int c=0;
	scanf("%s",&A[0]);
	scanf("%s",&A[1]);
	scanf("%s",&A[2]);
	for(int j=0;j<2;j++){
	for(int i=0;i<36;i++){
		if(A[j][i]==0){
			if(A[j][i-1]==A[j+1][0]){
				c++;
				break;
			}
			printf("NO\n");
			return 0;
		}
	}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  multimap<int, int> ab;
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    ab.emplace(a, b);
  }
  auto p = ab.equal_range(1);
  for (auto it = p.first; it != p.second; ++it) {
    auto p2 = ab.equal_range(it->second);
    for (auto it2 = p2.first; it2 != p2.second; ++it2) {
      if (it2->second == N) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 9600
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x = max(x)
y = min(y)

flag = True
for z in range(-100, 100+1):
    if x < z <= y and X < z <= Y:
        flag = False
        
if flag:
    print('War')
else:
    print('No War')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef jayinnn
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 100005;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();
    string s;
    cin >> s;
    ll tmp = 0;
    for(auto i:s){
        tmp += i - '0';
    }
    cout << (tmp % 9 == 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<=(end);i++)
#define REP(i, n) FOR(i,1,n)
#define IFOR(i, begin, end) for(int i=(end);i>=(begin);i--)
#define IREP(i, n) IFOR(i,1,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
using namespace std;

string substrEnd(string str, size_t len) {
    const size_t strLen = str.length();
 
    return str.substr(strLen - len, len);
}

int main()
{
	string S;
	cin>>S;
	while(S.length()>0){
		if(S.length()>6){
			if(substrEnd(S,7)=="dreamer") {
				S=S.substr(0,S.length()-7);
				continue;
			}

		}
		if(S.length()>5){
			if(substrEnd(S,6)=="eraser") {
				S=S.substr(0,S.length()-6);
				continue;
			}
		}

		if(S.length()>4){

			if(substrEnd(S,5)=="dream") {
				S=S.substr(0,S.length()-5);
				continue;
			}
			if(substrEnd(S,5)=="erase") {
				S=S.substr(0,S.length()-5);
				continue;
			}
		}
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("O3")

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int n;
	cin >> n;
	cout << n * n * n;
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
N = int(input())
M = [[0]*20 for _ in range(20)]
M2 = [[0]*20 for _ in range(20)]

for _ in range(N):
    A = input()
    x = 0
    decLen = 0

    if '.' in A:
        p = A.index('.')
        decLen = len(A) - p - 1
        x = int(A[:p])*10**decLen + int(A[p+1:])
    else:
        x = int(A)

    f2, f5 = -decLen, -decLen
    while(x%2 == 0):
        x /= 2
        f2 += 1

    while(x%5 == 0):
        x /= 5
        f5 += 1

    f2 = min(f2, 9)
    f5 = min(f5, 9)

    M[f2+9][f5+9] += 1



for i in range(18, -1, -1):
    for j in range(18, -1, -1):
        M2[i][j] = M[i][j] + M2[i+1][j] + M2[i][j+1] - M2[i+1][j+1]


ans = 0
for i in range(19):
    for j in range(19):
#        if M[i][j] > 0:
#            print(i, j, M[i][j], M2[18-i][18-j])

        ans += M[i][j]*M2[18-i][18-j]
        if i >= 9 and j >= 9:
            ans -= M[i][j]

print(ans//2)



    
        


Measured memory_bytes: 9248
n=gets.chomp.to_i
ary=Array.new
ary=gets.chomp.split(" ").map{|num| num.to_i}
k=0
i=n-1
while i>=0
	for j in i+1..n-1
		if ary[j] < ary[j-1]
			x=ary[j-1]
			ary[j-1]=ary[j]
			ary[j]=x
			k+=1
		end
	end
	i-=1
end
puts ary.join(" ")
puts k

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

int main()
{
  char b,ans;
  cin >> b;
  if (b == 'A'){
  	ans = 'T';
  }else if (b == 'T'){
  	ans = 'A';
  }else if (b == 'C'){
  	ans = 'G';
  }else{
  	ans = 'C';
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int n;
string s;

int main(){
	cin>>n;
	bool ans=1;
	int A=0;
	for(int i=0;i<n;i++){
		cin>>s;
		if(s=="A") A++;
		else if(A) A--;
		else ans=0;
		if(A<0) ans=0;
	}
	if(A) ans=0;
	if(ans) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}



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

int main() {
  int n, n5, n7;
  n5 = n7 = 0;
  for (int i = 0; i < 3; i++) {
    cin >> n;
    if (n == 5)
      n5++;
    else if (n == 7)
      n7++;
  }
  if (n5 == 2 && n7 == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 3552
S = input()
MOD = 2019
cnt = [0]*MOD
cur = 0 # 現在考えている部分文字列
cnt[cur] = 1 # 部分文字列'0'も作れると考える
d = 1 # 位を表す
for s in S[::-1]:
    cur += int(s)*d # 新たな桁を追加
    cur %= MOD
    cnt[cur] += 1
    # 後処理
    d *= 10 # 位を上げる
    d %= MOD # ただし数が巨大になるため、計算量を減らすために剰余をとる
ans = 0
for c in cnt:
    ans += c*(c-1)//2
print (ans)



Measured memory_bytes: 9376
def calc(c, q, h, w)
  n = 0
  while q.size > 0
    e = q.shift
    n += 1 if e[0] > n
    (-1..1).each do |di|
      (-1..1).each do |dj|
        i = e[1][0] + di
        j = e[1][1] + dj
        if i >= 0 && i < h && j >= 0 && j < w
          q.push([e[0] + 1, [i, j]]) if (c[i][j] -= 1) == 0
        end
      end
    end
  end
  n
end
1.times do
  c, q = [], []
  h, w = gets.split.map(&:to_i)
  h.times do |i|
    c[i] = gets.chomp.split(//).map(&:to_i)
    c[i].each.with_index do |e, j|
      q.push([0, [i, j]]) if c[i][j] == 0
    end
  end
  puts calc(c, q, h, w)
end

Measured memory_bytes: 20252
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	char b; cin >> b;
	if (b == 'A') cout << 'T' << endl;
	else if (b == 'T') cout << 'A' << endl;
	else if (b == 'C') cout << 'G' << endl;
	else cout << 'C' << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Vector.Mutable (IOVector, STVector)
import qualified Data.Vector.Mutable as VM

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    bp <- replicateM n f
    m <- readLn
    sg <- replicateM m f
    mapM_ putStrLn $ solve n bp sg
    main
  where
    f = map read <$> words <$> getLine
solve :: Int -> [[Int]] -> [[Int]] -> [String]
solve n bp sg = runST $ do
  bv <- VM.replicate n 0 :: ST s (STVector s Int)
  pv <- VM.replicate n (0, 0) :: ST s (STVector s (Int, Int))
  forM_ (zip [0..] bp) $ \(i, [b, x, y]) -> do
    VM.write bv i b
    VM.write pv i (x, y)
  dp <- VM.replicate (n ^ 2) (inf, []) :: ST s (STVector s (Double, [Int]))
  forM_ [0 .. n-1] $ \i -> do
    forM_ [0 .. n-1] $ \j -> do
      p1 <- VM.read pv i
      p2 <- VM.read pv j
      when (under50 p1 p2) $ write dp (i, j) (dist p1 p2, [])
  forM_ [0 .. n-1] $ \k -> do
    forM_ [0 .. n-1] $ \i -> do
      forM_ [0 .. n-1] $ \j -> do
        (d0, _) <- read dp (i, j)
        (d1, l1) <- read dp (i, k)
        (d2, l2) <- read dp (k, j)
        when (d0 > d1 + d2) $ do
          write dp (i, j) (d1 + d2, l1 ++ (k:l2))
  forM sg $ \[s, g] -> do
    si <- findIx bv n s
    gi <- findIx bv n g
    (d, l) <- read dp (si, gi)
    if d == inf
      then return "NA"
      else do
        sl <- forM ([si] ++ l ++ [gi]) $ \i -> do
          j <- VM.read bv i
          return (show j)
        return $ unwords sl
  where
    read v (x, y) = VM.read v (x * n + y)
    write v (x, y) z = VM.write v (x * n + y) z

inf :: Double
inf = 100000.0

eps :: Double
eps = 1e-9

dist :: (Int, Int) -> (Int, Int) -> Double
dist (x1, y1) (x2, y2) = sqrt $ fromIntegral $ (x1 - x2) ^ 2 + (y1 - y2) ^ 2

under50 :: (Int, Int) -> (Int, Int) -> Bool
under50 p1 p2 = let d = dist p1 p2
                in abs (d - 50) < eps || d < 50

findIx :: STVector s Int -> Int -> Int -> ST s Int
findIx v n x = foldM (\r i -> do
                         a <- VM.read v i
                         if a == x
                           then return i
                           else return r
                     ) 0 [0 .. n-1]



Measured memory_bytes: 5728
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 100100
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
ll n,m,x;
ll level[20][20];
ll cost[20];
void solve(vector<ll> v,ll ind,ll &sz)
{
//    cout<<"start\n";
    if(ind==n+1)
    {
//        cout<<"==========\n";
//        for(auto it:v)
//            cout<<it<<" ";cout<<endl;
//        cout<<"==========\n";
        ll inlevel[20]={0};
        for(ll i=0;i<v.size();i++)
        {
            for(ll j=1;j<=m;j++)
                inlevel[j]+=level[v[i]][j];
        }
        bool flag=true;
        for(ll i=1;i<=m;i++)
            if(inlevel[i]<x)
            {
                flag=false;
                break;
            }
        if(flag)
        {
            ll sum=0;
            for(ll i=0;i<v.size();i++)
                sum+=cost[v[i]];
            sz=min(sz,sum);
        }
        return;
    }
    v.push_back(ind);
    solve(v,ind+1,sz);
    v.pop_back();
    solve(v,ind+1,sz);
}
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin>>n>>m>>x;
    ll sz=INF;
    for(ll i=1;i<=n;i++)
    {
        cin>>cost[i];
        for(ll j=1;j<=m;j++)
            cin>>level[i][j];
    }
    vector<ll> v;
    solve(v,1,sz);
    cout<<(sz==INF?-1:sz)<<endl;
    return 0;
}


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

int main() {
  long long int n,a,b;
  cin>>n>>a>>b;  
  if(a==b){
    cout<<1;
    return 0;
  }
  if(n==1 || a>b){
    cout<<0;
    return 0;
  }
  if(a==b){
    cout<<1;
    return 0;
  }
  long long int min,max,ans;
  min=a*(n-1)+b;
  max=a+(n-1)*b;
  ans=max-min+1;
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
// E - Sequence Sum
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	ll n; int x, m; cin>>n>>x>>m;
	vector<pair<int,int>> P; // (x,pre_sum)
	ll sum_p = 0; // sum of pre + cycle
	vector<int> X(m, -1); // for cycle check & pre_len
	for(ll i=0; i<n; ++i){
		if(X[x] > -1){
			int cyc_len = P.size() - X[x];
			int nxt_len = (n - X[x]) % cyc_len;
			ll remain = P[X[x]].second;
			ll cyc = (sum_p - remain) * ((n - X[x]) / cyc_len);
			remain +=P[X[x]+nxt_len].second - P[X[x]].second;
			cout<< cyc + remain <<endl;
			return 0;
		}
		P.emplace_back(x, sum_p);
		sum_p += x;
		X[x] = i;
		x = (ll)x*x % m;
	}
	cout<< sum_p <<endl;
}


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

int main() {
    int n;
    cin >> n;
    int a[n], Max = 0, maxi = -1;
    for (int i = 0; i < n; i++)  {
        cin >> a[i];
        if (Max < a[i]) {
            Max = a[i];
            maxi = i;
        }
    }
    int mid1 = Max/2, mid2 = Max/2, r, deff = (1 << 30);
    if (Max % 2 != 0) mid2++;
    for (int i = 0; i < n; i++) {
        if (i == maxi) continue;
        int nowDeff = min(abs(mid1 - a[i]), abs(mid2 - a[i]));
        if (nowDeff < deff) {
            deff = nowDeff;
            r = a[i];
        }
    }
    cout << Max << " " << r << endl;
    return 0;
}

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

using namespace std;

struct edge {
    int to;
    int cost;
    edge(int a, int b) : to(a), cost(b) {}
};

vector<vector<edge>> e;
int N;

pair<int, int> dfs(int p, int par = -1)
{
    if (e[p].size() == 1 && par >= 0) return make_pair(0, p);
    pair<int, int> res = make_pair(-1, -1);
    for (auto x : e[p]) {
        if (x.to == par) continue;
        auto t = dfs(x.to, p);
        t.first += x.cost;
        res = max(res, t);
    }
    return res;
}

int main()
{
    cin >> N;
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    e.resize(N);
    for (int i = 0; i < N-1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        e[s].emplace_back(t, w);
        e[t].emplace_back(s, w);
    }
    auto res = dfs(0);
    res = dfs(res.second);
    cout << res.first << endl;
}


Measured memory_bytes: 15916
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s[105];
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>s[i];
	sort(s,s+n);
	for(int i=0;i<n;i++)printf("%s",s[i].c_str());
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

mod = 10**9+7

def power(a, n, mod):
    bi=str(format(n,"b")) #2進数
    res=1
    for i in range(len(bi)):
        res=(res*res) %mod
        if bi[i]=="1":
            res=(res*a) %mod
    return res


from collections import Counter
if n%2 == 0:
    C = Counter(A)
    for i in range(1, n+1):
        if i%2 == 0:
            continue
        else:
            if C[i] != 2:
                print(0)
                exit()
    else:
        print(power(2, n//2, mod))
else:
    C = Counter(A)
    for i in range(1, n+1):
        if i == 0:
            if C[i] != 1:
                print(0)
                exit()
        elif i%2 == 1:
            continue
        else:
            if C[i] != 2:
                print(0)
                exit()
    else:
        print(power(2, n//2, mod))


Measured memory_bytes: 93024
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2")
#pragma GCC optimize ("trapv")
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,a,b) for(lli i = (lli)(a); i < (lli)(b);i++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()
#define wis cout<<endl<<"I already speak english, bitch"<<endl;
 
typedef long long int lli;
typedef vector<lli> vi;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef pair<ii,lli> iii;
typedef long double C;
 
#define trace(args...) { string  _s =#args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
 
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
    cerr <<  *it  << " : " << a << endl;
    err(++it, args...);
}


int main(){
	fastio;
	string s;cin>>s;
	rep(i,0,sz(s)){
		if(s[i]==',') cout<<" ";
		else cout<<s[i];
	}


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
int cnt[2][105];
int h, w;
bool flag[110][110];

int main() {
	int n;
	double m;
	cin >> n >> m;
	vector<double>a(n);
	double total = 0;
	rep(i, n) {
		cin >> a[i];
		total += a[i];
	}
	sort(a.rbegin(), a.rend());
	total /= 4 * m;
	int res = 0;
	for (double i = 0;i < m;++i) {
		if (a[i] >= total)res++;
	}
	if (res >= m)puts("Yes");
	else puts("No");
	return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

ll rec_sol(ll a, ll b){
	return a ? a * (b / a + b / a) + rec_sol(b % a, a) : -b;
}

void solve(){
	ll n, x;
	cin >> n >> x;
	cout << n + rec_sol(min(n - x, x), max(n - x, x)) << endl;
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n, c;
    cin >> n >> c;
    vector<ll> x(n+2);
    vector<ll> v(n+2);
    x[0] = v[0] = v[n+1] = 0;
    x[n+1] = c;
    for(int i = 1; i <= n; i++)
    {
        cin >> x[i] >> v[i];
    }
    vector<ll> lback(n+1);
    vector<ll> rback(n+1);
    vector<ll> lst(n+1);
    vector<ll> rst(n+1);
    vector<ll> lvsum(n+1);
    vector<ll> rvsum(n+1);

    lback[0] = rback[0] = lst[0] = rst[0] = lvsum[0] = rvsum[0] = 0;
    for(int i = 1; i <= n; i++)
    {
        lvsum[i] = lvsum[i-1] + v[i];
        lback[i] = max(lback[i-1], lvsum[i] - 2 * x[i]);
        lst[i] = max(lst[i-1], lvsum[i] - x[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        rvsum[i] = rvsum[i-1] + v[n+1-i];
        rback[i] = max(rback[i-1], rvsum[i] - 2 * (c-x[n+1-i]));
        rst[i] = max(rst[i-1], rvsum[i] - (c-x[n+1-i]));
    }

    ll ans = 0;
    for(int i = 0; i <= n; i++)
    {
        ans = max(ans, lback[i] + rst[n-i]);
        ans = max(ans, rback[i] + lst[n-i]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int a, b; cin >> a >> b;
    int c = a + b, d = a - b, e = a * b;
    cout << max(max(c, d), e) << endl;
}

Measured memory_bytes: 3592
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;

int nextwhite(vi & vec, int now) {
	int next = now;
	for (; next < vec.size(); next++) {
		if (vec[next] == 0) {
			break;
		}
	}

	return next;;
}

int nextred(vi& vec, int now) {
	int next = now;
	for (; next > -1; next--) {
		if (vec[next] == 1) {
			break;
		}
	}
	return next;
}

int main() {
	int N; cin >> N;
	vector<int> vec(N); //{White 0 * Red  1}
	int white = 0, red = 0;
	for (int i = 0; i < N; i++) {
		char c; cin >> c;
		if (c == 'R') {
			vec[i] = 1;
			red++;
		}
		else if (c == 'W') {
			vec[i] = 0;
			white++;
		}
	}
	int j = N - 1;
	int cnt = min(red, white);
	int subwhi = 0, subre = 0;
	int swpcnt = 0;
	for (int i = 0; i < N; i++) {
		if (vec[i] == 0) {
			for (j; j > i; j--) {
				if (vec[j] == 1) {
					swap(vec[i], vec[j]);
					swpcnt++;
					break;
				}
			}
		}
		if (j > i) {
			subre = red - i - 1;
			subwhi = white - (N - 1 - j);
			cnt = min({ cnt,subre + swpcnt,subwhi + swpcnt });
		}
		else {
			break;
		}
		//comapre
	}

	cout << cnt << endl;
}

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


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


int main() {

	int n;
	cin >> n;

	vector<pair<pair<string, int>, int> > data;
	for(int i=0; i < n; i++){
		string s;
		int p;
		cin >> s >> p;
		data.push_back(make_pair(make_pair(s, -p), i+1));
	} 
	sort(data.begin(), data.end());

	for(int i=0; i<data.size(); i++){
		cout << data.at(i).second << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<class Z> Z rng(Z a, Z b) {
  static mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
  return uniform_int_distribution<Z>(a, b - 1)(mt);
}

struct RollingHash {
  static constexpr uint64_t P0 = 4111144441, P1 = 4111444111;
  static uint64_t B0, B1;
  static V<unsigned> powB0, powB1;
  const int n;
  V<unsigned> h0, h1;
  template<class Itr> RollingHash(Itr first, Itr last) : n(distance(first, last)), h0(n + 1), h1(n + 1) {
    for (int i = 0; i < n; ++i, ++first) {
      h0[i + 1] = (h0[i] * B0 + *first) % P0;
      h1[i + 1] = (h1[i] * B1 + *first) % P1;
    }
    while ((int)powB0.size() <= n) {
      powB0.push_back(powB0.back() * B0 % P0);
      powB1.push_back(powB1.back() * B1 % P1);
    }
  }
  unsigned get0(int l, int r) const { return (h0[r] + (P0 - h0[l]) * powB0[r - l]) % P0; }
  unsigned get1(int l, int r) const { return (h1[r] + (P1 - h1[l]) * powB1[r - l]) % P1; }
  pair<unsigned, unsigned> get(int l, int r) const { return {get0(l, r), get1(l, r)}; }
  template<class Itr> static unsigned get0(Itr first, Itr last) {
    unsigned res = 0;
    while (first != last) {
      res = (res * B0 + *first++) % P0;
    }
    return res;
  }
  template<class Itr> static unsigned get1(Itr first, Itr last) {
    unsigned res = 0;
    while (first != last) {
      res = (res * B1 + *first++) % P1;
    }
    return res;
  }
  template<class Itr> static pair<unsigned, unsigned> get(Itr first, Itr last) {
    return {get0(first, last), get1(first, last)};
  }
};
uint64_t RollingHash::B0 = rng<unsigned>(1, RollingHash::P0);
uint64_t RollingHash::B1 = rng<unsigned>(1, RollingHash::P1);
V<unsigned> RollingHash::powB0{1};
V<unsigned> RollingHash::powB1{1};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  RollingHash rh(begin(s), end(s));
  auto chk = [&](int x) -> bool {
    for (int i = 0; i + 2 * x <= n; ++i) {
      for (int j = i + x; j + x <= n; ++j) {
        if (rh.get(i, i + x) == rh.get(j, j + x)) {
          return true;
        }
      }
    }
    return false;
  };
  int ok = 0, ng = n / 2 + 1;
  while (ng - ok > 1) {
    int mid = ok + ng >> 1;
    (chk(mid) ? ok : ng) = mid;
  }
  cout << ok << '\n';
}

Measured memory_bytes: 384
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto N = RD;
	auto xy = new long[][](N);
	foreach (i; 0..N)
	{
		xy[i] = [RD, RD];
	}

	double f(double cx, double cy)
	{
		double res = 0.0;
		foreach (i; 0..N)
		{
			auto dx = cast(double)xy[i][0] - cx;
			auto dy = cast(double)xy[i][1] - cy;
			auto r2 = dx^^2 + dy^^2;
			res.chmax(r2);
		}
		return res;
	}

	double g(double x)
	{
		double ly = 0.0, ry = 1000.0;
		foreach (i; 0..10^^3)
		{
			double y1 = (ly*2.0+ry) / 3.0;
			double y2 = (ly+ry*2.0) / 3.0;

			if (f(x, y1) > f(x, y2))
				ly = y1;
			else
				ry = y2;
		}
		return f(x, ly);
	}

	double lx = 0.0, rx = 1000.0;
    foreach (i; 0..10^^3)
	{
        double x1 = (lx*2.0+rx) / 3.0;
        double x2 = (lx+rx*2.0) / 3.0;

		if (g(x1) > g(x2))
			lx = x1;
		else
			rx = x2;
    }
	auto ans = sqrt(g(lx));

	writefln(FMT_F, ans);
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [a, b, c, d] <- getIntegerList
  let ans = maximum [x * y | x <- [a, b], y <- [c, d]]
  print ans


Measured memory_bytes: 3832
# frozen_string_literal: true

n = gets.to_i
s = gets.chomp

alphabets = []
('A'..'Z').each do |alphabet|
  alphabets << alphabet
end

s.length.times do |i|
    the_index = alphabets.index(s[i]) + n
    the_index -= 26 if the_index >= 26
  print alphabets[the_index]
end

print "\n"


Measured memory_bytes: 3836
#include <iostream>

using namespace std;

int main(){
     int N;
    cin>>N;
   
    int  A[N];
    
    for(int i=0;i!=N;++i){
        A[i]=0;
    }
    
    int shain;
    
    for(int i=1;i!=N;++i){
        cin>>shain;
        ++A[shain-1];
        
    }
    
    for(int i=0;i!=N;++i){
        cout<<A[i]<<endl;
    }
}


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

int main()
{
  int n, a[22], b[22], c[22];
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    cin >> b[i];
  for (int i = 1; i < n; i++)
    cin >> c[i];

  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans += b[a[i]];
  for (int i = 1; i < n; i++)
    if (a[i] + 1 == a[i + 1])
      ans += c[a[i]];
  cout << ans << endl;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>p(m), y(m);
	for (int i = 0;i < m;i++) {
		cin >> p[i] >> y[i];
	}
	
	vector<vector<int>>py(n+1);
	for (int i = 0;i < m;i++) {
		py[p[i]].push_back(y[i]);
	}
	for (int i = 0;i <= n;i++) {
		sort(py[i].begin(), py[i].end());
	}
	for (int i = 0;i < m;i++) {
		printf("%06d", p[i]);
		printf("%06d\n", (lower_bound(py[p[i]].begin(), py[p[i]].end(), y[i]) - py[p[i]].begin()) + 1);
	}

	return 0;
}

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

using namespace std;

const int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

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

vector<int> dp[20202];
bool vis[20202];
//save vis in format {length, 9s, 8s, 7s, ... ,1s}
//size is always 10

void printVector(vector<int> v) {
  for(int i = 0; i < v.size(); ++i)
    cout << " " << v[i];
  cout << endl;
}

bool comparePairs(ii p1, ii p2) {
  return p1.first == p2.first ? p1.second > p2.second : p1.first < p2.first;
}

int id(int n) {
  return 10 - n;
}

vector<int> maxVector(vector<int> a, vector<int> b) {
  for(int i = 0; i < 10; ++i) {
    if(a[i] > b[i]) return a;
    if(a[i] < b[i]) return b;
  }
  return a; //same vector
}

bool validCost(vector<int> v, int n) {
  for(int i = 1; i < 10; ++i) n -= v[i] * cost[id(i)];
  return n == 0;
}

vector<int> solve(int n, vector<ii> a) {
  if(!vis[n]) {
    for(int i = 0; i < a.size(); ++i) {
      int val = a[i].first;
      int num = a[i].second;
      if(n - val < 0) continue; //cannot use this number, insufficient matchsticks
      vector<int> temp = solve(n - val, a);
      ++temp[0];
      ++temp[id(num)];
      if(validCost(temp, n))
        dp[n] = maxVector(dp[n], temp);
    }
    vis[n] = true;
  }
  return dp[n];
}

string convert(vector<int> v) {
  string s = "";
  for(int i = 1; i < 10; ++i) {
    for(int j = 0; j < v[i]; ++j)
      s += id(i) + '0';
  }
  return s;
}

int main() {
  int n;
  int m;
  vector<ii> a; a.clear();
  scanf("%d %d", &n, &m);
  for(int i = 0, temp; i < m; ++i) {
    scanf("%d", &temp);
    a.push_back(ii(cost[temp], temp));
  }
  sort(a.begin(), a.end(), comparePairs);

  for(int i = 0; i < 20202; ++i) dp[i] = vector<int> (10, 0);
  memset(vis, false, sizeof vis);
  //because it's not possible to make a number with 0 or 1 matchsticks
  vis[0] = true;
  vis[1] = true;
  vector<int> ans = solve(n, a);
  /*
  for(int i = 0; i <= n; ++i) {
    cout << i << ": ";
    printVector(solve(i, a));
  }
  */
  printf("%s\n", convert(dp[n]).c_str());
  return 0;
}


Measured memory_bytes: 3200
#ヒントで計算量の指摘あったので今後は計算量も考慮、ヒントのママ
#i>jのみ。つまり空売りなし
import math
n=int(input())
i=0
R=[0 for i in range(n)]
while i<n:
    R[i]=int(input())
    i+=1
maxp=R[1]-R[0]
mini=R[0]#たぶんminではいけない
for i in range(n-1):
#    print(maxp,mini)
    maxp = max([R[i+1]-mini,maxp])#逆だとi=jが含まれてしまう
    mini = min([R[i+1],mini])
print(maxp)
#print(mini)



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

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i = 0; i < N; i++) {
        cin >> H[i];
    }
    int count = 0;
    int ans = 0;
    for(int i = 0; i < N-1; i++) {
        if(H[i+1] <= H[i]) {
            count++;
            ans = max(count, ans);
        } else {
            count = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

long long a, b;
long long x;

int main() {
	cin >> a >> b >> x;
	if (a%x == 0) {
		cout << b / x - a / x + 1 << endl;
	}
	else cout << b / x - a / x << endl;
	return 0;
}

Measured memory_bytes: 256