akhauriyash/Code-Regression huggingface dataset:
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int a, b, c;

void init()
{
}

void solve()
{
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> c;
    cout << min(b/a, c) << endl;
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
long long Mat[505][505];
long long n, m, r, c;
int main()
{
    cin>>r>>c>>n>>m;
    for(int i = 1; i <= r; i++)
        for(int j = 1; j <= c; j++)
            Mat[i][j] = 1000;
    for(int i = n; i <= r; i += n)
        for(int j = m; j <= c; j += m)
            Mat[i][j] = -n*m*1000 + 999;
    long long sum = 0;
    for(int i = 1; i <= r; i++)
        for(int j = 1; j <= c; j++)
            sum += Mat[i][j];
    if(sum < 0) { cout<<"No"<<endl; }
    else {
        cout<<"Yes"<<endl;
        for(int i = 1; i <= r; i++){
            for(int j = 1; j <= c; j++)
                cout<<Mat[i][j]<<" ";
            cout<<endl;
        }
    }

}


Measured memory_bytes: 3584
import java.util.*;

public class Main{
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        System.out.println(calc(A,B));
    }

    public static long calc(long A,long B){
        if(A == B) {
            return 1;
        }
        long ans = 0;
        long k = 1;
        for(int i = 0; i <= 60; i++){
            k = k * 2;
        }
        while((A & k) == (B & k)){
            A = (A | k) ^ k;
            B = (B | k) ^ k;
            k = k / 2;
        }
        long s1 = k - A;
        long s2 = k - A;
        long s3 = maxbit(B - k);
        ans = s1 + s2 + s3;
        // System.out.println(s1+" "+s2+" "+s3);
        long rb = k + s3 - 1;
        long lb = k + A;
        if(rb >= lb){
            ans = ans - (rb - lb + 1);
        }
        return ans;
    }

    public static long maxbit(long n){
        if(n == 0){
            return 1;
        }
        long k = 1,ans = 0;
        for(int i = 0; i <= 60; i++){
            if((n & k) > 0){
                ans = k;
            }
            k = k * 2;
        }
        return ans * 2;
    }
}


Measured memory_bytes: 23892
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
k = int(input())
x = 1
for _ in range(n):
    x = min(x+k, 2*x)
print(x)


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

int dp[105][4][2];

int main() {
    string s;
    int t;
    cin >> s >> t;
    int n = s.size();
    dp[0][0][0] = 1;
    rep(i,n)rep(j,4)rep(k,2) {
        int nd = s[i] - '0';
        rep(d,10) {
            int ni = i+1, nj = j, nk = k;
            if (d != 0) nj++;
            if (nj > t) continue;
            if (k == 0) {
                if (d > nd) continue;
                if (d < nd) nk = 1;
            }
           //cout<< dp[ni][nj][nk]<<" "<<dp[i][j][k]<<endl;
            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    int ans = dp[n][t][0] + dp[n][t][1];
    //cout<<dp[n][t][0] <<" "<<dp[n][t][1] <<endl;
    cout << ans <<" "<<endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main(){
  ll A, B;
  cin >> A >> B;

  ll minB = 10*B;
  ll maxB = 10*(B + 1);

  ll ans = 0;

  rep2(i, minB, maxB){
    if((long)floor(i * 0.08) == A){
      ans = i;
      break;
    }
  }

  if(ans > 0){
    cout << ans << endl;
  } else{
    cout << -1 << endl;
  }
    
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int gcd(int x,int y){
	if (!y) return x;
	return gcd(y,x%y);
}
int lcm(int x,int y){
	return x/gcd(x,y)*y;
}
int main(){
	int n;
	cin>>n;
	int x[n-1];
	for (int i=0;i<n;++i) cin >> x[i];
	for (int i=0;i<n-1;++i) x[i+1]=lcm(x[i],x[i+1]);
	cout << x[n-1] << endl;
	return 0; 
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  long double x[3],y[3];
  rep(i,3) cin >> x[i] >> y[i];
  long double a,b,c;
  long double v[2], u[2], w[2];
  v[0]= x[2]-x[1];
  v[1]= y[2]-y[1];
  u[0]= x[0]-x[1];
  u[1]= y[0]-y[1];
  w[0]= x[2]-x[0];
  w[1]= y[2]-y[0];
  a=sqrt(u[0]*u[0]+u[1]*u[1]);
  b=sqrt(v[0]*v[0]+v[1]*v[1]);
  c=sqrt(w[0]*w[0]+w[1]*w[1]);

  long double r =abs(v[0]*u[1]-v[1]*u[0])/(a+b+c);
  long double d=max(max(a,b),c);
  //  cout << r << " " << d << endl;
  cout << fixed << setprecision(12) << (r*d)/(2*r+d) << endl;
  
  
  return 0;
    

}


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

using ll = long long;

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

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main() {
    int n;
    cin >> n;
    ll ans = 1LL;
    for(int i = 0; i < n; i++) {
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long n,k,i,j,x,y,z;
    cin>>n>>k;
    for (i=0;i<n;i++)
    {
    	cin>>arr[i];
	}
	for (i=(k);i<n;i++)
	{
		if (arr[i]>arr[i-k])
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
}

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

using ll = long long;
using Pi = pair < int, int >;

constexpr int INF = (1 << 30) - 1;
constexpr int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
constexpr int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

template < typename T > T gcd(T a, T b) { return ( b ? gcd(b, a % b) : a ); }
template < typename T > T lcm(T a, T b) { return ( a / gcd(a, b) * b ); }

int main()
{
	int A, B;
	char c[105][105];

	cin >> A >> B;

	for ( int i = 0; i < 100; i++ ) {
		for ( int j = 0; j < 100; j++ ) {
			if ( i < 50 ) c[i][j] = '#';
			else c[i][j] = '.';
		}
	}
	
	for ( int i = 0; i < A - 1; i++ ) {
		c[(i / 50) * 2 + 1][(i % 50) * 2] = '.';
	}

	for ( int i = 0; i < B - 1; i++ ) {
		c[(i / 50) * 2 + 1 + 50][(i % 50) * 2] = '#';
	}

	cout << 100 << " " << 100 << endl;

	for ( int i = 0; i < 100; i++ ) {
		for ( int j = 0; j < 100; j++ ) {
			cout << c[i][j];
		}
		cout << endl;
	}
	
	return ( 0 );
}


Measured memory_bytes: 256
// Exhaustive_Search.c

#include <stdio.h>

int solve(int, int);

int n, A[2000];

int main() {
	
	int i, q, m[2000], flag;

	scanf("%d", &n);
	for(i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	scanf("%d", &q);
	for(i = 0; i < q; i++) {
		scanf("%d", &m[i]);
	}

	for(i = 0; i < q; i++) {
		flag = solve(0, m[i]);
		if(flag >= 1) printf("yes\n");
		else printf("no\n");
	}

	return 0;
}

int solve(int i, int m) {

	int res;

	if(m == 0) return 1;
	if(i >= n) return 0;

	res = solve(i + 1, m) || solve(i + 1, m - A[i]);

	return res;

}

Measured memory_bytes: 588
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int main() {
	int n; scanf("%d", &n);
	vector<int> arr(n+1, 0);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &arr[i]);
	}
	arr.push_back(0);
	vector<ll> ans(n, 0);
	ll origDist = 0;
	// arr.size() == n + 2
	for (int i = 0; i < n + 1; ++i) {
		origDist += abs(arr[i] - arr[i+1]);
	}
	//printf("AA %lld\n", origDist);
	for (int i = 1; i <= n; ++i) {
		ans[i-1] = origDist - abs(arr[i-1] - arr[i]) - abs(arr[i] - arr[i+1]) + abs(arr[i-1] - arr[i+1]);
	}
	for (int i = 0; i < n; ++i) {
		printf("%lld\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 2424
#include<bits/stdc++.h>
#define INF 100001
using namespace std;
inline int read()
{
	register int number_read=0,if_ok_read=1;
	char ch_read=getchar();
	while(ch_read<'0'||ch_read>'9')
	{
		if(ch_read=='-')
			if_ok_read=-1;
		ch_read=getchar();
	}
	while(ch_read>='0'&&ch_read<='9')
	{
		number_read=number_read*10+ch_read-'0';
		ch_read=getchar();
	}
	return number_read*if_ok_read;
}
inline void write(register int x_write)
{
    if(x_write<0)
	{
    	putchar('-');
		x_write=-x_write;
	}
    if(x_write>9)
		write(x_write/10);
    putchar(x_write%10+'0');
    return ;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	string s;
	cin>>s;
	int len=s.length(),a[INF],top=0;
	for(int i=0;i<len;i++)
	{
		if(s[i]=='0')
			a[top++]=0;
		if(s[i]=='1')
			a[top++]=1;
		if(s[i]=='B')
			top=top<1?top:top-1;
	}
	for(int i=0;i<top;i++)
		write(a[i]);
	putchar('\n');
	return 0;
}


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

const ll INF = 1e9;

int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> dp((1 << n), INF);
	dp[0] = 0;
	for (ll i = 0; i < m; ++i) {
		ll a, b;
		cin >> a >> b;
		ll key = 0;
		for (ll j = 0; j < b; ++j) {
			ll c;
			cin >> c;
			key |= 1 << (c - 1);
		}
		for (ll j = 0; j < (1 << n); ++j) {
			dp[j | key] = min(dp[j | key], dp[j] + a);
		}
	}
	if (dp.back() == INF)cout << -1 << endl;
	else cout << dp.back() << endl;
}


Measured memory_bytes: 3648
#include <stdio.h>
#define MAX 100
#define INF 1000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, A[MAX][MAX];

void dijkstra(){
  int mv,d[MAX],color[MAX];
  int i,u,v;
  for(i=0;i<n;i++){
    d[i] = INF;
    color[i]=WHITE;
  }

  d[0]=0;
  color[0]=GRAY;
  while(1){
    mv=INF;
    u=-1;
    for(i=0;i<n;i++){
      if(mv>d[i]&&color[i]!= BLACK){
	u=i;
	mv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK&&A[u][v]!=INF){
	if(d[v]>d[u]+A[u][v]){
	  d[v] = d[u]+A[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
    
  }
}

int main(){
  int i,j,k,c,u,v;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j]=INF;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      A[u][v]=c;
    }
  }
  dijkstra();
  return 0;
  
}



Measured memory_bytes: 2040
n=int(input())
a=list(map(int,input().split()))

a.sort(reverse=True)

i1=-1
lena1=0
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        lena1=a[i+1]
        i1=i
        break
if i1==-1:        
    print(0)
elif i1+2<len(a)-1:        
    lena2=0
    for i in range(i1+2,len(a)-1):
#        if a[i]==a[i+1] and a[i]!=lena1:
        if a[i]==a[i+1] :
            lena2=a[i+1]
            break
    print(lena1*lena2)
else:
    print(0)



Measured memory_bytes: 14224
import sys
n = int(input())
txy = [list(map(int, input().split())) for _ in range(n)]
txy = sorted(txy)
t, x, y = 0, 0, 0
for i in range(n):
    T, X, Y = txy[i]
    delta_t = T-t
    delta_xy = abs(X-x)+abs(Y-y)
    if delta_xy <= delta_t and delta_t%2 == delta_xy%2:
        t, x, y = T, X, Y
    else:
        print("No")
        sys.exit()
print("Yes")

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

int main(){
	int n,i,count = 0;
	cin >> n;
	int p[n];
	for(i = 0; i < n; i++){
		cin >> p[i];
	}
	for(i = 0; i < n; i++){
		if(p[i] != i+1){
			count++;
		}
	}
	if(count <= 2){
		cout << "YES";
	}
	else if(count > 2){
		cout << "NO";
	}

	return 0;
}


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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int h,w,n,ans;
    cin>>h>>w>>n;
    ans=n/max(h,w);
    if(n%max(h,w)==0){
        cout<<ans;
    }else{cout<<ans+1;}
    return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <iomanip> //小数点以下を表示させる(setprecision())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'

//DP法
template <class T>
inline bool chmin(T &a, T b) //change minimum
{
        if (a > b)
        {
                a = b;
                return true;
        }
        return false;
}
template <class T>
inline bool chmax(T &a, T b) //change max
{
        if (a < b)
        {
                a = b;
                return true;
        }
        return false;
}

typedef long long ll; //64bit型
using namespace std;

// const long long INF = 1LL << 60; //無限大の値
int INF = 1000000;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //三項演算子を使ったgcd(最大公約数)
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //lcm(最小公倍数)

ll f(ll x, int C, int D)
{
        ll res = x;
        res -= x / C;
        res -= x / D;
        res += x / lcm(C, D);

        return res;
}

int main()
{
        ll A, B;
        int C, D;
        cin >> A >> B >> C >> D;
        ll ans = f(B, C, D) - f(A - 1, C, D);
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <complex>
#include <vector>
#include <cstdio>
using namespace std;
typedef complex<double> P;
const double pi = acos(-1);

int main() {
  int N;
  while(cin >> N && N != -1) {
    P pos(1.0, 0.0);
    double rad = pi;
    for(int i = 2; i <= N; ++i) {
      rad = rad + 1.5*pi;
      pos += P(cos(rad), sin(rad));
      rad = arg(pos) + pi;
    }
    printf("%.10f\n", pos.real());
    printf("%.10f\n", pos.imag());
  }
  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
  int d,l;
  cin >> d >> l;
  int ans;
  ans = d%l + d/l;
  cout << ans << endl;
}


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

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

  int tmp;
  if(a>b)
  {
    tmp=b;
    b = a;
    a = tmp;
  }
  int i;
  int c = 0;
  for(i=a;i>=1;--i){
    if(a%i==0 && b%i==0){
     ++c;
     if(c==k) break;
  }
}

  cout << i << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
 
template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }
 
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
 
template<class T> ostream& operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto& vv : V) os << vv << ","; os << "]";
  return os;
}
 
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif
 
const int MAX = 100101;
int n;
vector<PII> d[MAX*2];
bool cz[MAX*2];
int war[MAX*2];
int inf = 1e12;
PII dfs(int v,int wa){
  if(cz[v]){
    if(war[v] != wa){
      debug(v, war[v], wa);
      cout << "No\n";
      exit(0);
    }
    return {inf,inf};
  }
  war[v] = wa;
  cz[v] = 1;
  int w1 = wa,w2 = inf;
  for(PII ak:d[v]){
    int p1,p2;
    tie(p1,p2) = dfs(ak.FI, ak.SE - wa);
    mini(w1,p2);
    mini(w2,p1);
  }
  return {w1,w2};
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> n;
  cin >> n;
  R(i,n){
    int a,b,c;
    cin >> a >> b >> c;
    b+=MAX;
    d[a].PB({b, c});
    d[b].PB({a, c});
  }
  R(i,MAX*2){
    if(!cz[i]){
      PII pom = dfs(i,0);
      if(pom.FI + pom.SE < 0){
        cout << "No\n";
        return 0;
      }
    }
  }
  cout << "Yes\n";
}

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


int main() {
    int N;
    cin >> N;
    int B[N - 1];
    for(int i = 0; i < N - 1; i++){
        cin >> B[i];
    }
    int A[N];
    for(int i = 0; i < N; i++){
        A[i] = 0;
    }
    for(int i = 0; i < N; i++){
        if(i == 0){
            A[0] = B[0];
        }else if(i == N - 1){
            A[i] = B[N - 2];
        }else{
            A[i] = min(B[i - 1],B[i]);
        }
    }
    long long sum = 0;
    for(int i = 0; i < N; i++){
        sum += A[i];
    }
    cout << sum << endl;


}

Measured memory_bytes: 256
//package april2020;

import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

public class Main {
	static long[] dp;
	static int n,k, a[];
	static long MOD = (long)1e9+7;
	public static void main(String[] args) throws IOException {
		FastReader scn = new FastReader();
		OutputStream out = new BufferedOutputStream ( System.out );
		n = scn.nextInt();k = scn.nextInt();
		a = new int[n];
//		int sum=0;
		for(int i =0;i<n;i++) {
			a[i] = scn.nextInt();
//			sum+=a[i];
		}
		dp = new long[k+1];
		dp[0]=1;
		for(int child = 0;child<n;child++) {
			long[] fake = new long[k+1];
			
			for(int used =k;used>=0;used--) {
				long tmp = dp[used];
				int l = used+1;
				int r = used+ Math.min(a[child], k-used);
				if(l<=r) {
					fake[l]+=tmp;
					if(r+1<=k)
						fake[r+1]-=tmp;
				}
			}
			long ps = 0;
			for(int i=0;i<=k;i++) {
				ps+=(fake[i]%MOD);
				dp[i]+=(ps%MOD);
			}
		}
		out.write((dp[k]%MOD+"\n").getBytes());
		out.close();
	}
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}


Measured memory_bytes: 58068
N, K, Q = map(int, input().split())
ans = [0]*(N+1)
for i in range(Q):
    ans[int(input())] += 1
sum_ans = sum(ans)
for i in range(1,N+1):
    print('Yes' if K-(sum_ans-ans[i]) > 0 else 'No')

Measured memory_bytes: 9760
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#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 present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll k,x;
    cin>>k>>x;
    rep(i,x-k+1,x+k-1){
        cout<<i<<" ";
    }
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
#define endl '\n'
using namespace std;
using ll = long long int;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 212345;
graph g;
bool seen[MAXN];
int dist[MAXN];
void dfs(int u) {
    seen[u] = 1;
    dist[u] = 0;
    for (auto v : g[u]) {
        if (!seen[v]) dfs(v);
        dist[u] = max(dist[u], dist[v]+1);
    }
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    g.assign(n+1, vi());
    int u, v;
    while (m--) {
        scanf("%d %d", &u, &v);
        g[u].push_back(v);
    }
    int ans = 0;
    for (int i = 1; i<=n; ++i) {
        if (!seen[i]) {
            dfs(i);
            ans = max(ans, dist[i]);
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 8192
#include<iostream>
using namespace std;
int n,b[100],ans=0;
int main(void){
	cin>>n>>b[0];
	ans+=b[0];
	for(int i=1;i<n-1;i++){
		cin>>b[i];
		ans+=min(b[i],b[i-1]);
	}
	ans+=b[n-2];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import bisect
import collections
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

s = input()
t = input()

n = len(s)

def toi(c):
    return ord(c) - ord('a')

next_pos = array2d(n, 26, -1)

for i in range(n):
    c = toi(s[i])
    next_pos[i][c] = i

for i in range(n-2,-1,-1):
    for c in range(26):
        if next_pos[i][c] == -1 and next_pos[i+1][c] >= 0:
            next_pos[i][c] = next_pos[i+1][c]

res, now = 0, 0
for c in t:
    c = toi(c)
    if next_pos[now][c] < 0:
        res += n - now
        now = 0
        if next_pos[now][c] < 0:
            res = -1
            break
        else:
            res += next_pos[now][c] + 1
            now = next_pos[now][c] + 1
    else:
        res += next_pos[now][c] - now + 1
        now = next_pos[now][c] + 1
    now = now % n

print(res)


Measured memory_bytes: 44016
# -*- coding: utf-8 -*-

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

# solve
ans = 0
is_odd = False
while True:
    for i in range(N):
        if A[i] % 2 == 1:
            is_odd = True
    if not is_odd:
        for i in range(N):
            A[i] /= 2
        ans += 1
    else:
        break

# output
print(ans)


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    C = [0]*(N-1)
    S = [0]*(N-1)
    F = [0]*(N-1)
    for i in range(N-1):
        C[i], S[i], F[i] = map(int, input().split())
    
    for i in range(N-1):
        t = 0
        for j in range(i, N-1):
            if t<=S[j]:
                t = S[j] + C[j]
            elif t%F[j]==0:
                t += C[j]
            else:
                t = F[j]*(t//F[j] + 1) + C[j]
        print(t)
    print(0)


if __name__ == '__main__':
    main()

Measured memory_bytes: 42096
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		long H[] = new long[N];
		int sum = 0;
		int max = 0;
		
		for(int i=0; i<N; i++) {
			H[i] = sc.nextLong();
		}
		
		for(int i=0; i<N-1; i++) {
			if(H[i]>=H[i+1]) {
				sum++;
			}else {
				sum=0;
			}
			if(max<sum) {
				max = sum;
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 60288
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();

		for (int i = A; i <= B; i++) {
			if (i % K == 0) {
				System.out.println("OK");
				return;
			}
		}
		System.out.println("NG");
	}
}


Measured memory_bytes: 35800
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;

  ll s = H1 * 60 + M1;
  ll e = H2 * 60 + M2;

  ll ans = e - K - s;
  if (ans < 0) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }


  return 0;
}


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

int main(){
    int n;
    double s[1001]={0},m,a,sum;
    
    while(1){
        scanf("%d",&n);
        if(n==0) break;
        sum = a = 0;
        for(int i=0; i<n; i++){
            scanf("%lf",&s[i]);
            sum+=s[i];
        }
        m=sum/n;
        for(int i=0; i<n; i++){
            a+=(s[i]-m)*(s[i]-m);
            s[i]=0;
        }
        printf("%.8lf\n",sqrt(a/n));
    }
}




Measured memory_bytes: 2712
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
int main(int argc,char *argv[]){
	int N,M,a,b;
	std::cin >> N >> M;
	std::vector<std::pair<int,int> > List;
	for(int i=0;i<M;++i){
		std::cin >> a >> b;
		List.push_back( std::pair<int,int>(a,b) );
	}
	std::sort(List.begin(),List.end());
	int cnt = 1,bmin=1E6;
	for(int i=0;i<M-1;++i){
		bmin = std::min(bmin,List[i].second);
		int an = List[i+1].first;
		if(an >= bmin){
			++cnt;
			bmin = 1E6;
		}
	}
	std::cout << cnt << std::endl;
	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int K;
	string S;
	cin>>K>>S;
	
	if(S.length()>K){
		cout<<S.substr(0,K)<<"..."<<endl;
	}else{
		cout<<S<<endl;
	}
	
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli a,b;
	cin>>a>>b;

	for(lli i=0;i<=1000000;i++){
		lli c = i*8/100;
		lli d = i*10/100;
		if(c==a && d==b){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;

	return 0;
}

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

typedef pair<int,int> P;

vector<int> g[200010];
vector<int> add(200010);
bool used[200010];
int inf = 2000000007;
int ans[200010];

void dfs(int cur,int sum){
  used[cur] = true;
  ans[cur] = sum;
  for(int i = 0;i < g[cur].size();i++){
    int e = g[cur].at(i);
    if(used[e] != true){
      dfs(e,sum+add.at(e));
    }
  }
  return;
}

int main(){
  int n,q;
  cin >> n >> q;
  for(int i = 0;i < n-1;i++){
    int a,b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for(int i = 0;i < n+1;i++){
    used[i] = false;
  }
  for(int i = 0;i < q;i++){
    int p,x;
    cin >> p >> x;
    add.at(p) += x;
  }
  dfs(1,add.at(1));
  for(int i = 1;i <= n;i++){
    cout << ans[i] << ' ';
  }
  cout << ' ' << endl;
}

Measured memory_bytes: 24448
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

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

    int a,b; cin >> a >> b;
    cout<< a-b+1<<endl;
}

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

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

  string s;
  cin >> s;
  string ans;
  for (size_t i = 0; i < s.size(); ++i) {
    if (ans.empty()) {
      ans.push_back(s[i]);
    } else {
      if (ans.back() == 'S' && s[i] == 'T') {
        ans.pop_back();
      } else {
        ans.push_back(s[i]);
      }
    }
  }
  cout << ans.size() << "\n";
}


Measured memory_bytes: 916
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void READ() {
#define R READ();
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MEMX(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl
#define sz(x) int(x.size())
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#ifndef ONLINE_JUDGE
    freopen("A.in", "r", stdin);
#endif
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(6);
}
//////////////////////////////////////////
const int N = 5 + 5e5;

int n, a[N],b[N];
char s[N];
int main() {
    cin >> n ;
    cin>>s+1;
    rep(i,1,n)
    {
        if(s[i]=='W')
        a[i]=a[i-1]+1;
        else a[i]=a[i-1];
    }
    per(i,n,1)
    {
        if(s[i]=='E')
        b[i]=b[i+1]+1;
        else b[i]=b[i+1];

    }
    int ans=n;
    rep(i,1,n)
    {
        ans=min(ans,a[i-1]+b[i+1]);
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3712
#include<cstdio>
#include<vector>
const long long inf=1ll<<60;
int N,MX,MY,id[1000010],Y[1000010],rk_Y[1000010];
struct Point{int i,x,y;}P[200010];
int diff(int x,int y){return x>y?x-y:y-x;}
int dist(Point*p,Point*q){return diff(p->x,q->x)+diff(p->y,q->y);}
void cmin(int&x,int y){y<x?x=y:1;}
void cmax(int&x,int y){y>x?x=y:1;}
int pre_len[200010]; 
long long ans[200010];
int main(){
	scanf("%d",&N);
	for(int i=0,x,y;i<N;i++){
		scanf("%d%d",&x,&y);
		id[x]=i;Y[x]=y;rk_Y[y]++;
		cmax(MX,x);cmax(MY,y);
	}
	for(int i=1;i<=MY;i++)rk_Y[i]+=rk_Y[i-1];
	for(int x=1,n=0;x<=MX;x++)if(Y[x])P[n++]=(Point){id[x],x,Y[x]};
	for(int L=0,R=0;L<N;L=R){
		int mn=rk_Y[P[L].y],mx=mn;
		for(R=L+1;R<N&&diff(rk_Y[P[R].y],rk_Y[P[R-1].y])==1;R++){
			cmin(mn,rk_Y[P[R].y]);
			cmax(mx,rk_Y[P[R].y]);
		}
		if(R-L>1){
			int l=L,r=R;
			long long dis[2][2]={{0,inf},{inf,0}};
			bool fl=1;
//			printf("L=%d R=%d\n",L,R);
			while(fl){
				fl=0;
				Point*p[2][2]={{P+l,P+r-1},{P+l,P+r-1}};
				int G[2][2]={0},last_mn=mn,last_mx=mx;
				bool dir=l&&P[l-1].y<P[l].y;
				for(;l;fl=1){
					int y=rk_Y[P[l-1].y];
					if(y==mn-1&&dir)--mn;
					else if(y==mx+1&&!dir)++mx;
					else break;
					--l;
					G[0][0]+=dist(p[0][0],P+l);G[0][1]+=dist(p[0][0],P+l)*2;
					G[1][0]+=dist(p[0][1],P+l);G[1][1]+=dist(p[0][1],P+l)*2;
					p[0][0]=p[0][1]=P+l;
//					printf("[%d,%d;%d,%d]\n",G[0][0],G[0][1],G[1][0],G[1][1]);
				}
				if(p[0][0]!=p[0][1])G[1][0]+=dist(p[0][0],p[0][1]);
				dir=r<N&&P[r].y>P[r-1].y;
				mn=last_mn;mx=last_mx;
				for(;r<N;fl=1){
					int y=rk_Y[P[r].y];
					if(y==mn-1&&!dir)--mn;
					else if(y==mx+1&&dir)++mx;
					else break;
					G[0][0]+=dist(p[1][0],P+r)*2;G[0][1]+=dist(p[1][0],P+r);
					G[1][0]+=dist(p[1][1],P+r)*2;G[1][1]+=dist(p[1][1],P+r);
					p[1][0]=p[1][1]=P+r;r++;
//					printf("[%d,%d;%d,%d]\n",G[0][0],G[0][1],G[1][0],G[1][1]);
				}
				if(p[1][0]!=p[1][1])G[0][1]+=dist(p[1][0],p[1][1]);
				cmin(mn,rk_Y[P[l].y]);
				cmax(mx,rk_Y[P[l].y]);
				long long d[2][2]={{inf,inf},{inf,inf}};
				for(int i=0;i<2;i++)
					for(int j=0;j<2;j++)
						for(int k=0;k<2;k++)if(dis[i][j]+G[j][k]<d[i][k])d[i][k]=dis[i][j]+G[j][k];
//				printf("l=%d r=%d\n",l,r);
				for(int i=0;i<2;i++)
					for(int j=0;j<2;j++)dis[i][j]=d[i][j];//,printf("d(%d,%d)=%lld\n",i,j,d[i][j]);
			}
			pre_len[L]=0;
			for(int i=L;i+1<R;i++)pre_len[i+1]=pre_len[i]+dist(P+i,P+i+1);
			for(int i=L;i<R;i++){
				long long d[2]={pre_len[R-1]*2-pre_len[i],pre_len[R-1]+pre_len[i]};
				ans[P[i].i]=inf;
				for(int j=0;j<2;j++)
					for(int k=0;k<2;k++)if(d[j]+dis[j][k]<ans[P[i].i])ans[P[i].i]=d[j]+dis[j][k];
				ans[P[i].i]-=r-l-1;
			}
		}
	}
	for(int i=0;i<N;i++)printf("%lld\n",ans[i]);
}

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

int main(){
  map<string, int> yen;
  int N;
  cin >> N;
  for(int i=0; i<N; ++i){
    string s;
    cin >> s;
    if(s.length()<1 || s.length()>10){
      return 0;
    }
    yen[s]++;
  }
  int M;
  cin >> M;
  for(int i=0; i<M; ++i){
    string s;
    cin >> s;
    if(s.length()<1 || s.length()>10){
      return 0;
    }
    yen[s]--;
  }
  int max = INT_MIN;
  for(auto y: yen){
    if(y.second > max){
      max = y.second;
    }
  }
  if (max < 0){ // この場合いずれにもない文字列をいえばいい
    max = 0;
  }
  cout << max << endl;
}

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

l = [int(input()) for i in range(N)]

new_l = sorted(l)

fmax = new_l[N-1]
fmax2 = new_l[N-2]
smax = fmax

for j in reversed(range(N)):
    if not new_l[j] == fmax:
        smax = new_l[j]
        break

if fmax == fmax2:
    for k in range(N):
        print(fmax)
else:
    for m in range(N):
        if l[m] == fmax:
            print(smax)
        else:
            print(fmax)

Measured memory_bytes: 19044
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;

const int N = 500+7;
int n;
int dis[N][N];
int vis[N][N];
int dx[]= {0,0,1,-1};
int dy[]= {1,-1,0,0};
void dfs(int x,int y)
{
    int now=dis[x][y]+vis[x][y];
    for(int i=0; i<4; i++)
    {
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx >= 0 && nx < n && ny >= 0 && ny < n && dis[nx][ny] > now)
        {
            dis[nx][ny] = now;
            dfs(nx, ny);
        }
    }
}
int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
        {
            vis[i][j] = 1;
            dis[i][j] = min(min(i, j), min(n - 1 - i, n - 1 - j));
        }
    int x,y;
    ll ans=0;
    for(int i = 0, u; i < n * n; i++)
    {
        cin>>u;
        u--;
        x=u/n;
        y=u%n;
        ans+=dis[x][y];
        vis[x][y]=0;
        dfs(x,y);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 24804
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int K = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         //dp[i] = longest increasing seq
         int res = 1;
         int[] dp = new int[N];
         dp[0] = 1;
         for(int i=1; i < N; i++)
         {
            if(arr[i] > arr[i-1])
               dp[i] = dp[i-1]+1;
            else
               dp[i] = 1;
         }
         TreeSet<Integer> curr = new TreeSet<Integer>();
         for(int i=0; i < K; i++)
            curr.add(arr[i]);
         boolean yeet = dp[K-1] >= K;
         if(yeet)
            res--;
         for(int i=1; i < N-K+1; i++)
         {
            int right = arr[K-1+i];
            int left = arr[i-1];
            if((curr.first() != left || curr.last() > right) && dp[K-1+i] < K)
               res++;
            else if(dp[K-1+i] >= K)
               yeet = true;
            curr.remove(left);
            curr.add(right);
         }
         if(yeet)
            res++;
         System.out.println(res);
      }
   }

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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N)cin >> A[i];
    sort(A.begin(),A.end());
    ll bA = 99999999999999;
    rep(i,N){
        if(bA==A[i]){
            cout << "NO" << endl;
            return 0;
        }
        bA = A[i];
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int,int> mii;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = b-1; i >= a; i--)
#define F0Rd(i,a) for (int i = a-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
const int MOD = 1000000007;
double PI = 4*atan(1);

vector<ll> a1, a2;
ll ans=0;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int N,K; cin >> N >> K;
	a1.resize(N+1), a2.resize(N+1);
	FOR(i,1,N+1) {
		ll x; cin >> x;
		a1[i] = x+a1[i-1];
		if (x>0) a2[i] = x+a2[i-1];
		else a2[i] = a2[i-1];
	}
	FOR(i,1,N-K+2) {
		ll temp = max((ll)0,a1[i+K-1]-a1[i-1]);
		temp += a2[N]-a2[i+K-1];
		temp += a2[i-1];
		ans = max(ans,temp);
		// cout << i << " " << temp << "\n";
	}
	cout << ans;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,a[5],am = INF,ami,ans;

signed main() {
    cin >> n;
    rep(i,5) {
        cin >> a[i];
        if (a[i] < am) am = a[i],ami = i;
    }
    ans += (n+a[ami]-1)/a[ami];
    ans += 4;
    cout << ans << endl;


}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N, K = MI()
    V = LI()
    max_iter = min(N, K)
    ans = 0
    for a in range(max_iter+1):
        left = V[:a]
        for b in range(0, max_iter-a+1):
            right = V[-b:] if b != 0 else []
            k = K - a - b
            # print(a, b, k)
            # print(left, right)
            lst = sorted(left + right)
            # print(lst)
            sm = sum(lst)
            l = len(lst)
            for kk in range(1, k+1):
                if kk < l:
                    tmp = lst[kk-1]
                    if tmp >= 0: break
                    sm -= tmp
                    # print(tmp)
                else:
                    break
            ans = max(ans, sm)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int a, b;
    cin >> a >> b;
    string ans = "";
    for(int i = 0; i < max(a, b); i++) {
        ans += '0' + min(a, b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
      
        int ans = 0;
        for(int i = 1; i <= n; i++) {
          ans += i;
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 22740