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

#define FOR(a,b,c) for(int a=(b),a##_end__=(c);a<=a##_end__;a++)
#define chkmin(a,b) (a)=min((a),(b))
#define chkmax(a,b) (a)=max((a),(b))
#define x first
#define t second
#define ll long long 
#define db double
#define pb push_back
#define SZ(x) ((int)x.size())
#define M 100005
#define Mod 1000000007

int a[M],c[M][2],p[M];
int n,l,r;

int gcd(int a,int b,int& x,int& y){
    if(!b) {x=1;y=0;return a;}
    int res=gcd(b,a%b,y,x);
    (y-=x*(a/b)%Mod)%=Mod;
    return res;
}
void init(int n,int k){
    c[1][k]=n;
    FOR(i,1,n){
        int x,y;
        gcd(i+1,Mod,x,y);
        c[i+1][k]=((1LL*c[i][k]*(n-i)%Mod*x)%Mod+Mod)%Mod;
    }
}
void Rd(int &res){
    char c;res=0;
    while(c=getchar(),c<48);
    do res=(res<<3)+(res<<1)+(c^48);
    while(c=getchar(),c>47);
}

int main(){
    Rd(n);
    n++;
    memset(p,-1,sizeof(p));
    FOR(i,1,n){
        Rd(a[i]);
        if(~p[a[i]]) l=p[a[i]],r=i;
        p[a[i]]=i; 
    }
    init(n,0);init(n-r+l-1,1);
    //FOR(i,1,n) printf("%d\n",c[i][0]);
    printf("%d\n",n-1);
    FOR(i,2,n) printf("%d\n",((1LL*c[i][0]-c[i-1][1])%Mod+Mod)%Mod);
    
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
	ios::sync_with_stdio(0), cin.tie(0);
  	string s;
  	cin >> s;
  	for (int i = 0; i < s.size(); i ++) {
  		if (s[i] == '?') s[i] = 'D';
	  }
	  cout << s;
}

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


char c[1010][1010];
char joi[2][2];
int H,W;

int isjoi(int x,int y){
	if( x < 0 || y < 0 || x == W - 1 || y == H - 1 ) return 0;
	for(int i = 0 ; i < 2 ; i++)
		for(int j = 0 ; j < 2 ; j++)
			if( joi[i][j] != c[y+i][x+j] ) return 0;
	return 1;
}

int main(){
	cin >> H >> W;
	int ans = 0;
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			cin >> c[i][j];
			ans += isjoi(j-1,i-1);
		}
	}
	for(int i = 0 ; i < 2 ; i++)
		for(int j = 0 ; j < 2 ; j++)
			cin >> joi[i][j];
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			ans += isjoi(j,i);
		}
	}
	int mans = ans;
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			for(int k = 0 ; k < 3 ; k++){
				int tmp = ans - isjoi(j-1,i-1) - isjoi(j,i-1) - isjoi(j,i) - isjoi(j-1,i);
				char z = c[i][j];
				c[i][j] = "JOI"[k];
				tmp += isjoi(j-1,i-1) + isjoi(j,i-1) + isjoi(j,i) + isjoi(j-1,i);
				mans = max(tmp,mans);
				c[i][j] = z;
				
			}
		}
	} 
	cout << mans << endl;
}

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

int main() {
  long long int A,B,N;
  cin >> A >> B >> N;

  long long int result1,result2,result3;
  result1 = (A*N)/B;
  //result2 = (A*N)/B-A*(N/B);
  result3 = (A*(B-1))/B;

  cout << (N<B-1 ? result1:result3) << endl;

}


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

#define int long long

signed main() {
  int N, Q;
  cin >> N >> Q;

  int prev[N+1] = {};
  int next[N+1] = {};
  int head, tail;
  int A[N];  
  for ( int i = 0; i < N; i++ ) {
    cin >> A[i];    
    if ( i ) {
      prev[A[i]] = A[i-1];
      next[A[i-1]] = A[i];      
    }
    if ( i == 0 ) head = A[i];
    if ( i == N-1 ) tail = A[i];    
  }

  for ( int i = 0; i < Q; i++ ) {
    int q;
    cin >> q;
    if ( N == 1 ) {
      continue;      
    }
    int t1 = head, t2 = tail;
    int n = next[q], p = prev[q];
    if ( q == tail ) {
      next[q] = head;
      prev[q] = 0;
      next[p] = 0;
      prev[t1] = q;
      head = q;
      tail = p;      
    } else if ( q == head ) {
      next[q] = 0;
      prev[q] = tail;
      next[t2] = q;
      prev[n] = 0;
      head = n;
      tail = q;      
    } else {
      head = next[q];
      tail = prev[q];    
      next[q] = t1;
      prev[q] = t2;
      prev[t1] = q;
      prev[n] = 0;    
      next[t2] = q;
      next[p] = 0;
    }
  }

  while ( 1 ) {
    if ( next[head] == 0 ) break;
    cout << head << " ";
    head = next[head];    
  }
  cout << head << endl;  
  
  return 0;
}



Measured memory_bytes: 5424
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll INF=1e18;


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(10005);


//nPk
 mint f(int n, int k) {
    if (n < 0) return 0;
    // nPk = nCk * k!
    mint res = comb(n,k);
    res *= comb.fact[k];
    return res;
}




//組み合わせの数nCrを計算
   int calcNumOfCombination(int n, int r){
       int num = 1;
       for(int i = 1; i <= r; i++){
           num = num * (n - i + 1) / i;
       }
       return num;
   }




int main() {
  ll n,k;
  cin >> n>>k;
  for(ll i=1;i<=k;i++){
    mint t1=comb(k-1,i-1);
    mint t2=comb(n-k+1,i);

    t1*=t2;

    cout<<t1<<endl;
  }


}


Measured memory_bytes: 3756
#include <iostream>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#include <algorithm>
#include <bits/stdc++.h>
#define MOD 1000000000000000000
#define ll long long
#define mm(arr) memset(arr, 1, sizeof(arr))
#define scanArray(a,n) for(ll i = 0; i < n; i++){cin >> a[i];}
using namespace std;
int main(){
    FAST
     double n; cin >> n;
     double cnt;
     for(int i=1; i<=n; i++){
        if(i%2!=0){
            cnt++;
        }
     }
     cout << cnt/n << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
const ll N=210;

int main()
{
    fast();
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d);
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int const INF = 1000000;
int main(){
    ll n;
    cin>>n;
    ll a[n];
    ll ansm=0;
    ll ansn=0;
    ll sum=0;
   
    rep(i,n){
        cin>>a[i];
    }
    
    for(int i=0;i<n;i++){
        sum+=a[i];
        
        if(i%2==0){
            if(sum<=0){
                ansm+=abs(sum)+1;
                sum=1;
            }
        }else{
            if(sum>=0){
                ansm+=abs(sum)+1;
                sum=-1;
                
            }
    }
    }
        sum=0;
        for(int i=0;i<n;i++){
            sum+=a[i];
            if(i%2==0){
                if(sum>=0){
                    ansn+=abs(sum)+1;
                    sum=-1;
                    
                }
            }else{
                    if(sum<=0){
                        ansn+=abs(sum)+1;
                        sum=1;
                    }
            }
        }
    
            cout<<min(ansn,ansm)<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
string s[6] = {"Sunny", "Cloudy", "Rainy", "Sunny", "Cloudy", "Rainy"};
int A[123456];
int main(void)
{

	int N, K, Q;
	cin >> N >> K >> Q;
	for (int i = 1; i <= Q; ++i) {
		int t; scanf("%d", &t);
		A[t]++;
	}
	for (int i = 1; i <= N; ++i) {
		if (K - Q + A[i] > 0)
			puts("Yes");
		else
			puts("No");
	}
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = 0
if n <= 0 or 101 <= n:
  exit()
list1 = list(map(int, input().split()))

for i in range(len(list1)):
  minj = i
  for j in range(i, len(list1)):
    if list1[j] < list1[minj]:
      minj = j
  if i != minj:
    list1[minj], list1[i] = list1[i], list1[minj]
    a += 1
print(' '.join(map(str, list1)))
print(a)



Measured memory_bytes: 5596
from collections import deque
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ex=0
inda=-1
t=0
for i in range(len(a)):
    ex+=a[i]
    if ex<=k:
        inda=i
        t+=a[i]
    else:
        break
if inda!=-1:
    ans=inda+1
else:
    ans=0
aq=deque(a[:inda+1])
bq=deque(b)
now=ans
while len(aq)!=0 and len(bq)!=0:
    if t+bq[0]<=k:
        t+=bq.popleft()
        now+=1
        ans=max(ans,now)
    else:
        t+=bq.popleft()
        t-=aq.pop()
if len(bq)==0:
    print(ans)
else:
    while len(bq)!=0:
        t+=bq.popleft()
        if t<=k:
            now+=1
            ans=max(ans,now)
        else:
            break
    print(ans)


Measured memory_bytes: 40764
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const int inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n;
    cin>>n;

    vector<int> v(n);
    for(int i=0;i<n;++i)
        cin>>v[i];

    for(int i=0;i<n;++i)
    {
        if(v[i]%2==0 && v[i]%3!=0 && v[i]%5!=0)
        {
            cout<<"DENIED";
            return;
        }
    }

    cout<<"APPROVED";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,a,b,h[100000];
bool T(int t){
	int y=0;
	for(int i=0;i<n;i++){
		int x=h[i]-(b*t);
		if(x>0)y+=(x+(a-b)-1)/(a-b);
	}
	if(y>t)return false;
	return true;
}
main(){
	cin>>n>>a>>b;
	for(int i=0;i<n;i++)cin>>h[i];
	int left=-1,right=1000000007,c;
	while(right-left>1){
		c=(right+left)/2;
		if(T(c))right=c;
		else left=c;
	}
	cout<<right<<endl;
}

Measured memory_bytes: 1024
def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))
    return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])

s = input()
n = len(s)

print(dfs(0, s[0]))

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;

void solve() {
  int N;
  cin >> N;
  map<string, int> S;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    S[s]++;
  }
  int mx = 0;
  for (auto x : S) {
    mx = max(mx, x.second);
  }
  vector<string> ans;
  for (auto x : S) {
    if (x.second == mx) {
      ans.push_back(x.first);
    }
  }
  sort(all(ans));
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << fixed << setprecision(12);

  solve();

  return 0;
}


Measured memory_bytes: 25584
NK = tuple(map(int,input().split()))
S = input()
N = NK[0]
K = NK[1]
O = __import__("re").findall(r"(R+|L+)",S)
P = min(len(O)//2,K)
Sdash = ''.join(
    [(
        lambda val,key:[val,("R" if val[0] == "L" else "L")*len(val)][key%2 and key//2<P]
        )(O[k],k)
        for k in range(len(O))]
)
print(sum(map(
    lambda i: (lambda j:(0 <= j < N) and (Sdash[i] == Sdash[j]))(i + (-1 if Sdash[i] == "L" else 1))
    ,range(N))))

Measured memory_bytes: 6328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int N;
    string ans = "Yes";
    cin>>N;
    vint H(N);
    rep(i,N)
    {
        cin>>H[i];
    }
    for(int i = N-2;0<=i;i--)
    {
        if(H[i] > H[i+1])
        {
        if(H[i] == H[i+1] + 1)
        {
            H[i]--;
        }
        else ans = "No";
        }
    }
    rep(i,N-1)
    {
        if(H[i] > H[i+1])
        {
            ans = "No";
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640
n, *lst = map(int, open(0).read().split())
start = [0, 0, 0]
for i in range(n):
  tmplst = lst[3 * i : 3 * i + 3]
  tmp =  (tmplst[0] - start[0]) - (abs(tmplst[1] - start[1]) + abs(tmplst[2] - start[2]))
  if tmp < 0 or tmp % 2:
    print('No')
    quit()
  start = tmplst
else:
  print('Yes')

Measured memory_bytes: 26632
S_=input()
T=input()
N=len(S_)
M=len(T)
posi=[]
 
for i in range(N-M+1):
  flag=True
  for j in range(i,i+M):
    if S_[j]!=T[j-i] and S_[j]!="?":
      flag=False
  if flag==True:
    posi.append(S_[:i]+T+S_[i+M:])
#print(posi)
    
if posi==[]:
  print("UNRESTORABLE")
else:
  ans_list=[]
  for item in posi:
    ans=""
    for str in item:
      if str=="?":
        ans += "a"
      else:
        ans += str
    ans_list.append(ans)
  ans_list.sort()
  print(ans_list[0])

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

int sum_digits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main() {
  int N, A, B;
  int ret = 0;
  cin >> N >> A >> B;
  for(int i=1; i<=N; ++i) {
    int sum = sum_digits(i);
    if (sum >= A && sum <= B) ret += i;
  }
  cout << ret << endl;
}


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

typedef long long ll;

const int ms = 200200;

int n, k;
ll a[ms];

ll solve(int l, int r)
{
	if(l == r)
		return a[l] >= 0;
	int mid = (l + r) / 2;
	ll ans = solve(l, mid) + solve(mid + 1, r);
	std::vector<ll> right;
	ll sum = 0;
	for(int i = mid + 1; i <= r; i++)
	{
		sum += a[i];
		right.push_back(sum);
	}
	sum = 0;
	ll prv = ans;
	std::sort(right.begin(), right.end());
	for(int i = mid; i >= l; i--)
	{
		sum += a[i];
		ans += right.end() - std::lower_bound(right.begin(), right.end(), -sum);
	}
	prv = ans - prv;
	//std::cout << "on (" << l << ", " << r << ") found " << prv << '\n';
	return ans;
}


int main()
{
	// (al + al+1 + al+2 ... + ar) / (r - l + 1) >= k
	// (al + al+1 + al+2 ... + ar) >= k * (r - l + 1)
	// (al + al+1 + al+2 ... + ar) / k >= (r - l + 1)
	// ((al - k) + (al+1 - k) ... + (ar - k)) / k >= 0
	// ((al - k) + (al+1 - k) ... + (ar - k)) >= 0
	std::cin >> n >> k;
	for(int i = 0; i < n; i++)
		std::cin >> a[i];
	for(int i = 0; i < n; i++)
		a[i] -= k;
	std::cout << solve(0, n - 1) << '\n';
}

Measured memory_bytes: 3348
#include<stdio.h> 
int main (void){ 
    int x,y; 
    while(1){ 
        scanf("%d %d",&x,&y); 
        if(x == 0 && y == 0)break; 
        if(x<y){ printf("%d %d\n",x,y); }
        else{ printf("%d %d\n",y,x); } } 
        return 0;
        }


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

int main(){
  int n, x;
  cin >> n >> x;
  vector<int> l(n);

  
  for(int i = 0; i < n; i++) cin >> l[i];
  
  int dp = 0;
  
  int count = 1;
  
  for(int i = 0; i < n ; i++){
    dp += l[i];
    if(dp <= x) count++;
  }
  cout << count << endl;
}

    

Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] s = Console.ReadLine().Split(' ');
		int a = int.Parse(s[0]);
		int b = int.Parse(s[1]);
		int c = Math.Max(Math.Max(a+b,a-b),a*b);
		Console.WriteLine(c);
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using std::cout;
using std::cin;
using std::endl;

int main()
{
    int i=0, count=1;
    char num[1001];
    std::vector<int> sum(10, 0);
    //*c = getchar(); だとできない
    cin>>num;

    while (1)
    {
        if (strcmp(num, "0")==0)
            break;

        for (int j = 0; j < std::strlen(num); j++)
        {
            sum[i] +=  num[j] - '0';
        }

/*これだとsegmentation error
        j=0;
        while (num[j]!='\n')
        {
            sum[i] +=  num[j] - '0';
            cout<<num[j] - '0'<<endl;
            j++;
        }
*/
        if (++i==count*10)
        {
            count++;
            sum.resize(count*10);
        }

        cin>>num;
        
    }

    for (int j = 0; j < i; j++)
        cout<<sum[j]<<endl;

    
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl

ll n, cnt, ans, a, b, c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k;
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};
pair<ll, ll> p[ohara];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin >> n >> m;
    rep(i, m)
    {
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    sort(p, p + m);
    ll le = p[0].first, ri = p[0].second;
    rrep(i, 1, m)
    {
        if (le <= p[i].first && p[i].second <= ri)
        {
            le = p[i].first;
            ri = p[i].second;
        }
        else if (p[i].first <= le && le < p[i].second && p[i].second <= ri)
        {
            ri = p[i].second;
        }
        else if (le <= p[i].first && p[i].first < ri && ri <= p[i].second)
        {
            le = p[i].first;
        }
        else
        {
            ans++;
            le = p[i].first;
            ri = p[i].second;
        }
    }
    Cout(ans + 1);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <deque>
#include <map>
#include <bits/stdc++.h>
using namespace std;

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

    for(int i=1; i<10; i++){
        if(N%i == 0){
            int B = N / i;
            if(min(i,B) >= 1 && max(i,B) <= 9){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    
    cout << "No" << endl;
    return 0;
}

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

int is_ok(int x, int a){
	return x % a==0;
}

int main(){
	int a, b, x;
	scanf("%d %d", &a, &b);
	a = pow((double)100, (double)a);
	x = 0;
	for (;b>0;){
		x += a;
		if (x%a == 0 && x / a % 100 !=0 && (--b)==0){
			break;
		}
	}
	printf("%d\n", x);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;

const int MXN = 1e5 + 5;
int n, k;
int m[MXN][3];
int dp[MXN][4];

int x[3] = {0, 1, 2};

int Dp(int d, int lst) {
    if(d == n) return 0;
    if(dp[d][lst] != -1) return dp[d][lst];
    int ans = 0;
    for(int i = 0; i < 3; i++) {
        if(lst != x[i]) {
            ans = max(ans, Dp(d + 1, i) + m[d][i]);
        }
    }
    return dp[d][lst] = ans;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> m[i][0] >> m[i][1] >> m[i][2];
    }
    memset(dp, -1, sizeof dp);
    cout << Dp(0, 3) << endl;
    return 0;
}

Measured memory_bytes: 14160
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int k = 0, x = 0;
    cin >> k >> x;
    for (int i=x-k+1; i<=x+k-1; i++) {
        cout << i;
        if (i == x+k-1) cout << endl;
        else cout << " ";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int MAX_NM = 100005;
ll A[MAX_NM],B[MAX_NM],C[MAX_NM];
vector<P> v;

int main()
{
	int N,M;
	cin >> N >> M;
	rep(i,N)
	{
		cin >> A[i];
	}
	rep(i,M)
	{
		cin >> B[i] >> C[i];
		v.push_back(P(C[i],B[i]));
	}
	sort(A,A+N);
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	ll ans = 0;
	int idx = 0;
	rep(i,N)
	{
		if (v[idx].first > A[i] && v[idx].second > 0)
		{
			ans += v[idx].first;
			v[idx].second--;
			if (v[idx].second == 0 && idx < v.size()-1) idx++;
		}
		else
		{
			ans += A[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7392
import java.util.Scanner;

public class Main {

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        sc.close();
        int ans = -1;
        int ax, bx;
        for(int i = 1; i <= 1000; i++){
            ax = (int) (i * 0.08);
            bx = (int) (i * 0.1);
            if(ax == A && bx == B){
                ans = i;
                break;
            }
        }
        System.out.print(ans);
    }
}


Measured memory_bytes: 23892
N = int(input())
S = [list(map(int,list(input()))) for _ in [0]*N] 

E = [[] for _ in [0]*N]
for i,row in enumerate(S):
    for j,s in enumerate(row):
        if s :
            E[i].append(j)

def dist_bfs(N,E,start):
    d = [-1]*N
    d[start] = 0
    q = [start]
    while q:
        qq = []
        for i in q:
            di = d[i]
            for j in E[i]:
                if d[j]!=-1:continue
                d[j] = di+1
                q.append(j)
        q = qq
    return d

ans = -1
for i in range(N):
    d = dist_bfs(N,E,i)
    ans = max(ans,max(d)+1)
#check
for i,e in enumerate(E):
    for j in e:
        if j > i : break
        if abs(d[i] - d[j]) != 1 : ans = -1
print(ans)

Measured memory_bytes: 42076
L = [1 for i in range(55556)]
L[0] = 0
L[1] = 0
plist = []
for i in range(55556):
	if L[i] == 1:
		plist.append(i)
		c = 2
		while True:
			if i * c <= 55555:
				L[i * c] = 0
				c += 1
			else:
				break

plist5 = []
for i in plist:
	if i % 5 == 1:
		plist5.append(i)

N = int(input())
ans = []
for i in range(N):
	ans.append(str(plist5[i]))

print(" ".join(ans))

Measured memory_bytes: 3736
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#define _GLIBCXX_DEBUG
#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 <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
typedef pair<long long,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}



int main() {
    int N,K;cin >> N >> K;
    vector<int> save(N);
    for(int i = 0;i<N;i++){
        cin >> save.at(i);
    }
    long long ans = 0;
    long long sum = 0;
    int count = 0;

    for(int i = 0;i<=K;i++){
        for(int j = 0;j<=K;j++){
            if(i+j > K) break;
            deque<int> DQ;
            priority_queue<int,vector<int>,greater<int>> PQ;
            for(int a = 0;a<N;a++){
                DQ.push_back(save.at(a));
            }

            for(int k = 0;k<i;k++){
                if(DQ.empty()) break;
                PQ.push(DQ.front());
                sum += DQ.front();
                DQ.pop_front();
            }
            for(int l = 0;l<j;l++){
                if(DQ.empty()) break;
                PQ.push(DQ.back());
                sum += DQ.back();
                DQ.pop_back();
            }
            while(!PQ.empty() && PQ.top() <= 0 && i+j+count < K){
                sum -= PQ.top();
                PQ.pop();
                count++;
            }
            ans = max(ans,sum);
            sum = 0;
            count = 0;
        }
    }

    cout << ans << endl;
    // PLEASE GIVE ME THE "ACCEPTED" !
}

Measured memory_bytes: 256
require 'pp'

# Nと空白区切の入力値を数値の配列で返却する
def gets_n_and_i_list()
  return gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
end

N, a_list = gets_n_and_i_list
a_list.unshift(0)
a_list.push(0)

total = 0
(N+1).times do |i|
  total += (a_list[i]  - a_list[i + 1]).abs
end

1.upto(N) do |i|
  puts total - (a_list[i-1] - a_list[i]).abs - (a_list[i] - a_list[i+1]).abs + (a_list[i-1] - a_list[i+1]).abs
end

Measured memory_bytes: 12808
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const A = parseInt(args[0][0], 10)
	const B = parseInt(args[0][1], 10)
	console.log(Math.max(A + B, A - B, A * B) + 0)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

int main() {
  vector<int> v(3);
  for (int i = 0; i < 3; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  cout << v[0] + v[1] << endl;
}


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

long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}

typedef pair<long, long> P;

long GCD(long a, long b){
    if(b == 0) return a; 
    if(a < b) return GCD(b, a);
    else return GCD(b, a%b);
}

int main()
{   
    int K; cin >> K;
    string S; cin >> S;
    int s = S.length();
    if(s <= K) cout << S << endl;
    else{
        REP(i, K) cout << S[i];
        cout << "..." << endl;
    }
    /*
    int N; cin >> N;
    long A[200005], B[200005];
    REP(i, N) cin >> A[i] >> B[i];
    int bothzero = 0, azero = 0, bzero = 0, nonzero = 0;
    vector<P> ba(N), ab(N);
    REP(i, N){
        if(A[i] == 0l && B[i] == 0l) bothzero++;
        else if(A[i] == 0l && B[i] != 0l) azero++;
        else if(A[i] != 0l && B[i] == 0l) bzero++;
        else{
            long temp;
            temp = GCD(abs(A[i]), abs(B[i]));
            if(B[i]/temp > 0){
                ba[nonzero].first = B[i]/temp;
                ba[nonzero].second = A[i]/temp;
            }else{
                ba[nonzero].first = -B[i]/temp;
                ba[nonzero].second = -A[i]/temp;
            }

            if(A[i]/temp > 0){
                ab[nonzero].first = A[i]/temp;
                ab[nonzero].second = -B[i]/temp;
            }else{
                ab[nonzero].first = -A[i]/temp;
                ab[nonzero].second = B[i]/temp;
            }
            nonzero++;
        }
    }
    cout << nonzero << endl;
    REP(i, nonzero) cout << ab[i].first << " " << ab[i].second << endl;
    cout << endl;
    REP(i, nonzero) cout << ba[i].first << " " << ba[i].second << endl;

    long mod = 1000000007;
    long ans = 0l;
    ans += bothzero; ans %= mod;
    long temp;
    temp = azero*(azero-1l); temp %= mod;
    temp *= modinv(2l, mod); temp %= mod;
    ans += temp; ans %= mod;
    temp = (azero * nonzero) % mod;
    ans += temp; ans %= mod;
    temp = bzero*(bzero-1l); temp %= mod;
    temp *= modinv(2l, mod); temp %= mod;
    ans += temp; ans %= mod;
    temp = (bzero * nonzero) % mod;
    ans += temp; ans %= mod;
    */



    return 0;
}



Measured memory_bytes: 3628
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))

mod = 10**9 + 7
ans = 0

for i in range(60):
    c = len(A[A&1==1])
    A >>= 1
    ans = (ans + c*(N-c)*pow(2,i,mod))%mod

print(ans)

Measured memory_bytes: 48808
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <cstdio>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}


int main()
{
    ll n,W;
    cin>>n>>W;
    vector<ll>w(n+1);
    vector<ll>v(n+1);
    for(ll i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    ll dp[101][100001];
    for(int i=0;i<=n;i++)
    for(ll j=0;j<=100000;j++)
        dp[i][j]=1e18;
    dp[0][0]=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=0;j<=100000;j++)
        {
            if(j<v[i])
                dp[i][j]=dp[i-1][j];
            else
            {
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
            }
                
        }
    }
    ll ans=0;
    for(ll i=0;i<=100000;i++)
    {
        if(dp[n][i]<=W)
        {
            ans=max(ans,i);
            
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    long long int N,M,H,W,x,i,j,k,ans,count,cost,tmp;
    long long int S[11000];
    //long long int T[300000];
    //long long int U[300000];
    //long long int Ssum[300000];
    //string T,U,V,ans2;
    bool flag;
    count=0;
    ans=std::pow(10,18);
    ans=0;
    flag=false;
        cin >> N;
        //count=0;
    for (i=1;i<100;i++){
        for (j=1;j<100;j++){
            for (k=1;k<100;k++){
                x=i*i+j*j+k*k+i*j+j*k+k*i;
                if (x<10050  ){
                    S[x]+=1;
                    
                    
                }
                
            }
        }
    }
    //cout << count<<endl;
    for (j=1;j<=N;j++){
        count=0;
 
        cout << S[j]<<endl;
    }
    
    
    
    //cout << ans<<endl;

    return 0;
    
}


Measured memory_bytes: 3668
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	int k, s;
	int n, m;
	int x, y;
	bool z = true;
	int ans = 0;
	bool c[10];


	int a[100][10];
	int b[100][11];
	f(i, 100){
		f(j, 10)a[i][j] = 0;
		f(j, 11)b[i][j] = 0;
	}
	scanf("%d", &n);
	f(i, n){
		f(j, 10)scanf("%d", &a[i][j]);
	}
	f(i, n){
		f(j, 11)scanf("%d", &b[i][j]);
	}
	ans = -1000000009;



	for (int qq = 1; qq<1024; qq++){
		s = 0;
		x = qq;
		f(i, 10) {
			if (x % 2 == 1)c[i] = true;
			else c[i] = false;
			x = x / 2;
		}
		f(i, n){
			k = 0;
			f(j, 10){
				if (a[i][j] == 1 && c[j] == true)k++;
			}
			s += b[i][k];
		}
		if (ans < s)ans = s;
	}

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

	return 0;
}


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

using namespace std;
typedef long long int ll;

int sumofdig(ll a){
	string stra=to_string(a);
	int sum=0;

	for(auto s: stra){

		sum+=(s-'0');
	}
	return sum;
}


int main(){
	//freopen("g25aIn.txt","r",stdin);
	//freopen("g25aOut.txt","w",stdout);
	ll n,x,y;
	int mini=200;
	cin>>n;
	x=1;
	y=n-1;
	 while(x<=y){
	 	mini=min(mini,sumofdig(x)+sumofdig(y));
		x++;
	 	y--;
	}
	cout<<mini<<endl;





	return 0;
}

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


typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)



int main(){
  int x, a, b;
  cin >> x >> a >> b;

  cout << (x - a) % b << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

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

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    PUTS(180 * (n - 2));
}

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

using namespace std;

int main()
{
    long long int n,ar[1000000],i,m;
    cin>>n;
    for (i=0;i<n;++i){

        cin>>ar[i];

    }
    sort(ar,ar+n);
    m=n/2;
    cout<<(ar[m]-ar[m-1])<<endl;

    return 0;

}


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


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

	vector <int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}

	sort(p.begin(), p.end());

	p[n - 1] /= 2;

	int sum = 0;

	for (int i = 0; i < n; i++) {
		sum += p[i];
	}

	cout << sum << endl;


	return 0;

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 1e6+1;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
  if(n >= MAX){
    ll tmp = 1;
    rep(i,k){
      tmp *= (n-i);
      tmp %= MOD;
    }
    return tmp*finv[k]%MOD;
  }

  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll POW(ll x, ll n){
  ll ret = 1;

  if(n < 0){// n < 0 にも対応
    n *= -1;
    x = inv[x];
  }

  while(0 < n){
    if(n%2 == 0){
      x = x*x%MOD;
      n /= 2;
    }
    else{
      ret = ret*x%MOD;
      n--;
    }
  }

  return ret;
}

int main(){
  int n; string s;
  cin >> n >> s;
  vvi dp(n+1,vi(n+1));
  rrep(i,n) rrep(j,n) {
    if(s[i] != s[j]) dp[i][j] = 0;
    else dp[i][j] = dp[i+1][j+1] + 1;
  }

  int ans = 0;
  rep(i,n) rep(j,n) {
    int tmp = min(dp[i][j],abs(i-j));
    chmax(ans,tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 98304
#!/usr/bin/env python3
import sys
from bisect import bisect_left
MOD = 998244353  # type: int

import math


class SegmentTree(object):
    # セグメント木

    def __init__(self, N):
        """サイズNの配列を元にしたセグメント木
        """
        # 単位元
        self.idelem = -10**9
        # 比較関数
        self.func = max

        self.N0 = 1
        while self.N0 < N:
            self.N0 <<= 1
        self.tree = [self.idelem]*(2*self.N0)

    def update(self, k, x):
        """k番目の値をxに更新
        """
        k += self.N0-1
        self.tree[k] = x
        while k > 1:
            k = (k-1)//2
            self.tree[k] = self.func(self.tree[2*k+1], self.tree[2*k+2])

    def query(self, l, r):
        """区間[l, r)の最小値
        """
        l += self.N0-1
        r += self.N0-1
        s = self.idelem
        while l < r:
            if r % 2 == 0:
                r -= 1
                s = self.func(s, self.tree[r])

            if l % 2 == 0:
                s = self.func(s, self.tree[l])
                l += 1
            l //= 2
            r //= 2
        return s


def solve(N: int, X: "List[int]", D: "List[int]"):
    # グラフを構成しようとすると、O(N^2)が考えられる。
    # 接続先が単調に決まることを利用して、一番遠くだけ記憶しておく。
    reachable = [0]*N

    # ソートしておく
    X, D = zip(*sorted(zip(X, D)))
    # print(X, D)

    # O(NlogN)で直接的に影響範囲を整理する。
    for i, (x, d) in enumerate(zip(X, D)):
        reachable[i] = bisect_left(X, x+d)

    # SegmentTreeで、間接的な影響範囲を管理する
    seg = SegmentTree(N)

    # 後ろから、真の影響範囲を決めていく
    for v in reversed(range(N)):
        if v == N-1:
            seg.update(v, reachable[v])
            continue
        # vからreachable[v]-1までの間のノードの
        # 影響範囲の最大値が、真の影響範囲
        a = seg.query(v, reachable[v])
        if a > 0:
            seg.update(v, a)
        else:
            seg.update(v, v+1)

    true_reachable = [seg.query(v, v+1) for v in range(N)]

    # print(true_reachable)

    dp = [0]*(N+1)
    dp[N] = 1
    for v in reversed(range(N)):
        dp[v] = dp[v+1]+dp[true_reachable[v]]
        dp[v] %= MOD
    print(dp[0])

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    D = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        D[i] = int(next(tokens))
    solve(N, X, D)


if __name__ == '__main__':
    main()


Measured memory_bytes: 114700
K = int(open(0).readline())

def f(n):
    k = n
    n += 1
    d = 1
    c = sum(map(int, str(n)))
    p = n; q = c
    while d < n:
        b = (n // d) % 10
        n += (9 - b) * d
        c += 9 - b
        if p*c > n*q:
            p = n
            q = c
        d *= 10
    return p

ans = []
n = 0
for i in range(K):
    n = f(n)
    ans.append("%d\n" % n)
open(1, 'w').writelines(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
bool b[20];
bool f(int k) {
	while (k > 0) {
		int p = k % 10;
		k /= 10;
		if (b[p])return 0;
	}return 1;
}
signed main() {
	int n, k; cin >> n >> k;
	for (int i = 0; i < k; i++) {
		int p; cin >> p;
		b[p] = 1;
	}
	for (;; n++) {
		if (f(n)) {
			cout << n << endl;
			return 0;
		}
	}
}

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

int main(void){
    int n,ans=0,min;
    cin >>n;
    int p[n];
    for(int i=0;i<n;i++) cin >> p[i];
    min=p[0]; ans++;
    for(int i=1;i<n;i++){
        if(min>p[i]){
            ans++;
            min=p[i];
        }
    }
    cout << ans;
}

Measured memory_bytes: 4424
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
//#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
#define fi first
#define se second
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 998244353; const int MAX = 200020;
const double pi = 3.141593; const double EPS = 1e-12;
const ll INF = 2e18;
const int INT_INF = 1e9;
typedef pair<double, double>Pd;
double dist(P& p1, P& p2) {
	return sqrt((p1.first - p2.first) * (p1.first - p2.first) + (p1.second - p2.second) * (p1.second - p2.second));
}
double dist(Pd& p1, Pd& p2) {
	return sqrt((p1.first - p2.first) * (p1.first - p2.first) + (p1.second - p2.second) * (p1.second - p2.second));
}

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

void solve() {
	int A, B, C, D; cin >> A >> B >> C >> D;
	if (A + B == C + D)print("Balanced");
	else if (A + B > C + D)print("Left");
	else print("Right");
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 256
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int count = 0;
    rep(i, 1000)
    {
        string comp = to_string(i);
        if(i < 10){
            comp = "00" + comp;
        }else if(i < 100){
            comp = "0" + comp;
        }
        int index = 0;
        rep(j, n)
        {
            if(index >= 3) break;
            if(comp[index] == s[j])
            {
                index++;
            }
        }
        if(index == 3)
        {
            count++;
        }
    }
    cout << count << endl;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main(){
  ll X,Y,A,B,C; cin>>X>>Y>>A>>B>>C;//red,green,r,g,rg
  vector<ll> P(A),Q(B),R(C);
  rep(i,A)cin>>P.at(i);
  rep(i,B)cin>>Q.at(i);
  rep(i,C)cin>>R.at(i);
  sort(begin(P),end(P));
  sort(begin(Q),end(Q));
  sort(begin(R),end(R));
  reverse(begin(R),end(R));
  queue<ll> queP,queQ;
  rep(i,X)queP.push(P.at(i-X+A));
  rep(i,Y)queQ.push(Q.at(i-Y+B));
  ll res = 0;
  rep(i,C){
    ll p;
    ll q;
    if(queP.empty())p = MOD;
    else p = queP.front();
    if(queQ.empty())q = MOD;
    else q = queQ.front();
    ll r = R.at(i);
    if(p<q){
      if(r>=p){
        res += r;
        queP.pop();
      }else break;
    }else{
      //p>=q
      if(r>=q){
        res += r;
        queQ.pop();
      }else break;
    }
  }
  while(!queP.empty()){
    res += queP.front();
    queP.pop();
  }
  while(!queQ.empty()){
    res += queQ.front();
    queQ.pop();
  }
  cout<<res<<endl;
}


Measured memory_bytes: 4096
#include<iostream>
using namespace std;
int main(){
  int h,w,d[5]={0,1,0,-1,0};
  cin>>h>>w;
  char p[h][w];
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>p[i][j];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(p[i][j]=='#'){
        for(int k=0;k<4;k++){
          if(p[i+d[k]][j+d[k+1]]=='#')break;
          if(k==3){cout<<"No"<<endl;return 0;}
        }
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256