akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int a =1;a<=n;a++){
			String s = String.valueOf(a);
			if(a%3 == 0){
				System.out.print(" "+a);
			}else{
				int t = s.indexOf("3");
				if(t != -1){
					System.out.print(" "+a);
				}
			}
		}
		System.out.println("");
	}
}

Measured memory_bytes: 24192
#include<stdio.h>

const int MAX = 12800;

int abs(int x){
  return x > 0 ? x : -x;
}

int dp[80][80][12801];

int main(){
  int H, W;
  scanf("%d %d", &H, &W);
  
  int A[H][W];
  int B[H][W];
  for(int i = 0; i < H; i++)
    for(int j = 0; j < W; j++)
      scanf("%d", &A[i][j]);
  
  for(int i = 0; i < H; i++)
    for(int j = 0; j < W; j++)
      scanf("%d", &B[i][j]);
  
  for(int i = 0; i < H; i++)
    for(int j = 0; j < W; j++)
      for(int k = 0; k <= MAX; k++)
        dp[i][j][k] = 0;
  
  dp[0][0][abs(A[0][0] - B[0][0])] = 1;
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      for(int k = 0; k <= MAX; k++){
        if(dp[i][j][k] == 0) continue;
        if(i < H - 1){
          dp[i + 1][j][k + abs(A[i + 1][j] - B[i + 1][j])] = 1;
          dp[i + 1][j][abs(k - abs(A[i + 1][j] - B[i + 1][j]))] = 1;
        }
        if(j < W - 1){
          dp[i][j + 1][k + abs(A[i][j + 1] - B[i][j + 1])] = 1;
          dp[i][j + 1][abs(k - abs(A[i][j + 1] - B[i][j + 1]))] = 1;
        }
      }
    }
  }
  
  int b = 0;
  for(int k = 0; k <= MAX; k++){
    if(dp[H - 1][W - 1][k]){
      b = k;
      break;
    }
  }
  
  printf("%d\n", b);
  
  return 0;
}


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

int find(int n, int now, int k) {
	if(now > n) {
		return 0;
	}
	if(k == 1) {
		return 1;
	}
	int sum = 0;
	for(int i = 2; i <= n; i++) {
		int w = find(n, now * i, k - 1);
		if(w == 0) {
			break;
		}
		sum += w;
	}
	return sum;
}

signed main() {
	int n, k;
	cin >> n >> k;
	int sum = 0;
	for(int i = 1; i <= n; i++) {
		sum += find(n, i, k);
	}
	cout << sum << endl;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;

  sort(rbegin(a),rend(a));
  ll ans = 0;
  ans = a[0];
  int k = 0;
  int i = 1;
  while(k<n-2){
    dump(ans);
    if(k+2<n-1){
      ans += a[i++]*2;
      k += 2;
    }else{
      ans += a[i];
      k++;
    }
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 4840
a = input().split(" ")
N = eval(a[0])
M = eval(a[1])
b = input().split(" ")
hight_lst = list(map(eval, b))
lst = []
for i in range(N):
    lst.append(1)
for i in range(M):
    c = input().split(" ")
    c1 = eval(c[0]) - 1
    c2 = eval(c[1]) - 1
    if hight_lst[c1] > hight_lst[c2]:
        lst[c2] = 0
    elif hight_lst[c1] < hight_lst[c2]:
        lst[c1] = 0
    else:
        lst[c1] = 0
        lst[c2] = 0
count = 0
for i in lst:
    if i == 1:
        count += 1

print(count)

Measured memory_bytes: 20904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep (i, n) {
        cin >> a[i];
    }
    rep (i, n) {
        cin >> b[i];
    }
    ll ctr = 0;
    rep (i, n) {
        if (a[i] > b[i]) {
            ctr += a[i] - b[i];
        } else {
            ctr -= (b[i] - a[i]) / 2;
        }
    }
    cout << (ctr > 0 ? "No" : "Yes") << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
using namespace std;

int main() {
	int n; cin >> n;
	set<int> st;
	REP(i, n) {
		int tmp; cin >> tmp;
		st.insert(tmp);
	}
	cout << st.size() << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/

int x,y,a,b,c;
ll p[100010], q[100010], r[100010];
vector<ll> v;

int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    cin >> x >> y >> a >> b >> c;
    forn(i, a) cin >> p[i];
    forn(i, b) cin >> q[i];
    forn(i, c) cin >> r[i];
    sort(p, p+a, greater<ll>());
    sort(q, q+b, greater<ll>());
    forn(i, x) v.pb(p[i]);
    forn(i, y) v.pb(q[i]);
    forn(i, c) v.pb(r[i]);
    sort(v.begin(), v.end(), greater<ll>());
    ll ans = 0;
    forn(i, x+y) ans += v[i];
    cout << ans << endl;
}


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

const int INF = 100100100;

int c[10][1005];

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int ans;
  rep(div, 1<<(h-1)) {
    int g = 0;
    vector<int> id(h);
    rep(i, h) {
      id[i] = g;
      if (div>>i&1) ++g; // 区切り線にきたらg数を増やす
    }
    ++g;

    rep(i,g)rep(j,w) c[i][j] =0;
    rep(i,h)rep(j,w) c[id[i]][j] += (s[i][j]-'0');
    int num = g-1;
    vector<int> now(g);
    auto add = [&](int j) {
      // 全グループをチェック
      rep(i,g) now[i] += c[i][j];
      // ひとつでもK超えのグループがあればfalse
      rep(i,g) if (now[i]>k) return false;
      return true;
    };
    // あとは貪欲に. j列目を追加するとき
    // Kを超えるなら分割数++&now初期化
    rep(j,w) {
      if (!add(j))
      {
        num++;
        now = vector<int>(g); // 白カウンタ
        if (!add(j)) { // 今の行を足す必要
          num = INF;
          break;
        }
      }
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	string S, T;
	cin >> S;
	cin >> T;

	int ans = static_cast<int>(T.length());

	int difflen = static_cast<int>(S.length() - T.length());
	for (int i = 0; i <= difflen; i++)
	{
		int idxS = i;
		int idxT = 0;
		int unmatchlen = 0;
		do {
			if (S[idxS] != T[idxT])
			{
				unmatchlen++;
			}
			idxS++;
			idxT++;
		} while (idxT < T.length());
		ans = min(ans, unmatchlen);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<vi> vvi;
const int MOD = 1e9 + 7;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

int main() {
    fastIO;
    ll N;
    cin >> N;
    if (N % 1000 == 0)  cout << 0 << endl;
    else    cout << 1000 - (N % 1000) << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
vector<bool> seen;
void dfs(Graph G, int v){
  seen[v]=true;
  for(int next_v: G[v]){
    if(seen[next_v]) continue;
    dfs(G, next_v);
  }
}
int main(){
  int N, M;
  cin >> N >> M;
  Graph G(N+1), H(M+1);
  for(int i=1; i<=M; i++){
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);    
    H[i].push_back(a);    
    H[i].push_back(b);
  }
  int ans=0;
  for(int i=1; i<=M; i++){
    int a=H[i][0], b=H[i][1];
    for(int j=0; j<G[a].size(); j++){
      if(G[a][j]==b){
        G[a].erase(G[a].begin()+j);
        break;
      }
    }
    for(int j=0; j<G[b].size(); j++){
      if(G[b][j]==a){
        G[b].erase(G[b].begin()+j);
        break;
      }
    }
    seen.assign(N+1, false);
    dfs(G, 1);
    int num=0;
    for(int j=1; j<=N; j++){
      if(seen[j]) num++;
    }
    if(num!=N) ans++;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
C, N = gets.split.map &:to_i
p = N.times.map{gets.chomp}

bilateral = Array.new(N){Array.new(N/2)}
diphycercal = Array.new(N/2){Array.new(N)}
b = 0
d = 0
(N/2).times do |i|
  N.times do |j|
    bilateral[j][i] = p[j][i] == p[j][N-1-i]
    diphycercal[i][j] = p[i][j] == p[N-1-i][j]
    b += 1 unless bilateral[j][i]
    d += 1 unless diphycercal[i][j]
  end
end

ans = 0
ans += 1 if b.zero? && d.zero?

(C-1).times do
  gets.to_i.times do
    r, c = gets.split.map &:to_i
    r -= 1
    c -= 1
    rr = r < N/2 ? r : N - 1 - r
    cc = c < N/2 ? c : N - 1 - c
    b += (bilateral[r][cc] ? 1 : -1)
    d += (diphycercal[rr][c] ? 1 : -1)
    bilateral[r][cc] = !bilateral[r][cc]
    diphycercal[rr][c] = !diphycercal[rr][c]
  end
  ans += 1 if b.zero? && d.zero?
end
p ans

Measured memory_bytes: 18704
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(ll a=b;a<=c;a++)
#define PER(a,b,c) for(ll a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<ll,ll>
#define pii pair<pair<ll,ll>,ll>
using namespace std;
const double Pi=acos(-1.0);
const ll MAXN=1e6+5;
ll n,m,t,kk;
ll v[MAXN],p[MAXN];
ll vis[MAXN],ne[MAXN];
ll q[MAXN];
int main(){
    cin>>n>>kk;
    ll ans=-1e18;
    REP(i,1,n)cin>>p[i];
    REP(i,1,n)cin>>v[i];
    REP(i,1,n){
        if(!vis[i]){
            ll cnt=0;
            ll tmp=i;
            while(!vis[tmp]){
                vis[tmp]=1;
                ne[++cnt]=v[tmp];
                tmp=p[tmp];
            }
            REP(j,1,cnt*2)ne[j+cnt]=ne[j];
            REP(j,1,cnt*3){
                q[j]=q[j-1]+ne[j];
            }
            ll circle=q[cnt];
            ll tmpans=-1e18;
            REP(j,1,cnt){
                REP(k,j,j+cnt*2){
                    if(k-j+1>kk)continue;
                    ll left=kk-(k-j+1);
                    ll times=left/cnt;
                    tmpans=q[k]-q[j-1]+times*max(0ll,circle);
                    ans=max(ans,tmpans);
                }
            }
        }
    }
    cout<<ans;
}

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

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

    for(int i=0;i<a.size();i++){
        cout<<a[i];
        if(i>=b.size())
            break;
        cout<<b[i];
    }

    if(a.size()<b.size())
        cout<<b[b.size()-1];

    cout<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
     
    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();
        
      if(a==5 && b==5 && c==7 || a==5 && b==7 && c ==5 || a==7 && b==5 && c==5){
        System.out.println("YES");
      }
        else System.out.println("NO");
      }
    }

Measured memory_bytes: 35760
#define _USE_MATH_DEFINES

//#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <vector>
    
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
//using ll = long long;
    
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(ceil((double)c / (double)b) > ceil((double)a / (double)d) ){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }

} // end of main
    
//実行は、Opt + Ctl + N


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main()
{
    int H,N;
    cin >> H >> N;

    for (int i = 0; i < N; i++)
    {
        int A;
        cin >> A;
        H = H - A;
    }

    if (H <= 0)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
void Main(){
    int x,t;cin>>x>>t;
    cout<<max(0,x-t)<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
    #define int long long
    using namespace std;
    int32_t main()
    {
        int n,m;
        cin>>n;
        string p="",q="";
        for(int i=0;i<n;++i)
        {
            cin>>m;
            p+=(m+'0');
        }
        for(int i=0;i<n;++i)
        {
            cin>>m;
            q+=(m+'0');
        }
        string s="";
        int c=0,a=0,b=0;
        for(int i=1;i<=n;++i)
        {
            s+=char(i+'0');
        }
        do{
            ++c;
            if(s==p)
            a=c;
            if(s==q)
            b=c;

        }while(next_permutation(s.begin(),s.end()));
        cout<<abs(a-b);
    }

Measured memory_bytes: 3632
using System;
class example{
    public static void Main(){
        String[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        int c = int.Parse(str[2]);
        int count = 0;
        for(int i = a; i <= b; i++){
            if(c%i == 0)
                count++;
        }
        Console.WriteLine("{0}",count);
    }
}


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

int main()
{
   int n,a[100006],c=0;
   cin>>n;
   for(int i=0;i<n;i++){ 
       cin>>a[i];
   } 
   int l=a[0];
   int ans=1;
   for(int i=1;i<n;i++){ 
       if(a[i]<=l){ 
           ans++;
           l=a[i];
           c=max(ans,c);
       } 
       else{  ans=1;  l=a[i]; } 
       //cout<<ans<<" ";
   } 
   if(c==0)cout<<0;
   else cout<<c-1;
   
   
   
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

int main(void){
	string s;

	cin >> s;
	int flag1 = false, flag2 = false;
	rep(i, s.size()){
		if(s[i] == 'C') flag1 = true;
		if(s[i] == 'F' && flag1) flag2 = true;
	}
	if(flag1 && flag2){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        
        for(int i=0; i<3; i++){
            int num = Integer.parseInt(sc.next());
            if(map.get(num) == null){
                map.put(num, 1);
            }
        }
        
        System.out.println(map.size());
    }
}

Measured memory_bytes: 21844
A, B, M = [int(s) for s in input().split()]
As = [int(s) for s in input().split()] + [10000000000]
Bs = [int(s) for s in input().split()] + [10000000000]

Ms = []
for _ in range(M):
    tMs = [int(s) for s in input().split()]
    Ms.append(tMs)


C = min(*As) + min(*Bs)

for x, y, c in Ms:
    C = min(As[x-1] + Bs[y-1] - c, C)

print(C)


Measured memory_bytes: 34124
package main

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

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	sc.Split(bufio.ScanWords)
	// n, a, b := nextInt(), nextInt(), nextInt()
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	s := nextMega()
	// var s string
	// fmt.Scan(&s)
	rank := 0
	sum := 0
	for i := 0; i < n; i++ {
		ok := false
		if s[i] == 'a' && sum < a+b {
			sum++
			ok = true
		} else if s[i] == 'b' {
			rank++
			if sum < a+b && rank <= b {
				sum++
				ok = true
			}
		}
		if ok {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


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

string to_string(string s) { return '"' + s + '"'; }
string to_string(char c) { string s = "'"; s += c; return s + "'"; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 
template <typename A>
string to_string(A v) {
    bool first = true; 
    string res = "{";
    for (const auto &x : v) {
        if (!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}"; 
    return res;
}
istream_iterator<string> eos;
void dbg_out(istream_iterator<string> it) { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(istream_iterator<string> it, Head H, Tail... T) {
    cerr << *it << " = " << to_string(H);
    if(++it != eos) cerr << ", ";
    dbg_out(it, T...);
}
#ifdef LOCAL
    #define dbg(...) { string _s = #__VA_ARGS__; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); dbg_out(_it, __VA_ARGS__); }
#else
    #define dbg(...)
#endif

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define MP make_pair
#define sz(v) ((int)(v).size())
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

const int inf = (1LL << 60), mod = 1e9+7, nn = 2002;
int n;
vector <pii> a;
int dp[nn][nn];

int fun(int cur, int l) {
    if(cur == n) return 0;
    int r = (n - 1) - (cur - l);
    if(l > r) return 0;
    int &ans = dp[cur][l];
    if(ans != -1) return ans;

    int op1 = a[cur].ff * abs(a[cur].ss - l) + fun(cur+1, l+1);
    int op2 = a[cur].ff * abs(a[cur].ss - r) + fun(cur+1, l);
    return ans = max(op1, op2);
}

void solve(){
    cin >> n;
    fr(i, 0, n){
        int x; cin >> x;
        a.eb(x, i);
    }
    sort(a.rbegin(), a.rend());
    memset(dp, -1, sizeof dp);
    cout << fun(0, 0) << nl;
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

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

using namespace std;

int main(){
    int n=5;
    int dish[n],total,x=10;
    cin >>dish[0] >>dish[1] >>dish[2] >>dish[3] >>dish[4];
    for(int i=0;i<n;i++){
        if(dish[i]%10<x && dish[i]%10!=0){
            x=dish[i]%10;
        }
        if(dish[i]%10!=0){
            dish[i] = dish[i]/10 +1;
        }else{
            dish[i] = dish[i]/10;
        }
        total = total+dish[i];
    }
    cout << (total-1)*10+x <<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

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

int main() {
    int n; cin >> n;
    cout << 1 - n << endl;
}

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

int main(){
    while(1){
        int x,y,s;
        cin >> x >> y >> s;
        if(x==0) break;

        int ans=0;
        for(int i=1; i<s; i++){
            int xa = (double)i*(100+x)/100;
            if(s-xa<=0) break;
            int mb = (double)(s-xa)*100/(100+x);//lower bound of no tax
            while(1){
                int xb = (double)mb*(100+x)/100;
                if(xa+xb>s) break;
                if(xa+xb==s){
                    int tmp = (int)((double)i*(100+y)/100)
                        + (int)((double)mb*(100+y)/100);
                    ans = max(ans, tmp);
                }
                mb++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2960
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		scan.useDelimiter("\\n");
		String str1;
		char[] box = new char[1200];
		String str2 = "abcdefghijklmnopqrstuvwxyz";
		char[] az = str2.toCharArray();
		int[] ans = new int[26];
		
		do
		{
			str1 = scan.next();
			box = str1.toCharArray();
			
			for(int i = 0;i < box.length;i++)
			{
				if(Character.isUpperCase(box[i])){
					box[i] = Character.toLowerCase(box[i]);
				}
				
				for(int j = 0;j < 26;j++)
				{
					if(box[i] == az[j])
					{
						ans[j]++;
					}
				}
			}
		}while(scan.hasNext());
		
		for(int i = 0;i < 26;i++)
		{
			System.out.println(az[i] + " : " + ans[i]);
		}
	}
}

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

int main(void){

    const int num = 10000;
    int dataSet[num];
    int loopNum;
    
    for(int i = 0; i < num; i++) {
        std::cin >> dataSet[i];
        if(dataSet[i] == 0) {
            loopNum = i + 1;
            break;
        }
    }
    
    for(int i = 0; i < loopNum; i++) {
        if(dataSet[i] == 0) {
            break;
        }
        cout << "Case " << i + 1 << ": " << dataSet[i] << endl;
    }
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,ans=0;
  cin>>N>>M;
  unordered_map<int,vector<int>> mp;
  priority_queue<int> q;
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    mp[a].push_back(b);
    if(a==1){q.push(b);}
  }
  for(int i=1;i<=M;i++){
    if(!q.empty()){
      ans+=q.top();
      q.pop();
    }
    if(i==M){break;}
    for(int j=0;j<(int)mp[i+1].size();j++){
      q.push(mp[i+1].at(j));
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 8868
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n, k;
    cin >> n >> k;
    vi h(n);
    lli mah=0;
    rep(i,n){
        cin >> h[i];
        mah += h[i];
    }
    sort(all(h));
    reverse(all(h));
    lli ans=0;
    if(k>=n){
        ans = 0;
    }
    else{
        rep(i,k){
            mah -= h[i];
        }
        ans += mah;
    }
    out(ans);
}

Measured memory_bytes: 4876
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;


signed main(){
  ll N,K;
  ll ans = 0;
  cin >> N >> K;
  if(K == 0){
    cout << N*N << endl;
    return 0;
  }
  FOR(b,K+1,N+1){
    ll n = N/b;
    ans += (b-K)*n;
    ll mod = N%b;
    ans += max((ll)0,mod-K+1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.io.ObjectInputStream.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	//final static long MOD = 998244353;

	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solutionA(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solutionA(String[] args) throws Exception{
		int H = nextInt();
		int N = nextInt();
		int[] dp = new int[H+10];
		Arrays.fill(dp,Integer.MAX_VALUE/3);
		dp[H]=0;
		for(int i=0;i<N;i++) {
			int A =nextInt();
			int B =nextInt();

			int tmp;
			for(int hp=H;hp>0;hp--) {
				tmp=Math.max(0,hp-A);
				dp[tmp]=Math.min(dp[tmp],dp[hp]+B);
			}
		}
		pw.println(dp[0]);

	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}



Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define all(a) (a).begin(),(a).end()
#define X first
#define Y second
#define inf 1e18+5
using namespace std;
const int mod=1e9+7;
void solve()
{
  int n; cin>>n; int a[n][n];
  for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>a[i][j];
  int sz=pow(2,n);
  int dp[sz];
  memset(dp,0,sizeof(dp));
  dp[0]=1;
  for(int mask=1;mask<sz;mask++)
  {
      int cnt=0;
      for(int i=0;i<n;i++)if(mask&(1<<i))cnt++;
      for(int i=0;i<n;i++)
      {
          int t=1<<i;
          if(mask&t)
          {
              if(!a[cnt-1][i])continue;
              dp[mask]+=dp[mask&(~t)];
              dp[mask]%=mod;
          }
      }

  }
  cout<<dp[sz-1];
  return;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 20464
#include <iostream>
#include <vector>
#include <boost/multiprecision/cpp_int.hpp>
#define rep0(i, n) for(int i=0; i<(int)(n);i++)
typedef int64_t lint;
using namespace std;

int main(){
    lint n, k;
    cin >> n >> k;
    vector<lint> a(n);
    rep0(i, n){
        cin >> a[i];
    }
    lint kk = k * (k - 1) / 2;
    boost::multiprecision::cpp_int ans = 0;
    for (int i = 0; i < n; ++i) {
        lint left = 0;
        lint right = 0;
        for (int j = 0; j < n; ++j) {
            if(a[i] > a[j]){
                if(i > j)left ++ ;
                if(i < j)right ++ ;
            }
        }
        rep0(j,left)
        {
            ans += kk;
            ans %= 1000000007;
        }
        rep0(j,right)
        {
            ans += kk;
            ans %= 1000000007;
            ans += k;
            ans %= 1000000007;
        }     

    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);
    if((A > B) || ((N == 1) && (A != B)))
    {
       printf("0\n");
       return 0;
    }
    if(A == B)
    {
       printf("1\n");
       return 0;
    }
    printf("%lld\n", (long long)(B-A)*(N-2)+1);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int res = 0;
  for(int i = 0; i < 4; i++){
    if(s[i] == '+') res++;
    else res--;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  if (a == b)
    cout << c << endl;
  else if (a == c)
    cout << b << endl;
  else if (b == c)
    cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._

object Helpers {
  def readIntLine = readLine.split(" ").map(_.toInt)
  def readInts(n: Int) = Array.fill(n)(readInt)
  def readLines(n: Int) = Array.fill(n)(readLine)

  def splitDigits(i: Int): Seq[Int] = i.toString.map(_.asDigit)

  def log[A](x: A): A = {println(x); x}

  implicit class IntImplicits(val i: Int) {
    def isEven = i % 2 == 0
    def isOdd = !isEven

    def ** (exp: Int): Int = scala.math.pow(i, exp).intValue
  }

  implicit class LongImplicits(val i: Long) {
    def isEven = i % 2 == 0
    def isOdd = !isEven

    def ** (exp: Long): Long = scala.math.pow(i, exp).longValue
  }

  def mycomb[T](n: Int, l: List[T]): List[List[T]] =
    n match {
      case 0 => List(List())
      case _ => for(el <- l;
                sl <- mycomb(n-1, l dropWhile { _ != el } ))
                yield el :: sl
  }
  
  def comb[T](n: Int, l: List[T]): List[List[T]] = mycomb(n, l.distinct)
}

object Main extends App {
  import Helpers._

  val Array(n, l) = readIntLine
  val ss = readLines(n)

  println(ss.sorted.reduce(_ + _))
}



Measured memory_bytes: 30004
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 998244353
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
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<Pi> vPi;
typedef vector<Pll> vPll;
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<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n, m;

	cin>>n>>m;

	vs a(n), b(m);
	
	rep(i, n) cin>>a[i];

	rep(i, m) cin>>b[i];

	bool ans=false;
	rep(i, n-m+1){
		rep(j, n-m+1){
			bool flag=true;
			rep(k, m){
				rep(l, m){
					if(a[i+k][j+l]!=b[k][l]){
						flag=false; break;
					}
				}
				if(!flag) break;
			}
			if(flag) ans=true;
		}
	}
	cout<<yn(ans)<<endl;
}


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


def calc_divisor(x):
    divisor = []
    for i in range(1, int(x ** 0.5) + 1):
        if x % i == 0:
            if i != 1:
                divisor.append(i)
            if i != x // i:
                divisor.append(x // i)
    return divisor


cand = len(calc_divisor(N - 1))
divisor_n = calc_divisor(N)
for v in divisor_n:
    x = N
    while x % v == 0:
        x //= v

    if x % v == 1:
        cand += 1

print(cand)


Measured memory_bytes: 65496
import numpy as np

S = list(int(x) for x in input())

L1 = np.array([0 if x % 2 == 0 else 1 for x in range(len(S))] )
L2 = np.array([1 if x % 2 == 0 else 0 for x in range(len(S))])

print(min(sum(np.logical_xor(S, L2)), sum(np.logical_xor(S, L1))))

Measured memory_bytes: 15696
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int N,i;
  cin>>N;
  int A[N];
  double B[N];
  double sum;
  sum=0.0;
  for(i=0;i<N;i++){
  cin>>A[i];
    B[i]=1.0/A[i];
    sum=B[i]+sum;
  }
  cout<<1.0/sum<<endl;
}

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

int n;
int cnt = 0;
int A[1000000];
vector<int> G;

void insertionSort(int A[], int n, int g)
{
	for (int i = g; i < n; ++i)
	{
		int v = A[i];
		int j;
		j = i - g;
		while((j >= 0)&&(A[j] > v))
		{
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int n)
{
	for (int h = 1;;)
	{
		if (h > n)
		{
			break;
		}
		G.push_back(h);
		h = 3*h - 1;
	}

	for (int p = G.size() - 1; p >= 0; --p)
	{
		insertionSort(A, n, G[p]);
	}
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> A[i];
	}

	shellSort(A,n);

	cout << G.size() << "\n";
	for (int i = G.size() - 1; i >= 0; --i)
	{
		if (i != G.size() - 1)
		{
			cout << " ";
		}
		cout << G[i];
	}
	cout << "\n";

	cout << cnt << "\n";

	for (int i = 0; i < n; ++i)
	{
		cout << A[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 6988
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll n,k; cin>>n>>k;
    ll tmp = n%k;
    ll ans = min(tmp, abs(k-tmp));
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
}
  
  vector<int> num(n);
  for(int j=0; j<n-1; j++){
    num[a[j]-1]++;
  }
  
  for(int k=0; k<n; k++){
    cout << num[k] << endl;
  }
  
}


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

typedef long long ll;

#define debug(args...)do{cerr<< #args << " : ";shaon(args);}while(0)
void shaon () { cerr << endl; }
template <typename T, typename ... north>
void shaon(T arg, const north &... rest){cerr << arg << ' ';shaon(rest...);}

const ll N=1e5+5;
ll n, a[N][4], dp[N][4];

int main()
{
    scanf("%lld",&n);

    for(ll i=1; i<=n; i++){
        scanf("%lld %lld %lld",&a[i][0],&a[i][1],&a[i][2]);
    }

    dp[1][0]=a[1][0];
    dp[1][1]=a[1][1];
    dp[1][2]=a[1][2];

    for(ll i=2; i<=n; i++){
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }

    printf("%lld",max(dp[n][0],max(dp[n][1],dp[n][2])));

    return 0;
}


















Measured memory_bytes: 6528
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod=1000000007;
ll fac[2000007],finv[2000007],inv[2000007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<2000007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cominit();
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    c++;d++;
    cout<<(com(c+d,c)+com(a+b,a)-com(c+b,b)-com(a+d,a)+mod*2)%mod<<endl;
    return 0;
}


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

int main() {
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i += 2) {
        int ya = 0;
        REP(j, 1, i+1) {
            if (i % j == 0) ya++;
        }
        if (ya == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn=210;
int n,k,pri[10000010],linker[maxn],a[maxn],b[maxn];
bool mark[10000010],vis[maxn];
vector<int> v[maxn];
void pre()
{
	n=10000000;
	mark[1]=true;
	for (int i=2;i<=n;i++)
	{
		if (!mark[i])
		{
			pri[k++]=i;
		}
		for (int j=0;j<k;j++)
		{
			int m=i*pri[j];
			if (m>n)
			{
				break;
			}
			mark[m]=true;
			if (i%pri[j]==0)
			{
				break;
			}
		}
	}
}
bool dfs(int x)
{
	for (int i=0;i<v[x].size();i++)
	{
		int y=v[x][i];
		if (vis[y])
		{
			continue;
		}
		vis[y]=true;
		if (linker[y]==-1 || dfs(linker[y]))
		{
			linker[y]=x;
			return true;
		}
	}
	return false;
}
int main()
{
	pre();
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int k=0;
	b[++k]=a[1]-1;
	for (int i=2;i<=n;i++)
	{
		if (a[i]!=a[i-1]+1)
		{
			b[++k]=a[i-1];
			b[++k]=a[i]-1;
		}
	}
	b[++k]=a[n];
	n=k;
	for (int i=1;i<=n;i++)
	{
		linker[i]=-1;
		for (int j=i+1;j<=n;j++)
		{
			if ((b[i]+b[j])&1 && !mark[abs(b[i]-b[j])])
			{
				if (b[i]&1)
				{
					v[i].pb(j);
				}
				else
				{
					v[j].pb(i);
				}
			}
		}
	}
	int s=0;
	for (int i=1;i<=n;i++)
	{
		if (!(b[i]&1))
		{
			continue;
		}
		memset(vis,false,sizeof(vis));
		if (dfs(i))
		{
			s++;
		}
	}
	int s1=0,s2=0;
	for (int i=1;i<=n;i++)
	{
		if (b[i]&1)
		{
			s1++;
		}
		else
		{
			s2++;
		}
	}
	int ans=s+((s1-s)/2+(s2-s)/2)*2+((s1-s)&1)*3;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 14592
open Batteries

let () = 
        Scanf.sscanf (read_line ()) "%d" (
        fun k -> 
                let str = read_line () in
                        if (String.length str) <= k then
                                str
                        else
                                (String.sub str 0 k) ^ "..."
        ) |> Printf.printf "%s\n"


Measured memory_bytes: 5300
import java.util.Scanner;

public class Main {

	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		String str = scanner.nextLine();


		int[] arr = new int[300];
		
		for(int i = 0; i < 300; i++){
			arr[i] = 0;
		}
		
		for(char a : str.toCharArray()){
			arr[a] += 1;
		}

		boolean r = true;
		
		for(int i = 0; i < 300; i++){
			if(arr[i] % 2 == 1){
				r = false;
			}
		}
		if(r){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
		
	}

}


Measured memory_bytes: 9424
#include <iostream>
#include <vector>

using namespace std;

int main() {

    long long n, two;
    long long cheap = 1 << 30;

    for(int i = 0; i < 3; ++i) {
        long long p;
        cin >> p;
        cheap = min(cheap, p << (2 - i));
    }

    cin >> two;
    cin >> n;

    if(two < cheap * 2) {
        cout << n / 2 * two + cheap * (n % 2) << endl; 
    } else {
        cout << n * cheap << endl;
    }

}

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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template <class T> istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    map<string, ll> mp;
    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    vector<pair<string, ll>> v(mp.begin(), mp.end());
    // sort from bigger.
    sort(v.begin(), v.end(), [](pair<string, ll> a, pair<string, ll> b) {
        if (a.second == b.second) {
            return a.first < b.first;
        }
        return a.second > b.second;
    });
    cout << v[0].F << '\n';
    for (ll i = 0; i < v.size() - 1; ++i) {
        if (v[i].S == v[i + 1].S) {
            cout << v[i + 1].F << '\n';
        } else {
            break;
        }
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


Measured memory_bytes: 28288
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=20;
const int maxpos=65540;
int my_popcount[maxpos];
ll a[maxn][maxn],val[maxpos],maxx[maxpos];
vector<int> tmp,useful[maxn];
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
//    fl();
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++) 
			scanf("%lld",&a[i][j],&a[i][j]);
	for(int i=0;i<(1<<n);i++)
	{
		tmp.clear();
		for(int j=0;j<n;j++)
			if(i&(1<<j))
				tmp.push_back(j+1);
		for(int x=0;x<(int)tmp.size();x++)
			for(int y=x+1;y<(int)tmp.size();y++)
				val[i]+=a[tmp[x]][tmp[y]];
	}
	for(int i=0;i<(1<<n);i++)
	{
		my_popcount[i]=my_popcount[i>>1]+(i&1);
		useful[my_popcount[i]].push_back(i);
	}
	for(int i=1;i<=n;i++)
		for(int j=0;j<(int)useful[i].size();j++)
		{
			int mask=useful[i][j];
			maxx[mask]=val[mask];
			for(int sub=mask;sub;sub=(sub-1)&mask)
				maxx[mask]=max(maxx[mask],maxx[sub]+val[mask^sub]);
		}
	ll ans=maxx[(1<<n)-1];
	printf("%lld\n",ans);
	return 0;
}


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

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

  int n, m, q;
  vector<tuple<int, int, int, int>> a;

  cin >> n >> m >> q;
  for (int i = 0; i < q; ++i) {
    int x, y, z, w;
    cin >> x >> y >> z >> w;
    --x; --y;
    a.emplace_back(x, y, z, w);
  }

  vector<int> array(n);
  function<int(int, int)> brute = [&](int v, int last) {
    if (v == n) {
      int score = 0;
      for (int i = 0; i < q; ++i) {
        int x, y, z, w;
        tie(x, y, z, w) = a[i];
        if (array[y] - array[x] == z)
          score += w;
      }

      return score;
    }

    int best_score = 0;
    for (int i = last; i <= m; ++i) {
      array[v] = i;
      best_score = max(best_score, brute(v + 1, i));
    }

    return best_score;
  };

  cout << brute(0, 1) << '\n';
}

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

int main(){
    int y,m,d;
    char a,b;
    cin >> y >> a >> m >> b >> d;
    if(m<4 || (m==4 && d<=30)) cout << "Heisei" << endl;
    else cout << "TBD" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<stack>
#include<vector>


using namespace std;

vector<int> vec[1001];
bool ch[101]={};
stack<int> st;
int maxx = -1;


void DFS(int i,int val){
    if(val > maxx)maxx = val;
    //printf("%d ",i);
    for (int k=0; k<vec[i].size(); k++) {
        if(!ch[vec[i][k]]){
            ch[vec[i][k]] = true;
            DFS(vec[i][k],val+1);
            ch[vec[i][k]] = false;
        }
    }
}

int main(){
    maxx = -1;
    int n,a,b;
    scanf("%d",&n);
    if(n == 0)return 0;
    for (int i=0; i<n; i++) {
        scanf("%d %d",&a,&b);
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    for (int i=1; i<=100; i++) {
        ch[i] = true;
        DFS(i,0);
        ch[i] = false;
    }
    printf("%d\n",maxx+1);
    for (int i=0; i<=100; i++) {
        vec[i].clear();
    }
    main();
    
    
}

Measured memory_bytes: 2796