akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i=0; i<n; ++i){
        cin >> h[i];
    }
    int dp[n];
    for (int i=0; i<n; ++i){
        if(i == 0){dp[0] = 0;}
        else if(i == 1){dp[1] = abs(h[1] - h[0]);}
        else {
            int cost1 = dp[i-1] + abs(h[i] - h[i-1]);
            int cost2 = dp[i-2] + abs(h[i] - h[i-2]);
            dp[i] = min(cost1, cost2);
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n; n++;
  ll x = 1LL*n*(n+1)*(n-1)/6;
  for(int i = n-3; i >= 0; --i){
    int a,b; cin >> a >> b;    
    if(a > b)a^=b^=a^=b;
    x -= 1LL*a * (n-b);
  }
  cout << x;
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
#define N 100005
int n;long long x,y,ans;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%lld",&x);y+=x;
        if(!x) ans+=y>>1,y=0;
    }
    ans+=y>>1;printf("%lld\n",ans);
}


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


int main(){
	int a,b,A[3]={1,2,3};
	cin >> a >> b;
	for(int i=0;i<3;i++){
		if(A[i]==a||A[i]==b) A[i]=0;
	}
	
	for(int i=0;i<3;i++){
		if(A[i]!=0) cout << A[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl

vector<double> memo(200005);

int solveHope (int m) {
  return 2 * (1 + (m - 1) / (double)2);
}


void solve(long long N, long long K, std::vector<long long> p){
  vector<int> twoTimesHopes(N);
  REP(x, N) {
    twoTimesHopes.at(x) = solveHope(p.at(x));
  }

  int sum = 0;
  int maxHopes = 0;
  REP(x, K){
    sum += twoTimesHopes.at(x);
    maxHopes += twoTimesHopes.at(x);
  }

  for(int x = K; x < N; x++) {
    sum += twoTimesHopes.at(x);
    sum -= twoTimesHopes.at(x - K);

    maxHopes = max(maxHopes, sum);
  }

  printf("%f\n", maxHopes / 2.0);
}

signed main(){
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  std::vector<long long> p(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&p[i]);
  }
  solve(N, K, std::move(p));
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define RMAX 4294967295
#define equals(a,b)(fabs((a)-(b))<EPS)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef complex<double> comp;
typedef vector<complex<double>> vcomp;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef string::const_iterator State;
class ParseError {};
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


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

	string s;
	cin >> s;

	int stat = 0;
	bool a = false;
	rep(i, s.size()) {
		if (a && s[i] == 'A') {
			cout << "NO" << endl;
			return 0;
		}
		if (stat == 0 && s[i] == 'K') {
			stat++;
			a = false;
		}
		else if (stat == 1 && s[i] == 'I') {
			stat++;
			a = false;
		}
		else if (stat == 2 && s[i] == 'H') {
			stat++;
			a = false;
		}
		else if (stat == 3 && s[i] == 'B') {
			stat++;
			a = false;
		}
		else if (stat == 4 && s[i] == 'R') {
			stat++;
			a = false;
		}
		else if (s[i] == 'A') {
			if (stat == 1 || stat == 2) {
				cout << "NO" << endl;
				return 0;
			}
			else a = true;
		}
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	
	if (stat != 5) {
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 768
f=1
g=0
s=[]
def suretsu(n):
    if n%2==0:
        return n/2
    else:
        return 3*n+1
s.append(int(input()))
while g==0:
    f+=1
    s.append(int(suretsu(s[len(s)-1])))
    for i in range(len(s)-2):
        if s[len(s)-1]==s[i]:
            g=1
            break
print(f)

Measured memory_bytes: 3060
"""
後ろから考えていく

サンプル1のLRで考える

後手が勝つためには2ターン目終了以前に [2,3]にいる必要
→1ターン終了時に[2,2]にいること
→1ターン目初手終了時に[2,3]にいること
→最初に[2,2]にいること

→後手Lがくると右の範囲が1増える
→先手Lがくると左の範囲が1減る

最後に最初の地点が入ってれば後手が勝ち

"""
import sys

H,W,N = map(int, input().split() )

s,c = map(int,input().split())

S = input()
T = input()

u = 1
d = H
l = 1
r = W

for i in range(N):

    i = N - i - 1

    if T[i] == "U":
        d = min(d+1 , H)

    elif T[i] == "D":
        u = max(1 , u-1)

    elif T[i] == "L":
        r = min(r+1 , W)

    else:
        l = max(l-1 , 1)




    if S[i] == "U":
        u += 1

    elif S[i] == "D":
        d -= 1

    elif S[i] == "L":
        l += 1

    else:
        r -= 1


    if l > r or u > d or l > W or r < 1 or u > H or d < 1: 
        print ("NO")
        sys.exit()

#print (u,d,l,r)

if u <= s <= d and l <= c <= r:
    print ("YES")
else:
    print ("NO")




Measured memory_bytes: 48008
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,s=0;
    cin>>a;
    for(int i=1;i<=a;i++)
    {
        if(i%3!=0&&i%5!=0)
        {
            s+=i;
        }
    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 3648
// Isaunoya
#include<bits/stdc++.h>
using namespace std ;
using LL = long long ;
using uint = unsigned int ;
#define int long long
#define fir first
#define sec second
#define pb push_back
#define mp(x , y) make_pair(x , y)
template < typename T > inline void read(T & x) { x = 0 ; int f = 1 ; register char c = getchar() ;
  for( ; ! isdigit(c) ; c = getchar()) if(c == '-') f = -1 ;
  for( ; isdigit(c) ; c = getchar()) x = (x << 1) + (x << 3) + (c & 15) ;
  x *= f ;
}
template < typename T > inline void print(T x) {
  if(! x) { putchar('0') ; return ; }
  static int st[105] ;
  if(x < 0) putchar('-') , x = -x ;
  int tp = 0 ;
  while(x) st[++ tp] = x % 10 , x /= 10 ;
  while(tp) putchar(st[tp --] + '0') ;
}
template < typename T > inline void print(T x , char c) { print(x) ; putchar(c) ; }
template < typename T , typename ...Args > inline void read(T & x , Args & ...args) { read(x) ; read(args...) ; }
template < typename T > inline void sort( vector < T > & v) { sort(v.begin() , v.end()) ; return ; }
template < typename T > inline void unique( vector < T > & v) { sort(v) ; v.erase(unique(v.begin() , v.end()) , v.end()) ; }
template < typename T > inline void cmax(T & x , T y) { if(x < y) x = y ; return ; }
template < typename T > inline void cmin(T & x , T y) { if(x > y) x = y ; return ; }
const int Mod = LLONG_MAX ;
inline int QP(int x , int y) { int ans = 1 ;
  for( ; y ; y >>= 1 , x = (x * x) % Mod)
    if(y & 1) ans = (ans * x) % Mod ;
  return ans ;
}
template < typename T > inline T gcd(T x , T y) { if(y == 0) return x ; return gcd(y , x % y) ; }
template < typename T > inline T lcm(T x , T y) { return x * y / gcd(x , y) ; }
template < typename T > inline void mul(T & x , T y) { x = 1LL * x * y ; if(x >= Mod) x %= Mod ; }
template < typename T > inline void add(T & x , T y) { if((x += y) >= Mod) x -= Mod ; }
template < typename T > inline void sub(T & x , T y) { if((x -= y) < 0) x += Mod ; }

int n , k ;
const int N = 2e5 + 10 ;
int a[N] , b[N] ;
int sum[N] ;
inline bool chk(int mid) {
  int cnt = 0 ;
  for(register int i = 1 ; i <= n ; i ++)
    if(sum[i] > mid) cnt += (sum[i] - mid + b[i] - 1) / b[i] ;
  return cnt <= k ;
}
signed main() {
  read(n) ; read(k) ;
  for(register int i = 1 ; i <= n ; i ++)
    read(a[i]) ;
  for(register int i = 1 ; i <= n ; i ++)
    read(b[i]) ;
  sort(a + 1 , a + n + 1) ;
  sort(b + 1 , b + n + 1 , greater <int>()) ;
  for(register int i = 1 ; i <= n ; i ++)
    sum[i] = a[i] * b[i] ;
  // for(register int i = 1 ; i <= n ; i ++) print(sum[i] , '\n') ;
  int l = 0 , r = LLONG_MAX ; int ans = 0 ;
  while(l <= r) {
    int mid = l + r >> 1 ;
    if(chk(mid)) r = mid - 1 , ans = mid ;
    else l = mid + 1 ;
  } print(ans , '\n') ;
  return 0 ;
}

Measured memory_bytes: 4992
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int days = sc.nextInt();
    	int X = sc.nextInt();
    	int P[] = new int[N];
    	int total =0;


    	for(int i =0;i<N;i++){
    		P[i]=sc.nextInt();

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


    		for(int j =1;j<=days;j +=P[i] ){


    				total++;

    		}
    	}

    	total += X;


    	System.out.println(total);

}


}

Measured memory_bytes: 23764
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  string s;
  cin >> n >> s;
  if (s.size() % 2 == 1) {
    cout << "No\n";
    return 0;
  }

  bool ans = true;
  for (int i = 0; i < s.size() / 2; i++) {
    if (s[i] != s[i + s.size() / 2]) {
      ans = false;
      break;
    }
  }

  cout << (ans ? "Yes\n" : "No\n");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;

int main() {
  int a, b; cin >> a >> b;
  if (b % a == 0) {
    cout << a + b << endl;
  }else{
    cout << b - a << endl;
  }

  return 0;
}

//


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

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] ={ 1, 0, -1, 0 };
int dy[4] ={ 0, 1, 0, -1 };

int main()
{
int n;
cin>>n;
int maxh=0;
ll ans=0;
REP(i,n){
    int a;
    cin>>a;
    if(maxh<a){
        maxh=a;
    }
    if(maxh>a){
        ans+=(ll)(maxh-a);
    }
}
cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<stdio.h>

int main(void){
 	
  int A,B,C,D;
  
  scanf("%d %d %d %d",&A,&B,&C,&D);
  
  for(int i = 0;;i ++){
   	C -= B;
    if(C <= 0){
     	printf("Yes");
      	return 0;
    }
    A -= D;
    if(A <= 0){
     	printf("No");
      	return 0;
    }
  }
}

Measured memory_bytes: 1732
#include "iostream"
using namespace std;

int main() {
	int r, c, box = 0;
	int under[100] = { 0 };
	cin >> r >> c;
	int number[100][100];
	for (int i = 0; i < r;i++) {
		for (int j = 0; j < c;j++) {
			cin >> number[i][j];
		}
	}

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cout << number[i][j] << " ";
			box += number[i][j];
			under[j] += number[i][j];
		}
		cout << box << endl;
		box = 0;
	}
	for (int i = 0; i < c;i++) {
		cout << under[i] << " ";
		box += under[i];
	}
	cout << box << endl;
}

Measured memory_bytes: 1196
n, m = [int(x) for x in input().split()]

#a = [int(input()) for x in range(m)]
a = set(int(input()) for x in range(m))
_MOD = 1000000007

dp = [0] * (n + 1)
dp[0] = 1

if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(1,n):
    if (i + 1) in a:
        dp[i + 1] = 0
    else:
        dp[i + 1] = (dp[i] + dp[i - 1]) % _MOD

print(dp[n])


Measured memory_bytes: 11884
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	int K, T;
	cin >> K >> T;
	vector<int>a(T);
	for (int i = 0; i < T; i++)cin >> a[i];
	sort(all(a));

	int sum = 0;
	for (int i = 0; i < T - 1; i++)sum += a[i];
	puts(max(0, a[T - 1] - sum - 1));

	return 0;
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

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

int main()
{
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll x = max(a,c), y=min(b,d);
    if(y<x) cout << 0;
    else cout << y-x;
}


Measured memory_bytes: 256
#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;  // init
   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: 3880
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

int main(){
    int n;
    cin >> n;
    vector<double> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    vector<int> id(n);
    rep(i, n) id[i] = i;
    double sum = 0.0;
    int cnt = 0;
    auto calc = [&]() {
        double ret = 0.0;
        rep(i, n-1) {
            int j = id[i];
            int k = id[i+1];
            ret += sqrt((x[j]-x[k])*(x[j]-x[k])+(y[j]-y[k])*(y[j]-y[k]));
        }
        return ret;
    };
    do {
        ++cnt;
        sum += calc();
        // dump(calc()), dumpVL(id);
    }while(next_permutation(all(id)));
    printf("%.15lf\n", sum / cnt);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

int main() {
	int n = 4;

	std::vector<int> v(n);
	
	for (int& x : v) {
		std::cin >> x;
	}

	std::sort(v.begin(), v.end());

	if (v[0] == 1 && v[1] == 4 && v[2] == 7 && v[3] == 9) {
		std::cout << ("YES") << std::endl;
	}
	else {
		std::cout << ("NO") << std::endl;
	}

	//std::cout << ("NO") << std::endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8

# In[1]:


import numpy as np


# In[2]:


n = int(input())


# In[9]:


def func(s):
    if int(s) > n:
        return 0
    
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in "753":
        ret += func(s + c)
    return ret

print(func("0"))



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

int main() {
  int x1,y1,x2,y2,x,y;
  cin >> x1 >> y1 >> x2 >> y2;
  x = x2 - x1;
  y = y2 - y1;
  cout << x2-y<< " " << y2+x << " " << x1-y << " " << y1+x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

void pv(vector<int>&v){
	for(int i = 0;i<v.size();i++){
		if(i)cout<<' ';
		cout<<v[i];
	}
	cout<<endl;
}

void merge(pair<pair<int,int>,pair<int,int>>&a,pair<pair<int,int>,pair<int,int>> b){
	set<pair<int,int>>st;
	st.insert(a.fi);
	st.insert(a.se);
	st.insert(b.fi);
	st.insert(b.se);
	a.fi = *st.begin();
	st.erase(st.begin());
	a.se = *st.begin();
}

signed main()
{
	IOS();
	int N;
	cin >> N;
	vector<int>a(1ll<<N);
	vector<pair<pair<int,int>,pair<int,int>>>dp(1ll<<N,{{-1,INF},{-1,INF}});
	rep(i,0,1ll<<N){
		cin >> a[i];
		dp[i].fi = {-a[i],i};
	}
	rep(i,0,1ll<<N){
		rep(j,0,N){
			if((i&(1ll<<j))==0)continue;
			merge(dp[i],dp[i^(1ll<<j)]);
		}
	}
	vector<int>s(1ll<<N);
	rep(i,0,1ll<<N)s[i] = -dp[i].fi.fi - dp[i].se.fi;
	rep(i,0,(1ll<<N)-1)chmax(s[i+1],s[i]);
	rep(i,1,1ll<<N){
		cout<<s[i]<<endl;
	}
}


Measured memory_bytes: 15360
#include <iostream>
#include <math.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define DIV 1000000007;
#define INF 1e9

using namespace std;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x;
	cin >> x;
	cout << 1 - x;
	return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N,M;
    cin >> N >> M;
    vvi G(N);
    vi H(N);
    in(N,H);
    rep(i,M){
        int a,b;
        cin >> a >> b;
        a--,b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    
    int ans = 0;
    rep(i,N){
        int an = 0;
        for (int p : G[i]) {
            if(H[i] > H[p]) an++;
        }
        if(an == int(G[i].size())) ans++;
    }
    
    cout << ans << endl;
    
    
    

    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define inf 10000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

vint pos(5);
int k;
bool check=true;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a*b/2<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s,t;	cin>>s>>t;
	int a,b;	cin>>a>>b;
	string u;	cin>>u;
	if(u==s)
		cout<<a-1<<" "<<b<<endl;
	else
		cout<<a<<" "<<b-1;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s,t; cin>>s>>t;
  ll n=s.size();
  vector<set<ll>> v(26);
  vector<set<ll>> v2(26);
  rep(i,n){
    ll a=s[i]-'a', b=t[i]-'a';
    v[a].insert(b);
    v2[b].insert(a);
  }
  rep(i,26){
    if(v[i].size()>1 || v2[i].size()>1) {
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 916
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5+5;
const int inf=1e9;
int main() {
	int x;
	cin>>x;
	int p=8;
	for(int i=600;i<=2000;i+=200) {
		if(x<i) {
			cout<<p<<endl;
			break;
		}
		p--;
	}
}

Measured memory_bytes: 3616
import sys
N, M, *PS = sys.stdin.read().strip().split()
N = int(N)
ac = [0] * N
wa = [0] * N
for p, s in zip(*[iter(PS)] * 2):
  p = int(p) - 1
  if s == "AC":
    ac[p] = 1
  elif ac[p] == 0:
    wa[p] += 1
penalties = sum(w * a for a, w in zip(ac, wa))
print(sum(ac), penalties)

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define RFOR(i, k, j) for (int i = k - 1; i >= j; i--)
#define RREP(i, j) RFOR(i, j, 0)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

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

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

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

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;

    cout << n * n * n << endl;


    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 e;
	while (cin >> e && e) {
	  int64 res = INF_LL;
	  for (int64 z = 0; z*z*z <= e; z++) {
	    for (int64 y = 0; y*y <= e-z*z*z; y++) {
	      chmin(res, z+y+(e-z*z*z-y*y));
	    }
	  }
	  cout << res << endl;
	}
}



Measured memory_bytes: 3152
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{

    
    class Program
    {
       

        static void Main(string[] args)
        {

            Console.ReadLine();
            int[] data = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int ans = 0;
            for(int i = 0; i < data.Count(); i++)
            {
                ans += data[i] - 1;
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<cstdio>
#include<algorithm>
#define M 1000000007
#define N 3010
using namespace std;
int f[N][N][2],g[N][N][2][2];
int l,t,n,m,ans;
int main(){
    scanf("%d%d",&n,&m);
    f[0][0][1]=1;
    for (int i=1;i<=n;i++) f[0][i][0]=1;
    for (int i=0;i<=m-1;i++)
        for (int j=0;j<=n;j++)
            for (int k=0;k<=1;k++){
                if (j) (f[i+1][j-1][k|(j-1==0)]+=f[i][j][k])%=M;
                if (j) (f[i+1][j][k|(j==1)]+=f[i][j][k])%=M;
                if (n-j) (f[i+1][j][k]+=f[i][j][k])%=M;
                if (n-j) (f[i+1][j+1][k]+=f[i][j][k])%=M;
            }
    for (int i=0;i<=n;i++) (ans+=f[m][i][1])%=M;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 71040
function rotatePoint2D(nRadians, nX, nY) {
	var nSin = Math.sin(nRadians);
	var nCos = Math.cos(nRadians);
	var x = nCos * nX - nSin * nY;
	var y = nSin * nX + nCos * nY;
	return {x: x, y: y};
}
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const line0vars = line0.split(" ");

	// 3 4 9 0

	const a = parseInt(line0vars[0], 10); // 時針長さ
	const b = parseInt(line0vars[1], 10); // 分針長さ
	const h = parseInt(line0vars[2], 10); // 時
	const m = parseInt(line0vars[3], 10); // 分
	var output;

	// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

	// var aRad = Math.sin(h * 30 * (Math.PI / 180));
	// var bRad = Math.sin(m * 6 * (Math.PI / 180));
	var aRad = (h * 30 + m * 0.5) * (Math.PI / 180);
	var bRad = m * 6 * (Math.PI / 180);
	var x1, y1, x2, y2;
	resultA = rotatePoint2D(aRad, 0, a);
	resultB = rotatePoint2D(bRad, 0, b);
	x1 = resultA.x;
	y1 = resultA.y;
	x2 = resultB.x;
	y2 = resultB.y;
	// console.log(aRad, bRad);
	// console.log(x1, y1, x2, y2);
// var x1 = 10 ;
// var y1 = 20 ;
// var x2 = 30 ;
// var y2 = 40 ;

output = Math.sqrt( Math.pow( x2-x1, 2 ) + Math.pow( y2-y1, 2 ) ) ;

	//出力
	console.log(output);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)

Measured memory_bytes: 29892
#include<iostream>

using namespace std;

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

	if ((abs(b - a) <= d && abs(c - b) <= d) || abs(c - a) <= d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	cin >> a;

	return 0;
}

Measured memory_bytes: 256
import Data.List

takeIf _ [] = []
takeIf f (a:ax) =
  if f a
  then a:takeIf f ax
  else takeIf f ax

inc 1 v (t:ts) = (t+v):ts
inc i v (t:ts) = t:(inc (i-1) v ts)

inc' _ _ [] t = t
inc' a i (b:bs) t =
  if b == a
  then inc' a (i+1) bs t'
  else inc' a (i+1) bs t
  where
    t' = inc i 1 t

play :: [Int] -> (Int,[Int]) -> [Int]
play t (a,b) =
  let v1 = length $ takeIf (/= a) b
      t1 = inc  a v1 t
      t2 = inc' a 1 b t1
  in
    t2

ans n m a b = 
  let t = replicate n 0
      t'= foldl play t $ zip a b
  in
    t'

main = do
  n <- getLine
  m <- getLine
  a <- getLine
  b <- getContents
  let n' = read n :: Int
      m' = read m :: Int
      a' = map read $ words a :: [Int]
      b' = map (map read) $ map words $ lines b :: [[Int]]
      o  = ans n' m' a' b'
  mapM_ print o
  

Measured memory_bytes: 6520
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <functional>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, u, v;
    cin, n, u, v;
    u--;
    v--;
    vector<vector<int>> Tree(n);
    REP(i, 0, n - 1) {
        int a, b;
        cin, a, b;
        a--;
        b--;
        Tree[a].push_back(b);
        Tree[b].push_back(a);
    }
    vector<int> dep1(n, 0), dep2(n, 0);
    function<void(int, int, int, vector<int> &)> dfs = [&](int ver, int prev, int cnt, vector<int> &dep) {
        dep[ver] = cnt;
        for (auto &vv : Tree[ver]) {
            if (vv == prev) continue;
            dfs(vv, ver, cnt + 1, dep);
        }
    };
    dfs(v, -1, 0, dep1);  // 青木君
    dfs(u, -1, 0, dep2);  // 高橋君
    int ans1 = 0, ans2 = 1 << 30;
    bool update = false;
    REP(i, 0, n) {
        if (dep1[i] > dep2[i]) {
            chmax(ans1, dep1[i] - 1);
            update = true;
        } else if (dep1[i] == dep2[i]) {
            chmin(ans2, dep1[i]);
        }
    }
    if (!update) {
        ans1 = ans2;
    }
    cout << ans1 << endl;

    return 0;
}


Measured memory_bytes: 14208
#include<iostream>
int main(){
    int a[4][3][10]={};
    int n,b,f,r,v;
   
    std::cin >> n;

      for(int i=1;i<=n;i++){
        std::cin >> b >> f >> r >> v;
        a[b-1][f-1][r-1]=a[b-1][f-1][r-1]+v;
      }

    for(int k=0;k<=3;k++){
        for(int l=0;l<=2;l++){
            for(int m=0;m<=9;m++){
               std::cout << " " << a[k][l][m];
            }
            std::cout << std::endl;
        }
        if(k!=3){
            for(int x=1;x<=20;x++){
               std::cout << "#" ;
            }
            std::cout << std::endl;
        }

    }

}


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

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  int ans{};
  for (int i{}; i <= 999; ++i) {
    stringstream ss;
    ss << setw(3) << setfill('0') << i;
    string digits{ss.str()};
    int cur{};
    for (int j{}; j < N; ++j) {
      if (S[j] == digits[cur]) {
        if (++cur == 3) {
          ++ans;
          break;
        }
      }
    }
  }

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


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
const int SIZE=5+3*1e3;
const int INF=10+1e9;
bool ss[100][100];
bool mini[100][100];
int N,M;
bool solve(int y,int x){
	REP(i,M)
		REP(j,M){
			if(mini[i][j]!=ss[y+i][x+j]) return false;
		}
	return true;
}
int main(){
	string s;
	cin >> N >> M;
	REP(i,N){
		cin >> s;
		REP(j,s.size()) ss[i][j]=s[j]=='#';
	}
	REP(i,M){
	
		cin >> s;
		REP(j,s.size()) mini[i][j]=s[j]=='#';
	}
	REP(i,N-M+1)
		REP(j,N-M+1){
		if(solve(i,j)){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

struct range {
  int start;
  int end;
};

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))

#define BUF_SIZE 20

int main(void) {
  struct range range0, range1;
  char line[BUF_SIZE];
  FILE* fp = stdin;
  if(!fgets(line, BUF_SIZE, fp)) return 0;

  sscanf(line, "%d %d %d %d",
      &range0.start, &range0.end,
      &range1.start, &range1.end
  );
  int s = max(range0.start, range1.start);
  int g = min(range0.end, range1.end);
  printf("%d\n", (g-s>0)*(g-s));
  return 0;
}

Measured memory_bytes: 128
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

x, k, d = input_a
if x.abs >= d * k
  if x >= 0
    x = x - (k * d)
  else
    x = x + (k * d)
  end
  puts x.abs
  exit
else
  tmp = x.abs / d
  if x >= 0
    x = x - (tmp * d)
  else
    x = x + (tmp * d)
  end
  k = k - tmp
end

xx = -1
k.times do |i|
  if xx == x.abs
    if (k - i) % 2 == 1
      if x >= 0
        x = x - d
      else
        x = x + d
      end
    end
    break
  end
  if i % 2 == 0
    xx = x.abs
  end
  if x >= 0
    x = x - d
  else
    x = x + d
  end
end
puts x.abs


Measured memory_bytes: 14160
#include<iostream>
#include<cmath>
#include<unordered_map>
#include<math.h>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#include<iomanip>
#include<string>
#include<map>
#define PI 3.14159265
#define mod 998244353  
#define mod1 1000000007  
using namespace std;

// A Dynamic Programming based solution to compute nCr % p 


// Returns nCr % p 

void func(){
    long long n , k ;
    cin >> n >> k ;

    long long arr[n + 1];

    for(int i = 1 ; i <= n ; ++i) 
    {
        cin >> arr[i];
    }

    long long dp[n + 1][k + 1];
    dp[0][0] = 1;

    for(int i = 1 ; i <= k ; ++i)
    {
        dp[0][i] = 0;
    }
   

    for(int i = 1; i <= n ; ++i)
    {
        long long sum[k + 1];
        sum[0] = dp[i - 1][0];
       // cout << sum[0] << " ";
        for(int j = 1; j <= k ; ++j)
        {
            sum[j] = (sum[j - 1] + dp[i - 1][j]) % mod1;   
            //cout << sum[j] << " ";
        }

        for(int j = 0; j <= k ; ++j)
        {
            long long tot = sum[j];
            long long unr = j - arr[i] - 1 ;
            if(unr >= 0){
                tot = (tot - sum[unr] + mod1) % mod1;
            }
            dp[i][j] = tot;
            //cout << tot << " ";
        }
       // cout << "\n";
    }

    cout << dp[n][k] ;
    return;
}   

int main(){
int t = 1 , cnt = 0 ;
//cin >> t;

while(t--){  
    func();
}
}

Measured memory_bytes: 79872
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;

int mat[16][16];
bool ho[16];
int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		for(int j = 0;j < a;j++){
			int x, y;
			cin >> x >> y;
			if(y == 1){
				mat[i][x-1] = 1;
			}
			else if(y == 0){
				mat[i][x-1] = 2;
			}
		}
	}
	
	int ans = 0;
	for(int bit = 0;bit < (1<<n);bit++){
		bool can = true;
		int bs = 0;
		fill(ho,ho+n,false);
		for(int i = 0;i < n;i++){
			if((bit & (1<<i)) != 0){
				bs++;
				ho[i] = true;
			}
		}
		
		for(int i = 0;i < n;i++){
			if(ho[i]){
				for(int j = 0;j < n;j++){
					if(mat[i][j] == 1){
						if(!ho[j]){
							can = false;
							break;
						}
					}
					if(mat[i][j] == 2){
						if(ho[j]){
							can = false;
							break;
						}
					}
				}
			}
		}
		
		if(can) ans = max(ans,bs);
	}
	
	cout << ans;
	
	
}


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

int main(){
    int H,W;
    cin >> H >> W;
    
    vector<vector<char>> meiro(H,vector<char>(W));
    
    //迷路データ取得
    //白マスをカウント
    int white_mass = 0;
    rep(i,H){
        rep(j,W){
            cin >> meiro[i][j];
            if(meiro[i][j] == '.'){
                white_mass++;
            }
        }
    }
    
    //ゴールまでの最短経路を幅優先探索する。初期値は-1にしておく
    vector<vector<int>> step_su(H,vector<int>(W,-1));
    queue<pair<int,int>> que;
    
    //初期値を代入する
    que.push(pair(0,0));
    step_su[0][0] = 1;
    
    //BFS
    while(!que.empty()){
        auto q = que.front(); que.pop();
        
        //キューの座標を格納
        int x,y;
        x = q.first; y = q.second;
        
        vector<int> shui = {-1,0,1};
        
        for(int i:shui){
            for(int j:shui){
                
                if(i*j != 0) continue; //斜め移動しない
                if(x+i<0 || x+i>=H || y+j<0 || y+j>=W) continue; //範囲外チェック
                if(step_su[x+i][y+j] != -1) continue; //探索済みチェック
                if(meiro[x+i][y+j] == '#') continue; //壁チェック
                
                step_su[x+i][y+j] = step_su[x][y] + 1;
                que.push({x+i , y+j});
            }
        }
    }
    
    //最短距離が求まっているはず
    //cout << step_su[H-1][W-1] << endl;
    
    //ゴールにたどり着けないときは-1を出力
    if(step_su[H-1][W-1] == -1){
        cout << -1 << endl;
        return 0;
    }
    
    //最短経路以外は黒く塗れるので
    int ans = white_mass - step_su[H-1][W-1];
    cout << ans << endl;

}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
int res=0;
inline int cnt(int x)
{
	int r=0;
	while (x) x/=10,r++;
	return r;
} 
int main()
{
	cin >>n;
	for (int i=1;i<=n;i++) if (cnt(i)%2) res++; 
	cout <<res;
	return 0;
}

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

int main()
{
    int n, k, x, sum=0;
    cin >> n >> k;

    for(int i = 0;i < n;i++){
        cin >> x;
        if(x > k-x){
            sum += k-x;
        } else {
            sum += x;
        }
    }
    cout << sum*2 << endl;
}


Measured memory_bytes: 256
import io.StdIn.readInt

object Main extends App {
  val n = readInt

  println(Solver.solve(n))
}

object Solver {
  def solve(n: Int) = {
    (for {
      i <- 0 to n
      j = n - i
    } yield {
      val n6 = Stream.from(0).map(i => math.pow(6, i).toInt).takeWhile(_ <= i).map(pos => (math.floor(i / pos) % 6).toInt).sum
      val n9 = Stream.from(0).map(i => math.pow(9, i).toInt).takeWhile(_ <= j).map(pon => (math.floor(j / pon) % 9).toInt).sum

      n6 + n9
    }).min
  }
}

Measured memory_bytes: 117780
#include<stdio.h>
int main(){
	int n;
	while(scanf("%d",&n),n){
		int m[15][15]={0}, x=n/2, y=n/2+1, c;
		for(c=1;c<=n*n;c++){
			while(m[x%n][y%n]) {
				x--;
				y++;
			}
			m[x%n][y%n]=c;
			x++;
			y++;
		}
		for(y=0;y<n;y++){
			for(x=0;x<n;x++)
				printf("%4d",m[x][y]);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 0
while True:
	a, b, c = input().split()
	a = int(a)
	c = int(c)
	if b == "?":
		break
	if b == "+":
		print(a + c)
	if b == "-":
		print(a - c)
	if b == "*":
		print(a * c)
	if b == "/":
		print(a // c)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int l,r,ans;
    cin>>n;
    for(int i=1;i<=n;i++)
	{
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int mx = 0, n, t;
	int ans = 0;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> t;
		if(mx<=t){
			ans++;
		}
		mx = max(mx, t);
	}

	cout << ans << endl;

	return 0;
}

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

int main () {
    int N, K;
    long long arr[100000*2+1];
    cin >> N >> K;
    long long ans = 0;
    long long total = 0;
    for (int i = 0; i < N + 1; i ++ ) {
        total += i;
        arr[i] = total;
    }
    long long tmp;
    for (int i = K; i < N + 1; i++) {
        tmp = arr[N] - arr[N - i] - arr[i - 1] + 1;
        ans = (ans + tmp) % mod;
    }
    cout << (ans + 1) % mod << endl;
}


Measured memory_bytes: 5116
#include <iostream>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  if (n == 0) {
    printf("%d\n", 2);
    return 0;
  }
  int64_t pre = 2, now = 1;
  while (n > 1) {
    int64_t next = pre + now;
    pre = now, now = next;
    n--;
  }
  printf("%lld\n", now);
}


Measured memory_bytes: 256
F=lambda X:pow(X,M-2,M);M=10**9+7;H,W,A,B=map(int,input().split());Z=C=1
for I in range(min(W-1-B,H-1)):Z=C=C*(W+H-B-2-I)*F(I+1)%M
for I in range(1,H-A):C=C*(B-1+I)*F(I)*(H-I)*F(W+H-B-1-I)%M;Z=(Z+C)%M
print(Z)

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

typedef long long ll;
typedef unsigned long long ull;

int N, K, a[100];
int dp[100001];

int solve(int k){
    if(dp[k] != 0) return dp[k];
    int r = -1;
    for(int i=0;i<N;i++){
        if(k-a[i] >= 0 && solve(k-a[i]) == -1) r = 1;
    }
    dp[k] = r;
    return r;
}

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<=K;i++) dp[i] = 0;
    for(int i=0;i<*min_element(a,a+N);i++) dp[i] = -1;

    if(solve(K) == 1) cout << "First" << endl;
    else cout << "Second" << endl;
    
    return 0;
}

Measured memory_bytes: 5376
import numpy as np
n = int(input())
hList = np.array(list(map(int, input().split())))
mFlag = np.diff(hList) <= 0
#bFlag = False
cnt=0
ret =0
for f in mFlag:
    if f:
        cnt += 1
        if( ret<cnt):
            ret = cnt
    else:
        cnt=0
    
print(ret)

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

using namespace std;
long long int n,a[50000],ans=0;
int main()
{
        ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
        cin >> n;
        for(int i=1; i<=2*n; i++)
        {
                cin >> a[i];
        }
        sort(a+1,a+2*n+1);
        for(int i=1; i<=2*n; i+=2)
        {
                ans+=a[i];
        }
        cout << ans;
}


Measured memory_bytes: 256