akhauriyash/Code-Regression huggingface dataset:
open System
let M = (int64 1e9) + 7L
let (N, K) = let t = Console.ReadLine().Split() |> Array.map int in t.[0], t.[1]

let cusum =
    let nums = [0..N]
    let rec f = 
        function 
        | [], _ -> []
        | xs, [] -> xs
        | x::_ as xs, y::ys -> f ((x + y)::xs, ys) 
    f ([0L], List.map int64 nums)
    |> List.rev 
    |> Array.ofList

let f n =
    let min = cusum.[n]
    let max = cusum.[N + 1] - cusum.[N + 1 - n]
    max - min + 1L
    
List.map f [K .. N + 1]
|> List.reduce (fun acc x -> (acc + x) % M) 
|> Console.WriteLine

Measured memory_bytes: 67588
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};

int main(){
    ll ans = 0;
    string s; cin >> s;
    rep(i,3) if(s[i]=='1') ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
def dist(x,y):
    return abs(x[0]-y[0])+abs(x[1]-y[1])
H,W,D = map(int,input().split())
G = {}
for i in range(H):
    row = list(map(int,input().split()))
    for j in range(W):
        G[row[j]]=(i,j)
B = {i:0 for i in range(1,D+1)}
for i in range(1,D+1):
    for j in range(i+D,H*W+1,D):
        B[j] = B[j-D]+dist(G[j-D],G[j])
Q = int(input())
for _ in range(Q):
    L,R = map(int,input().split())
    print(B[R]-B[L])

Measured memory_bytes: 36008
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N, Q = map(int, input().split())
    
    h = N
    w = N
    a = [N]*N
    b = [N]*N
    ans = (N-2)**2
    for _ in range(Q):
        q, x = map(int, input().split())
        if q == 1:
            if x < w:
                for i in range(x, w):
                    b[i] = h
                w = x
            ans -= b[x] - 2
        elif q == 2:
            if x < h:
                for i in range(x, h):
                    a[i] = w
                h = x
            ans -= a[x] - 2
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 82056
#include <cstdio>
typedef long long lld;
const int MAXN = 55;
const int MOD = 1e9+7;
lld K;
int N;

struct Matrix {
  int data[MAXN][MAXN];

  int& at(int i, int j) { return data[i][j]; }

  Matrix& operator *= (Matrix other) {
    Matrix copy = *this;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        data[i][j] = 0;
        for (int k = 0; k < N; ++k) {
          int val = 1LL * copy.at(i, k) * other.at(k, j) % MOD;
          data[i][j] = (1LL * val + data[i][j]) % MOD;
        }
      }
    }
    return *this;
  }

  void identity() {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        data[i][j] = (i == j) ? 1 : 0;
      } // Identity
    }
  }

  int sum() const {
    int ans = 0;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        ans = (1LL * data[i][j] + ans) % MOD;
      }
    }
    return ans;
  }
} A, B;

void pow() {
  while (K) {
    if (K & 1LL) {
      B *= A;
    }
    A *= A;
    K /= 2;
  }
}

int main() {
  scanf(" %d%lld", &N, &K);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      scanf("%d", &A.at(i, j));
    }
  }
  B.identity();
  pow();
  printf("%d\n", B.sum());
  return 0;
}

Measured memory_bytes: 256
while true
    n = gets.to_i
    break if n == 0
    lines = []
    n.times{lines << gets.chomp.split}
    arr = [[0, 0, "lunch"], [0, 0, "dinner"], [0, 0, "midnight"], [0, 0, "etc"]]
    lines.each{|t, u|
        t1, t2 = t.split(":").map(&:to_i)
        u = u.to_i
        timezone = nil
        if t1.between?(11, 14)
            timezone = 0
        elsif t1.between?(18, 20)
            timezone = 1
        elsif t1.between?(21, 23) || t1.between?(0, 1)
            timezone = 2
        else
            timezone = 3
        end
        arr[timezone][0] += 1

        ok = false
        d = u - t2
        d += 60 if d < 0
        ok = true if d <= 8
        arr[timezone][1] += 1 if ok
    }
    arr[0..-2].each{|item|
        percentage = (item[0] == 0) ? "no guest" : 100 * item[1] / item[0]
        puts "#{item[2]} #{percentage}"
    }
end


Measured memory_bytes: 6884
#include <stdio.h>

#define MAX 7200

void out(int s){
  int f, m;
  f = s /3600;
  s %= 3600;
  m = s /60;
  s %= 60;
  printf("0%d:", f);
  printf(m / 10 > 0 ?"%d:" :"0%d:", m);
  printf(s / 10 > 0 ?"%d\n" : "0%d\n", s);
}

int main(){
  int f, m, s, i, j, junk;
  while(1){
    scanf("%d%d%d", &f, &m, &s);
    if(f == -1 && m == -1 && s == -1) break;

    s += 60 * m;
    s += 3600 * f;
    s = MAX - s;

    out(s);
    out(s *3);

  }
  return 0;
}

Measured memory_bytes: 600
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll dx[4] = {0,1,0,-1};
ll dy[4] = {1,0,-1,0};
int main()
{
	ll h,w,k;
	cin>>h>>w>>k;
	ll x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	x1--;x2--;y1--;y2--;
	vector<string>grid(h);
	VII d(h+1,vector<ll>(w+1,INF));
	for(int i=0;i<h;i++)cin>>grid[i];
	auto ok = [&](ll x,ll y){return (x>=0 && y>=0 && x<h && y<w && grid[x][y] == '.');};
	queue<pii>q;
	d[x1][y1] = 0;
	q.push({x1,y1});
	while(!q.empty()){
		ll x,y;
		x = q.front().fi;
		y = q.front().se;
		q.pop();
		if(x == x2 && y == y2){cout<<d[x2][y2];return 0;}
		for(int dir=0;dir<4;dir++){
			ll xn = x;
			ll yn = y;
			for(int i=0;i<k;i++)
			{
				xn+=dx[dir];
				yn+=dy[dir];
			  if(!ok(xn,yn))break;
			  if(d[xn][yn] <= d[x][y])break;
			  if(d[xn][yn] > d[x][y]+1){
				 d[xn][yn]=d[x][y]+1;
			     q.push({xn,yn});
			   }
			}	
		}
		//cout<<x<<" "<<y<<endl;
	}
	cout<<-1;
}


Measured memory_bytes: 26692
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

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

int main() {
	vector<vector<int>>A(3,vector<int>(3));
	vector<vector<int>>B(3,vector<int>(3,0));
	int n;
	rep(i,3){
		rep(j,3){
			cin >> A[i][j];
		}
	}
	cin >> n;
	vector<int>C(n);
	int x;
	rep(i,n){
		cin >> C[i];
	}

	rep(i,n){
		rep(j,3){
			rep(k,3){
				if(C[i] == A[j][k]){
					B[j][k] = 1;
				}
			}
		}
	}
	string ans = "No";
	rep(i,3){
		if(B[i][0] == 1 && B[i][1] == 1 && B[i][2] == 1){
			ans = "Yes"; 
			break;
		}
		if(B[0][i] == 1 && B[1][i] == 1 && B[2][i] == 1){
			ans = "Yes"; 
			break;
		}
	}
	if(B[0][0] == 1 && B[1][1] == 1 && B[2][2] == 1) ans = "Yes";
	if(B[2][0] == 1 && B[1][1] == 1 && B[0][2] == 1) ans = "Yes";
	cout << ans;
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	/*
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
	*/
	int n;
	cin>>n;

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

	int dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);

	for(int i=2;i<n;i++)
		dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),
				  dp[i-1]+abs(h[i]-h[i-1]));
	cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1024
N,M=map(int,input().split())
#最大公約数のバリエーションは高々M種類？
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

#約数は奇数個or偶数個
for i in reversed(make_divisors(M)):
    if M//i<N:
        pass
    else:
        print(i)
        exit()



Measured memory_bytes: 63568
from collections import deque
K = int(input())

if K < 10:
  print(K)
  exit()

count = 0
lunlun = []

queue = deque([1,2,3,4,5,6,7,8,9])

# BFS
while count < K:
  now = queue.popleft()
  diff = [-1,0,1]
  for i in range(3):
    tmp = now % 10 + diff[i]
    if 0<= tmp <= 9:
      queue.append(now*10 + tmp)
      lunlun.append(now*10 + tmp)
      count += 1

print(lunlun[K-10])

Measured memory_bytes: 10620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int R=scanner.nextInt();
        if(R<1200){
            System.out.println("ABC");
        }else if(R<2800){
            System.out.println("ARC");
        }else{
            System.out.println("AGC");
        }
    }
}


Measured memory_bytes: 21716
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define mod (int)1000000007
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = DBL_EPSILON;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline int gcd(int a, int b) {
	while (b) {
		int c = a;
		a = b; b = c % b;
	}
	return a;
}
inline int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
bool isprime(int n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
int mypow(int a, int b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int modpow(int a, int b, int m = mod) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	int memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
signed main() {
	int n, a;
	cin >> n;
	rep(i, n) {
		cin >> a;
		if (a % 2 == 0) {
			if (a % 3 && a % 5) {
				puts("DENIED");
				return 0;
			}
		}
	}
	puts("APPROVED");
	return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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



int main(){
    int N, W; cin >> N >> W;
    vector<Pi_i> vw;
    REP(i, N){
        int v, w; cin >> v >> w;
        vw.EB(MP(v, w));
    }
    auto comp = [](Pi_i a, Pi_i b){
        return (ll)a.first * b.second > (ll)b.first * a.second;
    };
    sort(ALL(vw), comp);
    double ans = 0.0;
    for(auto &p: vw){
        if(p.second <= W){
            ans += p.first;
            W -= p.second;
        }else{
            ans += W * (double)p.first / p.second;
            W = 0;
        }
        if(!W) break;
    }
    cout << fixed << setprecision(8) << ans << endl;
    return 0;
}



Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 3e5 + 9;
const ll mod = 1e9 + 7;
typedef pair<ll,ll> LL;

string s;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>s;
    if (s[2] == s[3]&&s[4] == s[5]) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 3652
//
//  main.c
//  ITP1_9_A
//
//  Created by k16031kk on 2018/05/27.
//  Copyright © 2018年 AIT. All rights reserved.
//

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    char word[10];
    char text[1000];
    char eot[12]="END_OF_TEXT";
    int count=0;
    scanf("%s", word);
    while(1) {
        scanf("%s", text);
        if(strcmp(text, eot)==0) break;
        for(int i=0; text[i]!='\0'; i++) {
            text[i]=tolower(text[i]);
        }
        if(strcmp(text, word)==0) {
            count++;
        }
    }
    
    printf("%d\n", count);
    
    return 0;
}




Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long A, B;
    cin >> A >> B;
    int K;
    cin >> K;


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

        if (i % 2 == 0){
            if (A % 2 == 1){
                A = A - 1;
            }
            B = B + A / 2;
            A = A / 2;
        }
        
        if (i % 2 == 1){
            if (B % 2 == 1){
                B = B - 1;
            }
            A = A + B / 2;
            B = B / 2;
        }
    }

    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
/* ex3_4
  bonbonc */

#include<stdio.h>
#include<stdbool.h>

int main(){
	int number;
	bool flag; /*終わったかどうか*/
	flag = false;
	scanf("%d",&number);
	for(int i = 1;i<=9;i++){/*全探索*/
		for(int j = 1;j<=9;j++){
			if(i*j==number){
				flag = true;
			}
		}
	}

	if(flag){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int now = 1, br = 0;
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        if(now == x){
            now++;
        }else{
            br++;
        }
    }
    cout << (br == n ? -1 : br) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define p pair<double, double>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n, 0);
    for (int i = 1; i < n; i++) {
        int b;
        cin >> b;
        a[b - 1]++;
    }
    for (int i = 0; i < n; i++) cout << a[i] << endl;
    return 0;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  I n;
  cin >> n;
  V v(n);
  VIN(v);
  SORT(v);
  REV(v);
  I t=0,c=MAX;
  REP(i,n){
    if (v.at(i) < c){
      t++;
      c = v.at(i);
    }
  }
  cout << t << endl;
  return 0;
}



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

int main(){
  string s;
  cin >> s;
  int pa, pz;
  rep(i,s.size()){if(s.at(i)=='A'){pa=i;break;}}
  reverse(s.begin(),s.end());
  rep(i,s.size()){if(s.at(i)=='Z'){pz=i;break;}}
  cout << s.size()-pa-pz << endl;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="Sunny")
       cout<<"Cloudy"<<endl;
    else if(s=="Cloudy")
       cout<<"Rainy"<<endl;
    else
      cout<<"Sunny"<<endl;


    return 0;
}


Measured memory_bytes: 256
H,W=map(int,input().split())
A=[input() for i in range(H)]

f=True
for i in range(H):
	for j in range(W):
		if A[i][j]=='#':
			g=False
			for a,b in [(-1,0),(1,0),(0,1),(0,-1)]:
				if 0<=i+a<H and 0<=j+b<W:
					if A[i+a][j+b]=='#':g=True
			if not(g):f=False

print('Yes' if f else 'No')

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
long long ans=0;
int mod=1e9+7;
long long a[2010];
int main()
{
	int n;
	scanf("%d",&n);
	if(n<3)
	{
		cout<<"0"<<endl;
		return 0;
	}
	a[3]=1;
	for(int i=4;i<=n;i++)
	{
		a[i]=((a[i-1]%mod)+(a[i-3]%mod))%mod;
	}
	printf("%lld\n",a[n]);
}
/*
0 1
0 2
1 3
1 4
1 5
2 6
3 7
4 8
6 9
9 10
*/

Measured memory_bytes: 3784
H,W=map(int,input().split())
A=[[int(i) for i in input().split()] for j in range(H)]
B=[[int(i) for i in input().split()] for j in range(H)]
dp=[[0 for j in range(W)] for i in range(H)]
M=161*161
dp[0][0]|=1<<(A[0][0]-B[0][0]+M)
dp[0][0]|=1<<(-A[0][0]+B[0][0]+M)

for i in range(H):
    for j in range(W):
        dij=abs(A[i][j]-B[i][j])
        if i>0:
            dp[i][j]|=dp[i-1][j]<<dij
            dp[i][j]|=dp[i-1][j]>>dij
        if j>0:
            dp[i][j]|=dp[i][j-1]>>dij
            dp[i][j]|=dp[i][j-1]<<dij
ans=[]
for k in range(2*M+1):
    if (1<<k)&dp[-1][-1]!=0:
        ans.append(abs(k-M))
print(min(ans))


Measured memory_bytes: 38324
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        String s=sc.next();
        int temp=Character.getNumericValue(s.charAt(0));
        String ans=String.valueOf(s.charAt(0));
        for (int i = 0; i <(1<<3) ; i++) {
            for (int j = 0; j < 3; j++) {
                if((1&i>>j)==1){
                    temp+=Character.getNumericValue(s.charAt(j+1));
                    ans+="+"+String.valueOf(s.charAt(j+1));
                }else{
                    temp-=Character.getNumericValue(s.charAt(j+1));
                    ans+="-"+String.valueOf(s.charAt(j+1));
                }
            }
            if(temp==7){
                ans+="=7";
                break;
            }else{
                temp=Character.getNumericValue(s.charAt(0));
                ans=String.valueOf(s.charAt(0));
            }
        }
        out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int ans = 0;
	VE a(n); rep(i, n)cin >> a[i];
	rep(i, n - 1) {
		if (a[i + 1] > a[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3624
from itertools import *

nim,mike=map(int,input().split())
x = [list(map(int, input().split())) for _ in range(nim)]
res = 0
for a in product([-1, 1], [-1, 1], [-1, 1]):
    ts = [sum(i*j for i,j in zip(a,t)) for t in x]
    s = sum(sorted(ts,reverse=True)[:mike])
    res = max(res, s)
print(res)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    int ans = n;
    char c = s[0];
    rep(i, n){
        if(c != s[i]){
            c = s[i];
            int l = max(i, n-i);
            ans = min(ans, l);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		char[] s = sc.next().toCharArray();
		sc.close();
		int cnt=0;
		for (i = 0; i < s.length/2; i++) {
			if(s[i]!=s[s.length-1-i]) cnt++;
		}
		out.println(cnt);
	}
}


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

using namespace std;
const int N=2e5+5,mod=1e9+7;
#define ll long long
bool broken[N];
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x;
        cin>>x;
        broken[x]=1;
    }
    a[0]=1;
    for(int i=1;i<=n;i++)
    {
        if(broken[i]) continue;
        if(!broken[i-1]) a[i]+=a[i-1];
        if(!broken[i-2]&&i-2>=0) a[i]+=a[i-2];
        a[i]%=mod;
    }
    cout<<a[n]<<endl;
    return 0;
}


Measured memory_bytes: 768
import math
a,b,x = map(int,input().split())
l = 2/a**2*(a**2*b-x)
if x >= a**2*b/2:
  if l != 0:
    print(90-math.degrees(math.atan(a/l)))
  else:
    print(0)
else:
  k = 2*x/(b*a)
  print(90-math.degrees(math.atan(k/b)))


Measured memory_bytes: 38408
//9-3=6 6-4=2
//2 3 4 6 9
//有可能拿到箱子里两个相同的么
//最大值9 最小值0
//从造数规律来看 放回去的数字一定比之前两个数字小 这意味着不可能拿到比一开始最大数字大的数字
//同时 放回去的数字如果和目前已知的重合了 那么等于没有放回去
//如果第一轮造数字没有出现新数字 当前数字里又没有k 那么一定不可能
//如果第一轮出现了新数字
//10005 2 100
//10003 98 9905
//9 6 4
//2 3
//2 4
//2 5
//3 1
//只要能在哪一轮拿到1就可以得到介质
//2 1342
//而要想拿到1 只需要数字两个互质
//互质的判断 大数余小数不为0
//快速判断一堆数字是否互质 如果不互质 最小的数字一定为其他数字的因数
//那么我们就拿所有数字去余最小数字
//公因数一定能被整除吗
//12 15 18 21
//
//一个质数不行
//如果没有两个互质 就拿不到1 最小步长就是最小公因数
//3 6 9 12 18
//如果没有两个互质 说明每个数都有公因数 那么所有数最小的公因数就是MIN 得到的就是MIN到最大值
//两个偶数一定得2
//两个奇数 15 35
//得最小公因数
//3 18
//7 11
//2 8
//6 4
//6 7 6 9 6 11 6 13 6 15
//最接近的两个数字如果为1的话 那么最小到最大介值都能取得
//最接近的两个数字如果为2的话
int GCD( int a , int b )
{
      int x=a%b;
      while(x != 0)     //即： while(n)
      {
            a = b;
            b = x;
            x = a % b;
      }
      return b;       //注意这里返回的是b 不是n
}
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MAXN 100005
using namespace std;
int a[MAXN],n,k,tem,flag,MIN;
int main()
{
    MIN=INF;
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]==k)
        {
            printf("POSSIBLE\n");
            return 0;
        }
    }
    sort(a+1,a+1+n);
    for(int i=2;i<=n;i++)
    {
        MIN=min(MIN,GCD(a[i],a[1]));
        if((GCD(a[i],a[1]))==1)
        {
            flag=1;
            break;
        }
    }
    if(flag)
    {
        if(a[n]>=k)
        {
            printf("POSSIBLE\n");
        }
        else
        {
            printf("IMPOSSIBLE\n");
        }
    }
    else
    {
        if((k%MIN==0)&&(a[n]>=k))
        {
            printf("POSSIBLE\n");
        }
        else
        {
            printf("IMPOSSIBLE\n");
        }
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;  
    int a,b;
    cin>>a>>b;
    if(a<10 && b<10)cout<<a*b;
    else cout<<-1;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main()
{

	int a, b;
	cin >> a >> b;

	if (a == b) {
		cout << a + b << endl;
	}
	else if (a > b) {
		cout << 2 * a - 1 << endl;
	}
	else {
		cout << 2 * b - 1;
	}

    return 0;
}

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

int main(void){
  int  i, l, f = 0;
  char s[101], t[101];

  scanf("%s", s);
  scanf("%s", t);
  l = strlen(s);
  for(i = 0; i < l; i++) { 
    if( strncmp(&s[0], &t[i], l - i) == 0 ) {
      if( strncmp(&s[l - i], &t[0], i ) == 0 ) { 
        f = 1;
      }
    }
  }
  printf("%s\n", f ? "Yes" : "No");

  return 0;
}



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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    string s;
    cin >> s;

    bool check[26] = {false};
    rep(i, s.size()){
        check[s[i]-'a'] = true;
    }

    rep(i, 26){
        if(check[i] == false){
            char ans = 'a' + i;
            cout << ans << endl;
            return 0;
        }
    }

    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> P(N);
    for(int i=0;i<N;i++) cin >> P[i];
    int mi = 1e9;
    int ans = 0;
    for(int i=0;i<N;i++){
        if(mi>=P[i]) ans++;
        mi = min(mi,P[i]);
    }
    cout << ans << endl;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> t(n+1);
  int a,b;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    t[a]++;
    t[b]++;
  }
  for (int i=1;i<=n;i++) cout << t[i] << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <bitset>
#include <queue>
#include <algorithm>
using namespace std;
 
int const MAX_N = 128 * 1024;
 
int main() {
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    
	int x,a,b;
	cin>>x>>a>>b;
	x -= a;
	cout<<(x%b);
    return 0;
}  


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a;
    cin >> a;
    for (int i = 1; i <= a; ++i){
        if ( i % 3 == 0 ){
            cout << " " << i;
        }else{
            for(int t = i; t!=0 ; t = t/10){
                if( t % 10 == 3){
                    cout << " " << i;
                    t=0;
                }
            }
        }
    }
    cout << endl;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    if (s.length()!=a+b+1)
    {
        cout<<"No\n"<<endl;
        return 0;
    }
    if (s[a]!='-'){
        cout<<"No\n";
        return 0;
    }
    for (int i=0;i<a;i++){
        if (s[i]>='0'&&s[i]<='9')
            continue;
        else{
            cout<<"No\n"<<endl;
        return 0;
        }
    }
    for (int i=a+1;i<s.length();i++){
          if (s[i]>='0'&&s[i]<='9')
            continue;
        else{
            cout<<"No\n"<<endl;
        return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[100001];
int ans,b,n;
int main(){
cin>>n;
for(int i=0;i<n;i++)
{
cin>>b;
if(b==0)
{a[0]++;
a[1]++;}
else{
a[b-1]++;
a[b]++;
a[b+1]++;}}
for(int i=0;i<=100001;i++)
ans=max(ans,a[i]);
cout<<ans;
return 0;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            out.println((N + 1) / 2);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23508
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void){
  int a[3];
  FOR(3)scanf("%d",&a[i]);
  char s[2][6]={"Close","Open"};
  PRS(s[a[0]*a[1]+a[2]]);
  return 0;
}



Measured memory_bytes: 2100
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    vector<vector<int>> a(n, vector<int>(n, 0));
    for (int i = 0, u, k; i < n; i++)
    {
        scanf("%d %d", &u, &k);
        u--;
        for (int j = 0, v; j < k; j++)
        {
            scanf("%d", &v);
            a[u][--v] = 1;
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            printf("%d%s", a[i][j], j != n - 1 ? " " : "\n");
        }
    }
}


Measured memory_bytes: 3280
using System;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Linq;
using System.IO;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            int X = cin.ReadInt;
            int N = cin.ReadInt;

            bool[] mem = new bool[1000];
            for (int i = 0; i < mem.Length; i++) mem[i] = false;

            for (int i = 0; i < N; i++)
            {
                mem[cin.ReadInt + 500] = true;
            }

            int ans = 0;
            for (int i = 0; ; i++)
            {
                if (!mem[X + 500 - i])
                {
                    ans = X - i;
                    break;
                }
                else if (!mem[X + 500 + i])
                {
                    ans = X + i;
                    break;
                }
            }

            Console.WriteLine(ans);
        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 17924
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string s;
  cin >> s;
  int n = s.size();
  bool ans = true;
  if (n % 2 == 0) {
    for (int i = 0; i < n; i += 2) ans &= s[i] == 'h' && s[i + 1] == 'i';
  } else ans = false;
  cout << (ans ? "Yes" : "No");

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int B[] = new int[N-1];
    for(int i=0; i<N-1; i++) B[i] = sc.nextInt();
    int ans = B[N-2];
    for(int i=N-2; i>0; i--){
      ans += Math.min(B[i], B[i-1]);
    }
    ans += B[0];
    out.println(ans);
  }
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    int cnt[4]={0,0,0,0};
    for(int i = 0; i < 6; i++){
        int a;
        cin >> a;
        a--;
        cnt[a]++;
    }
    for(int i = 0; i < 4; i++){
        if(cnt[i]==3){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;

}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  // 求める n 個の値のxor (偶数回xorするが、それぞれの値が1回xor対象でないので、その値が残る)
  int sum = 0;
  rep(i, n) {
    sum ^= a.at(i);
  }
  // 入力の値とのxorで求める値以外は相殺される
  vector<int> res(n);
  rep(i, n) {
    res.at(i) = sum ^ a.at(i);
  }
  // 出力
  rep(i, n) {
    cout << res.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 4752
#define _USE_MATH_DEFINES
//
#include <bits/stdc++.h>
//
using namespace std;
//
#define krep(i,k,n)      for(int i=k;i<n;++i)
#define rep(i,n)         for(int i=0;i<n;++i)
#define toupp(s)         transform(s.begin(),s.end(),s.begin(),::toupper) // string
#define tolow(s)         transform(s.begin(),s.end(),s.begin(),::tolower) // string
#define pb(v)            push_back(v)
#define all(v)           v.begin(),v.end()
#define mp               make_pair
#define __sort(v)        sort(v.begin(),v.end()) // vector
#define __stable_sort(v) stable_sort(v.begin(),v.end()) // vector
#define __exists(c,v)    (find(all(c), (v)) != (c).end()) // vector
#define __unique(v)      __sort(v);v.erase(unique(v.begin(),v.end()),v.end()) // vector
#define __swap(a, b, tmp)  tmp=a;a=b;b=tmp;
#define __memset(a)      memset(a,0,sizeof(a));
//
#define dumpVar(v)       cerr<<setw(30)<<#v" = ["<<v<<"]"<<endl
#define dumpArr(v, n)    for(int i=0;i<n;++i){cerr<<v[i]<<", ";} cerr<<endl
#define dumpPair(p)      cerr<<"<"<<p.first<<", "<<p.second<<">"<<endl
//
typedef long long              ll;
typedef vector<string>         vs;
typedef vector<double>         vd;
typedef vector<int>            vi;
typedef pair<int, int>         pii;
typedef pair<double, double>   pdd;
//

struct data{
int val1;
int val2;
};


// sort判定用関数
bool comp1(data x, data y){
return x.val1 > y.val1 ? true : false;
}
bool comp2(data x, data y){
return x.val2 <  y.val2 ? true : false;
}

//main関数内の使用例
/*
vector<data> arr; // 宣言
arr.push_back({_data1,_data2}); // 要素の追加
sort(arr.begin(), arr.end(),comp1); // comp1の条件に従ってソート
*/

int main ()
{
ios::sync_with_stdio ( false );
//
/* code start */
int N,tmp;
vector<data> arr;

cin >> N;
  krep(i,1,N+1){
    cin >> tmp;
    arr.push_back({i,tmp});
  }
  
  cerr << "----" << endl;
  rep(i,N)    cerr << arr[i].val1 << " " << arr[i].val2 << endl;

  sort(arr.begin(),arr.end(),comp2);

  cerr << "----" << endl;
  rep(i,N)    cerr  << arr[i].val1 << " " << arr[i].val2 << endl;
  
  rep(i,N){
    cout << arr[i].val1 << " ";
  }
  cout << endl;
	/* code end   */
	//
	return 0;
}


/* === 2次元配列 ソート ===
struct data{
	int val1;
	int val2;
};

// sort判定用関数
bool comp1(data x, data y){
	return x.day > y.day ? true : false;
}
bool comp2(data x, data y){
	return x.rew > y.rew ? true : false;
}

//main関数内の使用例
	vector<data> arr; // 宣言
	arr.push_back({_data1,_data2}); // 要素の追加
	sort(arr.begin(), arr.end(),comp1); // comp1の条件に従ってソート
*/


Measured memory_bytes: 1780
#include <iostream>

int main(void)
{
    int input, a, b, c, d;
    std::cin >> input;
    a = input / 1000;
    b = (input / 100) % 10;
    c = (input / 10) % 10;
    d = input % 10;
    bool good = (b == c) && ((a == b) || (c == d));
    std::cout << (good ? "Yes" : "No") << std::endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define F first
#define S second
#define pb push_back
#define all(c)  c.begin(), c.end()
#define vb vector<bool>
#define vll vector<ll>
#define vi vector<int>
#define vp vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define lb "\n"
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define INF 1000000007
#define MAX LLONG_MAX
#define PI 3.14159265358
ll max(ll x,ll y){if(x>y)return x;else return y;}
ll min(ll x,ll y){if(x>y)return y;else return x;}
ll dp[101][100001],dp2[101][100001];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
      #ifdef LOCAL
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
   ll i,j,k,h,w,p,n;
   cin>>n>>k;
   vll a(n);
   rep(i,0,n)
   cin>>a[i];
   rep(i,0,n+1)
   {
   dp[i][0]=1;
   dp2[i][0]=1;
   }
   rep(i,1,k+1)
   dp2[0][i]=dp2[0][i-1]+dp[0][i];
   rep(i,1,n+1)
   rep(j,1,k+1)
   {
       p=max(0,j-a[i-1]);
       if(p==0)
      dp[i][j]=dp2[i-1][j];
      else
        dp[i][j]=(dp2[i-1][j]-dp2[i-1][p-1]+INF)%(INF);
      dp2[i][j]=(dp2[i][j-1]+dp[i][j])%(INF);
   }
   cout<<dp[n][k];
}


Measured memory_bytes: 158080
#include<iostream>
using namespace std;
long long fact(int x)
{
	long long g=1;
	for(int i=2;i<=x;i++)
	{
		g*=i;
		g%=1000000007;
	}
	return g; 
}
int main()
{
	string s;
	long long k,n,l=0,ans=1;
	cin>>n;
	cin>>s;
	n*=2;
	for(int i=0;i<n;i++)
	{
		k=l%2;
		/*if(i>0 &&i<=n/2)
		{
			ans*=i;
			ans%=1000000007;
		}*/
		if((s[i]=='B' && k==1) || (s[i]=='W' && k==0))
		{
			ans*=l;
			ans%=1000000007;
			l--;
		}
		else
			l++;
		if(l<0 || l>n/2)
			break;	
	}
	if(l!=0)
		cout<<0<<endl;	
	else	
		cout<<(ans*fact(n/2))%1000000007<<endl;
} 

Measured memory_bytes: 640
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int counter = sc.nextInt();
    int answer = 0;
    for(int i=0;i<counter;i++){
      answer += sc.nextInt() -1;
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 25296