akhauriyash/Code-Regression huggingface dataset:
s = list(input())
flag = 0
start = 0
end = 0
for i in range(len(s)):
    if flag == 0 and s[i] == 'A':
        flag = 1
        start = i

    if flag == 1 and s[i] == 'Z':
        end = i
print(end - start + 1)

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<string> W(N);
  for(int i=0;i<N;i++){
    cin>>W[i];
  }
  
  bool res_1=true;
  
  bool res_2=true;
  
  
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(W[i]==W[j]){
        res_1=false;
        break;
      }
    }
  }
  
  if(res_1){
    for(int i=0;i<N-1;i++){
      if(W[i][W[i].size()-1]!=W[i+1][0]){
        res_2=false;
        break;
      }
    }
    if(res_2){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3628
L,R=map(int,input().split())
if R-L>=2019:
    minimum=0
else:
    left,right=L%2019,R%2019
    minimum=2018**2
    for i in range(left,right+1):
        for j in range(i+1,right+1):
            minimum=min(minimum,i*j%2019)
print(minimum)

Measured memory_bytes: 9156
#include <stdio.h>
int main(void){
  
  int n,abc=0,i;
  char s[51];
  
  scanf("%d",&n);
  scanf("%s",s);
  
  for(i=0; i<n-2; i++) if(s[i]=='A') if(s[i+1]=='B') if(s[i+2]=='C') abc++;
    
  printf("%d",abc); 
    
    return 0;  
}

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

int main(void){
    int n;
    scanf("%d", &n);
    char s[n][11];
    int p[n];
    int index[n];
    for(int i = 0; i < n; i++){
        scanf("%s", s[i]);
        scanf("%d", &p[i]);
        index[i] = i+1;
    }

    int buffer;
    char buf[11];
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            if(strcmp(s[i], s[j]) > 0){
                strcpy(buf, s[i]);
                strcpy(s[i], s[j]);
                strcpy(s[j], buf);
                buffer = p[i];
                p[i] = p[j];
                p[j] = buffer;
                buffer = index[i];
                index[i] = index[j];
                index[j] = buffer;
            }else if(strcmp(s[i], s[j]) == 0){
                if(p[i] < p[j]){
                    buffer = p[i];
                    p[i] = p[j];
                    p[j] = buffer;
                    buffer = index[i];
                    index[i] = index[j];
                    index[j] = buffer;
                }
            }
        }
    }

    for(int i = 0; i < n; i++){printf("%d\n", index[i]);}

    
    return 0;
}

Measured memory_bytes: 128
// フェルマーの小定理
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	p = 1000000007
)

var (
	fac []int
)

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func mpow(x int, n int) int {
	result := 1
	for n != 0 {
		if n&1 == 1 {
			result = result * x % p
		}
		x = x * x % p
		n >>= 1
	}
	return result
}

func mcomb(n int, k int) int {
	if n == 0 && k == 0 {
		return 1
	}
	if n < k || k < 0 {
		return 0
	}
	return (fac[n] * mpow(fac[n-k], p-2) % p) * mpow(fac[k], p-2) % p
}

func main() {
	X := readInt()
	Y := readInt()

	if (X+Y)%3 != 0 {
		fmt.Println(0)
		return
	}

	a := (2*Y - X) / 3
	b := (2*X - Y) / 3

	if a < 0 || b < 0 {
		fmt.Println(0)
		return
	}

	n := a + b
	k := min(a, b)

	fac = make([]int, n+1)
	fac[0] = 1
	for i := 0; i < n; i++ {
		fac[i+1] = fac[i] * (i + 1) % p
	}

	fmt.Println(mcomb(n, k))
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

int main(void){

int N,X=0,Y=0;
cin >> N;
int V[N],C[N];

for(int i=0; i<N; i++){
  cin >> V[i];
}

for(int i=0; i<N; i++){
  cin >> C[i];
}

for(int i=0; i<N; i++){
  if(V[i]>C[i]) X += V[i]-C[i];
}

cout << X << endl;

return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int n,m,head[105],cnt=0,qq,ans=0;
bool vis[105];
struct node
{
	int thispoint;
	int nextpoint;
	int lastline;
}line[5005];
void create(int a,int b)
{
	line[cnt].nextpoint=b;
	line[cnt].thispoint=a;
	line[cnt].lastline=head[a];
	head[a]=cnt;
	cnt++;
}
void check(int fir,int k)
{
	int p=head[fir];
	while(p!=-1)
	{
		if(p!=k&&p!=k+1)
		{
			if(vis[line[p].nextpoint]==false)
			{
				vis[line[p].nextpoint]=true;
				qq++;
				check(line[p].nextpoint,k);
			}
		}
		p=line[p].lastline;
	}
}
int main()
{
	int a,b;
	scanf("%d%d",&n,&m);
	for(int i=0;i<105;i++)head[i]=-1;
	while(m--)
	{
		scanf("%d%d",&a,&b);
		create(a,b);
		create(b,a);
	}
	for(int i=0;i<cnt;i+=2)
	{
		for(int j=0;j<105;j++)vis[j]=false;
		qq=1;
		vis[1]=true;
		check(1,i);
		if(qq!=n)ans++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()+[0]

money=1000
ans=1000
kabu=0

for i in range(n):
  if a[i]<a[i+1]:
    t_kabu=money//a[i]
    kabu+=t_kabu
    money-=t_kabu*a[i]
  elif a[i]>a[i+1]:
    money+=kabu*a[i]
    kabu=0

  ans=max(ans,money)

print(ans)

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

using namespace std;

const int maxn = 3e5 + 5;
char s[maxn];
int pre[maxn], pos[maxn];
int main() {
    int n;
    scanf("%d", &n);
    scanf("%s", s + 1);

    for (int i = 1; i <= n; ++i) {
            pre[i] = pre[i - 1] + (s[i] == 'E');
    }

    for (int i = n; i >= 1; --i) {
            pos[i] = pos[i + 1] + (s[i] == 'W');
    }

    int ans = INT_MAX;
    for (int i = 1; i <= n; ++i) {
        int qian = (i - 1) - pre[i - 1];
        int hou = (n - i) - pos[i + 1];
        if (ans > hou + qian) {
            ans = hou + qian;
//            cout << "pre " << pre[i - 1];
//            cout << "ans  " << i << endl;
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

using namespace std;

typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n = 5;
  int d[5];
  cin>>d[0]>>d[1]>>d[2]>>d[3]>>d[4];
 
  int max = -1;
  int index = 0;
  
  rep(i,n) {
    int target = d[i];
    int diff = 0;
    
    while(target % 10 != 0) {
      ++diff;
      ++target;
    }
    if(diff>=max) {
      max = diff;
      index = i;
    }
  }  
  
  int sum = 0;
  rep(i,n) {
    if(index == i) continue;
    
    int target = d[i];
    sum += target;
    while(sum % 10 != 0) {
      ++sum;
    }
  }
  
  sum += d[index];
  cout<<sum;
    
  return 0;
}

Measured memory_bytes: 3664
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int i;
        int count=0;
        Scanner sc= new Scanner(System.in);
        
        int n= sc.nextInt();
        int intarr[]=new int[n];
        for(i=0;i<n;i++){
            intarr[i]=sc.nextInt(); 
        }
        int qlong=sc.nextInt();
        int qintarr[]=new int[qlong];
        for(i=0;i<qlong;i++){
            qintarr[i]=sc.nextInt();
        }
       
        for(i=0;i<qlong;i++){
            int pivot[]={-1,n/2,n};
            while(true){
                if(intarr[pivot[1]]==qintarr[i]){
                    count++;
                    break;
                }else if(intarr[pivot[1]]>qintarr[i]){
                    if(pivot[1]-pivot[0]<=1){
                        break;
                    }
                    pivot[2]=pivot[1];
                    pivot[1]=(pivot[0]+pivot[1])/2;
                }else{
                    if(pivot[2]-pivot[1]<=1){
                        break;
                    }
                    pivot[0]=pivot[1];
                    pivot[1]=(pivot[1]+pivot[2])/2;
                }
            }         
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 67980
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int N;
  std::vector<int > edge[100004];
  scanf("%d", &N);
  int a, b;
  for (int i=0; i<N-1; i++){
    scanf("%d", &a);
    scanf("%d", &b);
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  int start[2]={0, N-1};
  int dist[2][100004];
  for (int i=0; i<2; i++){
    for (int j=0; j<100004; j++){
      dist[i][j]=-1;
    }
    std::queue<int > queue;
    queue.push(start[i]);
    dist[i][start[i]]=0;
    while(queue.size()>0){
      int v=queue.front();
      queue.pop();
      for (int j=0; j<edge[v].size(); j++){
	int vv=edge[v][j];
	if (dist[i][vv]!=-1) continue;
	dist[i][vv]=dist[i][v]+1;
	queue.push(vv);
      }
    }
  }
  int Fcount, Scount;
  for (int i=0; i<N; i++){
    if (dist[0][i]<=dist[1][i]){
      Fcount++;
    } else {
      Scount++;
    }
  }
  printf("%s\n", (Fcount>Scount)?"Fennec":"Snuke");
  return 0;
}


Measured memory_bytes: 6656
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<algorithm> 
#define int long long
using namespace std;

int d[1000001], m[1000001], c[1000001];
int mc[1000001], cm[1000001];
int P[1000001];
signed main() {
	int n; cin >> n;
	string s; cin >> s;
	for (int i = 1; i <= n; i++) {
		d[i] = d[i - 1];
		m[i] = m[i - 1];
		c[i] = c[i - 1];
		if (s[i - 1] == 'D') {
			d[i]++;
		}
		else if (s[i - 1] == 'M') {
			m[i]++;
		}
		else if (s[i - 1] == 'C') {
			c[i]++;
		}
	}
	int S = 0;
	for (int i = n; i > 0; i--) {
		cm[i - 1] = cm[i];
		if (s[i] == 'C')S++;
		if (s[i] == 'M')cm[i - 1] += S;
	}
	int D = d[n], M = m[n], C = c[n];
	int x = 0, y = C;
	for (int i = 0; i < n; i++) {
		P[i] = x*y;
		if (s[i] == 'M')x++;
		if (s[i] == 'C')y--;
	}
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int k; cin >> k;
		int ans = 0;
		for (int j = 1; j < n; j++) {
			if (s[j] == 'M')ans += d[j] * (C - c[j + 1]);
		}
		for (int j = 0; j <= n - k; j++) {
			if (s[j] == 'D') {
				ans -= (P[j + k]+cm[j+k-1]-(m[j]*(C-c[j+k])));
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 42116
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define NMAX 1000000
int main()
{
int N,A;
cin>> N;
int v[N+1];
std::fill_n(v, N+1 , 0);
for(int i=2;i<=N;i++)
{
  cin>>A;
  v[A-1]++;
}
  for(int i=0;i<N;i++)
  {
     cout<<v[i]<<endl;
  }
}


Measured memory_bytes: 4392
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;

const ll M = 1000000007;
 
vector<ll> fac(2000002); //n!(mod M)
vector<ll> ifac(2000002); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main(){
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<2000002; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    ll r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
    ll ans = 0;
    rep(i, r1+1, r2+2){
        ans += comb(c2+i, i);
        ans %= M;
    }
    rep(i, 1, c1+1){
        ans -= comb(r2+i, i);
        ans = ans%M;
    }
    rep(i, 1, r1+1){
        ans += comb(c1-1+i, i);
        ans = ans%M;
    }
    prt(abs(ans));
}

Measured memory_bytes: 31488
from collections import Counter
N = int(input())
A = [int(hoge) for hoge in input().split()]
Plus = []
Minus = []
for n,a in enumerate(A):
    Plus.append(n + a)#i + Ai
    Minus.append(n - a)#i - Ai
CPlus = Counter(Plus)#Max2万種類
CMinus = Counter(Minus)#Max2万種類
ans = 0
for p in Plus:
    ans +=CMinus[p]
print(ans)


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N;
    cin>>N;
    vi A(N);
    vector<pint> E;
    REP(i, 0, N) cin >> A[i];
    sort(A.begin(), A.end());
    int Least = A[0];
    int M, p;
    for(int i = N-1; i > 0; i--){
        if(A[i]>=0 && A[i-1] >= 0 && i >1){
            E.push_back({Least, A[i]});
            Least -= A[i];
        }else{
            M = A[i];
            E.push_back({M, Least});
            M -= Least;
            p = i;
            break;
        }
    }
    REP(i, 1, p){
        E.push_back({M, A[i]});
        M -= A[i];
    }
    cout << M << endl;
    REP(i, 0, N-1) cout << E[i].first << " " << E[i].second << endl;
}

Measured memory_bytes: 3188
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mInt = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 100000000



int main(){
	int N,Q;
	cin>>N>>Q;
	dsu D(N);
	
	rep(i,Q){
		int t,u,v;
		cin>>t>>u>>v;
		
		if(t==0){
			D.merge(u,v);
		}
		else cout<<D.same(u,v)<<endl;
	}
	
    return 0;
}

Measured memory_bytes: 4024
H, W = map(int, input().split())
M = [list(input().strip()) for _ in range(H)]
M_yoko = [[0 for _ in range(W)] for _ in range(H)]
M_tate = [[0 for _ in range(W)] for _ in range(H)]

for row in range(H):
    walls = [-1]
    for col in range(W):
        if M[row][col] == '#':
            walls.append(col)
    walls.append(W)
    for i in range(len(walls)-1):
        st = walls[i]
        ed = walls[i+1]
        for j in range(st+1, ed):
            M_yoko[row][j] = ed - st - 1

for col in range(W):
    walls = [-1]
    for row in range(H):
        if M[row][col] == '#':
            walls.append(row)
    walls.append(H)
    for i in range(len(walls)-1):
        st = walls[i]
        ed = walls[i+1]
        for j in range(st+1, ed):
            M_tate[j][col] = ed - st - 1

ans = 0
for row in range(H):
    for col in range(W):
        ans = max(ans, M_yoko[row][col] + M_tate[row][col])

print(ans-1)


Measured memory_bytes: 253192
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K,T;
    cin >> K >> T;
    ll a[110];
    rep(i,0,T) cin >> a[i];
    ll mx = 0, sum = 0;
    rep(i,0,T){
        mx = max(mx, a[i]);
        sum += a[i];
    }
    sum -= mx;
    mx -= sum;
    if(mx <= 1){
        print(0);
    }else{
        print(mx - 1);
    }


}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	double a, b, c, d, e, f;
	double x, y;

	while (~scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f)){
		x = (e * c - b * f) / (a * e - b * d);
		y = (a * f - d * c) / (a * e - b * d);

		if (x == 0.0) x = 0.0;
		if (y == 0.0) y = 0.0;

		printf("%.3lf %.3lf\n", x, y);
	}

	return (0);
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, K; cin >> N >> K;
    int sum = 0; vector<int> A(N);
    REP(i, 0, N) {
        cin >> A[i];
        sum += A[i];
    }

    set<int> divisors;
    for (int i = 1; i * i <= sum; i++) {
        if (sum % i != 0) continue;
        divisors.insert(i);
        divisors.insert(sum / i);
    }

    int ans = 1;
    for (auto d : divisors) {
        if (d == 1) continue;
        vector<int> r(N);
        for (int i = 0; i < N; i++) r[i] = A[i] % d;
        sort(ALL(r));
        REP(i, 1, N) r[i] += r[i - 1];
        REP(i, 0, N - 1) {
            int m = r[i];
            int p = (N - 1 - i) * d - (r.back() - r[i]);
            if (m == p && m <= K) {
                ans = d;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define _GLIBCXX_DEBUG
int main()
{
    int n,m;
    cin>>n>>m;
    vin k(n);
    vvin a(n,vin(m));
    rep(i,n){
        cin>>k[i];
        rep(j,k[i])cin>>a[i][j];
    }
    vin b(m,0);
    for(int i=1;i<=m;i++){
        rep(j,n){
            rep(l,k[j]){
                if(a[j][l]==i)b[i-1]++;
            }
        }
    }
    int sum=0;
    rep(i,m){
        if(b[i]==n)sum++;
    }
    cout<<sum<<endl;
}

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

#define MOD 1000000007
#define MAX_P 200005
Int fact[MAX_P],inv[MAX_P],finv[MAX_P];;
Int extgcd(Int a,Int b,Int& x,Int& y){
  Int d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;y=0;
  }
  return d;
}
Int mod_inverse(Int a,Int mod){
  Int x,y;
  extgcd(a,mod,x,y);
  return (mod+x%mod)%mod;
}

Int mod_pow(Int x,Int n,Int mod){
  Int res=1;
  while(n){
    if(n&1) (res*=x)%=mod;
    (x*=x)%=mod;
    n>>=1;
  }
  return res;
}

Int mod_inverse2(Int a,Int mod){
  return mod_pow(a,mod-2,mod);
}

void init(Int mod){
  fact[0]=1;
  for(Int i=1;i<MAX_P;i++)
    fact[i]=(fact[i-1]*i)%mod;

  inv[1]=1;
  for(Int i=2;i<MAX_P;i++)
    inv[i]=inv[mod%i]*(mod-mod/i)%mod;
  
  finv[0]=1;
  for(Int i=1;i<MAX_P;i++)
    finv[i]=finv[i-1]*inv[i]%mod;
}

Int mod_fact(Int n,Int mod,Int& e){
  e=0;
  if(n==0) return 1;
  Int res=mod_fact(n/mod,mod,e);
  e+=n/mod;
  if(n/mod%2!=0)return res*(mod-fact[n%mod]) %mod;
  return res*fact[n%mod]%mod;
}

Int mod_comb(Int n,Int k,Int mod){
  if(n==k||k==0) return 1;
  Int e1,e2,e3;
  Int a1=mod_fact(n,mod,e1),a2=mod_fact(k,mod,e2),a3=mod_fact(n-k,mod,e3);
  if(e1>e2+e3) return 0;
  return a1*mod_inverse(a2*a3%mod,mod)%mod;
}

Int mod_comb2(Int n,Int k,Int mod){
  Int res=1;
  for(Int i=0;i<k;i++){
    res*=(n-i)%mod;
    res%=mod;
    res*=mod_inverse(i+1,mod);
    res%=mod;
  }
  return res;
}

//only for prime mod
Int mod_comb3(Int n,Int k,Int mod){
  if(k<0||k>n) return 0;
  return fact[n]*finv[k]%mod*finv[n-k]%mod;
}

Int montmort(Int n,Int mod){
  Int res=0,inv=1;
  for(Int k=2;k<=n;k++){
    (inv*=mod_inverse(k,mod))%=mod;
    if(k%2) (res+=mod-inv)%=mod;
    else (res+=inv)%=mod;
  }
  for(Int i=1;i<=n;i++)
    (res*=i)%=mod;
  return res;
}

// calculate P(t) from given points in [0,N]
Int LagrangePolynomial(vector<Int> &y,Int t,const Int mod){
  init(mod);
  Int n=y.size()-1;
  Int num=1;
  for(Int i=0;i<=n;i++)
    num=num*((t-i)%mod)%mod;
  Int res=0;
  for(Int i=0;i<=n;i++){
    Int tmp=(y[i]*num%mod)*mod_inverse((t-i)%mod,mod)%mod;
    tmp=tmp*finv[i]%mod;
    tmp=tmp*finv[n-i]%mod;
    if((n-i)&1) tmp=mod-tmp;
    res=(res+tmp)%mod;
  }
  return res;
}

//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  init(MOD);
  if(n>k){
    cout<<0<<endl;
    return 0;
  }
  Int ans=fact[k]*finv[k-n]%MOD;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 7792
using System;

namespace ABC125
{
    class Program
    {
        static void Main(string[] args)
        {
			// 文字列の区切りの読み込み
			string[] inputs = Console.ReadLine().Split(' ');
			// 配列外参照の書き方
			if (inputs.Length < 3)
			{
				Console.WriteLine("wrong input.");
				return;
			}
			// 文字列から数値への変換
			int A = int.Parse(inputs[0]);
			int B = int.Parse(inputs[1]);
			int T = int.Parse(inputs[2]);
			// 計算
			int ans = B * (T / A);// T/Aは切り下げになるので、これでよい
			// 結果出力
			Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int N=2e6+1;
int n,k;
char c[N];
int main(){
	ios::sync_with_stdio(false);
	cin >> k;
	if(k%2==0 || k%5==0){
		return cout << "-1\n",0;
	}
	int cur=7%k;
	int ans=1;
	while(cur!=0){
		cur=cur*10+7;
		cur%=k;
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define repp(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define popcnt __builtin_popcount
#define all(v) v.begin(),v.end()
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
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;}
template<class T> T gcd(T a, T b){return b?GCD(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/GCD(a,b);}

int main(){
    int n,m,c; cin >> n >> m >> c;
    vint b(m); rep(i,m) cin >> b[i];
    vector<vint> a(n,vint(m)); rep(i,n)rep(j,m) cin >> a[i][j];
    int ans = 0, sum;
    
    rep(i,n){
        sum = c;
        rep(j,m){
            sum += a[i][j]*b[j];
        }
        if(sum>0) ++ans;
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int TEST=0,CASE=1;
#define         pf              printf
#define         si(x)           scanf("%d",&x)
#define         si2(x,y)        scanf("%d %d",&x,&y)
#define         si3(x,y,z)      scanf("%d %d %d",&x,&y,&z)
#define         sl(x)           scanf("%lld",&x)
#define         sl2(x,y)        scanf("%lld %lld",&x,&y)
#define         sl3(x,y,z)      scanf("%lld %lld %lld",&x,&y,&z)
#define         sd(x)           scanf("%lf ",&x)
#define         pb(x)           push_back(x)
#define         mp(x,y)         make_pair(x,y)
#define         clr(x,y)        memset(x,y,sizeof(x))
#define         all(x)          x.begin(),x.end()
#define         MX              401000
#define         left            (indx<<1)
#define         right           left+1
#define         mid             ((l+r)>>1)
#define         call            left,l,mid
#define         lnd             tree[left]
#define         calr            right,mid+1,r
#define         rnd             tree[right]
#define         cnd             tree[indx]
#define         speed           (ios::sync_with_stdio(false),cin.tie(0))
#define         fpoint(x)       (cout.precision(x),cout<<fixed)
#define         FOR(i,n)       	for(int i=1;i<=n;++i)
#define         FOR0(i,n)      	for(int i=0;i<n;++i)
#define		dx		xx+dirx[i]
#define		dy		yy+diry[i]
long long int         mod  =    1000000007LL;
const long double     pi   =    2.0*acos(0.0);
typedef long long int ll;
typedef long double ld;
int dirx[9]={0,0,0,-1,+1,+1,+1,-1,-1};
int diry[9]={0,-1,+1,0,0,-1,+1,-1,+1};
struct vpair{
        int a,b;
        vpair(int a,int b){this->a=a,this->b=b;}
};
bool cmp(int &a,int &b){
        return a<b;                ///ascending order
        return a>b;                ///descending order
}
int n,m,a,b,c,d,k,x,y,z;
ll ans=0,total=0;
int edge[100002][2];
ll arr[100002];
int parent[100002][2];
/*
int root(int src){
	while(parent[src][0]!=src){
		src=parent[src][0];
	}
	return src;
}
*/
int root(int src){
	if(parent[src][0]==src){
		return src;
	}else{
		return parent[src][0]=root(parent[src][0]);
	}
}
int main(void){
	si2(n,m);
	FOR(i,m){
		si2(a,b);
		edge[i][0]=a;
		edge[i][1]=b;
	}
	ans=n;
	ans=(ans*(ans-1))>>1;
	for(int i=1;i<=n;i++){
		parent[i][0]=i;
		parent[i][1]=1;
	}
	for(int i=m;i>=1;--i){
		arr[i]=ans;
		if(ans==0)continue;
		a=edge[i][0];
		b=edge[i][1];
		x=root(a);
		y=root(b);
		if(x==y)continue;
		ans-=(parent[x][1]*parent[y][1]);
		parent[x][1]+=parent[y][1];
		parent[y][0]=x;
	}
	for(int i=1;i<=m;i++){
		pf("%lld\n",arr[i]);
	}
        return 0;
}

/**
"G:\Work Station\OnlineJudge\Atcoder\D.cpp"
**/


Measured memory_bytes: 3712
import java.io.*;
import java.util.*;
import java.util.Map.Entry;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        TreeMap<Long,Long> map = new TreeMap<>(Comparator.reverseOrder());

        lines = in.readLine().split(" ");
        Long b = 0L;
        for (int i = 0; i < n; i++) {
          b = Long.parseLong(lines[i]);
          if(map.containsKey(b)) map.put(b, map.get(b) + 1);
          else  map.put(b, 1L);
        }

        Long c = 0L;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          b = Long.parseLong(lines[0]);
          c = Long.parseLong(lines[1]);
          if(map.containsKey(c)) map.put(c, map.get(c) + b);
          else map.put(c, b);
        }

        Long N = Long.valueOf(n);
        Long ans = 0L;
        Entry<Long, Long> entry;
        Long k, v;
        Iterator<Entry<Long, Long>> ite = map.entrySet().iterator();
        for(Long cnt = 0L; cnt < N; cnt += v) {
          entry = ite.next();
          k = entry.getKey();
          v = entry.getValue();
          if(cnt + v < N) ans += k * v;
          else ans += k * (n - cnt);
        }

        out.println(ans);
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 79564
import java.util.*;

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

    if(a<=b){
    System.out.println(a);
    }else{
    System.out.println(a-1);    
    }
}
}


Measured memory_bytes: 35704
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int N, K;
	string S;
	cin >> N >> K >> S;
	S[K - 1] = S[K - 1] - 'A' + 'a';
	cout << S << endl;
}

Measured memory_bytes: 256
S=input()
T=input()

l_s, l_t=len(S), len(T)
ans=len(T)
for i in range(l_s-l_t+1):
    string=S[i:i+l_t]
    count=0
    for j in range(l_t):
        if T[j]!=string[j]:
            count+=1
    if count<ans:
        ans=count
print(ans)

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


int main() {
  ll sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;

  rep(i,ty-sy) cout << 'U';
  rep(i,tx-sx) cout << 'R';
  rep(i,ty-sy) cout << 'D';
  rep(i,tx-sx+1) cout << 'L';
  rep(i,ty-sy+1) cout << 'U';
  rep(i,tx-sx+1) cout << 'R';
  cout << 'D';
  cout << 'R';
  rep(i,ty-sy+1) cout << 'D';
  rep(i,tx-sx+1) cout << 'L';
  cout << 'U';
  cout << endl;

  return 0;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) cout << n << '\n';
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int a; cin >> a;
    string s; cin >> s;
    if(a>=3200){out(s);}
    else out("red");

    return 0;
}

Measured memory_bytes: 256
h, w, d = [int(x) for x in input().split()]
a = []
xy = [(0, 0)] * (h * w + 1)
for i in range(h):
  a.append([int(x) for x in input().split()])
  for j in range(w):
    xy[a[i][j]] = (i, j)
q = int(input())
L = []
R = []
for i in range(q):
  l, r = [int(x) for x in input().split()]
  L.append(l)
  R.append(r)

pw = [0] * (h * w + 1)
for i in range(1, d + 1):
  for j in range(d, h * w + 1, d):
    n = i + j
    p = n - d
    if n > h * w:
      break
    pw[n] = pw[p] + abs(xy[n][0] - xy[p][0]) + abs(xy[n][1] - xy[p][1])

for i in range(q):
  print(pw[R[i]] - pw[L[i]])


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

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

const int INF = 1e9 + 7;

using namespace std;

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

	ll s;
	cin >> s;

	ll x1, y1, x2, y2, x3, y3;
	x1 = y1 = 0;
	x2 = 1e9;
	y2 = 1;

	y3 = ceil((double)s / x2);
	x3 = y3 * x2 - s;

	cout << x1 << " "
			 << y1 << " "
			 << x2 << " "
			 << y2 << " "
			 << x3 << " "
			 << y3 << endl;

	return 0;
}


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

const ll infll=9223372036854775806;
const int inf=2147483646;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(20);
	int n,k;
	cin>>n>>k;
	if (n>=13){
		cout<<k;
	}
	else if (n>=6){
		cout<<k/2;
	}
	else {
		cout<<"0";
	}
	return 0;
}

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

typedef long long ll;

using namespace std;

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

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;

#define MAX_N 100000
int prime[MAX_N+4];
bool is_prime[MAX_N+4];

int sieve(int X){
    int p=0;
    for(int i=0;i<= MAX_N+4;i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i=2;i<=MAX_N+4;i++){
        if(is_prime[i]){
            prime[p++] = i;
            if(i >= X) return p;
            for(int j=2*i;j<=MAX_N+4;j+=i) is_prime[j] = false;  
        }
    }
}

int main(){
    int X;
    cin >> X;
    cout << prime[sieve(X)-1] << endl;
    return 0;
}




Measured memory_bytes: 384
#include "bits/stdc++.h"

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> price(N);
    for(int i = 0; i < N; i++) cin >> price.at(i);
    sort(price.begin(), price.end());
    reverse(price.begin(), price.end());
    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += price.at(i);
    }
    sum -= price.at(0) / 2;

    cout << sum << endl;
}

Measured memory_bytes: 256
local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    local cnt = bls(1, i - 1)
    for j = 1, cnt do
      self.stage[i][j] = self.func(self.stage[i + 1][j * 2 - 1], self.stage[i + 1][j * 2])
    end
  end
end
SegTree.create = function(self, n, func, emptyvalue)
  self.func, self.emptyvalue = func, emptyvalue
  local stagenum, mul = 1, 1
  self.stage = {{}}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.stage[stagenum] = {}
  end
  self.stagenum = stagenum
  self.left_stage = {}
  for i = 1, n do
    local sp, sz = 1, bls(1, stagenum - 1)
    while(i - 1) % sz ~= 0 do
      sp, sz = sp + 1, brs(sz, 1)
    end
    self.left_stage[i] = sp
  end
  self.sz_stage = {}
  local tmp, sp = 1, stagenum
  for i = 1, n do
    if tmp * 2 == i then tmp, sp = tmp * 2, sp - 1 end
    self.sz_stage[i] = sp
  end
  for i = 1, mul do self.stage[stagenum][i] = emptyvalue end
  self:updateAll()
end
SegTree.getRange = function(self, left, right)
  if left == right then return self.stage[self.stagenum][left] end
  local stagenum = self.stagenum
  local ret = self.emptyvalue
  while left <= right do
    local stage = mma(self.left_stage[left], self.sz_stage[right - left + 1])
    local sz = bls(1, stagenum - stage)
    ret = self.func(ret, self.stage[stage][1 + brs(left - 1, stagenum - stage)])
    left = left + sz
  end
  return ret
end
SegTree.update = function(self, idx)
  for i = self.stagenum - 1, 1, -1 do
    local dst = brs(idx + 1, 1)
    local rem = dst * 4 - 1 - idx
    self.stage[i][dst] = self.func(self.stage[i + 1][idx], self.stage[i + 1][rem])
    idx = dst
  end
end
SegTree.setValue = function(self, idx, value, silent)
  self.stage[self.stagenum][idx] = value
  if not silent then
    self:update(idx)
  end
end

SegTree.right_bound = function(self, val, left, right)
  local ret, retpos = self.emptyvalue, left - 1
  local l, r = left, right
  local stage = mma(self.left_stage[left], self.sz_stage[right - left + 1])
  local stagenum = self.stagenum
  while true do
    local sz = bls(1, stagenum - stage)
    local tmp = self.func(ret, self.stage[stage][mce(l / sz)])
    if tmp < val then
      ret, retpos = tmp, l + sz - 1
      if retpos == right then break end
      if l + sz <= r then
        l = l + sz
        stage = mma(self.left_stage[l], self.sz_stage[r - l + 1])
      else break end
    else
      if sz ~= 1 then stage, r = stage + 1, l + sz - 2
      else break end
    end
  end
  return retpos + 1
end

SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

local n, q = io.read("*n", "*n")
local st = SegTree.new(n, mma, -1)
for i = 1, n do
  local a = io.read("*n")
  st:setValue(i, a, true)
end
st:updateAll()
for iq = 1, q do
  local a, b, c = io.read("*n", "*n", "*n")
  if a == 1 then
    st:setValue(b, c)
  elseif a == 2 then
    print(st:getRange(b, c))
  else
    print(st:right_bound(c, b, n))
  end
end


Measured memory_bytes: 10908
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


//////////////////////////////////////


int main(){
    string s;
    cin>>s;
    int n=s.size();
    string ans="";

    rep(i,n){
        if(s[i]=='?'){
            if(i>0&&s[i-1]=='P')ans+="D";
            else ans+="D";
        }
        else{
            ans+=s[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

int arr[100005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n; cin >> n;

    int cur = 0, best = 0;

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

    for(int i = 1; i < n; ++i){
        if(arr[i] > arr[i - 1]){
            best = max(best, cur); cur = 0;
        } else {
            ++cur;
        }
    }

    cout << max(cur, best);

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n;
string s;
int aftr[4020],aftg[4020],aftb[4020];
int main(){
	#ifdef FILIN
		#ifndef LOCAL
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>s;
	s="?"+s;
	for(int i=n;i>=1;i--)
		aftr[i]=aftr[i+1]+(s[i]=='R');
	for(int i=n;i>=1;i--)
		aftg[i]=aftg[i+1]+(s[i]=='G');
	for(int i=n;i>=1;i--)
		aftb[i]=aftb[i+1]+(s[i]=='B');
	long long res=0LL;
	char desire;
	for(int i=1;i<=n-2;i++){
		for(int j=i+1;j<=n-1;j++){
			if(s[i]==s[j]) continue;
			if(s[i]=='R'&&s[j]=='G'){
				desire='B';
				res+=(long long)(aftb[j+1]);
			}
			if(s[j]=='R'&&s[i]=='G'){
				desire='B';
				res+=(long long)(aftb[j+1]);
			}
			if(s[i]=='R'&&s[j]=='B'){
				desire='G';
				res+=(long long)(aftg[j+1]);
			}
			if(s[j]=='R'&&s[i]=='B'){
				desire='G';
				res+=(long long)(aftg[j+1]);
			}
			if(s[i]=='B'&&s[j]=='G'){
				desire='R';
				res+=(long long)(aftr[j+1]);
			}
			if(s[j]=='B'&&s[i]=='G'){
				desire='R';
				res+=(long long)(aftr[j+1]);
			}
			if(j*2-i<=n)
				if(s[j*2-i]==desire)
					res-=1LL;
		}
	} 
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3700
N = int(input())
ta_lst = list(map(int, input().split()))
h_lst = list(map(int, input().split()))

min_diff = 10**10
for n, i in enumerate(h_lst):
    diff = abs((ta_lst[0] - i * 0.006) - ta_lst[1])
    if diff < min_diff:
        min_diff = diff
        min_diff_index = n
print(min_diff_index+1)

Measured memory_bytes: 3060
K = gets.to_i
as = gets.split.map(&:to_i).reverse

min = 2
max = 2

as.each do |a|
    after_min = (min + a - 1) / a * a
    after_max = max / a * a
    if after_min > after_max
        puts -1
        exit
    end
    min = after_min 
    max = after_max + a - 1
end

print min, ' ', max, "\n"

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

int main(){
	int H,W;
	cin >> H >> W;
	vector<vector<char>> a;
	a = vector<vector<char>>(H,vector<char>(W));
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			cin >> a[i][j];
	
	vector<bool> row(H,false);
	vector<bool> col(W,false);
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(a[i][j]=='#') {
				row[i]=true;
				col[j]=true;
			}
		}
	}

	for(int i=0;i<H;i++){
		if(row[i]){
			for(int j=0;j<W;j++){
				if(col[j])
					cout << a[i][j];
			}
			cout << endl;
		}
	}
}


Measured memory_bytes: 256
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, R);
    ll ans = R;
    if (N < 10)
    {
        ans = R + 100 * (10 - N);
    }
    OUT(ans);
}

Measured memory_bytes: 256
program main
    implicit none
    integer n, x, y
    integer i,j,k
    integer, allocatable, dimension(:) :: d
    integer d1, d2, min
    read(*,*) n, x, y
    allocate(d(n-1))

    d = 0

    do i = 1, n-1
        do j = i+1, n
            d1 = j-i
            d2 = abs(i-x)+abs(j-y)+1
            if(d1 < d2) then
                min = d1
            else
                min = d2
            end if
            d(min) = d(min) + 1
        end do
    end do

    do k = 1, n-1
        write(*,*) d(k)
    end do

end program

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define N 100
#define M 100
#define inrange(i,j) ((i)>=0&&(i)<m&&(j)>=0&&(j)<n)
using namespace std;

int main(void){
	int m,n;
	string c;
	cin>>m>>n;
	bool is[M][N];
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			is[i][j]=true;
			if(i==0)is[i][j]=false;
		}
	}
	for(int i=0;i<m;i++){
			cin>>c;
		for(int j=0;j<n;j++){
			if(c[j]=='x'){
				if(inrange(i,j))is[i][j]=false;
				if(inrange(i+1,j))is[i+1][j]=false;
				if(inrange(i-1,j))is[i-1][j]=false;
				if(inrange(i,j+1))is[i][j+1]=false;
				if(inrange(i,j-1))is[i][j-1]=false;
				if(inrange(i+1,j+1))is[i+1][j+1]=false;
				if(inrange(i-1,j+1))is[i-1][j+1]=false;
				if(inrange(i+1,j-1))is[i+1][j-1]=false;
				if(inrange(i-1,j-1))is[i-1][j-1]=false;
			}else if(c[j]=='o'){
				if(inrange(i,j))is[i][j]=false;
				if(inrange(i,j+1))is[i][j+1]=false;
				if(inrange(i,j-1))is[i][j-1]=false;
			}
		}
	}
	int a=0;
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(is[i][j])a++;
		}
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 3192
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] a) {
    int n = cast(int)a.length;
    auto indices = new int[n];
    for (int i = 0; i < n; i++) {
        indices[a[i]-1] = i;
    }

    int maxlen = 1;
    int len = 1;
    for (int i = 1; i < n; i++) {
        if (indices[i-1] < indices[i]) {
            len++;
            maxlen = max(maxlen, len);
        }
        else len = 1;
    }
    return n - maxlen;
}

void main() {
    int n = readint;
    int[] a;
    foreach (_; 0..n) a ~= readint;

    writeln(calc(a));
}


Measured memory_bytes: 4860