akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

long long ans,p,cur,t,cnt[200010];
string s;

int main()
{
    cin >> s;
    p = 2019;
    cnt[0] = 1,t = 1;
    for(int i = s.size() - 1;i >= 0;i--)
    {
        cur = (cur + t*(s[i] - '0')%p) % p;
        t = t*10 % p;
        ans += cnt[cur]++;
    }
    
    cout << ans << endl;
    return 0;
}

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

public static class Program
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var hash = new HashSet<string>();
        for (int i = 0; i < n; i++)
            hash.Add(Console.ReadLine());
        Console.Write(hash.Count);
    }
}

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

int main() {
    int a,b,c;
    int x = 0;
    cin >> a >> b >> c;
    for (int i = a; i<=b; i++) {
        if (c%i==0) {
            x++;
        }
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3112
def main():
    n = int(input())
    ss = [c == 'E' for c in input()]
    c_l = 0
    c_r = len([t for t in ss[1:] if t])
    res = c_r
    for i in range(1, n):
        c_l += int(not ss[i - 1])
        c_r -= int(ss[i])
        res = min(res, c_l + c_r)
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10448
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

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 INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  string s, t;
  cin >> s >> t;
  vector<char> ss(s.size()), tt(t.size());
  rep(i, s.size()) ss[i] = s[i];
  rep(i, t.size()) tt[i] = t[i];
  sort(ALL(ss));
  sort(ALL(tt), greater<char>());
  for (int i = 0; i < min(ss.size(), tt.size()); i++) {
    if (ss[i] < tt[i]) {
      puts("Yes");
      return 0;
    } else if (ss[i] > tt[i]) {
      puts("No");
      return 0;
    }
  }

  if (ss.size() < tt.size()) puts("Yes");
  else puts("No");

  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
D = []
A = []
count = 0
for i in range(k):
	d = int(input())
	D.append(d)
	a = list(map(int, input().split()))
	for l in a:
		A.append(l)

for m in range(1, n + 1):
	if m not in A:
		count += 1

print(count)

Measured memory_bytes: 9196
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var s = new string[n];
        var t = new int[n];
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            s[i] = line[0];
            t[i] = int.Parse(line[1]);
        }
        var x = Console.ReadLine().Trim();
        getAns(n, s, t, x);
    }
    static void getAns(int n, string[] s, int[] t, string x)
    {
        var w = Array.FindIndex(s, a => a == x);
        var ans = 0;
        for (int i = w + 1; i < n; i++) ans += t[i];
        Console.WriteLine(ans);
    }
}


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

int main()
{
	int n;
	std::cin >> n;

	std::vector<int>h;
	for(int i = 0; i < n; i++)
	{
		int value;
		std:: cin >> value;
		h.push_back(value);
	}

	std::vector<int>dp(n+1);
	dp[1] = abs(h[1]-h[0]);
	dp[2] = std::min(abs(h[2]-h[0]), dp[1]+abs(h[2]-h[0]));

	for(int i = 3; i < n; i++)
	{
		dp[i] = std::min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
	}

	std::cout << dp[n-1];
	return 0;
}

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

using namespace std;

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

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

char s[125252];
ll dp[125252][13];

int main(){
    scanf("%s",s);
    dp[0][0] = 1;
    int n = strlen(s);
    REP(i,n)REP(j,13){
        REP(d,10)if(s[i]=='?' || s[i]-'0'==d){
            (dp[i+1][(j*10+d)%13] += dp[i][j]) %= MOD;
        }
    }
    printf("%lld\n",dp[n][5]);
    return 0;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int N,M,n,m;
int a[9123][9123];

int main(){

cin>>N>>M>>n>>m;

for(int i=n;i<=N;i+=n)
    for(int j=m;j<=M;j+=m)
        a[i][j]=-1e7 -1;

for(int i=1;i<=N;i+=n)
    for(int j=1;j<=M;j+=m)
            a[i][j]=1e7;

if( N%n==0 && M%m==0 ){

    cout<<"No"<<endl;

}else{

    cout<<"Yes"<<endl;
    for(int i=1;i<=N;i++)
        for(int j=1;j<=M;j++)
            cout<<a[i][j]<<" \n"[j==M];

}

return 0;
}


Measured memory_bytes: 19328
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

  ll n, a, b;cin >> n >> a >> b;
  ll ans = (n / (a + b)) * a + min((n % (a + b)), a);
  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
using namespace std;
int main() {
    int n;
    cin >> n;
    set<string> st;
    for (int i = 0; i < n; ++i) {
        string command, str;
        cin >> command >> str;
        if (command[0] == 'i') {
            st.insert(str);
        } else {
            if (st.find(str) != st.end()) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 32180
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

typedef vector<int> vi;

struct Dice {
  static const int DN = 6;
  vi ds;

  // 0=X+(top), 1=Y+(front), 2=Z+(right), 3=Z-(left), 4=Y-(back), 5=Z-(bottom)
  Dice(vi &_ds): ds(_ds) {}
  Dice(const int _ds[]) { ds.assign(_ds, _ds + DN); }
  //Dice(): ds(ids, ids + DN) {}

  bool operator==(const Dice &d) const {
    for (int i = 0; i < DN; i++)
      if (ds[i] != d.ds[i]) return false;
    return true;
  }

  bool operator<(const Dice &d) const {
    for (int i = 0; i < DN; i++)
      if (ds[i] != d.ds[i]) return (ds[i] < d.ds[i]);
    return false;
  }

  inline int top()    { return ds[0]; }
  inline int front()  { return ds[1]; }
  inline int right()  { return ds[2]; }
  inline int left()   { return ds[3]; }
  inline int back()   { return ds[4]; }
  inline int bottom() { return ds[5]; }
  
  Dice rotx(int n = 1) { // 1, 2, 4, 3
    Dice r(*this);
    while (n--) {
      int t = r.ds[1];
      r.ds[1] = r.ds[3]; r.ds[3] = r.ds[4]; r.ds[4] = r.ds[2];
      r.ds[2] = t;
    }
    return r;
  }

  Dice roty(int n = 1) { // 2, 0, 3, 5
    Dice r(*this);
    while (n--) {
      int t = r.ds[2];
      r.ds[2] = r.ds[5]; r.ds[5] = r.ds[3]; r.ds[3] = r.ds[0];
      r.ds[0] = t;
    }
    return r;
  }

  Dice rotz(int n = 1) { // 0, 1, 5, 4
    Dice r(*this);
    while (n--) {
      int t = r.ds[0];
      r.ds[0] = r.ds[4]; r.ds[4] = r.ds[5]; r.ds[5] = r.ds[1];
      r.ds[1] = t;
    }
    return r;
  }

  void print() {
    for (int i = 0; i < DN; i++) printf("%d", ds[i]); putchar('\n');
  }

  static void alldices(const Dice &d0, set<Dice> &s) {
    Dice d(d0);
    for (int z = 0; z < 4; z++) {
      Dice dz = d.rotz(z);
      for (int y = 0; y < 4; y++) {
	Dice dy = dz.roty(y);
	for (int x = 0; x < 4; x++)
	  s.insert(dy.rotx(x));
      }
    }
  }
};

typedef set<Dice> sd;

/* global variables */

int ds0[6], ds1[6];

/* subroutines */

/* main */

int main() {
  for (int i = 0; i < 6; i++) cin >> ds0[i];
  for (int i = 0; i < 6; i++) cin >> ds1[i];

  Dice d0(ds0), d1(ds1);

  sd dset;
  Dice::alldices(d0, dset);

  for (sd::iterator sit = dset.begin(); sit != dset.end(); sit++)
    if (*sit == d1) {
      puts("Yes");
      return 0;
    }

  puts("No");
  return 0;
}

Measured memory_bytes: 1168
from collections import Counter
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())
cnt = Counter([a1, b1, a2, b2, a3, b3])
if sorted(cnt.values()) == [1, 1, 2, 2]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3444
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
bool cmp(pair<ll,ll> a,pair<ll,ll> b){
    if(a.F!=b.F)
        return a.F<b.F;
    else
        return a.S>b.S;
}
ll mod=1000000007;
const ll N=200005;
int main()
{
fast;
    ll n;
    cin>>n;
    ll a[n];
    f(i,n)
        cin>>a[i];
    ll c=0;
    f1(i,n-1)
    {
        if(a[i]>=a[i-1])
            continue;
        c+=a[i-1]-a[i];
        a[i]=a[i-1];
    }
    cout<<c;
    return 0;
}

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

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

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

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

ll N;
ll D[100];
int main(int argc, char **argv)
{
	cin >> N;
	D[0] = 0;
	REP(i, N)
		cin >> D[i+1];
	++N;

	vector<ll> cnt(13, 0);
	REP(i, N)
		++cnt[D[i]];

	REP(i, 13)
	{
		if (i == 0 || i == 12)
		{
			if (cnt[i] >= 2)
			{
				std::cout << 0 << std::endl;
				return 0;
			}
		}
		else if (cnt[i] >= 3)
		{
			std::cout << 0 << std::endl;
			return 0;
		}
	}
	
	ll res{0};
	for (ll time = 0; time < (1ll<<11); ++time)
	{
		vector<ll> tmp;

		if (cnt[0])
			tmp.push_back(0);
		if (cnt[12])
			tmp.push_back(12);

		for (ll i = 1; i < 12; ++i)
		{
			if (cnt[i] == 2)
			{
				tmp.push_back(i);
				tmp.push_back(24-i);
			}
			else if (cnt[i] == 1)
			{
				if (time & (1ll << (i-1)))
					tmp.push_back(24-i);
				else
					tmp.push_back(i);
			}
		}

		ll tmp2{INF};
		for (ll i = 0; i < N-1; ++i)
			for (ll j = i + 1; j < N; ++j)
			{
				ll t = abs(tmp[i] - tmp[j]);
				tmp2 = min(tmp2, min(24-t, t));
			}

		res = max(res, tmp2);
	}


	std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int b[200005];
vector<int> ve;
int main()
{
    int ans=0;
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
    for(int i=1; i<=n; i++)
        scanf("%d",&b[i]);
    long long tmp=0;
    for(int i=0; i<=29; i++)
    {
        ve.clear();
        int mod=(1<<(i+1));
        for(int j=1; j<=n; j++)
            ve.push_back(b[j]%mod);
        mod/=2;
        sort(ve.begin(),ve.end());
        tmp=0;
        for(int j=1; j<=n; j++)
        {
            int tmpl,tmpr;
            tmpl=lower_bound(ve.begin(),ve.end(),mod*1-a[j]%(mod*2))-ve.begin()-1;
            tmpr=lower_bound(ve.begin(),ve.end(),mod*2-a[j]%(mod*2))-ve.begin()-1;
            tmp+=tmpr-tmpl;
            tmpl=lower_bound(ve.begin(),ve.end(),mod*3-a[j]%(mod*2))-ve.begin()-1;
            tmpr=lower_bound(ve.begin(),ve.end(),mod*4-a[j]%(mod*2))-ve.begin()-1;
            tmp+=tmpr-tmpl;
        }
        if(tmp%2==1) ans=(1<<i)|ans;
    }
    printf("%d\n",ans);

}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
#define s size
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 100000007
#define F first
#define S second
#define aLL(str) (str).begin(), (str).end()
#define IOS                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0)
#define ll long long
typedef vector<ll> vl;
typedef map<ll,ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;

int main()
{IOS;
int t;
t=1;
while(t--)
{ll x,y,a,b;
cin>>x>>y;
a=x*2;
b=x*4;
if(y<=b && y>=a && y%2==0)cout<<"Yes";
else cout<<"No";
}
return 0;}

Measured memory_bytes: 3544
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int score = 0;
	rep(i, n - 1) {
		if (s[i] == s[i + 1])score++;
	}
	int ans = min(score + 2 * k, n - 1);
	cout << ans;
	return 0;
}

Measured memory_bytes: 3712
#include<stdio.h>
int main(){
	double a,b;
	scanf("%lf%lf",&a,&b);
	if (a - b != 0){
		if (a - b < 0){
			printf("LESS\n");
			}
			else if(a - b > 0){
				printf("GREATER\n");
				}
		}
		else{
			printf("EQUAL\n");
			}
	return 0;
	}

Measured memory_bytes: 128
from collections import defaultdict
n = int(input())

# l = [[0]  * 10 for _ in range(10)]
d=defaultdict(lambda:defaultdict(int))

for i in range(1,n+1):
    s=str(i)
    # l[int(s[0])][int(s[-1])] +=1
    d[int(s[0])][int(s[-1])] +=1

r=0
for i in range(1,10):
    for j in range(1,10):
        # r += l[i][j] * l[j][i]
        r += d[i][j] * d[j][i]

print(r)

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
using namespace std;
int N; long long T, a[200009], sum[100009];
int main() {
	cin >> T >> N;
	for (int i = 0; i < 2 * N; i += 2) cin >> a[i] >> a[i + 1];
	for (int i = 0; i < N; i++) sum[i + 1] = sum[i] + a[i * 2 + 1] - a[i * 2];
	long long ret = 0;
	for (int i = 0; i < 2 * N; i += 2) {
		int ptr = lower_bound(a, a + 2 * N, a[i] + T) - a - 1;
		long long res = 0;
		if (ptr % 2 == 0) res = sum[ptr / 2] - sum[i / 2] + (a[i] + T) - a[ptr];
		else res = sum[ptr / 2 + 1] - sum[i / 2];
		ret = max(ret, res);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 5440
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int x, y;
    cin >> x >> y;
    if(y%2!=0)
    cout << "No";
    else if((y/2 - x) < 0 || 2*x - (y/2) < 0)
    cout << "No";
    else
    cout << "Yes";    
    return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define INF 0x7fffffff
using namespace std;
typedef long long ll;
int n,a[200001],b;
ll ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        a[i]-=i;
    }
    sort(a+1,a+n+1);
    b=a[(n+1)/2];
    for(int i=1;i<=n;i++)
       ans+=abs(a[i]-b);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  string S;
  cin>>S;
  int num=0;
  for(int i=0;i<3;i++){
    if(S.at(i)=='o'){
      num++;
    }
  }
  cout<<700+100*num<<endl;

}


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

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            String upper = in.next();
            String lower = in.next();
            out.println((new StringBuilder(upper)).reverse().toString().equals(lower) ? "YES" : "NO");
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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


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

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

	int cnt =0;
	for(int x =a; x <=b; x++){
	if(c%x ==0) cnt++;
}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;
using ld  = long double;
using vd  = vector<ld>;
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)

int N, M;
vvl edges;
ld ans;

int main() {
    cin >> N >> M;
    edges.resize(N);
    ans = 1e9;
    rep(i,M) {
        int a, b; cin >> a >> b; a--; b--;
        edges[a].push_back(b);
    }
    rep(k,N) {
        vd dp(N, 0);
        per(i,N) {
            ld sum = 0, mx = 0;
            int sz = edges[i].size();
            for (auto j : edges[i]) {
                mx = max(mx, dp[j]);
                sum += dp[j];
            }
            if (i == k and sz >= 2) { sum -= mx; sz--; }
            if (sz >= 1) sum = (sum + sz) / sz;
            dp[i] = sum;
        }
        ans = min(ans, dp[0]);
    }
    printf("%.10Lf\n", ans);
    return 0;
}


Measured memory_bytes: 2560
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
	/*??¶?´???????????????????*/
	public static int judge(ArrayList<Integer> parse,int len){
		int result=0;
		for(int j=0;j<len;j++){
			if(parse.get(j)<1||parse.get(j)>10000){
				result = 1;
			}
			else{
				result = 0;
			}
		}
		return result;
	}

	public static void main(String[] args) throws IOException{
		String str;

		/* ???????????£?¨? */
		ArrayList<String> st = new ArrayList<String>();
		ArrayList<Integer> parse = new ArrayList<Integer>(); // int??????

		/*?????????????????\???*/
		Scanner scan = new Scanner(System.in);
		for (int i = 0; i < 3; i++) {
			st.add(scan.next());
		}

		int len = st.size(); // ?????????????´???°

		/* String???int????????¨int????????????????´? */
		for (int p = 0; p < len; p++) {
			str = st.get(p);
			int temp = Integer.parseInt(str);
			parse.add(temp);
		}


		/*????????¨????????????*/
		if(judge(parse,len) == 0){
        Collections.sort(parse); //???????????????
		System.out.println(parse.get(0)+(" ")+parse.get(1)+(" ")+parse.get(2));
		}
		else if(judge(parse,len) == 1){
			System.out.println("??\???????????????1~10000??§???.???????????????.");
		}
	}
}

Measured memory_bytes: 26176
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();
      if(a==1||b==1){
      	if(a==b)System.out.println("Draw");
        else if(a==1)System.out.println("Alice");
        else System.out.println("Bob");
      }
      else if(a==b) System.out.println("Draw");
      else if(a > b)System.out.println("Alice");
      else System.out.println("Bob");
    }
}

Measured memory_bytes: 21332
#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 s,w;
    cin>>s>>w;
    if(w<s){
        cout<<"safe"<<endl;
    }else{
        cout<<"unsafe"<<endl;
    }

} // end of main
    

Measured memory_bytes: 3624
//In the Name of God
//Let Our Voices Echo
#include<bits/stdc++.h>
using namespace std;
#define X real()
#define Y imag()
typedef long long ll;
typedef double ld; 
typedef complex<ld> point;
const ld eps=1e-9;
const int MAX=1e5+9,MOD=1e9+7;
int n,root,a[MAX];
vector<int> g[MAX];
long long dfs(int v,int p=-1)
{
	if (g[v].size()==1) return a[v];
	long long x=0,y=0,mx=0;
	for (auto u:g[v])
		if (u!=p)
		{
			x++;
			ll k=dfs(u,v);
			mx=max(mx,k);
			y+=k;
		}
	if (x==1 && a[v]!=y) cout<<"NO",exit(0);
	if (2*a[v]-y<0 || y-a[v]<0 || a[v]<mx) cout<<"NO",exit(0);
	return 2*a[v]-y;
}
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	for (int i=1,v,u;i<n;i++)
	{
		cin>>v>>u,v--,u--,g[v].push_back(u),g[u].push_back(v);
		if (g[v].size()>1) root=v;
		if (g[u].size()>1) root=u;
	}
	if (n==2)
	{
		if (a[0]==a[1]) cout<<"YES";
		else cout<<"NO";
		return 0;
	}
	if (dfs(root)) cout<<"NO";
	else cout<<"YES";
	return 0;
}


Measured memory_bytes: 13952
package main

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

const (
	maxN = 200005
	mod  = 1000000007
)

func main() {
	n := nextInt()
	as := make([]int, n+2)
	var maxNum int
	for i := 1; i <= n+1; i++ {
		as[i] = nextInt()
		maxNum = max(maxNum, as[i])
	}
	var s int
	vis := make([]bool, maxNum+1)
	for i := 1; i <= n+1; i++ {
		if vis[as[i]] {
			s = as[i]
		}
		vis[as[i]] = true
	}
	var pre int
	for i := 1; i <= n+1 && as[i] != s; i++ {
		pre++
	}
	var nex int
	for i := n + 1; i >= 0 && as[i] != s; i-- {
		nex++
	}
	f := make([]int, maxN)
	invf := make([]int, maxN)
	f[0], invf[0] = 1, 1
	inv := make([]int, maxN)
	inv[1], f[1], invf[1] = 1, 1, 1
	for i := 2; i <= nex+pre || i <= n+1; i++ {
		inv[i] = mod - (mod/i)*inv[mod%i]%mod
		f[i] = f[i-1] * i % mod
		invf[i] = invf[i-1] * inv[i] % mod
	}
	for i := 1; i <= n+1; i++ {
		ans := (c(n+1, i, f, invf) - c(pre+nex, i-1, f, invf) + mod) % mod
		fmt.Println(ans)
	}
}

func c(n, m int, f, invf []int) int {
	if n < m {
		return 0
	}
	return f[n] * invf[m] % mod * invf[n-m] % mod
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long double ll;
typedef pair <int,int> P;

int n,k;
ll nl,kl;
int w[30];

int main(){
  cout << setprecision(20) << fixed;
  cin >> n >> k;
  nl = (ll)n;
  w[0] = 1;
  rep(i,0,22) w[i+1] = w[i]*2;
  ll ans = 0;
  rep(i,1,n+1){
    int t = (k+i-1)/i;
    int u = *lower_bound(w,w+20,t);
    ll ul = (ll)u;
    //cout << t << " " << u << endl;
    ans += (1/ul);
  }
  ans /= nl;
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MODULO 1000000007
#define PI 3.14159265359
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
   int n;
   cin>>n;
   if(n%1000==0)
   cout<<"0"<<endl;
   else
   {
   	int x=(n/1000)+1;
   	int y=x*1000-n;
   	cout<<y<<endl;
   }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int N;
ll A[3100];
ll memo[3100][3100];

ll func(ll x, ll y, ll remain){
    if(remain == 0){
        return 0;
    }

    if(memo[x][y] >= 0){
        return memo[x][y];
    }

    ll xi = x;
    ll yi = N-1-y;

    ll ret = 0;
    ll left = remain - func(x+1, y, remain-A[xi]);
    ll right = remain - func(x, y+1, remain-A[yi]);
    ret = max(left, right);
    return memo[x][y] = ret;
}

int main(){
    cin >> N;
    ll sum = 0;
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
        sum += a;
    }

    REP(i,N){
        REP(j,N){
            memo[i][j] = -1;
            memo[i][j] = -1;
        }
    }

    ll X = func(0, 0, sum);

    //printf("\n");
    //REP(i,N){
    //    REP(j,N){
    //        if(memo[i][j] == -1) continue;
    //        printf("%lld ", memo[i][j]);
    //    }
    //    printf("\n");
    //}

    ll Y = sum - X;
    ll ans = X - Y;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 74112
import math
A, B, H, M = map(int, input().split())
alpha = abs(H + M / 60 - M / 5)

if 6 < alpha:
    alpha = 12 - alpha

print(math.sqrt(A ** 2 + B ** 2 - (math.cos(alpha * math.pi / 6) * 2 * A * B)))

Measured memory_bytes: 9380
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n;
	cin>>n;
	int y,m,d;
	rep(i,0,n){
		cin>>y>>m>>d;
		int days;
		if(y%3) days=195*(y-1)+5*((y-1)/3)+20*(m-1)-(m-1)/2+d;
		else days=195*(y-1)+5*((y-1)/3)+20*(m-1)+d;
		o(196471-days);
	}
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <array>

const uint32_t D = 365 + 1;
const uint32_t contests = 26 + 1;

int main() {
  {
    uint32_t Dtmp = 0;
    std::cin >> Dtmp;
  }

  std::array<uint32_t, contests> cost;
  for (size_t c = 1; c < contests; c++) std::cin >> cost[c];
  
  std::array<std::array<uint32_t, contests>, D> sat;
  for (size_t d = 1; d < D; d++) for (size_t c = 1; c < contests; c++) std::cin >> sat[d][c];
  
  // solve problem
  std::array<uint32_t, D> test;
  for (size_t d = 1; d < D; d++) std::cin >> test[d];

  // calc satisfaction
  std::array<int64_t, D> value;
  value[0] = 0;
  std::array<uint32_t, contests> last;
  last.fill(0);
  for (size_t d = 1; d < D; d++)
  {
    value[d] = value[d-1] + sat[d][test[d]];
    last[test[d]] = d;

    int64_t c_sum = 0;
    for (size_t c = 0; c < contests; c++) c_sum += cost[c]*(d-last[c]);    
    value[d] -= c_sum;
  }

  for(size_t d = 1; d < D; d++) std::cout << value[d] << std::endl;
  

  return 0;
}

Measured memory_bytes: 3672
#pragma GCC optimize ("-O3")
    #include <bits/stdc++.h>  
     
    using namespace std;
     
    typedef long long ll;
    typedef long double ld;
    typedef pair<int,int> p32;
    typedef pair<ll,ll> p64;
    typedef pair<double,double> pdd;
    typedef vector<ll> v64;
    typedef vector<int> v32;
    typedef vector<vector<int> > vv32;
    typedef vector<vector<ll> > vv64;
    typedef vector<vector<p64> > vvp64;
    typedef vector<p64> vp64;
    typedef vector<p32> vp32;
    ll MOD = 998244353;
    #define forn(i,e) for(ll i = 0; i < e; i++)
    #define forsn(i,s,e) for(int i = s; i < e; i++)
    #define rforn(i,s) for(ll i = s; i >= 0; i--)
    #define rforsn(i,s,e) for(ll i = s; i >= e; i--)
    #define ln "\n"
    #define dbg(x) cout<<#x<<" = "<<x<<ln
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define INF 1e18
    #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
    #define all(x) (x).begin(), (x).end()
    #define sz(x) ((ll)(x).size())
     
    ll mpow(ll a, ll b){
        if(b >= (MOD-1)) b %= (MOD-1);
        if(b==0) return 1;
        ll t1 = mpow(a,b/2);
        t1 *= t1;
        t1 %= MOD;
        if(b%2) t1 *= a;
        t1 %= MOD;
        return t1;
    }
     
    ll mpow(ll a, ll b, ll p){
        if(b==0) return 1;
        ll t1 = mpow(a,b/2,p);   t1 *= t1;
        t1 %= p;
        if(b%2) t1 *= a;
        t1 %= p;
        return t1;
    }
    ll modinverse(ll a, ll m){
        ll m0 = m; 
        ll y = 0, x = 1; 
        if (m == 1) return 0; 
        while (a > 1){
            ll q = a / m; 
            ll t = m; 
            m = a % m, a = t; 
            t = y; 
            y = x - q * y; 
            x = t; 
        }
        if (x < 0) x += m0; 
        return x; 
    }
    ll range(ll l, ll r){
        return l + rand()%(r-l+1);
    }

    int main()
    {
        ll a,b,c,k;
        cin>>a>>b>>c>>k;
        ll ans = 0;
        ans = min(a,k);
        k = k-a;
        if(k>=0)k=k-b;
        if(k>=0)ans-=min(k,c);
        cout<<ans<<endl;
        
        return 0;
    }

Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;

int main(){
    int n;
    cin >> n;
    int input[n];

    for (int i=0;i<n;i++){
        cin >> input[i];
    }
    for (int i=0;i<n;i++){
        cout << input[n-i-1];
        if (i!=n-1){
            cout << " ";
        }else{
            cout << endl;
        }
    }
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  map<int, int> m;
  rep(i, n-1){
    int t;cin>>t;t--;
    m[t]++;
  }

  rep(i, n)cout<<m[i]<<endl;

  return 0;
}

Measured memory_bytes: 13012
#include<bits/stdc++.h>
using namespace std;
int n,m,a[100001];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	int sum=0;
	for(int i=1;i<=m;i++)sum+=a[i];
	cout<<sum;
}


Measured memory_bytes: 3628
h,w,k=map(int,input().split())
board=[list(input()) for _ in range(h)]
ans=0
for paint_h in range(2**h):
  for paint_w in range(2**w):
    cnt=0
    for i in range(h):
      for j in range(w):
        if (paint_h>>i)&1==0 and (paint_w>>j)&1==0 and board[i][j]=='#':
          cnt+=1
    if cnt==k:
      ans+=1
print(ans)

Measured memory_bytes: 68144
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<vector>
#include<climits>
using namespace std;

int main(void){

    int n;
    cin>>n;

    vector<int> v;

    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        v.push_back(a);
    }

    int start = 0;

    while(1){

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

        if(start == n-1){
            cout<<v[n-1]<<endl;
            break;
        }else if(v[start]==1){
            cout<<1<<endl;
            break;
        }

        for(int i=start;i<n;i++){
            if(v[i]==0){
                start++;
            }else if(i!=start){
                v[i] = v[i]%v[start];
            }
        }

        
    }
    
}

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

int main(){
  vector<int> A(3);

  cin >> A[0] >> A[1] >> A[2];
  sort(A.begin(), A.end());

  if(A[0] == 5 && A[1] == 5 && A[2] == 7){
    cout << "YES" << endl; 
  } else {
    cout << "NO" << endl;
  }

}

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

int main()
{
    string S;
    cin >> S;
    int N = S.size();
    string ans = "";
    rep(i, N)
    {
        //     cout << "ans=" << ans << endl;
        if (S[i] == '0')
            ans = ans + '0';
        else if (S[i] == '1')
            ans = ans + '1';
        else
        {
            int M = ans.size();
            if (M == 0)
                continue;
            else
                ans.erase(M - 1);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W, D;
    cin >> H >> W >> D;
    REP(i, H) {
        REP(j, W) {
            ll a;
            cin >> a;
            a--;
            A[a] = pll(i, j);
        }
    }
    vector<vector<ll>> v(D);
    REP(i, D) {
        v[i].push_back(0);
        ll n = i;
        while (n + D < H * W) {
            ll c = abs(A[n].first - A[n + D].first) + abs(A[n].second - A[n + D].second) + v[i].back();
            v[i].push_back(c);
            n += D;
        }
    }

    ll Q;
    cin >> Q;
    REP(i, Q) {
        ll l, r;
        cin >> l >> r;
        ll a = (l - 1) / D;
        ll b = (r - 1) / D;
        ll n = (l - 1) % D;
        ll ret = v[n][b] - v[n][a];
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 6784
n=int(input())
h=list(map(int,input().split()))
dp=[10**9]*n

dp[0]=0
dp[1]=h[1]-h[0]
for i in range(1,n):
    c1=abs(h[i]-h[i-1])
    c2=abs(h[i]-h[i-2])
    dp[i]=min(dp[i-1]+c1,dp[i-2]+c2)
    
print(dp[n-1])

Measured memory_bytes: 13976
#include <iostream>
#include <string>
#include <cassert>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>

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

const int MN = 1010;
int n, ro;
int l[MN], r[MN];


int solve() {
//	cout << n << " " << ro << endl;
//	for (int i = 0; i < n; i++) {
//		cout << l[i] << " " << r[i] << endl;
//	}

	for (int i = 0; i < n; i++) {
		if (r[i] < l[i]) r[i] += ro;
	}
	int mi = 100000;
	for (int i = 0; i < n; i++) {
		vector<P> v;
		for (int j = 0; j < n; j++) {
			if (l[j] <= l[i] && l[i] < r[j]) continue;
			if (l[j] <= l[i]+ro && l[i]+ro < r[j]) continue;
			if (l[i] < l[j]) {
				v.push_back(P(l[j], r[j]));
			} else {
				v.push_back(P(l[j]+ro, r[j]+ro));
			}
		}

		sort(v.begin(), v.end(), [&](const P &l, const P &r){
			if (l.second != r.second) return l.second < r.second;
			return l.first < r.first;
		});

		int m = (int)v.size();
		int re = 1;
		int ba = l[i];
		for (int j = 0; j < m; j++) {
			if (ba < v[j].first) {
				re++;
				ba = v[j].second-1;
			}
		}
//		printf("%d %d %d %d %d\n", i, m, re, v[0].first, v[0].second);
		mi = min(mi, re);
	}
	return mi;
}

int main() {
	int w, h;
	cin >> n >> w >> h;
	ro = 2*(h+w);
	for (int i = 0; i < n; i++) {
		int x, y; char c;
		cin >> x >> y; cin >> c; y = h-y;
		int di[4];
		if (y + (w-x) < h) {
			di[0] = w+y+(w-x);
		} else {
			di[0] = w+h+w-(x+(h-y));
		}

		if (x - (h-y) > 0) {
			di[1] = w+h+w-(x-(h-y));
		} else {
			di[1] = w+h+w+h-(y+x);
		}

		if (y - x > 0) {
			di[2] = w+h+w+h-(y-x);
		} else {
			di[2] = x-y;
		}

		if (x + y < w) {
			di[3] = x+y;
		} else {
			di[3] = w+y-(w-x);
		}
//		cerr << di[0] << " " << di[1] << " " << di[2] << " " << di[3] << endl;
		switch (c) {
		case 'E':
			l[i] = di[3];
			r[i] = di[0];
			break;
		case 'S':
			l[i] = di[0];
			r[i] = di[1];
			break;
		case 'W':
			l[i] = di[1];
			r[i] = di[2];
			break;
		case 'N':
			l[i] = di[2];
			r[i] = di[3];
			break;
		default:
			assert(false);
		}
		r[i]++;
	}
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 3112
from operator import mul
from functools import reduce


A = input()
N = len(A)
ans = N*(N-1)//2

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for i in range(26):
    num = A.count(chr(ord('a') + i))
    
    if num >= 2:
        ans -= cmb(num,2)

print(ans+1)

Measured memory_bytes: 4124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9

const int M = 100000;
int a[M], b[M], c[M];
int dp_a[M], dp_b[M], dp_c[M];

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i] >> b[i] >> c[i];

	dp_a[0] = a[0];
	dp_b[0] = b[0];
	dp_c[0] = c[0];
	for (int i = 1; i < N; i++) {
		dp_a[i] = max(dp_b[i - 1], dp_c[i - 1]) + a[i];
		dp_b[i] = max(dp_a[i - 1], dp_c[i - 1]) + b[i];
		dp_c[i] = max(dp_b[i - 1], dp_a[i - 1]) + c[i];
	}

	int ans = max(dp_a[N - 1], dp_b[N - 1]);
	ans = max(ans, dp_c[N - 1]);
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int MAX = 50;

int main() {
    int N, A; cin >> N >> A;
    vector<int> x(N);
    for (int& xi : x) cin >> xi;
    vector<vector<vector<ll>>> dp(N + 1,
        vector<vector<ll>>(N + 1, vector<ll>(MAX * N + 1, 0)));
    dp[0][0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= i * MAX; k++) {
                dp[i + 1][j][k] += dp[i][j][k];
                dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
            }
        }
    }
    ll ans = 0;
    for (int j = 1; j <= N; j++) ans += dp[N][j][j * A];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 52224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {


	public static void main(String[] args) throws IOException {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = new String(in.readLine());

		String[] strings = new String[3];
		strings = s.split("\\s+");

		// N(1~10000)
		String number = strings[0];
		String[] numbers = null;
		int intNumber = Integer.parseInt(number);

		// Nの各桁を足し合わせた数のKey,Value
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for (int i = 1; i <= intNumber; i++) {
			int plusNum = 0;
			numbers = String.valueOf(i).split("");
			for (String n : numbers) {
				plusNum += Integer.parseInt(n);
			}
			map.put(i, plusNum);
		}

		// A ≦ mapのvalue ≦ Bとなっている数値を取得し、総和する
		int outputSum = 0;
		Integer a = Integer.parseInt(strings[1]);
		Integer b = Integer.parseInt(strings[2]);

		for (Integer key : map.keySet()) {

			if (a <= map.get(key) && map.get(key) <= b) {
				outputSum += key;
			}
		}

		// 結果出力
		System.out.println(outputSum);



	}
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int l=s.size();
  for(int i=0;i<l;i++){
    char a;
    a=s.at(i);
    a+=n;
    if(a>90) a-=26;
    cout << a;
  }
  cout << endl;
}

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

void insert_sort(vector<int> &a) {
  for (int i = 0; i < a.size(); i++) {
      int key = a[i];
      int j = i - 1;
      while (j >= 0 && a[j] > key) {
          a[j+1] = a[j];
          j--;
      }
      a[j+1] = key;
      for (int j = 0; j < a.size(); j++) {
        cout << a[j];
        if (j != a.size() - 1) cout << " ";
      }
      cout << endl;
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
      cin >> a.at(i);
  }
  insert_sort(a);
}


Measured memory_bytes: 3112
from fractions import gcd

N, X = [int(a) for a in input().split()]
x = [int(a) for a in input().split()]

x.sort()

if X < x[0]:
    d = x[0] - X
elif X > x[N - 1]:
    d = X - x[N - 1]
else:   # x[i] <= Xである最大のiを求める
    ok = 0      # x[0] <= Xを満たす
    ng = N - 1  # x[N - 1] > X
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if x[mid] <= X:
            ok = mid
        else:
            ng = mid
    d = gcd(X - x[ok], x[ok + 1] - X)

for i in range(1, N):
    d = gcd(d, x[i] - x[i - 1])

print(d)


Measured memory_bytes: 16276
#include <iostream>
#include <cstdlib>

using namespace std;

int main() {
	int a;
	int b;
	int c;
	cin >> a >> b >> c;
	if (a*b <= c) {
		cout << a * b;
	}
	else {
		cout << c;
	}

	return 0;
}

Measured memory_bytes: 256
///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define pb push_back
#define mp make_pair
#define fe first
#define se second
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl
#define SPD_emergency ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
int M = 1e9 + 7;
const int N = 3e5 + 10;
const int IM = 1e15 + 37;
const int PI = 3.14159265;
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " "; cout << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << ' ' ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
inline void PP(int n) { cout << n << " ";}
inline void PP(int n, int m) { cout << n << " " << m << endl;}
inline void PP(int n, int m, int q) {  cout << n << " " << m << " " << q << endl;}
inline void PP(int n, int m, int q, int u) {  cout << n << " " << m << " " << q << " " << u << endl;}
inline void op() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
// <-------------------------------------------------------------------------------------------------------------------------------------------------------------------------> Ignore This--> priority_queue setprecision memset substr pop_back  insert tuple first second push_back string continue make_pair break deque stack queue sort reverse accumulate  count lower_bound upper_bound next_permutation copy_n __builtin_popcount make_tuple
// <========================================================================================================================================================================

signed  main() {
    SPD_emergency
    //op();
    int i, j, x, y, u;
    //int t; cin >> t; while (t--)
    {   i = j = x = y = u  = 0;

        int x;
        double d;
        cin >> x >> d;
        y = round(d * 100);
        x = (x * y) / 100;
        PT(x);


        /**/
    }

    return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
namespace mp = boost::multiprecision;

template<typename T>
constexpr T _gcd(T m, T n) noexcept {
	T g = 1;

	while (m != 0) {
		if (m < n) std::swap(m, n);

		if (m & 1) {
			if (n & 1) m = (m - n) >> 1;
			else n = n >> 1;
		}
		else {
			if (n & 1) {
				m = m >> 1;
			}
			else {
				n = n >> 1;
				m = m >> 1;
				g = g << 1;
			}
		}
	}

	return g * n;
}

template<typename T>
constexpr T _lcm(T m, T n) noexcept {
	return (m * n) / gcd(m, n);
}

template<typename T>
constexpr std::vector<std::pair<T, T>> primeFactorization(T number) noexcept {
	std::vector<std::pair<T, T>> primeFactors;
	T quotient = number;
	for (T i = 2; i*i <= quotient; ++i) {
		if (quotient%i == 0) {
			T prime = i, power = 1;

			quotient /= i;
			while (quotient%i == 0) {
				++power;
				quotient /= i;
			}

			primeFactors.push_back(std::pair<T, T>(prime, power));
		}
	}
	if (quotient != 1) primeFactors.push_back(std::pair<T, T>(quotient, 1));

	return primeFactors;
}

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

	int n;
	cin >> n;
	ll* a = new ll[n];
	rep(i, n) cin >> a[i];

	ll maxA = a[0];
	ll t = a[0];
	REP(i, 1, n) {
		t = _gcd(t, a[i]);
		maxA = max(maxA, a[i]);
	}

	if (t == 1) {
		auto primes = primeFactorization(a[0]);

		set<ll> x;
		rep(i, primes.size()) {
			x.insert(primes[i].first);
		}

		REP(i, 1, n) {
			primes = primeFactorization(a[i]);
			rep(j, primes.size()) {
				if (x.find(primes[j].first) != x.end()) {
					cout << "setwise coprime" << "\n";
					return 0;
				}
				else {
					x.insert(primes[j].first);
				}
			}
		}

		cout << "pairwise coprime" << "\n";
	}
	else {
		cout << "not coprime" << "\n";
	}

	return 0;
}


Measured memory_bytes: 11404