akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 3223372036854775807
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se>b.se;
}
ll cmp(ll a,ll b){
    return abs(a)<abs(b);
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //------------------------------
    ll nn,mm,dd;cin>>nn>>mm>>dd;
    double n=nn,m=mm,d=dd;
    double ans;
    if(dd>0){
        if(dd<=nn/2){
            ans = 2.0*(n-d)*(m-1.0)/(n*n);
        }
        else if(dd<n){
            ans = 2.0*(n-d)*(m)/(n*n);
        }
        else{
            ans=0.0;
        }
    }
    else{
        ans=(m-1.0)/n; 
    }
    printf("%.10lf\n",ans);
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //------------------------------- 
    return 0;
}
//----------------------------------------------------------------------






















































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

int main() {
    int H, W;
    cin >> H >> W;
    string S[50];

    for (int i=0; i<H; i++) {
        cin >> S[i];
    }

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

    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            if ( S[i][j] == '.') {    
                int num = 0;
                for (int d=0; d<8; d++) {
                    int ni = i + dx[d];
                    int nj = j + dy[d];

                    if (ni < 0 or H <= ni) continue;
                    
                    if (nj < 0 or W <= nj) continue;
                    
                    if (S[ni][nj] == '#') num++;
                }
                S[i][j] = num+'0';
            }
        }
    }
    for (int i=0; i<H; i++) {
        cout << S[i] << endl;
    }
    return 0;
}

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

using namespace std;
 
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
 
int gcd3(int x, int y, int z) {
 
  for (int i = 1; i < z; i++) {
    x = gcd(x, y);
  }
  
  return x;
}

 int main(){
    int N;
    long ans;
 
    ans = 0;
 
    cin >> N;
 
    for(int a=1; a<N+1;a++){
        for(int b=a; b<N+1;b++){
            for(int c=b; c<N+1;c++){
                if((a != b) && (b != c)){
                    ans += 6*gcd(a,gcd(b,c));
                }
                else if((a == b) && (b != c)){
                    ans += 3*gcd(a,gcd(b,c));
                }
                else if((a != b) && (b == c)){
                    ans += 3*gcd(a,gcd(b,c));
                }
                else{
                    ans += gcd(a,gcd(b,c));
                }
//                cout << a << b << c << gcd(a,gcd(b,c)) << ans << endl;
            }
        }
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

struct Dish {
  int64_t a, b, sum;
  Dish(int l, int r) {
    a   = l;
    b   = r;
    sum = a + b;
  }
  bool operator<(const Dish &another) const {
    return sum < another.sum;
  };
  bool operator>(const Dish &another) const {
    return sum > another.sum;
  };
};

bool cmp(const Dish &a, const Dish &b) {
  return a.sum > b.sum;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  std::vector<Dish> dish;
  int n;
  cin >> n;
  int64_t tak = 0, aok = 0;

  for (int i = 0; i < n; i++) {
    int m1, m2;
    cin >> m1 >> m2;
    dish.push_back(Dish(m1, m2));
  }
  std::sort(dish.begin(), dish.end(), cmp);

  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      tak += dish[i].a;
    } else {
      aok += dish[i].b;
    }
  }

  cout << tak - aok << endl;

  return 0;
}


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

int ma[4][4];
bool res[4][4];

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> ma[i][j];
        }
    }
    int n; cin >> n;
    while (n--) {
        int b; cin >> b;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (ma[i][j] == b) res[i][j] = true;
            }
        }
    }

    bool ans = false;
    if ((res[0][0] && res[0][1] && res[0][2]) || (res[1][0] && res[1][1] && res[1][2]) || (res[2][0] && res[2][1] && res[2][2]) || (res[0][0] && res[1][0] && res[2][0]) || (res[0][1] && res[1][1] && res[2][1]) || (res[0][2] && res[1][2] && res[2][2]) || (res[0][0] && res[1][1] && res[2][2]) || (res[0][2] && res[1][1] && res[2][0])) {
        ans = true;
    }
    cout << (ans ? "Yes" : "No") << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
int main()
{
  int n,m;
  char c1,c2;
  map<char,char>convert;
  while(cin>>n,n){
    convert.clear();
    while(n-->0){
      cin>>c1>>c2;
      convert[c1]=c2;
    }
    cin>>m;
    while(m-->0){
      cin>>c1;
      if(convert.find(c1)!=convert.end())printf("%c",convert[c1]);
      else printf("%c",c1);
    }
    puts("");
  }
}

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

int main() {
    double a;
    while (cin >> a) {
        double sum = 0;
        sum += a;
        sum += a * 2;
        sum += a * 2 / 3;
        sum += a * 4 / 3;
        sum += a * 4 / 9;
        sum += a * 8 / 9;
        sum += a * 8 / 27;
        sum += a * 16 / 27;
        sum += a * 16 / 81;
        sum += a * 32 / 81;
        cout.precision(8);
        cout << fixed;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1276
a,b,m=gets.split.map(&:to_i)
as=gets.split.map(&:to_i)
bs=gets.split.map(&:to_i)
cs=[]
m.times {cs.push(gets.split.map(&:to_i))}
min=as.min+bs.min

cs.each { |x,y,c| min = as[x-1]+bs[y-1]-c if as[x-1]+bs[y-1]-c < min }

p min

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

int main(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    cout << (H-h) * (W-w) << endl;
}

Measured memory_bytes: 256
N,W=map(int,input().split())
k=[[0,0] for i in range(N)]
dp=[[W+1]*(1001*101+1) for j in range(N+1)]
R=set()
for i in range(N):
    k[i][0],k[i][1]=map(int,input().split())
#dp[0][:k[0][1]]=[k[0][0]]*(k[0][1]+1)
dp[0][0]=0
for i in range(0,N):
    for v in range(1001*101):
        if v - k[i][1]>=0:
            dp[i+1][v] = min(dp[i][v-k[i][1]]+k[i][0],dp[i][v])
        else:
            dp[i+1][v]=min(dp[i+1][v],dp[i][v])

        if dp[i][v]<W:
             R.add(v)


for v in reversed(range(1001*101+1)):
    if dp[N][v]<=W:
        print(v)
        exit()

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 212345;
int dp[MAX_N][3];

string get(const string& s, int start, int len) {
  return s.substr(start, len);
}

int main2() {
  REP(i, MAX_N) REP(j, 3) dp[i][j] = -1001001001;
  string s; cin >> s;
  const int N = s.size();
  dp[1][1] = 1;
  dp[2][2] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 1; j <= 2; j++) {
    for (int k = 1; k <= 2; k++) {
      if (i - j >= 0 && i + k <= N && get(s, i - j, j) != get(s, i, k)) {
        chmax(dp[i+k][k], 1 + dp[i][j]);
      }
    }
    }
  }

  int ans = max(dp[N][1], dp[N][2]);
  cout << ans << endl;

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3076
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int min(int a, int b) {
	if (a < b) {
		return a;
	}
	else {
		return b;
	}
}

int max(int a, int b) {
	if (a > b) {
		return a;
	}
	else {
		return b;
	}
}


int main() {

	//変数設定
	int N;
	vector<int> P, Q;
	int temp;
	int a = 0;
	int b = 0;

	//データ入力
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> temp;
		P.push_back(temp);
	}
	for (int i = 0; i < N; i++) {
		cin >> temp;
		Q.push_back(temp);
	}

	//計算
	for (int i = 0; i < N - 2; i++) {
		int Factorial = 1;
		for (int j = 1; j < N - i; j++) {
			Factorial *= j;
		}
		int countA = 1;
		int countB = 1;
		for (int j = 0; j < i; j++) {
			if (P[i] > P[j]) {
				countA++;
			}
			if (Q[i] > Q[j]) {
				countB++;
			}
		}
		a += (P[i] - countA)*Factorial;
		b += (Q[i] - countB)*Factorial;
	}
	a += 1;
	b += 1;
	if (P[N - 2] > P[N - 1]) {
		a += 1;
	}
	if (Q[N - 2] > Q[N - 1]) {
		b += 1;
	}

	//結果出力
	cout << abs(a - b);

	getchar();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int X,ure;
  scanf("%d",&X);
  if(X>=500)
  {
    ure=1000*(X/500);
    X=X-500*(X/500);
    if(X>=5)
    {
      ure=ure+5*(X/5);
      printf("%d",ure);
    }
    else
    {
      printf("%d",ure);
    }
  }
  else if(X>=5)
  {
    ure=5*(X/5);
    printf("%d",ure);
  } 
  else
  {
  printf("%d",0); 
  }
}
      

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

using namespace std;
const int N=1e5+5;
int n,f[N],h[N];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>h[i];
    f[1]=0;
    f[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)
        f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
    cout<<f[n];
    //for(int i=1;i<=n;i++) cout<<' '<<f[i];
    return 0;
}


Measured memory_bytes: 1024
// Starting with the name of Allah

#include <bits/stdc++.h>
#define ll long long
#define nl endl
#define flash_all ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define gcd(a,b)         __gcd(a,b)
#define lcm(a,b)         (a/gcd(a,b))*b


using namespace std;



int main()
{
	flash_all;
	ll a,sum=1,sum1=1,i;
	cin>>a;
	for(i=1;i<=2;i++){
		sum=sum*a;
	}
	for(i=1;i<=3;i++){
		sum1=sum1*a;
	}
	cout<<a+sum+sum1<<nl;
	return 0;
}
//Happy Coding......

Measured memory_bytes: 3644
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()

po = [0 for i in range(n)]

for i in range(n-1):
    po[a[i]-1] += 1
for i in range(n):
    print(po[i])


Measured memory_bytes: 96496
import java.util.ArrayList;
import java.util.Collections;
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();
		ArrayList<Integer> arrayList = new ArrayList<Integer>();
		arrayList.add(calculation(A));
		arrayList.add(calculation(B));
		arrayList.add(A+B);
		System.out.println(Collections.max(arrayList));
	}
	
	private static int calculation(int input) {
		return input + (input-1);
	}
}


Measured memory_bytes: 23764
s = int(input())
a = s//100
b = s%100
if 1 <= a <= 12:
  if 1 <= b <= 12:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if 1 <= b <= 12:
    print('YYMM')
  else:
    print('NA')

Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt()-1;
        }
        Map<String, Integer> pairs = new HashMap<>();
        for (int i = 0; i < N; i++) {
            int x = i;
            int y = a[i];
            int min = Math.min(x, y);
            int max = Math.max(x, y);
            int count = pairs.getOrDefault(min + ":" + max, 0);
            pairs.put(min + ":" + max, count+1);
        }
        int answer = 0;
        for (int x : pairs.values()) {
            if (x == 2) {
                answer += 1;
            }
        }
        System.out.println(answer);
    }
}


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

#define endl '\n'
#define rep(i,n)       for(int i=0; i<n; i++)
#define clr(arr)       memset(arr, 0, sizeof arr)
#define all(x)         x.begin(), x.end()
const int MOD = 1e9 + 7;

#ifdef SMIT
template<class F, class S> ostream& operator<<(ostream &out, const pair<F, S> &p)
{
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out)
{
	out << '{';
	for (auto i = x.begin(); i != x.end(); i++)
		out << *i << (i == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dmp() {}
template<class T, class... Args> void dmp(T &&x, Args... args)
{
	cerr << x << ";  "; dmp(args...);
}
struct Nl {~Nl() {cerr << '\n';}};
#define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dmp(x), Nl(), cerr << ""
#else
#define debug(...) {}
#endif
// Yes you CAN

const int N = 1001;
int h, w;
char a[N][N];
int dp[N][N];
void solve()
{
// #define TEST
	memset(dp, 0, sizeof dp);
	cin >> h >> w;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < h; i++)
	{
		if (a[i][0] == '#')
			break;
		dp[i][0] = 1;
	}
	for (int j = 0; j < w; j++)
	{
		if (a[0][j] == '#')
			break;
		dp[0][j] = 1;
	}
	for (int i = 1; i < h; i++)
	{
		for (int j = 1; j < w; j++)
		{

			if (a[i][j] == '.')
				dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % MOD;
			debug(dp[i][j]);
		}
	}
	cout << dp[h - 1][w - 1] << endl;
}

int32_t main()
{
#ifdef SMIT
	// freopen("/home/smit/Desktop/in.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	int t = 1;
#ifdef TEST
	cin >> t;
#endif
	while (t--)
		solve();
}

Measured memory_bytes: 8480
import java.io.*;
import java.math.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        long n=Long.parseLong(bu.readLine());
        long p=100,t=0;
        while(p<n)
        {
            p=(long)Math.floor(1.0*p*(101.0/100));
            t++;
        }
        System.out.print(t);
    }
}


Measured memory_bytes: 32724
#include <algorithm>
#include <iostream>
using namespace std;
int n;
int main() {
  while (cin >> n && n>0) {
    int A[n];
    A[0] = 1;
    for (int i=1; i<=n; ++i) { 
      A[i] = A[i-1];
      if (i>1) A[i] += A[i-2];
      if (i>2) A[i] += A[i-3];
    }
    cout << ((A[n]+9)/10+364)/365 << endl; 
  }
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(ll key, ll value){
      this->key = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

short int dp[100000+1];

/*
int search(const vll& a, const int K, vector<short int>& dp){
  if(dp[K]>=0) return dp[K];
  for(ll num : a){
    if(num <= K){
      int tmp = search(a, K-num, dp);
      if(tmp%2==0){
        return dp[K] = (tmp+1)%2;
      }
    }
  }
  return dp[K] = 0;
}
*/

int search(const vll& a, const int K){
  if(dp[K]>=0) return dp[K];
  for(ll num : a){
    if(num <= K){
      int tmp = search(a, K-num);
      if(tmp%2==0){
        return dp[K] = (tmp+1)%2;
      }
    }
  }
  return dp[K] = 0;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, K;
  cin >> N >> K;
  vll a(N);
  rep(i, 0, N){
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<ll>());
  //vector<short int> dp(K+1, -1);
  memset(dp, -1, sizeof(dp));

  //if(search(a, K, dp)%2==1) printf("First\n");
  if(search(a, K)%2==1) printf("First\n");
  else printf("Second\n");

  return 0;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);

bool isPrime(int n) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) return false;
  }
  return n != 1;
}

int main(){
  int n;

  scanf("%d", &n);

  vector<int> v, ans;

  FOR (i, 2, 55556) {
    if (isPrime(i)) v.push_back(i);
  }

  int i = 0;
  while ((int)ans.size() < n) {
    if (v[i] % 5 == 1) ans.push_back(v[i]);
    i++;
  }

  REP (i, ans.size()) {
    printf("%d", ans[i]);
    printf("%s", i == (int)ans.size() - 1 ? "\n" : " ");
  }
}


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

using ll=long long;

int main(){
    vector<vector<ll>> a(500,vector<ll>(500,0));
    vector<int> isPrime(5000,true);
    vector<ll> primes;
    for(int i=2;i<isPrime.size();i++){
        if(isPrime[i]){
            primes.push_back(i);
            for(int j=2;j<isPrime.size();j+=i){
                isPrime[j]=false;
            }
        }
    }
    set<ll> vs;
    swap(primes[0],primes[213]);
    swap(primes[1],primes[224]);
    swap(primes[2],primes[171]);
    for(int i=499;i>=0;i--){
        for(int j=i%2;j<500;j+=2){
            a[i][j]=primes[i/2]*primes[j/2];
            int tmp=2;
            while(vs.count(a[i][j])){
                a[i][j]=a[i][j]/(tmp-1)*tmp;
                tmp++;
            }
            vs.insert(a[i][j]);
        }
    }
    auto isRange=[](int x,int y){
        return 0<=x && x<500 && 0<=y && y<500;
    };
    auto lcm=[](ll x,ll y){
        return x/__gcd(x,y)*y;
    };
    int dx[]={0,1,0,-1};
    int dy[]={1,0,-1,0};

    for(int i=0;i<500;i++){
        for(int j=(i+1)%2;j<500;j+=2){
            ll v=1;
            for(int k=0;k<4;k++){
                if(isRange(i+dx[k],j+dy[k])){
                    v=lcm(v,a[i+dx[k]][j+dy[k]]);
                }
            }
            a[i][j]=v;
            int tmp=2;
            while(vs.count(a[i][j]+1)){
                a[i][j]=a[i][j]/(tmp-1)*tmp;
                tmp++;
            }
            a[i][j]++;
            if(a[i][j]<=1e15) vs.insert(a[i][j]);
        }
    }
    ios_base::sync_with_stdio(false);
    
    int n;
    cin>>n;
    int cnt=0;
    for(int i=0;i<n;i++){
        for(int j=0;j+1<n;j++){
            if(a[i][j]>1e15){
                cnt++;
                cerr<<i<<" "<<j<<endl;
                vs.insert(a[i][j]);
            }
            cout<<a[i][j]<<" ";
        }
        cout<<a[i][n-1]<<"\n";
    }
    cerr<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 16512
import java.io.*;
import java.util.StringTokenizer;

public 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(1, in, out);
        out.close();
    }

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.nextLine();
            out.println(s.lastIndexOf('Z') - s.indexOf('A') + 1);

        }
    }


    static class InputReader implements AutoCloseable {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            //reader = new BufferedReader(new FileReader(stream), 32768);
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return "";
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public void close() {
        }

    }
}

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

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

    cout << abs(max({a, b, c}) - min({a, b, c})) << endl;
    return 0;
}

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

using namespace std;

int main(void) {

	int n;
	cin>>n;
	int o = 0;
	for(int i = 0; i < n; ++i) {
		int x;
		cin>>x;
		if(x&1)	o++;
	}

	if(o&1) {
		cout<<"NO";
	}
	else {
		cout<<"YES";
	}

	return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;

	for (int i = 1; i <= 9; i++)
		for (int j = 1; j <= 9; j++)
			if (i * j == n)
			{
				cout << "Yes";
				return 0;
			}
	cout << "No";
}

Measured memory_bytes: 3596
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	/** 構築時に使う定数 */
	private static final int K = 50;
	/** 白いコマを表す文字 */
	private static final char WHITE = '.';
	/** 黒いコマを表す文字 */
	private static final char BLACK = '#';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt();
			// 2K × 2K のグリッドを用意する。
			char[][] s = new char[2 * K][2 * K];
			// 上から K 行以内にあるマスを全て黒く塗り、残りのマスをすべて白く塗る。
			IntStream.range(0, K).forEach(i -> Arrays.fill(s[i], BLACK));
			IntStream.range(K, 2 * K).forEach(i -> Arrays.fill(s[i], WHITE));
			// 上から K − 1 行以内のマスのうち A − 1 個のマスを上下左右斜めに隣り合わないように選び、それらの色を白に変える。
			fill(s, 1, a - 1, WHITE);
			fill(s, K + 1, b - 1, BLACK);
			System.out.println(2 * K + " " + 2 * K);
			IntStream.range(0, 2 * K).forEach(i -> System.out.println(s[i]));
		}
	}

	/**
	 * コマの配列にコマをcount個入れる
	 * 
	 * @param s     コマの配列
	 * @param i     入れる開始行数
	 * @param count 入れる個数
	 * @param koma  入れるコマ
	 */
	private static void fill(final char[][] s, int i, int count, final char koma) {
		int j = 1;
		while (count > 0) {
			s[i][j] = koma;
			j += 2;
			count--;
			if (j >= 2 * K - 1) {
				i += 2;
				j = 1;
			}
		}
	}
}


Measured memory_bytes: 36644
#include <bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define int long long

using namespace std;

const int N = 5e5 + 5;

int t[N], n, a[N], Q, ans[N];
vector<pair<int, int> > q[N];
int last[N];

void add(int r, int x) {
    for (; r <= n; r = (r | (r + 1)))
        t[r] += x;
}

int sum(int r) {
    int res = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1)
        res += t[r];
    return res;
}

int get(int l, int r) {
    //cout << r << ' ' << sum(r) << endl;
    return sum(r) - sum(l - 1);
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> Q;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= Q; i++) {
        int l, r;
        cin >> l >> r;
        q[r].pb({l, i});
    }
    for (int i = 1; i <= n; i++) {
        if (last[a[i]] != 0)
            add(last[a[i]], - 1);
        last[a[i]] = i;
        add(last[a[i]], 1);
        for (auto [l, id]: q[i])
            ans[id] = get(l, i);
    }
    for (int i = 1; i <= Q; i++)
        cout << ans[i] << "\n";
    return 0;
}


Measured memory_bytes: 44216
n, k = gets.split.map(&:to_i)

pr = 0
nn = 0
if n >= k
  pr += (n-k+1).to_f/n 
  nn = k-1
else
  nn = n
end

(1..nn).each do |i|
  pr += (1.0 / (2**Math.log2(k.to_f/i).ceil) / n)
end

puts pr

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

struct Node{
  int num;
  struct Node *left;
  struct Node *right;
  struct Node *parent;
  struct Node *next;
};

struct Node *root,*NIL;

struct Node *makeNode(void);
void initialize(struct Node*);
void insert(int);
void inParse(struct Node*);
void preParse(struct Node*);
void findNumber(struct Node*,int);

int main(){
  int n;
  int i=0,j,number;
  char order[10];

  scanf("%d",&n);


  for(i=0;i<n;i++){
    scanf("%s",order);
    if(strcmp(order,"insert")==0){
      scanf("%d",&number);
      insert(number);
    }
    if(strcmp(order,"print")==0){
      inParse(root);
      printf("\n");
      preParse(root);
      printf("\n");
    }
    if(strcmp(order,"find")==0){
      scanf("%d",&number);
      findNumber(root,number);     
    }
  }

  return 0;
}


struct Node *makeNode(void){	
  return  (struct Node*)malloc(sizeof(struct Node));
}  

  
void insert(int key){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  
  z=makeNode();

  z->num=key;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->num < x->num){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }

  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if(z->num < y->num){
      y->left=z;
    }
    else{
      y->right=z;	
    }
  }

}
  
void inParse(struct Node *p){
  if(p==NIL) return;
  
  inParse(p->left);
  printf(" %d",p->num);
  inParse(p->right);
}

void preParse(struct Node *p){
  if(p==NIL) return;

  printf(" %d",p->num);
  preParse(p->left);
  preParse(p->right);
}
void findNumber(struct Node *p,int number){
  while(p!=NIL && number!=p->num){
    if(p->num<number){
      p=p->right;
    }
    else{ p=p->left; }
  }
  if(p==NIL) printf("no\n");
  else printf("yes\n");

}

Measured memory_bytes: 19360
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n = in.nextInt(), goal = in.nextInt();
		Problem[] p = new Problem[n];
		for (int i=0; i<n; i++) {
			p[i] = new Problem(in.nextLong(), (i+1)*100, in.nextLong());
		}

		//ビット全探索+@
		long min = Long.MAX_VALUE;
		for (int i=0; i<(1<<n); i++) {

			int num = 0; //その組み合わせでは何問解いたか？
			long sum = 0L; //その組み合わせで得られたスコアの合計

			//全完していない問題のうち、最もスコアが高いもの、すなわち
			//i をビット表現したときに最も右側にある 0 の位置を記録する変数
			int rightMost = -1;

			for (int j=n-1; j>=0; j--) { //
				if ((1&i>>j) == 1) {
					sum += p[j].num * p[j].score + p[j].bonus;
					num += p[j].num;
				}
				else if ((1&i>>j) == 0 && rightMost == -1) {
					rightMost = j;
				}
			}

			//sum が目標スコア以上の場合は、解いた問題の数をそのまま min に記録する
			if (sum >= goal) {
				min = Math.min(min, num);
				continue;
			}
			else if (rightMost != -1){
				//そうでない場合かつ、全完していない問題が少なくとも1つある場合

				//目標スコアに届くまで、スコアが最も多い問題を needNum 回解く必要がある
				long needNum = (goal-sum+p[rightMost].score-1) / p[rightMost].score;

				if (needNum > p[rightMost].num) {
					//スコアが最も多い問題が needNum 問より少ないなら、放棄
					continue;
				}
				else {
					//そうでないなら、スコアが最も多い問題を needNum 問解き、
					//min を更新する
					min = Math.min(min, num + needNum);
				}
			}

		}

		System.out.println(min);

	}

	static class Problem {
		long num, score, bonus;
		Problem (long a, long b, long c) {
			num = a; score = b; bonus = c;
		}
	}


}

Measured memory_bytes: 21972
#include <stdio.h>

double gaiseki(double x1,double y1, double x2,double y2){
	return x1*y2-x2*y1;
}


int main(){
	double x[3],y[3],px,py;
	double vex[3],vey[3],pvex[3],pvey[3];
	int i,j,k,n;
	int b=1;
	
	while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&px,&py)!=EOF){
		vex[0]=x[1]-x[2];
		vey[0]=y[1]-y[2];
		vex[1]=x[2]-x[0];
		vey[1]=y[2]-y[0];
		vex[2]=x[0]-x[1];
		vey[2]=y[0]-y[1];
		
		pvex[0]=px-x[2];
		pvey[0]=py-y[2];
		pvex[1]=px-x[0];
		pvey[1]=py-y[0];
		pvex[2]=px-x[1];
		pvey[2]=py-y[1];

		if(gaiseki(vex[0],vey[0],pvex[0],pvey[0])*gaiseki(vex[1],vey[1],pvex[1],pvey[1])>0&&gaiseki(vex[0],vey[0],pvex[0],pvey[0])*gaiseki(vex[2],vey[2],pvex[2],pvey[2])>0)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

int main()
{
    int a[300]={0};
    char flag=0,ch;
    while((ch=getchar())!='\n')
    {
        if(a[ch])flag=1;
        a[ch]++;
    }
    if(flag)cout<<"no";
    else cout<<"yes";
}


Measured memory_bytes: 256
val SHEEP = 'S'
val WOLFE = 'W'
val UNDEFINED = ' '
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val s = readLine()!!

    var a = Array(N, { UNDEFINED })
    // Assume that (a[0], a[-1]) = (S ,S)
    a[0] = SHEEP
    a[N - 1] = SHEEP
    if (isValid(s, a)) {
        println(a.joinToString(""))
        return
    }

    // Assume that (a[0], a[-1]) = (S ,W)
    a = Array(N, { UNDEFINED })
    a[0] = SHEEP
    a[N - 1] = WOLFE
    if (isValid(s, a)) {
        println(a.joinToString(""))
        return
    }

    // Assume that (a[0], a[-1]) = (W ,S)
    a = Array(N, { UNDEFINED })
    a[0] = WOLFE
    a[N - 1] = SHEEP
    if (isValid(s, a)) {
        println(a.joinToString(""))
        return
    }

    // Assume that (a[0], a[-1]) = (W ,W)
    a = Array(N, { UNDEFINED })
    a[0] = WOLFE
    a[N - 1] = WOLFE
    if (isValid(s, a)) {
        println(a.joinToString(""))
        return
    }

    println("-1")
}

fun flip(char: Char) : Char {
    if (char == 'S') {
        return 'W'
    }
    return 'S'
}

fun isValid(s: String, a: Array<Char>) : Boolean {
    val N = s.length
    s.forEachIndexed { i, c ->
        val left = if (i ==0) N - 1 else i - 1
        val right = if (i == N - 1) 0 else i + 1
        var rightShouldBe = UNDEFINED
        if (c == 'o') {
            if (a[i] == SHEEP) {
                rightShouldBe = a[left]
            }
            if (a[i] == WOLFE) {
                rightShouldBe = flip(a[left])
            }
        } else {
            if (a[i] == SHEEP) {
                rightShouldBe = flip(a[left])
            }
            if (a[i] == WOLFE) {
                rightShouldBe = a[left]
            }
        }

        if (a[right] == UNDEFINED) {
            a[right] = rightShouldBe
        } else {
            if (a[right] != rightShouldBe) {
                return false
            }
        }
    }

    return true
}


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

int main() {
  int N;
  cin >> N;
  pair<int, int> A[N];
  int a, b;
  for (int i=0; i<N; i++) {
    cin >> a >> b;
    A[i] = make_pair(b, a);
  }
  sort(A, A+N);
  int sum_time = 0;
  for (int i=0; i<N; i++) {
    sum_time += A[i].second;
    if (sum_time > A[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
const int MAX_V = 100000;
int main() {
	int prime[MAX_V+1];
    int i, k, v,a=0,n;
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1;
    } 
    for(i = 2; i*i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0;
            }
            
        } 
        
    }
    while(1){
      scanf("%d",&n);
      if(n==0)break;
      for(i=0;i<=n-2;i++){
          int isprime = prime[i];
          int isprimex = prime[i+2];
          if(isprime && isprimex){
             if(a<i)a=i;
          }
        }
        printf("%d %d\n",a,a+2);
    	a=0;
    }
    return 0; 
    
}

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

int N, M;
int fact[100100];
 
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M;
    fact[0] = 1;
    for (int i=1; i<100100; i++) fact[i] = fact[i-1]*i%MOD;
    if (N==M) cout << 2*(fact[N]*fact[M]%MOD)%MOD << endl;
    else if (abs(N-M)==1) cout << fact[N]*fact[M]%MOD << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 1024
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashSet;

fn main() {
    input! {
        N: usize,
        M: usize,
        X: usize,
        As: [usize; M],
    }

    // 累積和しときますか
    // いやB問題で要るか?
    // 制約的に両側に進んでみて小さいほうを採る、でOK

    let fee_points: HashSet<usize> = As.into_iter().collect();

    let mut cand1 = 0i64;
    for i in 0..=X {
        if fee_points.contains(&i) {
            cand1 += 1;
        }
    }

    let mut cand2 = 0i64;
    for i in X..=N {
        if fee_points.contains(&i) {
            cand2 += 1;
        }
    }

    let ans = min(cand1, cand2);
    println!("{}", ans);
}


Measured memory_bytes: 2132
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}
 
int32_t main() {
    fio
    
    cout << fixed << setprecision(15);
    
    int n;
    cin >> n;
    pair<int,int> p[n];
    
    fff(i,n) {
        int x;cin >> x;
        p[i].ff=x;
        p[i].ss=i+1;
    }
    sort(p,p+n);
    
    fff(i,n)
    cout << p[i].ss << " ";  
    
    
	return 0;
    
}

Measured memory_bytes: 11008
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define dll deque<ll>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mapll map<ll,ll>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define deb(x) cout<<x
using namespace std;
void swap(auto*,auto*);
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,W; cin>>n>>W;
        ll val[n]; ll w[n];
        for(ll i=0;i<n;i++) 
        {
            cin>>w[i]>>val[i];
        }
        ll dp[n+1][W+1];
        for(ll i=0;i<=n;i++) dp[i][0]=0; for(ll i=0;i<=W;i++) dp[0][i]=0;
        for(ll i=1;i<=n;i++)
        {
            for(ll j=1;j<=W;j++){
                dp[i][j]=dp[i-1][j];
                if(w[i-1]<=j)
                {
                    dp[i][j]=max(dp[i][j],val[i-1]+dp[i-1][j-w[i-1]]);
                }
            }
        }
        cout<<dp[n][W]<<endl;
    }
void swap(auto &a,auto &b)
{
    auto temp=a; a=b; b=temp;
}

Measured memory_bytes: 82452
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Text.Printf

helpMod::Integer->Integer->Integer->Integer
helpMod a d n= fun a d where
    fun a 1 = mod a n
    fun a 2 = mod (a^2) n
    fun a d = let
            p=fun (mod (a^2) n) (div d 2)
            q=if odd d then mod (a*p) n else p
          in mod q n

isProbable::Integer-> Bool
isProbable n |n<=1 = False
         |n==2 = True
         |even n = False
         |otherwise = rabinMiller [2,3,5,7,11,13,17,19] n s d where
             d=until (\x->mod x 2/=0) (`div` 2) (n-1) --(n-1=2^s*d)
             s=until (\x->d*2^x==pred n) (+1) 0  --counts the power


rabinMiller::[Integer]->Integer->Integer->Integer-> Bool
rabinMiller [] _ _ _ = True
rabinMiller (a:xs) n s d =  if a == n then True
                 else  case x==1 of
                    True -> rabinMiller xs n s d
                    _ -> if any ( ==pred n) $ take (fromIntegral s) $ iterate (\e->mod (e^2) n)  x then rabinMiller xs n s d
                          else  False
                   where x=helpMod a d n
main = do
    n<-getLine
    a<- replicateM (read n) getLine
    print $ length $ filter isProbable (map (read::String->Integer) a)


Measured memory_bytes: 9296
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 12, 2020 17:27:07 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


def main():
  N, K = list(map(int, input().split()))
  V = list(map(int, input().split()))

  max_ = 0
  for i in range(N+1):
    for j in range(N+1):
      res = K-(i+j)
      if i+j == 0 or i+j > N or K-(i+j) < 0:
        continue
      temp = sorted(V[:i]+V[-j if j else len(V):])
      start = 0
      for k in range(min(res, len(temp))):
        if temp[k] < 0:
          start += 1
      max_ = max(max_, sum(temp[start:]))
      # print('--', i, j, res, start, '--')
      # print(temp)
      # print(max_)
      # print()

  print(max_)


if(__name__ == '__main__'):
  main()


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

int main() {
    long long k;
    cin >> k;

    cout << 50 << endl;
    long long m = k % 50;
    for (int i = 0; i < 50; i++) {
        if (m > 0) {
            cout << 49 + 50 * (k / 50 + 1) - (k - (k / 50 + 1)) << " ";
            m--;
        }
        else cout << 49 + 50 * (k / 50) - (k - k / 50) << " ";
    }
}

Measured memory_bytes: 256
#  入力
#  足場の高さ
input()
h = list(map(int, input().split()))


#  方針
#  i番目の足場にいるという状態に対して
#  その足場に最も少ないコストを記録する．

#  スタートはコスト0
dp = [0]

#  i番目の足場でのコストを
#  i-1, i-2番目のコストを利用して計算する
#  1番目は手動で更新した方がコードが簡単になる．
dp.append(dp[0] + abs(h[1] - h[0]))

for i in range(2, len(h)):
    dp.append(min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])))

print(dp[len(h) - 1])


Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

bool is_viable_to_beat_all_with(lint n, vec<lint>& hp, lint A, lint B) {
    lint sum_num_As = 0;
    lint diff = A - B;
    for (const auto h : hp) {
        if (h / A + (h % A == 0 ? 0 : 1) > n) return false;
        else if (h / B + (h % B == 0 ? 0 : 1) <= n) continue;
        lint num_As = (h - n * B) / diff + ((h - n * B) % diff == 0 ? 0 : 1);
        assert(num_As >= 0LL);
        sum_num_As += num_As;
    }
    return sum_num_As <= n;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N, A, B;
    cin >> N >> A >> B;
    vec<lint> hp(N);
    range(i, 0, N) cin >> hp.at(i);
    lint lo = 0, hi = 2e14;
    // searching space: (lo, hi]
    while (hi - lo > 1) {
        lint mid = (hi - lo) / 2 + lo;
        if (is_viable_to_beat_all_with(mid, hp, A, B)) {
            hi = mid;
        } else {
            lo = mid;
        }
    }
    cout << hi << "\n";
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> A(H);

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

    for (int i=0; i<W+2; i++) {
        cout << "#";
    }

    cout << endl;
    for (int i=0; i<H; i++) {
        cout << "#";
        cout << A.at(i);
        cout << "#";
        cout << endl;
    }
    
    for (int i=0; i<W+2; i++) {
        cout << "#";
    }

}

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

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int n_ints = 4;
constexpr int min_int = 0;
constexpr int max_int = 9;

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

    int n, res;

    while (true) {
        cin >> n;
        if (cin.eof()) { break; }

        res = 0;
        FOR(a,min_int,max_int+1)
        FOR(b,min_int,max_int+1)
        FOR(c,min_int,max_int+1)
        FOR(d,min_int,max_int+1) {
            int sum = a + b + c + d;
            if (sum == n) {
                ++res;
            }
        }
        cout << res << endl;
    }

    return 0;
}

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

int  main () {
  int N;
  cin >> N;
  vector<long long> h(N);
  for (int i = 0; i < N; i++) cin >> h.at(i);
  long long sum = 0;
  for (int i = 1; i < N; i++){
    if (h.at(i) < h.at(i-1)) {
      sum += h.at(i-1) - h.at(i);
      h.at(i) = h.at(i-1);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 4840