akhauriyash/Code-Regression huggingface dataset:
$dx = [0,1,0,-1]
$dy = [1,0,-1,0]
def bfs(f, sy, sx, h, w, n, cur)
    steps = Array.new(h).map{Array.new(w,-1)}
    steps[sy][sx] = 0
    q = [[sy,sx]]
    visited = Array.new(h).map{Array.new(w)}
    visited[sy][sx] = true
    while q.size > 0
        sy, sx = q.shift
        for i in 0..3
            cy = sy + $dy[i]
            cx = sx + $dx[i]
            if cy.between?(0,h-1) && cx.between?(0,w-1) && !visited[cy][cx] && f[cy][cx]!= "X"
                q.push([cy,cx])
                visited[cy][cx] = true
                if cur == f[cy][cx].to_i
                    return [steps[sy][sx] + 1, cy, cx]
                end
                steps[cy][cx] = steps[sy][sx] + 1
            end
        end
    end
end

h, w, n = gets.split.map(&:to_i)
f = h.times.map{gets.chomp}
sy = sx = 0
f.each_with_index do |r,i|
    if r.include?("S")
        sy = i
        sx = r.index("S")
        break
    end
end
ret = 0
1.upto(n) do |i|
    a = bfs(f, sy, sx, h, w, n, i)
    ret += a[0]
    sy = a[1]
    sx = a[2]
end
puts ret

Measured memory_bytes: 30780
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    string s,t; cin>>s>>t;
    cout<<t<<s<<endl;
}

Measured memory_bytes: 256
<>=~$";$/=$";$a=<>-$';
sub f{
    my($a,$b)=@_;
    ($a,$b)=($b,$a)if($a>$b);
    until($a==0){
        ($a,$b)=($b%$a,$a)
    }
    return $b;
}
$a=&f($a,$_-$')for<>;
print abs($a)

Measured memory_bytes: 17664
#include <iostream>
#include <vector>
using namespace std;
int c[100][100];
int w, h;
void dfs(int x,int y) {
	c[x][y] = 0;
	for (int i = -1; i <= 1; i++) {
		for (int j = -1; j <= 1; j++) {
			if (x + i < w&&x + i >= 0 && y + j >= 0 && y + j < h) {
				if (c[x + i][y + j] == 1) {
					dfs(x + i, y + j);
				}
			}
		}
	}
}

int main(void) {
	int ans;
	while (1) {
		ans = 0;
		cin >> w >> h;
		if (w == 0 && h == 0) {
			break;
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> c[j][i];
			}
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (c[j][i] == 1) {
					dfs(j, i);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3220
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
c = [0]*n
for i in range(n):
    b[i] = i - a[i]
for j in range(n):
    c[j] = a[j] + j
b.sort()
c.sort()
#print(b)
#print(c)
i = 0
j = 0
k = 0
m = 0
count = 0
while i < n and j < n:
    if b[i] < c[j]:
        i += 1
    elif b[i] > c[j]:
        j += 1
    else:
        k = i
        m = j
        ck = 0
        cm = 0
        while k < n - 1:
            if b[k] == b[k+1]:
                ck += 1
                k += 1
            else:
                break
        while m < n - 1:
            if c[m] == c[m+1]:
                cm += 1
                m += 1
            else:
                break
        if ck == 0 and cm == 0:
            count += 1
            if i < n-1:
                i += 1
            elif j < n-1:
                j += 1
            else:
                i += 1
                j += 1
        elif ck == 0:
            count += cm + 1
            j = m + 1
        elif cm == 0:
            count += ck + 1
            i = k + 1
        else:
            count += (ck+1)*(cm+1)
            i = k + 1
            j = m + 1        
print(count)

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

const int nmax = 8;
vector<vector<int>> graph(nmax, vector<int>(nmax, 0));

int dfs(int v, int N, vector<bool> visited) {
  bool all_visited=true;

  for (int i=0; i<N; i++) {
    if (visited[i] == false) all_visited=false;
  }
  if (all_visited) return 1;

  int ret=0;
  for (int i=0; i<N; i++) {
    if (graph[v][i] == false) continue;
    if (visited[i]) continue;

    visited[i] = true;
    ret += dfs(i, N, visited);
    visited[i] = false;
  }
  return ret;
}

void solve()
{
  int ans=0;

  int n; cin >> n;
  int m; cin >> m;

  for (int i=0; i<m; i++) {
    int a, b;
    cin >> a >> b;
    graph[a-1][b-1] = 1;
    graph[b-1][a-1] = 1;
  }

  vector<bool> visited(nmax, false);
  visited[0] = true;
  ans = dfs(0, n, visited);

  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[300007];
int dp[2][300007],ans=0;
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<(1<<n);i++){
		cin>>a[i];
		dp[0][i]=a[i];
	}
	for(int i=0;i<n;i++){
		for(int mask=0;mask<(1<<n);mask++){
			if(mask&(1<<i)){
				dp[1][mask]=max(dp[1][mask],dp[0][mask^(1<<i)]);
				if(dp[0][mask]<dp[1][mask]) swap(dp[0][mask],dp[1][mask]);
			}
		}
	}
	for(int i=1;i<(1<<n);i++){
		ans=max(ans,dp[0][i]+dp[1][i]);
		cout<<ans<<"\n";
	}
}


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

using namespace std;

void solve()
{
    int N, X, T; cin >> N >> X >> T;

    int ans = (N + (X-1))/ X;

    cout << ans * T << endl;
}

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

    //int TT;
    //cin >> TT;

    //for (int T = 0; T < TT; T++) {
        solve();
    //}
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>

int main(void)
{
        int hen1 = 0, hen2 = 0, x = 0;
        int ccount = 0 , hcount = 0;

        while(scanf("%d,%d,%d",&hen1, &hen2, &x) != EOF)
        {


                        if(hen1 == hen2)
                        {
                                hcount++;
                        }
                        else if(x*x == hen1*hen1 + hen2*hen2)
                        {
                                ccount++;
                        }
        }
        printf("%d\n",ccount);
        printf("%d\n",hcount);
        return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;


int main() {
  ll N,K;
  cin>>N>>K;
  vector<pair<ll,ll>> a(N+1);
  a[0]={0,0};
  for(int i=1;i<=N;i++){
    cin>>a[i].first>>a[i].second;
  }
  sort(a.begin(),a.end());
  for(int i=1;i<=N;i++){
    a[i].second+=a[i-1].second;
  }
  for(int i=0;i<=N;i++){
    if(a[i].second>=K){
      cout<<a[i].first;
      break;
    }
  }
  
}

Measured memory_bytes: 1792
#include <stdio.h>

int main (void){

	long long N,i,j,k;
  	long long A[101],B[101];
  	long long sum = 0;
  	long long min=1000000000;
  	scanf("%lld",&N);
  	for(i=0;i<N;i++){
    	scanf("%lld",&A[i]);
    }
  	
  	for(i=-100;i<=100;i++){
    	for(j=0;j<N;j++){
        	B[j] = (A[j]-i)*(A[j]-i);
          	sum +=B[j];
        }
      	if(min>sum){
        	min=sum;
          	//printf("%lld\n",min);
        }
      	sum=0;
    }
  	printf("%lld",min);
  	return 0;
}


Measured memory_bytes: 1692
N = int(input())
X = list(map(int, input().split()))
S = sum(X)
M = min(X)
if N % 2:
    if S%2:
        print("First")
    else:
        print("Second")
else:
    if S%2:
        print("First")
    elif M%2:
        print("First")
    else:
        print("Second")



Measured memory_bytes: 28344
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
    int N, M;
    int running_sum = 0;
    cin >> N >> M;
    while (M > 0) {
        int days;
        cin >> days;
        running_sum += days;
        M--;
    }

    if (N < running_sum) {
        cout << -1 << endl;
    } else {
        cout << N - running_sum << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
MOD = 998244353

lim = 200000
inv_t = [-1 for i in range(lim+1)]
factrial = [-1 for i in range(lim+1)]
factrial_inv = [-1 for i in range(lim+1)]


def set_inv(max=lim):
    inv_t[0] = 0
    for i in range(1, max):
        inv_t[i] == mod_inv(i)


def mod_inv(x, mod=MOD):
    y, u, v, _x = mod, 1, 0, x
    while y:
        t = _x//y
        _x -= t*y
        _x, y = y, _x
        u -= t*v
        u, v = v, u
    u %= mod
    if u < 0:
        u += mod
    return u


def mod_pow(a, n, mod=MOD):
    res = 1
    while n:
        if n & 1:
            res = res*a % mod
        a = a*a % mod
        n >>= 1
    return res


def set_factrial(max=lim, mod=MOD):
    c = 1
    factrial[0] = factrial_inv[0] = 1
    for i in range(1, max):
        c *= i
        c %= mod
        factrial[i] = c
        factrial_inv[i] = mod_inv(c, mod)


def comb(a, b, mod=MOD):
    if factrial[0] == -1:
        set_factrial()
    return (factrial[a]*factrial_inv[b]*factrial_inv[a-b]) % mod


n, m, k = [int(_) for _ in input().split()]
ans = 0
for i in range(k+1):
    ans += m*comb(n-1, i)*mod_pow(m-1, n-1 - i)
    ans %= MOD
    # print(ans)
print(ans)


Measured memory_bytes: 26324
#include <bits/stdc++.h>
#define MAX (int)1e5+1
using namespace std;

int main(){
  int n,m,x[MAX],
      i,j,las,sum=0;
  array <int,2> a[MAX];
  
  cin >> n >> m;
  for(i=0;i<m;i++){
    cin >> x[i];
  }
  sort(x,x+m);
  
  for(i=0;i<m-1;i++){
    a[i][0] = i;
    a[i][1] = x[i+1]-x[i];
  }
  
  if(m<=n){
    cout << 0;
    return 0;
  }
  
  sort(a,a+m-1,[](auto& k, auto& l){return k[1] > l[1];});
    
  sort(a,a+n-1,[](auto& k, auto& l){return k[0] < l[0];});
  
  for(i=0,las=0;i<n-1;i++){
    sum += x[a[i][0]] - x[las];
    las = a[i][0] + 1;
  }
  sum += x[m-1] - x[las];
  
  cout << sum;
  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>

void merge(int arr[], int l, int m, int r) 
{ 
    int i, j, k; 
    int n1 = m - l + 1; 
    int n2 =  r - m; 
  
    /* create temp arrays */
    int L[n1], R[n2]; 
  
    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++) 
        L[i] = arr[l + i]; 
    for (j = 0; j < n2; j++) 
        R[j] = arr[m + 1+ j]; 
  
    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray 
    j = 0; // Initial index of second subarray 
    k = l; // Initial index of merged subarray 
    while (i < n1 && j < n2) 
    { 
        if (L[i] <= R[j]) 
        { 
            arr[k] = L[i]; 
            i++; 
        } 
        else
        { 
            arr[k] = R[j]; 
            j++; 
        } 
        k++; 
    } 
  
    /* Copy the remaining elements of L[], if there 
       are any */
    while (i < n1) 
    { 
        arr[k] = L[i]; 
        i++; 
        k++; 
    } 
  
    /* Copy the remaining elements of R[], if there 
       are any */
    while (j < n2) 
    { 
        arr[k] = R[j]; 
        j++; 
        k++; 
    } 
} 
  
/* l is for left index and r is right index of the 
   sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r) 
{ 
    if (l < r) 
    { 
        // Same as (l+r)/2, but avoids overflow for 
        // large l and h 
        int m = l+(r-l)/2; 
  
        // Sort first and second halves 
        mergeSort(arr, l, m); 
        mergeSort(arr, m+1, r); 
  
        merge(arr, l, m, r); 
    }  
} 

int countTriangles(int* arr, int n)
{
   
    mergeSort(arr, 0, n-1);
    int i,j,count = 0;
    int k=0;;
    for( int i = n-1; i >= 1; i--)
    { 
        int l = 0, r = i-1; 
        while( l < r)
        { 
            if( arr[l] + arr[r] > arr[i])
            { 
                count += r - l ;  
                r--;   
            } 
            else 
            {
                l++;
            }
        } 
    } 
    return count;
}

int main()
{
    int i,result,j,k, N;
    int* num;

    scanf("%d",&N);
    num = (int*)malloc(N * sizeof(int));
    for(i=0;i<N;i++)
    {
        scanf("%d",&num[i]); 
    }
    
    printf("%d",countTriangles(num,N));
}

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

int main(){
  int a, b, c, N;
  int flag[3][1000], judge[1000], info[301];

  while(cin >> a >> b >> c , a+b+c){
    fill_n(info,301,2);
    cin >> N;
    for(int i = 0 ; i < N ; i++ ){
      for(int j = 0 ; j < 3 ; j++) cin >> flag[j][i];
      cin >> judge[i];
      if(judge[i] == 1) for(int j = 0 ; j < 3 ; j++ ) info[flag[j][i]] = 1;
    }
    for(int i = 0 ; i < N ; i++ ){
      if(!judge[i]){
        for(int j = 0 ; j < 3 ; j++){
          if(info[flag[j][i]] == 1 && info[flag[(j+1)%3][i]] == 1){
            info[flag[(j+2)%3][i]] = 0;
          }
        }
      }
    }
    for(int i = 1 ; i <= a+b+c ; i++ ) cout << info[i] << endl;
  }
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N, 0);
    REP(i, N)
    {
        cin >> A[i];
    }

    // A を降順に並び替える
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    //　長方形候補の辺の長さ(a >= b)
    ll a = 0, b = 0;
    bool aFlag = false, bFlag = false;
    for (int i = 1; i < N; ++i)
    {
        if (!aFlag)
        {
            if (A[i] == A[i -1])
            {
                a = A[i];
                aFlag = true;
                i++;
            }
        }
        else if (!bFlag)
        {
            if (A[i] == A[i -1])
            {
                b = A[i];
                bFlag = true;
            }
        }

        if (aFlag && bFlag)
        {
            break;
        }
    }

    ll ans = a * b;
    cout << ans << endl;
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const int N = 1e6+5;
string s,t = "Yes";
vector<int> v[N];
int n,result;
int a[N];

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

  cin >> s;
  if(s == "SUN") n = 7;
  else if(s=="MON") n=6;
  else if(s=="TUE") n=5;
  else if(s=="WED") n=4;
  else if(s=="THU") n=3;
  else if(s=="FRI") n=2;
  else if(s=="SAT") n=1;
  cout << n << endl;
}


Measured memory_bytes: 25600
import java.util.Scanner;

public class Main {
	
	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			int w = sc.nextInt();
			int h = sc.nextInt();
			sc.nextLine();
			if(w == 0 && h == 0) break;
			else calc(w,h);
		}
	}

	public void calc(int w, int h){
		int[][] tile = new int[w][h];
		int nowX = 0;
		int nowY = 0;
		for(int j = 0; j < h; j++){
			String line = sc.nextLine();
			for(int i = 0; i < w; i++){
				char c = line.charAt(i);
				if(c == '.') tile[i][j] = 1;
				else if(c == '@'){
					tile[i][j] = 1;
					nowX = i;
					nowY = j;
				}
			}
		}
		System.out.println(calc2(tile, tile, nowX, nowY));
	}
	public int calc2(int[][] tile, int[][] tile2, int X, int Y){
		tile2[X][Y] = 0;
 		int ue = 0;
		if(Y > 0 && tile[X][Y-1] == 1 && tile2[X][Y-1] != 0) 
			ue = calc2(tile, tile2, X, Y-1);
		int shita = 0;
		if(Y < tile[X].length - 1 && tile[X][Y+1] == 1 && tile2[X][Y+1] != 0) 
			shita = calc2(tile, tile2, X, Y+1);
		int hidari = 0;
		if(X > 0 && tile[X-1][Y] == 1 && tile2[X-1][Y] != 0)
			hidari = calc2(tile, tile2, X-1, Y);
		int migi = 0;
		if(X < tile.length - 1 && tile[X+1][Y] == 1 && tile2[X+1][Y] != 0)
			migi = calc2(tile, tile2, X+1, Y);
		
		return ue + shita + migi + hidari + 1;
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 41212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P, ll> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, d;
    cin >> n >> d;
    cout << (n-1)/(d*2+1)+1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF 1e9+7
#define LLINF 1e18
// #define int ll
using namespace std;
const int MOD = 1e9 +7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    if(a>=13) cout<<b<<endl;
    else if(a>=6 && a<=12) cout<<b/2<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<iomanip>
#include<fstream>
#include<ctime>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

int n, i, a, res;
map<int, int> mapa;
map<int, int>::iterator it;

int main() {
scanf("%d", &n);
mapa.clear();
for (i=0;i<n;i++) {
	scanf("%d", &a);
	mapa[a]++;
}
res = 0;
for (it = mapa.begin();it!=mapa.end();it++) {
	if (it->second < it->first) res += it->second;
	else res += it->second - it->first;
}
printf("%d\n", res);
return 0;
}



Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <sstream>
#include <iomanip>
using namespace std;
int main(void){
  int N;
  string S;
  cin >> N;
  cin >> S;
  
  int count = 0;
  for(int i=0;i<1000;i++){
    std::ostringstream sout;
    sout << std::setfill('0') << std::setw(3) << i;
    std::string s = sout.str();
    
    int pos = 0;
    for(int j=0;j<N;j++){
      if(s[pos]==S[j]){
        pos++;
        if(pos==3){
          count++;
          break;
        }
      }
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();
            int X = sc.nextInt();
            int[] C = new int[N];
            int[][] A = new int[N][M];
            for (int i = 0; i < N; i++) {
                C[i] = sc.nextInt();
                for (int j = 0; j < M; j++) {
                    A[i][j] = sc.nextInt();
                }
            }

            int inf = (int) 1e9;
            int min = inf;
            maskLoop: for (int mask = 0; mask < (1 << N); mask++) {
                int[] sum = new int[M];
                for (int i = 0; i < N; i++) {
                    if ((mask & (1 << i)) == 0) {
                        continue;
                    }
                    for (int j = 0; j < M; j++) {
                        sum[j] += A[i][j];
                    }
                }
                for (int j = 0; j < M; j++) {
                    if (sum[j] < X) {
                        continue maskLoop;
                    }
                }

                int cost = 0;
                for (int i = 0; i < N; i++) {
                    if ((mask & (1 << i)) == 0) {
                        continue;
                    }
                    cost += C[i];
                }
                if (cost < min) {
                    min = cost;
                }
            }

            System.out.println(min == inf ? -1 : min);
        }
    }

    private static boolean isValid(int mask, int[][] a, int x) {
        return false;
    }
}


Measured memory_bytes: 28848
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int N;
    cin >> N;
    int ans = 0;
    srep(i,1,N/2+1) {
        int p = N - i;    
        if (p != i) ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

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

int main()
{
  string s;
  cin >> s;
  rep(i,4)
    {
      cout << s[i];
    }
  cout << " ";
  for(int i = 4; i < 12; i++)
    {
      cout << s[i];
    }
  cout << endl;

  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(cin >> s){
		if(s[0]=='S') cout << "Cloudy\n";
		else if(s[0]=='C') cout << "Rainy\n";
		else if(s[0]=='R') cout << "Sunny\n";
	}
}

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

#define el '\n'

using namespace std;

int pc[18];

int main() {
    int m,k;
    
    cin >> m >> k;
    for (int i=0;i<18;i++) pc[i]=1<<i;
    
    if (k>=pc[m]){
        cout << -1 << el;
        return 0;
    } 
    
    if (m==1){
        if (k==1){
            cout << -1 << el;
            return 0;
        } 
        cout << "0 0 1 1" << el;
        return 0;
    }
    
    int n=pc[m]*2;
    int ans[n],conv=(k^(pc[m]-1));
    
    ans[0]=0;
    ans[1]=pc[m]-1;
    ans[2]=0;
    for (int pl=0;pl<pc[m]-1;pl++){
        ans[3+pl]=pl+1;
        ans[n-1-pl]=pl+1;
    }
    
    for (int i=0;i<n-1;i++){
        cout << (ans[i]^conv) << " ";
    }
    cout << (ans[n-1]^conv) << el;
    
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX=200000;
int main(){
    int R[MAX],n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>R[i];
    int maxv=-2000000000;
    int minv=R[0];
    for(int i=1;i<n;i++){
        maxv=max(maxv,R[i]-minv);
        minv=min(minv,R[i]);
    }
    cout<<maxv<<endl;
    return 0;
}



Measured memory_bytes: 3852
object Main extends App {
  val Array(n, m, x, y) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  val x_list = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList
  val y_list = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList

  var ans = false

  (x + 1 until y).foreach { z =>
    if (ans || (x_list.forall(_ < z) && y_list.forall(_ >= z))) {
      ans = true
    }
  }


  if (ans) {
    println("No War")
  } else {
    println("War")
  }
}


Measured memory_bytes: 27460
N = int(input())
sch = []
for _ in range(N):
    x, l = map(int, input().split())
    sch.append([x + l, x - l])

sch.sort()
ans = 0
t = -float('inf')
for ed, st in sch:
    if t <= st:
        ans += 1
        t = ed
print(ans)

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long

const int N = 1e2 + 10;
const int mod = 1e9 + 7;


map<int, int> mp;

void fac(int n){
	while(n%2 == 0){
		n /= 2;
		mp[2]++;
	}
	int sq = sqrt(n);
	for(int i = 3 ; i <= sq ; i+=2){
		while(n%i == 0){
			n /= i;
			mp[i]++;
		}
	}

	if(n != 1){
		mp[n]++;
	}

}
int32_t main(){
	boost;
	int n , a , b;
	cin >> n >> a >> b;
	int arr[n];

	for(int i = 0; i < n ; ++i){
		cin >> arr[i];
	}
	int ans = 0;
	for(int i = 1 ;  i < n ; ++i){
		ans += min( (arr[i] - arr[i-1]) * a , b);
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int main()
{
	char c[50];
	scanf("%s",c);
	for(int i=0;i<5;i++)
	printf("%c",c[i]);
	printf(" ");
	for(int i=6;i<13;i++)
	printf("%c",c[i]);
	printf(" ");
	for(int i=14;i<19;i++)
	printf("%c",c[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define DIV (1000000007)

int main(void) {
	int N;
	long long ans = 1;
	cin >> N;

	vector <pair<int, int>> sosu;

	// 素数を計算
	for (int i = 2; i <= N; i++) {
		int x = i;
		for (int j = 0; j < sosu.size(); j++) {
			int y = sosu[j].first;
			while (x % y == 0) {
				x /= y;
				sosu[j].second++;
			}
		}
		if (x == i) {
			sosu.push_back(make_pair(x, 1+1)); // 1とその数自身で1+1
		}
	}

	for (int i = 0; i < sosu.size(); i++) {
		ans *= sosu[i].second;
		ans = ans % DIV;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp72 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int W = st[0];
            int H = st[1];
            int N = st[2];

            var x = new int[N];
            var y = new int[N];
            var a = new int[N];

            for (int i = 0; i < N; i++) {
                var b = Console.ReadLine().Split().Select(int.Parse).ToArray();
                x[i] = b[0];
                y[i] = b[1];
                a[i] = b[2];
            }

            int x_min = 0;
            int x_max = W;
            int y_min = 0;
            int y_max = H;

            for (int i = 0; i < N; i++) {
                switch (a[i]) {
                    case 1:
                        x_min = Math.Max(x_min, x[i]);
                        break;
                    case 2:
                        x_max = Math.Min(x_max, x[i]);
                        break;
                    case 3:
                        y_min = Math.Max(y_min, y[i]);
                        break;
                    case 4:
                        y_max = Math.Min(y_max, y[i]);
                        break;
                }
            }

            Console.WriteLine(Math.Max(x_max - x_min, 0) * Math.Max(y_max - y_min, 0));

        }
    }
}

Measured memory_bytes: 13268
open System
open System.Linq;


let N=stdin.ReadLine()|>int
let d=stdin.ReadLine().Split()|>Array.map int

[<EntryPoint>]
let sf argv =
    let mutable ans=0
    for i in [0..N-2] do
        for j in [i+1..N-1] do
            ans <- ans + d.[i]*d.[j]
    printfn "%d" ans
    0 

Measured memory_bytes: 14044
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  V<> t(n), d(n); for (int i = 0; i < n; ++i) cin >> t[i] >> d[i], --t[i];
  V<> mx(n);
  for (int i = 0; i < n; ++i) {
    mx[t[i]] = max(mx[t[i]], d[i]);
  }
  auto _mx = mx;
  sort(rbegin(_mx), rend(_mx));
  V<lint> cmx(n + 1);
  for (int i = 0; i < n; ++i) {
    cmx[i + 1] = cmx[i] + _mx[i];
  }
  for (int i = 0; i < n; ++i) {
    if (mx[t[i]] == d[i]) {
      mx[t[i]] = d[i] = 0;
    }
  }
  sort(rbegin(d), rend(d));
  V<lint> cd(n + 1);
  for (int i = 0; i < n; ++i) {
    cd[i + 1] = cd[i] + d[i];
  }
  lint res = 0;
  int m = set<int>(begin(t), end(t)).size();
  for (lint x = 1; x <= min(m, k); ++x) {
    res = max(res, cmx[x] + cd[k - x] + x * x);
  }
  cout << res << '\n';
}

Measured memory_bytes: 8064
#include <iostream>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;

int main(void) {
    Int n, y;
    cin >> n >> y;
    for (Int i = 0; i <= min(y / 10000, n); ++i) {
        for (Int j = 0; j <= min(y / 5000, n - i); ++j) {
            if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y) {
                cout << i << " " << j << " " << n - i - j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}



Measured memory_bytes: 3640
def main():
    N = int(input())
    P = [int(_) for _ in input().split()]

    i = 1
    output = 0
    while i <= N:
        if i == P[i-1]:
            output += 1
            if i < N and i+1 == P[i]:
                i += 2
                continue
        i += 1
    print(output)
    return

if __name__ == '__main__':
    main()


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

vector<int> in, pre;

typedef struct _node {
  int id;
  struct _node *left;
  struct _node *right;
} node;

node *new_node(int id, node *l, node *r)
{
  node *v = (node *)malloc(sizeof(node));
  v->id = id;
  v->left = l;
  v->right = r;
  return v;
}

pair<node *, int> tree(int pre_i, int in_l, int in_r)
{
  if (in_l+1 == in_r) {
    if (in[in_l] != pre[pre_i]) {
      cerr << "error" << endl;
      return make_pair((node *)NULL, pre_i);
    }
    return make_pair(
             new_node(in[in_l], NULL, NULL),
             pre_i+1
           );
  } else {
    int root = pre[pre_i];
    int sep = -1;
    for (int i = in_l; i < in_r; i++) {
      if (root == in[i]) {
        sep = i;
        break;
      }
    }
    if (sep == -1)
      return make_pair((node *)NULL, pre_i);

    pair<node *, int> p = tree(pre_i+1, in_l, sep);
    node *l = p.first;
    pair<node *, int> q = tree(p.second, sep+1, in_r);
    node *r = q.first;
    return make_pair(
             new_node(root, l, r),
             q.second
           );
  }
}

void postorder(node *v, vector<int> &out)
{
  if (v == NULL) return;
  postorder(v->left, out);
  postorder(v->right, out);
  out.push_back(v->id);
}
void output(node *v)
{
  if (v == NULL) {
    cout << "*";
    return;
  }
  cout << "(" << v->id << " ";
  output(v->left);
  cout << " ";
  output(v->right);
  cout << ")";
}


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

  node *v = tree(0, 0, n).first;
  // output(v);
  vector<int> out;
  postorder(v, out);
  for (int i = 0; i < out.size(); i++)
    cout << out[i] << (i==out.size()-1?'\n':' ');

  return EXIT_SUCCESS;
}




Measured memory_bytes: 3160
a = list(map(int, input().split(" ")))
 
p1 = (a[0], a[1])
p2 = (a[2], a[3])
 
dif = (p2[0]-p1[0], p2[1]-p1[1])
 
p3 = (p2[0]-dif[1], p2[1]+dif[0])
p4 = (p3[0]-dif[0], p3[1]-dif[1])
 
print(p3[0], p3[1], p4[0], p4[1])

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

int a[105],n,cnt;

bool check(int z,int b,int c) {
    if(z+b <= c || z + c <= b || b + c <= z) {
        return false;
    }
    return true;
}

int main() {
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    for(int i=0;i<n;i++) {
        for(int j=i;j<n;j++) {
            for(int k=j;k<n;k++) {
                if(i == k || j == k || i == j)continue;
                if(a[i] == a[j] || a[i] == a[k] || a[j] == a[k])continue;
                if(check(a[i],a[j],a[k])) {
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, x, y;
    cin>>x>>y;
    if(y%2){
        cout<<"No"<<'\n';
    }
    else{
        b=(y/2)-x;
        a=x-b;
        if(a>=0 && b>=0){
            cout<<"Yes"<<'\n';
        }
        else{
            cout<<"No"<<'\n';
        }
    }
    return 0;
}   

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>

using namespace std;

signed main() {
   
   string s;
   cin>>s;
   long long j=0;
  long long k=0;
   if(s[0]=='A'){
      for(int i=1;i<s.size();i++){
         if(s[i]>='A'&&s[i]<='Z') j++;
        if(i>1&&i<s.size()-1&&s[i]=='C') k++;
      }
   }
   cout<<((j==1&&k==1)?"AC":"WA")<<endl;
}











Measured memory_bytes: 256
# coding: UTF-8
def euclidean_algorithm(x,y):
    if x > y:
        p = y
        r = x%y
        while r != 0:
            a = p
            b = r
            p = b
            r = a%b
        return p
    elif x == y:
        return x
    elif x < y:
        p = x
        r = y%x
        while r != 0:
            a = p
            b = r
            p = b
            r = a%b
        return p

num1,num2 = raw_input().split()
maximam = euclidean_algorithm(int(num1), int(num2))
print(maximam)



Measured memory_bytes: 4664
#include <stdio.h>
int main(void){
    int a, b, c;
    0 <= a, b, c <= 100;
    scanf("%d %d %d",&a, &b, &c);
    if(a < b && b < c)
         printf("Yes\n");
    else
        printf("No\n");
    return 0;
}



Measured memory_bytes: 2044
import time
from random import randint
d = int(input())
c = list(map(int,input().split()))
starttime = time.time()
timelimit = 1.8
ans = []
fin = [1]*d
pen = [0]*26
sattemp = 0
sat = 0
sl = [list(map(int,input().split())) for i in range(d)]
for i in range(d):
    s = sl[i]
    sp = sum(pen)
    temp = -(10**9)
    for j in range(26):
        if s[j]-(sp-pen[j]) > temp:
            temp = s[j]-(sp-pen[j])
            tempans = j+1
    ans += [tempans]
    sat += s[tempans-1]-sp+pen[tempans-1]
    for j in range(26):
        pen[j] += c[j]
        pen[tempans-1] = 0
fin = ans
ans = []
pen = [0]*26
while time.time() - starttime <= timelimit:
    ans = fin
    d1 = randint(0,d-1)
    d2 = randint(d1,min(d-1,d1+15))
    if randint(0,1):
        ans[d1],ans[d2] = ans[d2],ans[d1]
    else:
        ans[d1] = randint(1,26)

    pen = [0]*26
    sattemp = 0
    for i in range(d):
        # print(i,fin,fin[i])
        s = sl[i]
        sp = sum(pen)
        tempans = ans[i]
        sattemp += s[tempans-1]-sp+pen[tempans-1]
        for j in range(26):
            pen[j] += c[j]
            pen[tempans-1] = 0
        # print(sattemp)
    if sattemp > sat:
        fin = ans
        sat = sattemp
        # print(sat)

for i in fin:
    print(i)
# print(sat)

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
    if(s== "SUN"){
      cout << 7 << endl;
    }
    if(s== "MON"){
      cout << 6 << endl;
    }
    if(s=="TUE"){
      cout << 5 << endl;
    }
    if(s=="WED")
      cout << 4 << endl;
    if(s=="THU")
      cout << 3 << endl;
    if(s=="FRI")
      cout << 2 << endl;
    if(s=="SAT")
      cout << 1 << endl;

  return 0;
}


Measured memory_bytes: 888
#include<iostream> 
using namespace std;
int main()
{
	long long n,a,b,x,y,tir=0;;
	cin>>n>>a>>b>>x;
	n--;
	while(n--){
		cin>>y;
		if((y-x)*a>b)tir+=b;
		else tir+=(y-x)*a;
		x=y;
	}cout<<tir;
	return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n;
    cin>>n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    ll first=0,second=0;
    for (int i = 0; i < n; i++)
    {
        if(a[i]>=first)
        {
            second = first;
            first = a[i];
        }
        else if(a[i]>=second)
        {
            second = a[i];
        }
    }
    for (int i = 0; i < n; i++)
    {
        if(a[i]==first)
        {
            cout<<second<<endl;
        }
        else cout<<first<<endl;
    }
    
        
    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define base 200000
#define inf 0x3f3f3f3f
using namespace std;
int n,m,x,y,w,ans,maxn,minn,dist[100010],vi[100010];
vector<int> g[100010],l[100010];
queue<int> q;
bool flag=false;

bool spfa(int s){
	memset(dist,0x3f,sizeof(dist));
	dist[s]=0,maxn=minn=0,q.push(s),vi[s]=1;
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=0;i<g[u].size();i++){
			int v=g[u][i];
			if(!vi[v]){
				dist[v]=dist[u]+l[u][i];
				q.push(v),vi[v]=1;
				maxn=max(maxn,dist[v]),minn=min(minn,dist[v]);
			}
			else if(dist[v]!=dist[u]+l[u][i]) return true;
		}
	}
	return false;
}

int main(){
//	freopen("line.in","r",stdin);
//	freopen("line.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&x,&y,&w);
		g[x].push_back(y),l[x].push_back(w),g[y].push_back(x),l[y].push_back(-w);
	}
	for(int i=1;i<=n;i++){
		if(!vi[i]){
			flag=spfa(i);
			if(flag){
//				printf("impossible");
				printf("No");
				return 0;
			}
			ans=max(ans,maxn-minn);
		}
	}
//	printf("%d",ans);
	printf("Yes");
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

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

    // シグマ計算をするとkからn+1までの和をいい感じに計算できる
    // 答えは
    // M = N + 1, L = K - 1とおくと、
    // M(M^2 + 5) / 6 + L(2L^2 + 3L - 5 - 3M(L+1)) / 6となる

    long long m = n + 1;
    long long l = k - 1;
    long long ans = m * (m * m + 5) / 6 + l * (2 * l * l + 3 * l - 5 - 3 * m * (l + 1)) / 6;
    cout << ans % MOD << endl;
}

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

b = [0] * n

for i in range(n-1):
    if a[i] + b[i] > a[i+1]:
        b[i+1] += (a[i] + b[i]) - a[i+1]
ans = sum(b)
print(ans)


Measured memory_bytes: 32228
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  //input
  lint n,m,i;cin>>n>>m;
  vint l(m);vint r(m);
  for(i=0;i<m;i++){
    cin>>l[i]>>r[i];
  }
  //caricurate
  lint s,e;
  s=*max_element(l.begin(),l.end());
  e=*min_element(r.begin(),r.end());
  //output
  if(e<s){e=s-1;}
  cout<<(e-s+1)<<endl;
}

Measured memory_bytes: 1024
n,a,b = map(int,input().split())
l = list(map(int,input().split()))
ans = 0

for i in range(1,n):
  if (l[i]-l[i-1])*a >= b:
    ans += b
  else:
    ans += (l[i]-l[i-1])*a
print(ans)

Measured memory_bytes: 15020
#include<bits/stdc++.h>
#include<vector>
using namespace std;
vector< vector<int> > c(50, vector<int> (50));
void dfs(int x, int y, int w, int h){
  c[y][x] = 0;

  for(int i = -1 ; i <= 1 ; i++){
    for(int j = -1 ; j <= 1 ; j++){
      int nx = x + i, ny = y + j;

      if(0 <= nx && nx < w && 0 <= ny && ny < h && c[ny][nx] == 1)
        dfs(nx, ny, w, h);
    }
  }
}

int main(void){

while(true){
  int w, h;   cin >> w >> h;
  if(w == 0 && h == 0)    break;
  for(int i = 0 ; i < h ; i++){
    for(int j = 0 ; j < w ; j++){
      cin >> c[i][j];
    }
  }

  int ans = 0;
  for(int i = 0 ; i < h ; i++){
    for(int j = 0 ; j < w ; j++){
      if(c[i][j] == 1){
        dfs(j, i, w, h);
        ans++;
      }
    }
  }

  cout << ans << endl;
}

  return 0;
}


Measured memory_bytes: 3280
#include <iostream>
using namespace std;
const int MAXN=2e5+7;
int n,k,a[MAXN];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=k+1;i<=n;i++)
		if(a[i]>a[i-k]) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
#define debug(a,b) cerr << #a<<" = "<<a<<"   |   "<<#b<<" = "<<b<<'\n'
#define endl '\n'
#define SZ(a) ((int)a.size())
using namespace std;
typedef pair<int, int> pi32;
typedef pair<ll, ll> pi64;
typedef vector<int> vi32;
typedef vector<ll> vi64;
typedef vector<pi32> vp32;
typedef vector<pi64> vp64;
const ll mod = 1e9 + 7;
const int MX = 2e5+7;
//vector<int>adj[MX];

int dist[MX];
int ans[MX];
int main()
{
      int n,m;
      cin>>n>>m;
      vector<vector<int>>adj(n+1);
      for(int i=0;i<m;i++){
		  int u,v;cin>>u>>v;
		  adj[u].pb(v);
		  adj[v].pb(u);
	  }
	  //for(int i=1;i<=n;i++){
		  //cout<<i<<" : "; 
		  //for(auto it:adj[i])cout<<it<<' ';
		  //cout<<endl;
	  //}
	   
	   for(int i=1;i<=n;i++)dist[i]=1e9;
	   dist[1]=0;
	   queue<int>q;q.push(1);
	   Mem(ans,0);
	   while(!q.empty()){
		   int node=q.front();
		   //cerr(node);
		   q.pop();
		   for(auto child:adj[node]){
			   if(dist[child]!=1e9)continue;
			   dist[child]=dist[node]+1;
			   ans[child]=node;
			   q.push(child);
		   }
	   }
	   cout<<"Yes\n";
	   for(int i=2;i<=n;i++)cout<<ans[i]<<endl;
      
    return 0;
}


Measured memory_bytes: 11004
import sys
read = sys.stdin.buffer.read
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n, m = (int(x) for x in read().split())
    ans = (1900 * m + 100 *(n - m)) * 2 ** m    
    print(ans)
    # editorialカンニングした
    # m個TLEがあるとき、次に提出したときにそれらがすべてACとなる確率は(1/2)**m
    # 確率の期待値が1になる実行回数は逆数で2**mってこと？
    # 本当ならlimitを計算すべきなんだろうが...

if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
/*
Keep clam  Believe youself
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<cmath>
#define Xiaobo main
#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
const int maxn=3e5+7;
const int mod=1e9+7;
const double eps=1e-15;
const double pi=acos(-1);
const int INF=0x3f3f3f3f;
typedef unsigned long long ll;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}
//别急 dp找状态 问题看看本身的规律 贪心找方法
ll a[maxn]; 
ll qmi(ll a,ll b) {
	ll res=1;
	while(b) {
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
int Xiaobo()
{	
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
	}
	ll res=0;
	for(int i=0;i<=62;i++) {
		ll l=0,y=0;
		for(int j=1;j<=n;j++) {
			if(a[j]>>i&1) y++;
			else l++;
		}
	//	DEBUG((l*y)*(qmi(2,i)));
		res=(res+(l*y%mod)*(qmi(2,i))%mod)%mod;
	}
//	cout<<res<<'\n';
	cout<<(res%mod+mod)%mod<<'\n';
	return 0;
}	

Measured memory_bytes: 2560
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int S = s.nextInt();

        int W = s.nextInt();

        if(S > W) {
            System.out.println("safe");
        } else {
            System.out.println("unsafe");
        }
    }
}

Measured memory_bytes: 35780
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>Pair;
const int INF = 1000000;
ll dx[] = { 0,1,0,-1 };
ll dy[] = { 1,0,-1,0 };
ll R, C;
ll sx, sy;
ll gx, gy;
char c[100][100];
ll d[100][100];
ll bfs() {
	queue<Pair>que;
	for (ll i = 0; i < R; i++) {
		for (ll j = 0; j < C; j++) {
			d[i][j] = INF;
		}
	}
	que.push(Pair(sy, sx));
	d[sy][sx] = 0;
	while (que.size()) {
        Pair p= que.front(); 
      	que.pop();
		if (p.first == gy && p.second == gx)break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C&&c[ny][nx] == '.'&&d[ny][nx] == INF) {
				que.push(Pair(ny, nx));
				d[ny][nx] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[gy][gx];
}

int main() {
	cin >> R >> C;
	sy=1,sx=1;
  	gy=R,gx=C;
	sy--; sx--; gy--; gx--;
  	ll cnt=0;
	for (ll i = 0; i < R; i++) {
		for (ll j = 0; j < C; j++) {
			cin >> c[i][j];
          	if(c[i][j]=='#') cnt++;
		}
	}
  	ll res= bfs();
  	if(res==INF){cout<<-1<<endl; return 0;}
  	cout<<C*R-res-cnt-1<<endl;
	return 0;
}
	

Measured memory_bytes: 256