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

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T> inline void scf(T &x)
{
    bool f = 0;
    x = 0;
    char c = getchar();
    while(c != '-' && (c < '0' || c > '9')) c = getchar();
    if(c == '-') f = 1, c = getchar();
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    if(f) x = -x;
    return;
}

template <typename T1, typename T2> void scf(T1 &x, T2 &y)
{
    scf(x);
    return scf(y);
}

template <typename T1, typename T2, typename T3> void scf(T1 &x, T2 &y, T3 &z)
{
    scf(x);
    scf(y);
    return scf(z);
}

template <typename T1, typename T2, typename T3, typename T4> void scf(T1 &x, T2 &y, T3 &z, T4 &w)
{
    scf(x);
    scf(y);
    scf(z);
    return scf(w);
}

inline char mygetchar()
{
    char c = getchar();
    while(c == ' ' || c == '\n') c = getchar();
    return c;
}

template <typename T> inline bool chkmax(T &x, const T &y)
{
    return y > x ? x = y, 1 : 0;
}

template <typename T> inline bool chkmin(T &x, const T &y)
{
    return y < x ? x = y, 1 : 0;
}

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

//---------------------------------------------------------head----------------------------------------------------

map<int, int> M;

int main()
{
    int n, m;
    scf(n);
    while(n--) {
        int x;
        scf(x);
        if(M.find(x) == M.end()) {
            M[x] = 0;
        }
        ++M[x];
    }
    scf(m);
    while(m--) {
        int x;
        scf(x);
        --M[x];
        if(M[x] < 0) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int main() {
	int n, a[110], count = 0;
	cin >> n;
	rep(i,n) {
		cin >> a[i];
	}
	rep(i,n) {
		for(int j = n-1; j > i; j--) {
			if(a[j] < a[j-1]) {
				swap(a[j],a[j-1]);
				count++;
			}
		}
	}
	rep(i,n) {
		cout << a[i];
		if(i < n - 1) cout << " ";
	}
	cout << endl;
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1160
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
p_array = list(map(int,input().split()))

sum_max = sum(p_array[:K])
now_sum = sum_max
for i in range(1,N-K+1):
    now_sum -= p_array[i-1]
    now_sum += p_array[i+K-1]
    if now_sum > sum_max:
        sum_max = now_sum
    # print(now_sum)
print((K+sum_max)/2)


Measured memory_bytes: 67824
#include<iostream>

using namespace std;
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int train, bus;
  if(a>b){
    train = b;
      }else{
    train = a;
      }

  if(c>d){
    bus = d;
      }else{
    bus = c;
      }

  cout << train + bus << endl;
  return 0;
}

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

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

void solve(void){
  ll n; cin >> n;
  vector<ll> a(n, 0);
  rep(n, i) cin >> a[i];
  ll q; cin >> q;
  vector<ll> b(q, 0);
  vector<ll> c(q, 0);
  rep(q, i) cin >> b[i] >> c[i];

  map<ll, ll> m;
  rep(n, i) ++m[a[i]];

  ll res = 0;
  rep(n, i) res += a[i];

  rep(q, i) {
    res += m[b[i]] * (c[i] - b[i]);
    cout << res << endl;

    ll t = m[b[i]];
    m[b[i]] -= t;
    m[c[i]] += t;
  }
}

int main(void) {
  solve();
  return 0;
}


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

using namespace std;

int main() {
    string s;
    cin>>s;
    int l=s.size(),x=0;
    for(int i=0;i<l;i++)
    {
        x=(x+(s[i]-'0'))%9;
    }
    if(x>0) cout<<"No";
    else cout<<"Yes";
}


Measured memory_bytes: 3716
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
int wa_no[100000];
bool accepted[100000];
int main(){
  int N;
  int M;
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    int p;
    string S;
    cin >> p >> S;
    if(S == "WA" && !accepted[p - 1]){
      wa_no[p - 1] ++;
    }
    if(S == "AC"){
      accepted[p - 1] = true;
    }
  }
  int total_ac_no = 0;
  int total_penalty_no = 0;
  for(int i = 0; i < N; i++){
    if(accepted[i]){
      total_ac_no ++;
      total_penalty_no += wa_no[i];
    }
  }
  cout << total_ac_no << " " << total_penalty_no << endl;
  return 0;
}

Measured memory_bytes: 768
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

#a = list(map(int, input().split()))


n,m,v,p = list(map(int, input().split()))
aa = list(map(int, input().split()))
a = [[aa[i],i+1] for i in range(n)]

a.sort(key=lambda x:x[0])
#print(a)
b = [a[i][0] for i in range(n)]
anum = [a[i][1] for i in range(n)]
#print(anum)

sums = []
now = 0
for i in range(n):
    now += b[i]
    sums.append(now)
#print(sums)
ans = 0

firstMove = 1
for i in range(100):
    if(firstMove < n/2+0.1):
        firstMove*=2
    else:
        break

migis = []
'''
#print(firstMove)
for i in range(n):
    tall = b[i]+m
    #print("tall",tall)
    now = i
    move = firstMove
    while(move!=0):
        if(now+move < n):
            if(tall >= b[now+move]):
                now += move
        move = move//2
        #print(i,now)
    migis.append(now)
#print(migis)
'''
for i in range(n):
    if(i >= n-p):
        ans+=1
        continue
    if(b[i]+m < b[n-p]):
        continue
    k = b[i]+m
    amount = 0
    amount += m * (i+1)
    #print("--------roop:",i)
    #print("a+=",m*(i+1))
    amount += m * (p-1)
    #print("a+=",m*(p-1))
    amount += (b[i]+m)*(n-p-i)-(sums[n-p]-sums[i])
    #print("tttttt")
    #print(b[i]+m,n-p-i,sums[n-p],sums[i])
    #print("a+=",(b[i]+m)*(n-p-i)-(sums[n-p]-sums[i]))
    #print(amount,m*v)
    if(amount < m*v):
        continue
    else:
        ans+=1
        #print("ba:",i)
        continue

print(ans)


Measured memory_bytes: 104340
#include<stdio.h>

int main(void){
	char s[11] = {0};
	char t[12] = {0};
	int cont = 0;
	int len = 0;

	scanf("%s", s);
	scanf("%s", t);

	while(s[len]){
		len++;
	}

	for(int i = 0; s[i] != 0; i++){
		if(s[i] == t[i]){
			cont++;
		}

	}
	if(cont == len){
		printf("Yes");
	}
	else
		printf("No");

	return 0;
}

Measured memory_bytes: 1736
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))
    res=[0]*N
    for i in range(N-1):
        res[A[i]-1]+=1
    for i in range(N):
        print(res[i])
if __name__=="__main__":
    main()

Measured memory_bytes: 30956
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 200005;

int n, a[MAXN];

inline ll calc( int now ){
	ll ret = 0;
	for( int i = 1; i <= n; ++i )
		ret += abs( a[i] - now );
	return ret;
}

int main(){
	scanf( "%d", &n );
	int L = INF, R = -INF;
	for( int i = 1; i <= n; ++i ){
		int x; scanf( "%d", &x );
		a[i] = x - i;
		L = min( L, a[i] );
		R = max( R, a[i] );
	}
	while( R - L > 5 ){
		int M = ( L + R ) >> 1;
		int LM = ( L + M ) >> 1;
		if( calc(LM) < calc(M) ) R = M;
		else L = LM;
	}
	int ans = L;
	for( ++L; L < R; ++L )
		if( calc(ans) > calc(L) )
			ans = L;
	printf( "%lld\n", calc(ans) );
	return 0;
}

Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		String[] Ws = W.split(" ");
		long A = Long.parseLong(Ws[0]);
		long B = Long.parseLong(Ws[1]);
		long K = Long.parseLong(Ws[2]);

		System.out.println(Math.max(0, A-K)+" "+Math.max(0,B-Math.max(0,K-A)));

	}
}


Measured memory_bytes: 20948
import collections, sys
sys.setrecursionlimit(100005)
N = int(input())
A = [int(_) for _ in input().split()]
INF = float('inf')
memo = collections.defaultdict(lambda: INF)


def c(start, res):
    if memo[start, res] != INF:
        return memo[start, res]
    elif 2 * res - 1 > N - start:
        memo[start, res] = -INF
    elif start >= N:
        memo[start, res] = -INF
    elif res > 1:
        memo[start, res] = max(A[start] + c(start + 2, res - 1),
                               c(start + 1, res), c(start + 2, res))
    else:
        memo[start, res] = max(A[start], c(start + 1, res))
    return memo[start, res]


print(c(0, N // 2))


Measured memory_bytes: 261700
import java.util.Scanner;

public class Main {
  
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    
    int c = a + b;
    
    if (c % 2 == 0) {
      System.out.println(c / 2);
    } else {
      System.out.println(c / 2 + 1);
    }
  }
}

Measured memory_bytes: 25044
num = list(map(int, input().split()))

vote = list(map(int, input().split()))

sum = 0

item = 0

for i in range(len(vote)):
  sum += vote[i]

for i in range(len(vote)):
  if vote[i] >= sum * (1/(4*num[1])):
    item += 1

if item >= num[1]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int n,a[1000010],t,m,p[1000010],sz,mu[1000010];
long long sum,F[1000010],f,ans;
int POW(int x,int y){
	int tot=1;
	while(y)y&1?tot=1ll*tot*x%mod:0,x=1ll*x*x%mod,y>>=1;
	return tot;
}
int main(){
	scanf("%d",&n),mu[1]=1;
	for(int i=1;i<=n;++i)scanf("%d",&t),++a[t],m=max(m,t);
	for(int i=2;i<=m;++i){
		if(!p[i])p[++sz]=i,mu[i]=-1;
		for(int j=1;j<=sz&&i*p[j]<=m;++j){
			p[i*p[j]]=1;
			if(i%p[j]==0)break;
			mu[i*p[j]]=-mu[i];
		}
	}
	for(int i=1;i<=m;++i,sum=0)for(int j=i;j<=m;j+=i)F[i]=(F[i]+sum*j*a[j]+(1ll*a[j]*(a[j]-1)/2)*j%mod*j)%mod,sum=(sum+1ll*j*a[j])%mod;
	for(int i=1;i<=m;ans=(ans+f*POW(i,mod-2))%mod,++i,f=0)for(int j=i;j<=m;j+=i)f=(f+mu[j/i]*F[j])%mod;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 19840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, i, j, a;
  cin >> N >> M;
  vector<int> road(N+1, 0);
  
  for(i=0; i<2*M; i++){
    cin >> a;
    for(j=0; j<N; j++){
      if(j+1 == a){
        road[j+1] += 1;
        break;
      }
    }
  }
  for(i=0; i<N; i++){
    cout << road[i+1] << endl;
  }
}
  

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;

int main() {
    int n; cin >> n;
    int x;
    rep(k,0,n) {
        int a = 0, b = 0;
        bool can = true;
        rep(i,0,10) {
            cin >> x;
            if(a < x && b < x){
                if(x - a > x - b) b = x;
                else a = x;
            }
            else if(a < x) a = x;
            else if(b < x) b = x;
            else {can = false;}
        }
        if(can) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

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

 using namespace std;

 int main() {
   string S;
   int i, ans;

   cin >> S;

   ans = 0;
   for (i = 0; i < 6; i++) {
     if (S.at(i) == '1') ans++;
   }

   cout << ans << endl;
  
 }


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

int main(){
  int s;
  cin>>s;
  set<int>st;
  int x=s;
  while(st.count(x)==0){
    st.insert(x);
    if(x%2==0){
      x/=2;
    }
    else{
      x=x*3+1;
    }
  }
  cout<<st.size()+1<<endl;
}
  


Measured memory_bytes: 256
#include <cstdio>

int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    int ans = 0;
    if(a > b){
        ans = 2 * a - 1;
    }else if(a == b){
        ans = 2 * a;
    }else{
        ans = 2 * b - 1;
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

std::string s;

signed main(){
	std::cin >> s;
	if(s[5] == '1' || s[6] > '4'){
		printf("TBD\n");
	}else{
		printf("Heisei\n");
	}
	return 0;
}


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

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

    set<int> data;
    int cnt = 0;

    for(int i=0; i<n; i++){
        if(a[i] >= 3200) cnt++;
        else data.insert(a[i]/400); 
    }

    int mi,ma;
    ma = (int)data.size() + cnt;
    if(data.size() == 0) mi  = 1;
    else mi = (int)data.size();

    cout<<mi<<" "<<ma<<endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 22 16:06:57 2017

@author: 0048005387
"""

strA, op, strB = map(str, raw_input().split())
A = int(strA)
B = int(strB)

if op == '+':
	print(A+B)
elif op == '-':
	print(A-B)


Measured memory_bytes: 27884
#include <iostream>

int main(){
   int N;
   std::cin >> N;
   int A[N];
   int S = 0;
   for(int i=0; i<N; ++i){
      std::cin >> A[i];
      S += A[i];
   }

   int y[N];
   y[0] = S;
   for(int i=1; i<N; i=i+2)
      y[0] -= 2*A[i];

   std::cout << y[0] << ' ';
   for(int i=0; i<N-1; ++i){
      y[i+1] = 2*A[i] - y[i];
      std::cout << y[i+1] << ' ';
   }
   std::cout << std::endl;
   return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <queue>
#include <climits>
#include <vector>
using namespace std;
typedef pair<pair<int,int>,int> NODE;
#define cost first.first
#define ticket first.second 
#define pos second
#define ppp(a,b,c) make_pair(make_pair(a,b),c)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<21)

int info[100][100];
int n;

int dijk(int a,int b,int c){
	priority_queue<NODE,vector<NODE>,greater<NODE> >  Q;
	int memo[100][11];
	rep(i,100)rep(j,11)memo[i][j] = INF;
	rep(j,11)memo[a][j] = 0;
	
	Q.push(ppp(0,c,a));
	while( !Q.empty() ){
		NODE q = Q.top();Q.pop();
		for(int i=0;i<n;i++){
			if( info[q.pos][i]+q.cost < memo[i][q.ticket]){
				 memo[i][q.ticket] = info[q.pos][i]+q.cost;
				Q.push(ppp(info[q.pos][i]+q.cost ,q.ticket,i));
			}
			if( q.ticket && info[q.pos][i]/2+q.cost < memo[i][q.ticket-1] ){
					Q.push( ppp( info[q.pos][i]/2+q.cost , q.ticket-1, i));
				 memo[i][q.ticket-1] = info[q.pos][i]/2+q.cost;
			}
		}
	}
	int mi = (1<<21);
	rep(j,11)mi = min(memo[b][j],mi);
	return mi;
}
int main(){
	int c,m,s,d,a,b,f;
	while(cin >> c >> n >> m >> s >> d ,c ){
		s--;d--;
		rep(i,100)rep(j,100)info[i][j]=INF*2;
		
		for(int i=0;i<m;i++){
			cin >> a >> b >> f;
			a--;b--;
			info[a][b] = info[b][a] = f;
		}
		cout << dijk(s,d,c) << endl;
	}
}

Measured memory_bytes: 0
#include <stdio.h>

int main(){
    
    char in[12345];
    
    while(scanf("%s",in)!=EOF){
        
    int JOI=0,IOI=0;
    
    for(int i=0;in[i]!='\0';i++){
        if(in[i]=='J'&&in[i+1]=='O'&&in[i+2]=='I') JOI++;
        if(in[i]=='I'&&in[i+1]=='O'&&in[i+2]=='I') IOI++;
    }
    
    printf("%d\n%d\n",JOI,IOI);
    }
        
    return 0;
}

Measured memory_bytes: 2584
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n,q;
	cin>>n>>q;
	vector<vector<int>> g(n,vector<int>());
	vector<LL> ans(n,0);
	FOR(i,1,n){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].PB(b);
		g[b].PB(a);

	}
	FOR(i,0,q){
		int p,x;
		cin>>p>>x;
		p--;
		ans[p]+=x;
	}
	cerr<<"t"<<endl;
	queue<pll> qu;
	vector<int> used(n,0);
	qu.push(MP(0,0));
	used[0]=1;
	while(qu.size()){
		auto pr=qu.front();
		qu.pop();
		int nw=pr.ST;
		LL sc=pr.ND;
		ans[nw]+=sc;
		cerr<<nw<<" "<<ans[nw]<<endl;
		for(const auto x:g[nw]){
			if(used[x])continue;
			qu.push(MP(x,ans[nw]));
			used[x]=1;
		}
	}
	FOR(i,0,n){
		cout<<ans[i]<<" ";
	}

	return 0;
}


Measured memory_bytes: 19700
input_string = input()
total_area = 0
num_lake = 0
lake_areas = []

v_lakes = [] # (湖の始まりidx, 湖の面積)
idx_stack = [] #地形管理

for i, c in enumerate(input_string):
    if c == "\\":
        idx_stack.append(i)
    elif c == "/" and idx_stack:
        poped_i = idx_stack.pop()
        total_area += i - poped_i
        tmp_area = i - poped_i
        while v_lakes and v_lakes[-1][0] > poped_i:
            tmp_area += v_lakes.pop()[1]
            
        v_lakes.append((poped_i, tmp_area))
#print(v_lakes)

print(total_area)
ans = [area[1] for area in v_lakes] 
print(len(v_lakes), *ans)


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

int main()
{
    
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ll i,n,a=0;
    cin>>n;
    forn(i,a,n)
    {
      cout<<"ACL";
    }
    return 0;
}

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

using namespace std;

int match(char* s,char* ss,int n){
    int count=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]!=ss[i])count++;
    }
    return count/2;
}
int main()
{
    int n,r=0,w=0;
    cin>>n;
    char s[n+1],ss[n+1];
    cin>>s;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='W')w++;
        else r++;
    }
    for(int i=1;i<=n;i++)
    {
        if(i<=r)ss[i-1]='R';
        else ss[i-1]='W';
    }
    cout<<match(s,ss,n);
}


Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

int main(){
  int X = 0, N = 0, l = 0;
  int i = 0;
  std::vector<int> p;
  
  while(std::cin >> l){
    if(i == 0){X = l;++ i;}
    else if(i == 1){N = l;++ i;}
    else{
      p.push_back(l);
    }
  }
  
  for(int j = 0, k = 0; k == 0; j++){
    if(std::find(p.begin(), p.end(), X-j) == p.end()){
      std::cout << X - j;
      k = 1;
    }
    else if(std::find(p.begin(), p.end(), X+j) == p.end()){
      std::cout << X + j;
      k = 1;
    }
  }
  
  return 0;
}

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

int main() {
    int x, y;
    while(1) {
        cin >> x >> y;
        if ( x == 0 && y == 0 ) break;  
        
        cout << min(x, y) << ' ' << max(x, y) <<endl;
        
    }
}


Measured memory_bytes: 3056
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ma=sum(b)
for i in range(0,n-1):
    if a[i+1]-a[i]==1:
        ma+=c[a[i]-1]
print(ma)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
int T[N];
int count = 0;
  for(int i = 0; i<N; i++){
    cin >> T[i];
    count = count + T[i];
  }
  
  int M;
  cin >> M;
  int P[M],X[M],sum[M];
  for(int j = 0; j<M; j++){
      cin >> P[j] >> X[j];
      sum[M] = count - (T[P[j]-1] - X[j]);
      cout<<sum[M]<<endl;
  }
  return 0;
}

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

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

    int num=7%K;

    if((K%2 == 0) or (K%5 == 0)){
        cout << -1 << endl;
        return 0;
    }

    int L = 9*K;

    for(double i = 0;i < L;i++){
        if(num%K == 0){
            cout << i+1;
            break;
        }
        num = (num*10+7)%K;
    }
    return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <string>
using namespace std;
string S;
bool check(int l, int r) {
  bool ok = true;
  while(l < r) {
    if(S[l++] != S[r--]) {
      ok = false;
      break;
    }
  }
  return ok;
}
int main() {
  cin >> S;
  int N = S.size();
  bool ok = check(0, N-1) && check(0, (N-2)/2) && check((N+2)/2, N-1);
  cout << (ok?"Yes":"No") << endl;
}

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

int main() {
    int n;
    cin >> n;
    int count = 0;
    
    vector<int> button(n);
    for(int i = 0; i < n; i++)
    {
        cin >> button.at(i);
    }
    
    int i;
    int next = 0;
    for(i = 0; i < n; i++)
    {
        next = button.at(next) - 1;
        count++;
        if(next == 1)
        {
            break;
        }
    }
    if(i == n)
    {
        count = -1;
    }
    
    cout << count << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int A,B;
	int a,b,c,ans;
	scanf("%d%d",&A,&B);
	a=A+B;
	b=A-B;
	c=A*B;
	if(a>b){
		ans=a;
	}else{
		ans=b;
	}
	if(ans<c){
		ans=c;
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
#define all(v) v.begin(),v.end()
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
struct edge { int to, cost; };
int n, k, a[111111], ans;
string s;
vector<int>v;
signed main() {
	cin >> n >> k >> s;
	rep(i, n)a[i] = (int)s[i] - '0';
	v.push_back(0);
	if (a[0] == 0)v.push_back(0);
	for (int i = 1; i < n; i++)if (s[i] != s[i - 1])v.push_back(i);
	rep(i, 2 - a[n - 1])v.push_back(n);
	for (int i = 1; i < v.size(); i += 2) {
		int memo = min((int)v.size() - 1, i + 2 * k);
		ans = max(ans, v[memo] - v[i - 1]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2296
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end


str = gc
ans = 'AKIHABARA'.split('')
flag = true
while str.size > 0 || ans.size > 0
  if str.last == ans.last
    str.pop
    ans.pop
    flag = true
  elsif ans.last == 'A'
    ans.pop
  else
    flag = false
    break
  end
end

puts flag ? 'YES' : 'NO'


Measured memory_bytes: 4348
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String ans="";
int a=Integer.parseInt(sc.next());
int b=Integer.parseInt(sc.next());
int x=Integer.parseInt(sc.next());
if(x<a||x>a+b){ans="NO";}else{ans="YES";}
  System.out.println(ans);

}
}


Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n;
	while (true) {
		cin >> n;
		if (n == 0) {
			cin >> n; return 0;
		}
		int sum = 1000 - n, num = 0;
		if (sum >= 500) {
			num++;
			sum = sum - 500;
		}
		if (sum >= 100) {
			num += sum / 100;
			sum = sum % 100;
		}
		if (sum >= 50) {
			num++;
			sum = sum - 50;
		}
		if (sum >= 10) {
			num += sum / 10;
			sum = sum % 10;
		}
		if (sum >= 5) {
			num++;
			sum = sum - 5;
		}
		num += sum;
		cout << num << endl;
	}
	cin >> n;
}


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

int main() {
  int N;
  cin >> N;
vector<int> vec(N);
  vector<int> vecb(N);
  
for(int i=0;i<N;i++){
  cin>>vec.at(i);
}
  
for(int i=0;i<N;i++){
  vecb.at(vec.at(i)-1)=i+1;
}
  
  for(int i=0;i<N;i++){
    if(i<N-1){
    cout << vecb.at(i)<<" ";
    }
    else{
      cout << vecb.at(i) << endl;
    }
  }
  
}

Measured memory_bytes: 1536
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    from itertools import accumulate
    from bisect import bisect_right

    n, m, k = map(int, readline().split())
    a = [0] + list(accumulate(map(int, readline().split())))
    b = list(accumulate(map(int, readline().split())))
    ans = 0
    for i, aa in enumerate(a):
        if k < aa:
            break
        ans = max(ans, bisect_right(b, k - aa) + i)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43548
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math

MOD = 10 ** 9 + 7
# MOD = 998244353

a, b = input().split()
a = int(a)
b = "".join(b.split("."))
b = b + "0"*(3 - len(b))
b = int(b)
ans = a*b
print(ans//100)

Measured memory_bytes: 68536
l_raw = input().split()
l = [int(n) for n in l_raw]

while l!=[0,0,0,0]:
    if l[2] <= l[0]/l[1]:
        print(0)
    else:
        print(-(-(l[2]*l[1]-l[0])//l[3]))
    l_raw = input().split()
    l = [int(n) for n in l_raw]


Measured memory_bytes: 5612
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<ll, ll>P;
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; }
void SAY(bool YES){cout<<(YES?"YES":"NO")<<endl;};
void Say(bool Yes){cout<<(Yes?"Yes":"No")<<endl;};

const ll MOD = 1000000007;

int main(){

    ll a, b, c;
    cin >> a >> b >> c;
    SAY(b - a == c - b);

    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
H = LI()

ans = 0
a = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        a += 1
    else:
        ans = max(ans,a)
        a = 0
ans = max(ans,a)
print(ans)


Measured memory_bytes: 87180
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
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; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
 
template <typename T>
struct UnionFind {
   vector<T> par; 
 
   UnionFind(T N) : par(N) { 
        for(T i = 0; i < N; i++) par[i] = i;
   }
 
   int root(T x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
   }
 
   void unite(T x, T y) { 
       T rx = root(x); 
       T ry = root(y); 
       if (rx == ry) return; 
       par[rx] = ry; 
   }
 
   bool same(T x, T y) { 
       T rx = root(x);
       T ry = root(y);
       return rx == ry;
   }
};

using pint = pair<int,int>;

int N;
vector<vector<pint>> v;

bool judge(int bit){

    for(int i=0; i<N; i++){

        if(!(bit & (1<<i))) continue;

        for(pint xy : v[i]){

            int x=xy.first;
            int y=xy.second;

            if(y==1 && !(bit & (1<<x))) return false;
            if(y==0 && (bit & (1<<x))) return false;

        }
    }

    return true;
}


int main() {

    cin >> N;
    v.resize(N);
    
    for(int i=0; i<N; i++){
        int A;
        cin >> A;
        v[i].resize(A);
        for(int j=0; j<A; j++){
            cin >> v[i][j].first >> v[i][j].second;
            v[i][j].first--;
        }
    }

    int ans=0;
    for(int bit=0; bit<(1<<N); bit++){

        if(judge(bit)){

            int count=0;
            for(int i=0; i<N; i++){
                if(bit & (1<<i)) count++;
            }
            chmax(ans,count);
        }
        
    }

    cout << ans << endl;
    
    
}

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

int main() {
  int n;
  int cou = 0;
  cin >> n;
  
  for(int a = 1;a < n; a++){
    for(int b = 1; b < n; b++){
      if(a * b < n){
        cou++;
      }else{
      	break;  
      }
    }
  }
  cout << cou << endl;
}

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, a;
  cin >> n;
  rep(i, n) {
    vector<int> ch;
    rep(j, 3) {
      cin >> a;
      ch.pb(a);
    }
    sort(ch.begin(), ch.end());
    if(pow(ch[0], 2) + pow(ch[1], 2) == pow(ch[2], 2)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
	return 0;
}


Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int K, S;
  cin >> K >> S;
  
  int count = 0;
  for(int x=0; x<=K; x++){
    int y_max = min(K, S-x);
    for(int y=0; y<=y_max; y++){
      if(S - x - y <= K) count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from sys import stdin

def solve():
    s = stdin.readline().strip()
    n = len(s)

    best = 753
    for i in range(n-2):
        num = int(s[i:i+3])
        diff = abs(num-753)
        if diff<best:
            best = diff
    
    print(best)
    pass

solve()

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

int main() {
    unsigned long n;
    char s[1<<18];
    int t[1<<18];
    int i=0, j;
    scanf("%ld", &n);
    t[i]=(int)'\0';
    while(n){
        n--;
        t[i++]=(int)'a'+(int)(n%26);
        n/=26;
    }
    for(j=i-1;j>-1;j--) printf("%c", t[j]);
    printf("\n");
    return 0;
}

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

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

using namespace std;

int main(){
	string s; cin>>s;
	int ans=0;
	rep(i,16) if(s[i]!="CODEFESTIVAL2016"[i]) ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <fstream>
#include <iterator>
#include <stdlib.h>
#include <map>
#include <queue>
#include <vector>
#include <functional>
#include <set>
#include <list>
#include <algorithm>
#include <math.h>

using namespace std;

// vector cout
template<typename _Ty>
ostream& operator << (ostream& os, const vector<_Ty>& v) {
	os << "{";
	for (size_t i = 0; i < v.size(); i++)
	{
		if (i != 0) os << ", ";
		os << v[i];
	}
	os << "}";

	return os;
}

//point
class Point {
public:
	double x;
	double y;

	Point() {
		x = 0; y = 0;
	}
	Point(int x, int y) {
		this->x = x; this->y = y;
	}

	bool operator== (const Point& a) {
		if (x != a.x) return false;
		if (y != a.y) return false;
		return true;
	}

	bool operator !=(const Point& a) {
		if (x != a.x) return true;
		if (y != a.y) return true;
		return false;
	}

	bool operator < (const Point& a) {
		if (x == a.x) return (y < a.y);
		return x < a.x;
	}
};


//point cout
ostream& operator << (ostream& os, const Point& p) {
	return os << "(" << p.x << ", " << p.y << ")";
}


//AB ?? AC
double crossProduct(Point A, Point B, Point C) {
	return (B.x - A.x)*(C.y - A.y) - (B.y - A.y)*(C.x - A.x);
}

double distanceSquare(Point A, Point B) {
	return (A.x - B.x)*(A.x - B.x) + (A.y - B.y)*(A.y - B.y);
}

//S:????????????????????????
int convexhull(vector<Point>& S)
{
	//L:??????????§?????????????????????????
	vector<Point> L;

	//sort
	sort(S.begin(), S.end());

	Point A, B, C;

	A = S[0];
	do {
		L.push_back(A);
		B = S[0];
		for (int i = 1; i < S.size(); i++){
			C = S[i];
			if (B == A) B = C;
			else {
				double v = crossProduct(A, B, C);
				if (v > 0 || ((fabs(v) < 1e-8) && (distanceSquare(A, C) > distanceSquare(A, B)))) B = C;
			}
		}
		A = B;
	} while (A != L[0]);

	return S.size() - L.size();
}

int main() {

	while (1) {

		int n;
		vector<Point> Points;
		cin >> n;
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			Point p;
			string input;
			cin >> input;

			stringstream ss(input);

			ss >> p.x;
			ss.ignore();
			ss >> p.y;

			Points.push_back(p);
		}
		cout << convexhull(Points) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
int main() {
	int r,g,b,num;
	cin >> r >> g>>b>>num;
	int ans = 0;
	for (int rn = 0; rn <= num; rn++) {
		int sum = r * rn;
		if (sum > num) {
			break;
		}
		for (int gn = 0; gn <= num; gn++) {
			;
			if (sum + g * gn > num) {
				break;
			}
			if ((num - (sum + g * gn)) % b == 0) {
				ans++;
			}
		}
	}
	cout <<ans<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

double dist(Point p) { return abs(p); }//ベクトルpの絶対値
double dist(Point a, Point b) {//2点間の距離
	return abs(a - b);
}

int n;
int sum[100100];

int main() {
	cin >> n;
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		sum[a]++;
		sum[b + 1]--;
	}
	rep(i, 100100 - 1)sum[i + 1] += sum[i];
	ll ans = 0;
	rep(i, n + 1) {
		ll num = i + 1;
		if (sum[num] >= i)ans = max(ans, i);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3512
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) cout << #var << ": " << var << endl
using namespace std;
using Int = int64_t;
using Uint = uint64_t;
constexpr Uint mod = 1e9 + 7;
constexpr Int INF = LLONG_MAX;
constexpr Int Int_max = LLONG_MAX;
constexpr Int Int_min = LLONG_MIN;
using Container = vector<Int>;
template<typename T>
using Grid = vector<vector<T>>; // 二次元配列。[y][x]
template<typename T, typename U>
using Umap = unordered_map<T, U>;
template<typename T>
using Uset = unordered_set<T>;
template<typename T>
using P = pair<T, T>;


int main() {

	Int H, N; cin >> H >> N;
	rep(i, N) {
		Int A; cin >> A;
		H -= A;
	}

	if (H <= 0)cout << "Yes";
	else cout << "No";

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int k=0, n=0, a[200000] = {0}, b[200000] = {0} , i, m=0, ans=0;
	
	scanf("%d", &k);
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	
	for(i = 0; i < n-1; i++){
		b[i] = a[i+1] - a[i];
		//printf("%d\n", b[i]);
		if(b[i] > m){
			m = b[i];
		}
	}
	b[n-1] = k - a[n-1] + a[0];
	if(b[n-1] > m){
		m = b[n-1];
	}
	
	//printf("%d\n", m);
	ans = k - m;
	printf("%d", ans);
	
	return 0;
}

Measured memory_bytes: 896
// 解き直し.
// ABC 146解説.
// https://img.atcoder.jp/abc146/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(LL i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define a first
#define b second
const int MAX = 202020;
LL A[MAX], CUM[MAX];

int main(){
    
    // 1. 入力情報.
    LL N, K;
    scanf("%lld %lld", &N, &K);
    rep(i, N) scanf("%lld", A + i), CUM[i + 1] = CUM[i] + A[i];
    
    // 2. 条件を満たす連続部分列をカウント(TLE版).
    // (N + 1) * N / 2 の 計算量があるはず.
    LL ans = 0;
    // rep(i, N){
    //     repx(j, i, N){
    //         if((CUM[j + 1] - CUM[i]) % K == j - i + 1) ans++, printf("i=%d j=%d\n", i, j);
    //     }
    // }
    
    // 3. 解説通り.
    // (CUM[j] - j) % K == (CUM[i] - i) % K かつ j - i < K となるものを集計.
    // -> 1 <= j <= N で, (CUM[j] - j) % K == (CUM[i] - i) % K を 満たす
    // j - K < i < j となる iの個数を調べるとのこと.
    // ex. 
    // [入力例]
    // 10 7
    // 14 15 92 65 35 89 79 32 38 46
    // index     0   1   2   3   4   5   6   7   8   9  10
    // S[i]      0  14  29 121 186 221 310 389 421 459 505
    // S[i] - i  0  13  27 118 182 216 304 382 413 450 495
    // mod K     0   6   6   6   0   6   3   4   0   2   5
    // 
    // [計算メモ]
    //  j  j - K < i < j  S[j] - j  個数   マップ
    //  0    -7 < i <  0      0      0    {0:1}
    //  1    -6 < i <  1      6      0    {0:1}, {6:1}
    //  2    -5 < i <  2      6      1    {0:1}, {6:2}
    //  3    -4 < i <  3      6      2    {0:1}, {6:3}
    //  4    -3 < i <  4      0      1    {0:2}, {6:3}
    //  5    -2 < i <  5      6      3    {0:2}, {6:4}
    //  6    -1 < i <  6      3      0    {0:2}, {3:1}, {6:4}
    //  7     0 < i <  7      4      0    {0:1}, {3:1}, {4:1}, {6:4}
    //  8     1 < i <  8      0      1    {0:2}, {3:1}, {4:1}, {6:3}
    //  9     2 < i <  9      2      0    {0:2}, {2:1}, {3:1}, {4:1}, {6:2}
    // 10     3 < i < 10      5      0    {0:2}, {2:1}, {3:1}, {4:1}, {5:1}, {6:1}
    // -----------------------------------------------------------------------------
    // 合計                          8
    map<LL, LL> m;
    LL cur = 0, bef = 0;
    rep(i, N + 1){
        cur = (CUM[i] - i) % K;
        m[cur]++;
        if(i - K >= 0){
            bef = (CUM[i - K] - (i - K)) % K;
            m[bef]--;
        }
        ans += m[cur] - 1;
        // printf("cur=%lld bef=%lld\n", cur, bef);
        // for(auto &p : m) printf("{%lld:%lld}, ", p.a, p.b);
        // printf("\n");
    }
    
    // 4. 出力.
    printf("%lld\n", ans);
    return 0;

}

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

#define task "D"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 5002;
int n, k, a[N];
bool pre[N][N], suf[N][N];
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> k;
    rep(i, 1, n) cin >> a[i];
    pre[0][0] = 1;
    rep(i, 1, n) rep(j, 0, k)
    {
        pre[i][j] = pre[i - 1][j];
        if (j >= a[i]) pre[i][j] |= pre[i - 1][j - a[i]];
    }
    suf[n + 1][0] = 1;
    Rep(i, n, 1) rep(j, 0, k)
    {
        suf[i][j] = suf[i + 1][j];
        if (j >= a[i]) suf[i][j] |= suf[i + 1][j - a[i]];
    }
    int ans = 0;
    rep(i, 1, n)
    {
        if (a[i] >= k)
        {
            ans++;
            continue;
        }
        int numr = 0;
        rep(j, k - a[i], k - 1) numr += suf[i + 1][j];
        if (pre[i - 1][0] && numr) ans++;
        else
        {
            int r = k - a[i] - 1;
            rep(l, 1, k - 1)
            {
                numr -= suf[i + 1][r + a[i]];
                numr += suf[i + 1][r];
                r--;
                if (pre[i - 1][l] && numr)
                {
                    ans++;
                    break;
                }
            }
        }
    }
    cout << n - ans;
    return 0;
}


Measured memory_bytes: 52508
# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

N,K = map(int,input().split())
A = sorted(map(int,input().split()))
MOD = 10**9+7

cnt = 0

t = 1
for n,a in enumerate(A[K-1:], start=K-1):
    cnt += a*t
    cnt %= MOD
    t *= (n+1)*modinv(n-K+2, MOD)
    t %= MOD


t = 1
for n,a in enumerate(reversed(A[:N-K+1]), start=K-1):
    cnt -= a*t
    cnt %= MOD
    t *= (n+1)*modinv(n-K+2, MOD)
    t %= MOD

print(cnt)

Measured memory_bytes: 127400
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pb  push_back
#define  F   first
#define  S   second
const int N=1e5+5;
ll a[N];
int main()
{
    ft
    ll t,i,j,n,m,l,r,p,q,s=0;
    cin>>n;
    (n<1200)? cout<<"ABC\n":cout<<"ARC\n";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n!=0)
    {
        if(n%10==7)
        {
            cout<<"Yes";
            return 0;
        }
        n=n/10;
    }
    cout<<"No";
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F(i, a, b) for (int i = (a); i <= (b); i++)
#define D(i, a, b) for (int i = (a); i >= (b); i--)
#define R(i, a, b) for (int i = (a); i < (b); i++)
#define N 500000
#define ALL(vt) vt.begin(), vt.end()
void solve(string s)
{
    int n = s.length();
    
    if(n <= 3){
        map<char, int> dem;
        for(char c : s){
            ++dem[c];
        }
        if(n != dem.size())  cout << 1 << " " << n;
        else cout << -1 << " " << -1;
        return;
    }
    R(i, 0, n - 3)
    {
        map<char, int> dem;
        R(j, i, i + 3) ++dem[s[j]];        
        if (dem.size() != 3)
        {
            cout << i + 1 << " " << i + 3;
            return;
        }
    }
    cout << -1 << " " << -1;
}
int main()
{

    string s;
    cin >> s;
    solve(s);
    return 0;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

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

    string S;
    cin >> S;

    ll N = S.length();

    vll r(N, 0);
    ll t = 1;
    ll s = 0;
    irep(i, N){
        ll d = S[i] - '0';
        s = (s + d*t) % 2019;
        r[i] = s;
        t = t*10 % 2019;
    }
    vll a(2019, 0);
    rep(i, N) ++a[r[i]];

    ll total = 0;
    rep(i, 2019) total += a[i]*(a[i]-1) / 2;
    rep(i, N) if(r[i]==0) ++ total;

    cout << total << endl;
}


Measured memory_bytes: 5208