akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>

using namespace std;

#define int long long

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

constexpr int TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); };

const int inf = TEN(18) + 10;

signed main()
{
	int n;cin>>n;
	vector<int> a(3*n);
	rep(i,3*n)cin>>a[i];
	sort(begin(a),end(a));

	int ans = 0;

	int cur = 3*n - 2;
	rep(i, n) {
		ans += a[cur];
		cur -= 2;
	}

	cout << ans << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<stdlib.h>
#include<algorithm>

using namespace std;

#define OUT cout <<
#define IN cin >>
#define E << endl;
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define RFOR(i,a,b) for(int i = a; i >= b;i--)

string str;
string rstr;
int countt = 0;

int main(){
	while(IN str){
		RFOR(i, str.size() - 1, 0){
			rstr += (str[i]);
			//OUT str[i] E
		}
		//OUT rstr E
		if(str == rstr){
			countt++;
		}
		rstr.erase(rstr.begin(), rstr.end());
	}
	OUT countt E

}	

Measured memory_bytes: 2996
#include<stdio.h>
#define N 100
int main(){
  int n,A[N],foo,minA,mini,sum=0,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<n-1;i++){
    minA=A[i];
    mini=i;
    for(j=i+1;j<n;j++){
      if(minA>A[j]){
	minA=A[j];
	mini=j;
      }
    }
    if(i!=mini){
    A[mini]=A[i];
    A[i]=minA;
    sum++;
    }
  }
  for(i=0;i<n;i++){
    if(i!=0)
      printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",sum);
  return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long dp[1001][1001];
int main() {
    ios::sync_with_stdio(false);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int h, w;
    cin>>h>>w;
    bool grid[1001][1001];
    for(int i = 0; i<h; i++){
        for(int j =0; j<w; j++){
            char x;
            cin>>x;
            grid[i][j] = (x == '#')?0:1;
        }
    }
    dp[0][0] = 1;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            dp[i+1][j] += grid[i+1][j] * dp[i][j];
            dp[i][j+1] += grid[i][j+1] * dp[i][j];
            dp[i+1][j]%=MOD;
            dp[i][j+1]%=MOD;
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}


Measured memory_bytes: 9088
k,n = map(int,input().split())
if k%2 == 0:
  ans = [k//2]+[k]*(n-1)
else:
  t = n//2
  ans = [k//2+1]*n
  for i in range(t):
    if ans[-1] == 1:
      ans.pop()
    else:
      ans[-1] -= 1
      while len(ans) < n:
        ans.append(k)
print(*ans)

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

string s;
int main() {
	int n;
	cin>>n;
    vector<int> vec(n);
    for(int i=0; i<n; i++){
        cin>>vec.at(i);
    }

    int pre=-999;
    for(int i=0; i<n; i++){
        if(pre<=vec[i]-1){
            pre=vec[i]-1;
        }else if(pre==vec[i]){
            pre=vec[i];
        }else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

signed main() {
	int t, x;
	cin >> t >> x;
	printf("%.14f\n", (double)t / x);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int x,y,i;
	for(i=0;i<10000;i++){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0) break;
		if(x > y)printf("%d %d\n",y,x);
		else printf("%d %d\n",x,y);
	}
	return 0;	
}

Measured memory_bytes: 2576
/*
 ID: swagchicken1
 PROG:
 LANG: C++11
 */

#include <iostream>
#include <tuple>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <vector>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <cctype>
#include <climits>
#include <chrono>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;

#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)

//#define endl '\n';

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1000000007;

long double PI = 4*atan(1);
long double eps = 1e-12;



int main() {
    //auto start = chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);cin.tie(0);
    //ofstream cout("output.txt");
    //ifstream cin("input.txt");
    ll n; cin >> n;
    ll k; cin >> k;
    ll ans = 0;
    for(ll i = k; i < n+2; i++) {
        ans +=  ((n)*(n+1))/2 - ((n - i)*(n+1 - i))/2    -  (i*(i-1))/2 + 1;
        ans %= MOD;
    }
    cout << ans << endl;
    
    
    
    //auto stop = chrono::high_resolution_clock::now();
    //auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
    //cout << duration.count() << endl;
    //cin.close();
    //cout.close();
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  int P = 0, W = 0, G = 0, Y = 0;
  
  cin >> N;
  
  for ( int i = 0; i < N; i++) {
    cin >> S;

    if ( S == "P" ){
      P++;
    } else if ( S == "W" ){
      W++;
    } else if ( S == "G" ){
      G++;
    } else if ( S == "Y" ){
      Y++;
    } 
  }

  if ( Y == 0 ){
    cout << "Three" << endl;
  } else {
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val a = readLine()!!.toMutableList().map(Char::toString).sorted()
    var r = if(a.count() > 1) "Yes" else "No"
    var tmp = ""
    a.forEachIndexed{i,l ->
        when(i % 2){
            0 -> tmp = l
            1 -> if(l != tmp) r = "No"
        }
    }
    println(r)
}

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

int main() {
int x,y;
cin>>x>>y;
if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11)) cout<<"Yes"<<endl;
else if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12)){
  cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#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 fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 2e5 + 20;
const int inf = 1e9 + 7;

int n, m;
int a[200];
int dp[N][2];

int go(int x, int p) {
	if (x == 0 && p == 0) re 2;
	if (x == 0 && p == 1) re 1;
	if (dp[x][p]) re dp[x][p];
	if (p == 0) {
	    int ans = 2;
		for (int i = 0; i < n; i++)
			if (x - a[i] >= 0 && go(x - a[i], 1) == 1)
				ans = 1;
		re dp[x][p] = ans;
	} else {
	    int ans = 1;
		for (int i = 0; i < n; i++)
			if (x - a[i] >= 0 && go(x - a[i], 0) == 2)
				ans = 2;
		re dp[x][p] = ans;
	} 
}	

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> a[i];
	int p = go(m, 0);
	if (p == 1) cout << "First";
	else cout << "Second";
	return 0;
}


Measured memory_bytes: 8832
import sys
def frog2(N,h,k):
    dp=[sys.maxsize-1]*N
    dp[0]=0
    for i in range(N):
        for j in range(i+1,i+k+1):
            if j<N:
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))
    return dp[N-1]

N,k=map(int,input().split())
h=list(map(int,input().split()))
print(frog2(N,h,k))

Measured memory_bytes: 52448
#include <cstdio>
#include <cmath>
using namespace std;

#define N 100010
#define INF 1e9+7

int n, h[N], f[N], k;

int main() {
  scanf("%d%d", &n, &k);
  for (int i=1; i<=n; i++) scanf("%d", &h[i]);
  f[1] = 0;
  for (int i=2; i<=n; i++) {
    f[i] = f[i-1] + fabs(h[i]-h[i-1]);
    for (int j=2; j<=k && i-j>0; j++)
      f[i] = fmin(f[i], f[i-j]+fabs(h[i]-h[i-j]));
  }
  printf("%d\n", f[n]);
  return 0;
}


Measured memory_bytes: 896
nums = gets.split.map!(&:to_i)
i_ary = o_ary = []
nums[0].times{i_ary << gets.split('')}

nums[0].times{|i|
  nums[1].times{|j|
    if i_ary[i][j] == "#"
      o_ary[i][j] = "#"
      next
    end
    m = 0
    if i == 0
      if j== 0
        m += 1 if i_ary[i][j+1] && i_ary[i][j+1] == "#"
        m += 1 if i_ary[i+1] && i_ary[i+1][j] && i_ary[i+1][j] == "#"
        m += 1 if i_ary[i+1] && i_ary[i+1][j+1] && i_ary[i+1][j+1] == "#"
      else
        m += 1 if i_ary[i][j-1] == "#"
        m += 1 if i_ary[i][j+1] && i_ary[i][j+1] == "#"
        m += 1 if i_ary[i+1] && i_ary[i+1][j-1] && i_ary[i+1][j-1] == "#"
        m += 1 if i_ary[i+1] && i_ary[i+1][j] && i_ary[i+1][j] == "#"
        m += 1 if i_ary[i+1] && i_ary[i+1][j+1] && i_ary[i+1][j+1] == "#"
      end
    else  # i != 0
      if j == 0
        m += 1 if i_ary[i-1][j] == "#"
        m += 1 if i_ary[i-1][j+1] && i_ary[i-1][j+1] == "#"
        m += 1 if i_ary[i][j+1] && i_ary[i][j+1] == "#"
        m += 1 if i_ary[i+1] && i_ary[i+1][j] && i_ary[i+1][j] == "#"
        m += 1 if i_ary[i+1] && i_ary[i+1][j+1] && i_ary[i+1][j+1] == "#"
      else
        m += 1 if i_ary[i-1][j-1] == "#"
        m += 1 if i_ary[i-1][j] == "#"
        m += 1 if i_ary[i-1][j+1] && i_ary[i-1][j+1] == "#"
        m += 1 if i_ary[i][j-1] == "#"
        m += 1 if i_ary[i][j+1] && i_ary[i][j+1] == "#"
        m += 1 if i_ary[i+1] && i_ary[i+1][j-1] && i_ary[i+1][j-1] == "#"
        m += 1 if i_ary[i+1] && i_ary[i+1][j] && i_ary[i+1][j] == "#"
        m += 1 if i_ary[i+1] && i_ary[i+1][j+1] && i_ary[i+1][j+1] == "#"
      end
    end
    o_ary[i][j] = m
  }
}

o_ary.each{|o| puts o.join}

Measured memory_bytes: 2300
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
bool is(int n) {
	string s = to_string(n);
	int k = s.length();
	rep(i, s.length() / 2) {
		if (s[i] != s[k - i - 1]) return 0;
	}
	return 1;
}

int main() {
	int a, b;
	cin >> a >> b;
	int d = b - a;
	int cnt = 0;
	for (int i = a; i <= b; i++) {
		if (is(i))cnt++;
		
	}
	cout << cnt;


	return 0;
}





Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int min = Math.min(a,b);
        int max = Math.max(a,b);
        System.out.println(Math.min(min,c)+" "+Math.max(max,c));
    }
}


Measured memory_bytes: 26360
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        int k = sc.nextInt();
        int s = sc.nextInt();
        int counter = 0;
        outer:
        for(int x=0; x<=k; x++){
            for(int y=0; y<=k; y++) {
                int z = s - x - y;
                if(0 <= z && z <= k ) counter++;
            }
        }
        System.out.println(counter);

    }

    static 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());}
    }
}

Measured memory_bytes: 21332
#include<cstdio>

#define Fast register
char BUF[40],*S=BUF;
inline int Getint(){
	Fast int s=0;Fast char c;
	while(c=*S++,c<48||c>57);
	while(s=s*10+c-48,c=*S++,c>47&&c<58);
	return s;
}

int main(){
	fread(BUF,1,40,stdin);
	Fast int A=Getint(),B=Getint(),C=Getint(),X=Getint(),Ans=0;
	for(Fast int i=0;i<=A;++i){
		for(Fast int j=0;j<=B;++j){
			for(Fast int k=0;k<=C;++k){
				if(i*500+j*100+k*50==X)++Ans;
			}
		}
	}
	printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;



int main(){
  ll n;
  cin >> n;

  ll ans = 0;
   for(ll a = 1; a < n; a++){
     ans += (n-1)/a;
  }
  
   cout << ans << endl;
}


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


int main(){
    ll n;cin>>n;
    vector<pair<ll,ll> > MN(n);
    vector<pair<ll,ll> > MX(n);
    rep(i,0,n){
        ll a,b;cin>>a>>b;
        MN[i]=make_pair(a,b);
        MX[i]=make_pair(b,a);
    }
    sort(MN.begin(),MN.end());
    sort(MX.begin(),MX.end());
    double an;
    if(n%2==1){
        double l=MN[(n-1)/2].first;
        double r=MX[(n-1)/2].first;
        an=(r-l);
    }
    else{
        double l=(MN[n/2].first+MN[n/2-1].first)/2.0,r=(MX[n/2].first+MX[n/2-1].first)/2.0;
        an=(r-l)*2;
    }
    ll ans=an;
    cout<<ans+1<<endl;
    
}

    









Measured memory_bytes: 9604
N,K = map(int,input().split())
D = list(map(int,input().split()))

isNotMin = True

temp = N * 1

while isNotMin:
    for i in str(temp):
        if int(i) in D:
            temp += 1
            isNotMin = True
            break
        else:
            isNotMin = False

print(temp)


Measured memory_bytes: 2940
package main

import "fmt"
import "sort"

func main() {
	var N, K int
	fmt.Scanf("%d %d\n", &N, &K)
	A := make([]int, N)
	for i := range A {
		fmt.Scanf("%d", &A[i])
	}
	counts := make([]int, N+1) // Don't use 0-th.
	for _, a := range A {
		counts[a]++
	}
	c := sort.IntSlice(counts)
	c.Sort()
	total := 0
	for _, n := range c[:len(c)-K] {
		total += n
	}
	fmt.Println(total)
}
	

Measured memory_bytes: 6656
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	K := nextInt()
	Q := nextInt()

	C := make([]int, N+1)
	for i := 0; i < Q; i++ {
		a := nextInt()
		C[a]++
	}
	for i := 1; i <= N; i++ {
		if K-(Q-C[i]) > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
#define INF 10000000000
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    int n,k,ans;
    cin>>n>>k;
    ans=1;
    rep(i,n){
        if(ans<k){
            ans*=2;
        }
        else{
            ans+=k;
        }
    }
    out(ans);
}

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

int main(){
    int N;
    long long ans=2e18, tmp;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++){
	cin >> a[i];
    }

    for(int i=1; i<=100; i++){
	tmp=0;
	for(int j=0; j<N; j++){
	    tmp += (a[j]-i)*(a[j]-i);
	}
	if(ans>tmp)
	    ans=tmp;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> 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); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

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

  int N;
  cin >> N;
  vector<int> W(N);
  cin >> W;
  int sum = accumulate(ALL(W),0LL);
  int tmp = 0, ans = INF;
  for (int i = 0; i < N; i++) {
    tmp += W[i];
    ans = min(ans,abs(sum-2*tmp));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);


struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 19;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

modint dp[3005][3005];
void solve() {
	int n; cin >> n;
	string s; cin >> s;
	dp[1][0] = 1;
	rep1(i, n - 1) {
		char c = s[i - 1];
		if (c == '<') {
			modint s = 0;
			rep(j, i + 1) {
				dp[i + 1][j] = s;
				s += dp[i][j];
			}
		}
		else {
			modint s = 0;
			per(j, i + 1) {
				s += dp[i][j];
				dp[i + 1][j] = s;
			}
		}
	}
	modint ans = 0;
	rep(i, n)ans += dp[n][i];
	cout << ans << "\n";
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//init();
	//int t; cin >> t;rep(i,t)
	solve();
	stop
		return 0;
}


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

int main(void){
	int a, b;
	cin >> a >> b;
	int ans = 0;
	if(abs(a-b)<=1){
		ans = a + b;
	}else{
		ans = max(a,b) * 2 - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 1e11
using namespace std;

struct thing {
    int w, v;
};

int main() {
    int N, W;
    cin >> N >> W;
    vector<thing> A(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> A.at(i).w >> A.at(i).v;
    }

    vector<vector<long>> dp(N + 1, vector<long>(100001, INF));
    dp.at(0).at(0) = 0;

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < 100001; j++) {
            if (j - A.at(i).v >= 0) {
                if (dp.at(i).at(j) > dp.at(i - 1).at(j - A.at(i).v) + A.at(i).w) {
                    dp.at(i).at(j) = dp.at(i - 1).at(j - A.at(i).v) + A.at(i).w;
                }
            }
            if (dp.at(i).at(j) > min(dp.at(i - 1).at(j), dp.at(i).at(j))) {
                dp.at(i).at(j) = min(dp.at(i - 1).at(j), dp.at(i).at(j));
            }
        }
    }

    int ans = 0;
    for (int i = 100000; i >= 0; i--) {
        if (dp.at(N).at(i) <= W) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

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

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

int main(){
	int a, b;
	cin >> a >> b;
	if(a > b)
		cout << "a > b" << "\n";
	else if(a < b)
		cout << "a < b" << "\n";
	else
		cout << "a == b" << "\n";

	return 0;
}

Measured memory_bytes: 1124
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
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;}

int main(){
    int N,K;
    cin >> N >> K;
    ll R,S,P;
    cin >> R >> S >> P;
    string T;
    cin >> T;

    for(int i=K; i<N; i++){
        if(T[i-K] == T[i]){
            T[i] = 'a';
        }
    }

    ll ans = 0;
    for(auto c : T){
        switch(c){
        case 'r':
            ans += P;
            break;
        case 's':
            ans += R;
            break;
        case 'p':
            ans += S;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3780
import math
def com(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,p = map(int, input().split())
al = list(map(int, input().split()))

a0 = 0
a1 = 0
for a in al:
    if a%2 == 0:
        a0 += 1
    else:
        a1 += 1

ans = pow(2,a0)
ans2 = 0
if p == 0:
    for i in range(0,51,2):
        if a1 < i:break
        ans2 += com(a1,i)

else:
    for i in range(1,51,2):
        if a1 < i:break
        ans2 += com(a1,i)
print(ans*ans2)

Measured memory_bytes: 62232
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N = 1e5 + 5;
 
int32_t main()
{
        IOS;
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        char a;
        cin>>a;
        if(a==tolower(a)){
                cout<<"a"<<endl;
        }
        else{
                cout<<"A"<<endl;
        }
        return 0;
}

Measured memory_bytes: 3656
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

macro_rules! input {
    (source = $s:expr; $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
#[allow(unused_imports)]
use std::cmp::*;
trait Each: Iterator {
    fn each<F>(self, mut f: F)
    where
        Self: Sized,
        F: FnMut(Self::Item),
    {
        self.fold((), move |(), item| f(item));
    }
}
impl<T: Iterator> Each for T {}

const SEPARATOR: &'static str = " ";

fn solve(source: &str) -> String {
    let mut result: Vec<String> = vec![];
    macro_rules! p {
        ([$x: expr]) => {
            $x.iter().each(|&x| p!(x))
        };
        ([$x: expr]; $s:expr)=>{
            p!($x.iter().map(|x|x.to_string()).collect::<Vec<_>>().join($s));
        };
        ($($x: expr),* $(,)*) => {
            $(result.push($x.to_string()));*
        };
    }
    //---------------------------------------------------------------//

    input! {
        source = source;
        n:usize,
        s:chars,
    }
    let mut ans = 1;
    for i in 0..n-1{
        if s[i]!=s[i+1]{
            ans+=1;
        }
    }
    p!(ans);
    

    //---------------------------------------------------------------//
    return result.join(SEPARATOR);
}
fn main() {
    let mut s;
    let source = {
        use std::io::Read;
        s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s.as_str()
    };
    println!("{}", solve(source));
}
#[test]
fn testcase() {
    assert_eq!(solve(r"10
aabbbbaaca
"),r"5");
assert_eq!(solve(r"5
aaaaa
"),r"1");
assert_eq!(solve(r"20
xxzaffeeeeddfkkkkllq
"),r"10");
}

Measured memory_bytes: 4352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemA solver = new ProblemA();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemA {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int[] a = new int[2 * n];
			for (int i = 0; i < a.length; i++) {
				a[i] = in.nextInt();
			}
			Arrays.sort(a);
			int ans = 0;
			for (int i = 0; i < a.length; i += 2) {
				ans += a[i];
			}
			out.println(ans);
		}

	}

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

		public FastScanner(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: 8276
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> as(N);
  vector<int> sas(N);
  for(int i = 0; i < N; ++i) {
    cin >> as[i];
    sas[i] = as[i];
  }
  sort(sas.begin(), sas.end(), greater<int>());
  for(auto a : as) {
    if(a == sas[0]) {
      cout << sas[1] << endl;
    } else {
      cout << sas[0] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3200
#include <iostream>
using namespace std;
int main() {
    int x; cin >> x;
    bool dp[x+105] = {true};
    for (int i = 0; i < x; i++)
        if (dp[i]) for (int j = 100; j <= 105; j++) dp[i+j] = true;
    cout << (int)dp[x] << endl;
}


Measured memory_bytes: 384
main :: IO ()
main = do
    [n,m] <- (map read) . words <$> getLine
    print $ solve n m

solve :: Integer -> Integer -> Integer
solve n m | abs (n - m) >= 2 = 0
          | abs (n - m) == 1 = let x = max n m
                                in x * (fact (x-1))^2 `mod` lim
          | otherwise = (2 * (fact n)^2) `mod` lim

fact :: Integer -> Integer
fact 1 = 1
fact i = i * fact (i-1)

lim = 10^9 + 7 :: Integer


Measured memory_bytes: 7224
n,a,b = map(int,input().split())
s = list(input())

count = 0
b_count = 0
for i in range(n):
    c = s[i]
    if c=='c':
        print('No')
        continue
    if c=='a':
        if a+b>count:
            count+=1
            print('Yes')
        else:
            print('No')

    if c=='b':
        if a+b>count and (b_count+1)<=b:
            count+=1
            b_count+=1
            print('Yes')
        else:
            b_count+=1
            print('No')





Measured memory_bytes: 4712
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    final int mod = 998244353;
    int[] tree;

    private void add(int num, int from, int to, int a, int b, int node) {
        if (from <= a && b <= to) {
            tree[node] += num;
            tree[node] %= mod;
            return;
        }

        int mid = (a + b) / 2;
        if (from <= mid) add(num, from, to, a, mid, node * 2);
        if (to > mid) add(num, from, to, mid + 1, b, node * 2 + 1);
    }

    private int getSum(int index, int a, int b, int node) {
        if (a == b) return tree[node];

        int mid = (a + b) / 2;
        int sum = 0;
        if (index <= mid) sum += getSum(index, a, mid, node * 2);
        if (index > mid) sum += getSum(index, mid + 1, b ,node * 2 + 1);

        sum += tree[node];
        sum %= mod;

        return sum;
    }

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        int n = Integer.parseInt(tokenizer.nextToken());
        int k = Integer.parseInt(tokenizer.nextToken());
        int[][] intervals = new int[k][2];
        for (int i = 0; i < k; i++) {
            tokenizer = new StringTokenizer(f.readLine());
            intervals[i][0] = Integer.parseInt(tokenizer.nextToken());
            intervals[i][1] = Integer.parseInt(tokenizer.nextToken());
        }

        tree = new int[4 * n];
        add(1, 0, 0, 0, n - 1, 1);

        for (int i = 0; i < n; i++) {
            for (int[] interval : intervals) {
                if (i + interval[0] >= n) continue;
                add(getSum(i, 0, n - 1, 1), i + interval[0], Math.min(i + interval[1], n - 1), 0, n - 1, 1);
            }
        }

        out.println(getSum(n - 1, 0, n - 1, 1));

        out.close();
    }
}

Measured memory_bytes: 39908
import sys
input=sys.stdin.readline
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
#print(cnt)

ans=0
for i in cnt.values():
    ans=ans+i*(i-1)//2

for i in a:
    print(ans-cnt[i]+1)


Measured memory_bytes: 25916
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 1040

int n, m, ans;
int s[AC], top, tmp;
bool f[AC][AC];

inline int read()
{
	int x = 0;char c = getchar();
	while(c > '9' || c < '0') c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x;
}

void pre(){
	n = read(), m = read();	
}

void work()
{
	for(R i = 1; i <= m; i ++)
	{
		int x = read(), y = read();
		if(f[y][y] || f[x][x]) //这一切的前提都是自己要活着。。。。
		{
			f[x][x] = f[y][y] = true;
			continue;
		}
		top = 0;
		for(R j = 1; j <= n; j ++) if(f[x][j])	s[++ top] = j;//找到y需要连哪些边
		tmp = top;
		for(R j = 1; j <= n; j ++) if(f[y][j]) s[++ top] = j;
		for(R j = 1; j <= tmp; j ++) f[y][s[j]] = f[s[j]][y] = true;
		for(R j = tmp + 1; j <= top; j ++) f[x][s[j]] = f[s[j]][x] = true; 
		f[x][y] = f[y][x] = true;
	}
	
	for(R i = 1; i <= n; i ++)
		for(R j = i + 1; j <= n; j ++) 
			if(!f[i][j] && !f[j][j] && !f[i][i]) ++ ans;//需要两者都不是必须死的，而且没有不能共存的限制
	printf("%d\n", ans);
}

int main()
{
	//freopen("in.in", "r", stdin);
	pre();
	work();
	//fclose(stdin);
	return 0;
}

Measured memory_bytes: 768
import scala.collection.mutable.ListBuffer

object Main extends App {

  private val alphabets = Array.ofDim[Int](26)
  private val buff = ListBuffer.empty[String]
  val sc = new java.util.Scanner(System.in)
  while(sc.hasNext){
    buff += sc.next
  }
  
  buff.mkString("").foreach{ c =>
    val idx = c.toLower - 'a'
    if(idx >= 0) alphabets(idx) += 1
  }
  println(('a' to 'z').map(f => f.toString + " : " + alphabets(f - 'a')).mkString(f"%n"))
  
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x = 0): x((x%mod+mod)%mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2); }
  mint& operator /= (const mint a) { return *this *= a.inv(); }
  mint operator / (const mint a)  const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

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

  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];
  vector<mint> q(s+1);
  mint ans = 0;
  rep(i, 0, n) {
    q[0] += 1; // q += 1
    { // q *= (1 + x^a[i])
      vector<mint> q2(s+1);
      rep(j, 0, s+1) {
        q2[j] += q[j];
        if (j+a[i] <= s) q2[j+a[i]] += q[j];
      }
      q = q2;
    }
    ans += q[s];
  }

  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int X = scan.nextInt();
		int A = scan.nextInt();
		int B = scan.nextInt();
		if(B - A <= 0) {
			System.out.println("delicious");
		} else {
			if(B - A > X) {
				System.out.println("dangerous");
			} else {
				System.out.println("safe");
			}
		}
		scan.close();
	}

}


Measured memory_bytes: 22996
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n;
	cin >> n;
	int num[2] = {};
	REP(i,n)
	{
		int tmp;cin>>tmp;
		if(tmp%4 == 0)num[1]++;
		else if(tmp%2 == 0)num[0]++;
	}
	if(num[0] > 0)num[0]--;
	
	if(n - num[0] - num[1] - 1 <= num[1])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//以下回答
int main(){
    ll N,P;
    cin>>N>>P;
    ll ans=1;
    map<ll,ll> m;
    m=prime_factor(P);
    for(auto p:m){
        auto v=p.second;
        auto k=p.first;
        ll a=v/N;
        rep(i,a){
            ans*=k;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;

    // time, index
    vector<tuple<ll, ll, ll>> ins;
    vector<tuple<ll, ll, ll>> outs;

    vector<tuple<ll, ll, ll>> STXs(N);
    REP(n, N) {
        int s, t, x;
        cin >> s >> t >> x;
        STXs[n] = mt(s, t, x);

        ins.pb(mt(s - x, x, n));
        outs.pb(mt(t - x, x, n));
    }
    sort(ALL(ins));
    sort(ALL(outs));

    vector<ll> Ds(Q);
    REP(q, Q) cin >> Ds[q];

    int pos1 = 0;
    int pos2 = 0;
    set<pair<ll, ll>> event;  // <座標, idx>
    for(auto d: Ds) {
		//cerr << "d = " << d << endl;
        while(pos1 < N && get<0>(ins[pos1]) <= d) {

			auto t1 = get<1>(ins[pos1]);
			auto t2 = get<2>(ins[pos1]);

			event.insert(mp(t1, t2));
            ++pos1;
        }
        while(pos2 < N && get<0>(outs[pos2]) <= d) {

			auto t1 = get<1>(outs[pos2]);
			auto t2 = get<2>(outs[pos2]);
			event.erase(mp(t1, t2));
			++pos2;
        }
		//cerr << "event: "; for (auto e : event) cerr << e << " "; cerr << endl;
        if (event.empty()) cout << -1 << endl;
        else {
            auto itr = *event.begin();
			auto idx = itr.second;
            cout << get<2>(STXs[idx]) << endl;
        }
        
    }
    

    return 0;
}


Measured memory_bytes: 31132
/* {{{ Definitions */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ios>
#include <utility>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
/* }}}------------------------------------------- */
int n;
void solve(){
	cout << n * n * n << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
		solve();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<sstream>
#include<math.h>
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	ll n;
	cin >> n;
	ll ans = 1e18;
	for (ll i = 1; i*i <= n; i++) {
		if (n%i != 0)continue;
		ll j = n / i;
		ans = min(i + j - 2, ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
G = [4, 1, 4, 1, 2, 1, 2, 1]
N = 8
ans = []
for line in open(0).readlines():
    *P, = map(int, line.split())
    Q = None; c = -1
    for i in range(N):
        R = G[i:] + G[:i]
        d = 0
        for j in range(N):
            d += min(R[j], P[j])
        if c < d:
            c = d
            Q = R
        elif c == d and R < Q:
            Q = R
    print(*Q)


Measured memory_bytes: 5728