akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll A, B, C;
        cin >> A >> B >> C;
        bool c1 = A < C and C < B;
        bool c2 = B < C and C < A;
        if (c1 or c2) {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }
}


Measured memory_bytes: 3616
#include <iostream>
#include <queue>
#include <utility>
#include <array>

using namespace std;

typedef pair<int, int> pii;

int height, width;
int sx, sy;


void bfs(vector<vector<char>>& field)
{
    int ans = 1;
    array<int, 4> dx = {0, 0, 1, -1};
    array<int, 4> dy = {1, -1, 0, 0};

    queue<pii> p;
    p.push({sx, sy});
    
    while (!p.empty()) {
        pii q = p.front(); p.pop();
        
        //??????
        int cx = q.first;
        int cy = q.second;

        for (int i = 0; i < 4; ++i) {
            int nx = cx + dx.at(i);
            int ny = cy + dy.at(i);

            if (nx >= 0 && nx < width && ny >= 0 && ny < height 
                    && field.at(ny).at(nx) == '.') {

                ans++;
                field.at(ny).at(nx) = '#';
                p.push({nx, ny});
            }
        }
    }

    std::cout << ans << std::endl;
}


int main()
{
    while (cin >> width >> height) {
        if (height == 0 && width == 0) break;

        vector<vector<char>> field(height, vector<char>(width));

        for (int y = 0; y < height; ++y) {
            for (int x = 0; x < width; ++x) {
                cin >> field.at(y).at(x);

                if (field.at(y).at(x) == '@') {
                    sx = x; sy = y;
                }
            }
        }

        bfs(field);
    }

    return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
struct pr{int a,b;};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,h; cin>>n>>h;
	vector<pr>ab(n); for(auto&i:ab)cin>>i.a>>i.b;
	int amx=max_element(ab.begin(),ab.end(),[](auto a,auto b){return a.a<b.a;})->a;
	sort(ab.begin(),ab.end(),[](auto a,auto b){return a.b>b.b;});
	int ans=0;
	for(int i=0;i<n;++i){
		if(ab.at(i).b<=amx||h<=0)break;
		h-=ab.at(i).b,++ans;
	}
	if(h>0)ans+=h/amx;
	if(h>0&&h%amx)++ans;
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<stack>
#include<locale>

using namespace std;

int main()
{
  stack<int> xs;
  string tok;
  while (cin>>tok) {
    if (not (tok == "+" or tok == "-" or tok == "*")) xs.push(stoi(tok));
    else {
      int operand2 = xs.top(); xs.pop();
      int operand1 = xs.top(); xs.pop();
      if (tok == "+")
        xs.push(operand1 + operand2);
      else if (tok == "*")
        xs.push(operand1 * operand2);
      else // c == '-'
        xs.push(operand1 - operand2);
    }
  }
  if (xs.size()) cout << xs.top() << endl;
}


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

int main(){
    int n,k; cin >> n >> k;
    if(k==1) cout << 0 << endl;
    else cout << n  - k << endl;
}

Measured memory_bytes: 3596
n = int(input())

def f(x):
    if int(x) > n:
        return 0
    if all([x.count(a) > 0 for a in '753']):
        num = 1
    else:
        num = 0
    for a in '753':
        num += f(x + a)
    return num

print(f('0'))

Measured memory_bytes: 54492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); 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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
template <typename T>
void warshall_floyd(vector<vector<T>> &g, T inf) {
    rep(k, g.size()) {
        rep(i, g.size()) {
            rep(j, g.size()) {
                if (g[i][k] == inf || g[k][j] == inf) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}

/*
vector<vector<ll>> G(V, vector<ll>(V,INF));
rep(i,V) G[i][i]=0;
rep(i,E)G[from][to]=cost;
warshall_floyd(G, )
*/
int main() {
    init();
    ll N, M;
    cin >> N >> M;
    vvc<ll> COST(N,vl(N,INF)),G(N, vl(N, INF));
    rep(i, N) G[i][i] = 0;
    rep(i,M){
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        COST[a][b] = c;
        COST[b][a] = c;
        G[a][b] = c;
        G[b][a] = c;
    }

    warshall_floyd(G, INF);

    ll ans = 0;
    rep(i,N-1)repe(j,i+1,N){
        if (COST[i][j] == INF) continue;

        if (COST[i][j] != G[i][j]) ans++;
    }

    cout << ans << endl;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int, int> ii;

const int mod = 1e9 + 7;
const ll INF = (1LL<<50);
const double EPSILON = 0.001;
const int N = 200005;
int main(){
	fastio;
	string a,b;
	cin >> a >> b;
	int ans = 1;
	for(int i = 0; i < sz(a); i++){
		if(a[i] != b[i])ans = 0;
	}
	if(sz(b) > sz(a) + 1)ans = 0;
	cout << (ans?"Yes":"No") << '\n';
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
char a[N];
stack<char>s;
int main()
{
    ios::sync_with_stdio(false);
    cin>>a;
    for(int i=0;a[i];i++)
    {
        if(s.empty())s.push(a[i]);
        else
        {
            if(s.top()!=a[i])s.pop();
            else s.push(a[i]);
        }
    }
    printf("%d\n",strlen(a)-s.size());
    return 0;
}


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

int main(int argc, char **argv)
{
	ll n; cin >> n;
	vector<ll> a(n); for (ll i = 0; i < n; ++i) cin >> a[i];
	ll odd_num{0};
	for (auto &e : a)
	{
		if (e & 1) ++odd_num;
	}
	std::cout << (odd_num & 1 ? "NO" : "YES" )<< std::endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int x;
  cin>>x;
  if(x==7 || x == 5 || x == 3) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,a,b,c,d;
string s;
bool r[200005];
bool ok(int L,int R){
	memset(r,0,sizeof(r));
	r[L] = 1;
	for(int i=L;i<=R;i++){
		if(r[i] == false) continue;
		for(int j=1;j<=2;j++){
			if(i+j >= n) continue;
			if(s[i+j] == '#') continue;
			r[i+j] = true;
		}
	}
	return r[R];
}
bool check(int L,int R){
    for(int i=L-1;i<=R-1;i++){
        if(s[i]=='.' && s[i+1]=='.' && s[i+2]=='.') return true;
    }
    return false;
}
int main(){
	cin >> n >> a >> b >> c >> d; a--; b--; c--; d--; cin >> s;
	if(c < d){
	    if(ok(a,c) && ok(b,d)) puts("Yes");
	    else puts("No");
	}
	else{
	    if(ok(a,c) && ok(b,d) && check(b,d)) puts("Yes");
	    else puts("No");
	}
	
}

Measured memory_bytes: 772
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException{
		Scanner scan = new Scanner(System.in);
		String[] abc = scan.nextLine().split(" ");
		if(Integer.parseInt(abc[1]) - Integer.parseInt(abc[0]) == Integer.parseInt(abc[2]) - Integer.parseInt(abc[1])){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 20820
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k; cin >> n >> k;
	vector<bool> islike(10, true);
	rep(i, k) {
		int a; cin >> a;
		islike[a] = false;
	}
	while (1) {
		int n2 = n;
		bool isans = true;
		while (n2 > 0) {
			if (!islike[n2 % 10]) isans = false;
			n2 /= 10;
		}
		if (isans) break;
		else n++;
	}
	cout << n << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a=n%10;
  if(a==2 || a==4 || a==5 || a==7 || a==9){
    cout<<"hon"<<'\n';
  }
  else if(a==0 || a==1 || a==6 || a==8){
    cout<<"pon"<<'\n';
  }
  else{
    cout<<"bon"<<'\n';
  }
  return(0);
}


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

using namespace std;
#define dbg(x) cerr << #x"=" << x << endl;
typedef long long LL;
const int MAX_N = 2*1e5+100;
char s[MAX_N];

int main(int argc, char const *argv[]){
	//freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    cin >> (s+1);
    bool ok = true;
    for(int i = A+1; i <= C-2 && ok; ++i){
        if(s[i] == '#' && s[i+1] == '#') {ok = false; break;}
    }
    for(int i = B+1; i <= D-2 && ok; ++i){
        if(s[i] == '#' && s[i+1] == '#') {ok = false; break;}
    }
    if(ok && D < C){ // A C之间可达
        bool can = false;
        s[A] = '#';
        s[C] = '#';
        for(int i = B; i <= D; ++i){
            if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') { can = true; break;}
        }
        ok &= can;
    }
    cout << (ok ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define mod 1000000007

using namespace std;
long long A,B,ans=1;
int main(){
	cin >> A >> B;
	if( abs(A-B)>1 ){
		cout << 0 << endl;
		return 0;
	}
	if( A==B )ans*=2;
	for(int i=1;i<=A;i++)ans=ans*i%mod;
	for(int i=1;i<=B;i++)ans=ans*i%mod;
	cout << ans%mod << endl;
	return 0;
}

Measured memory_bytes: 256
/*
 * ABC081_C.cpp
 *
 *  Created on: May 17, 2018
 *      Author: 13743
 */
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

int nums[200001];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int K, N;
	cin >> N >> K;
	int tmp;
	REP(i, N) {
		cin >> tmp;
		nums[tmp]++;
	}
	sort(nums, nums+200001);
	int rm = 0;
	for(int i=200000, k=0; k<K&&i>=0; i--,k++) {
		rm += nums[i];
	}
	cout << N - rm << endl;
}






Measured memory_bytes: 1024
//https://atcoder.jp/contests/dp/tasks/dp_a
#include<bits/stdc++.h>
#define endl "\n"
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
typedef long long int ll;
const int INF = 1e9;

using namespace std;

void solve()
{
    ll i, j, n, k;
    cin>>n>>k;

    vector<ll> arr(n);

    for(auto &ele: arr) cin>>ele;

    vector<ll> dp(n, INF);
    dp[0] = 0;

    for(i=0; i<n; ++i)
    {
        for(j=i+1; j<=i+k; ++j)
        {
            if(j<n) dp[j] = min(dp[j], dp[i] + abs(arr[i]-arr[j]));
        }
    }

    cout<<dp[n-1]<<endl;
}
 
int main()
{
    FASTIO
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
	int n;
	while(cin >> n,n){
        int array[120] = {0};
        for(int i = 0; i < n; i++){
            cin >> array[i];
        }
        int cnt = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n-1; j++){
                if(array[j] > array[j+1]){
                    array[j] ^= array[j+1];
                    array[j+1] ^= array[j];
                    array[j] ^= array[j+1];
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc103_b
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray().ToList();
            var t = Console.ReadLine().ToCharArray().ToList();

            bool value = true;
            value = Check(s, t);
            if(!value){
                for(int i=0; i<s.Count; i++){
                    var tmp = s[0];
                    s.RemoveAt(0);
                    s.Add(tmp);
                    value = Check(s, t);
                    if(value) break;
                }
            }

            if(value) WriteLine("Yes");
            else WriteLine("No");
        }
        static bool Check(List<char> s, List<char> t){
            bool value = true;
            for(int i=0; i<s.Count; i++){
                if(s[i] != t[i]){
                    value = false;
                    break;
                }
            }
            return value;
        }
    }
}

Measured memory_bytes: 13268
//Name: Pankaj Mandrawal (pankaj_m05)
//Problem: OCD
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define INF LLONG_MAX
#define NINF LLONG_MIN
#define mod 10000000009
#define sz(c) int((c).size())
#define sortall(x) sort(all(x))         
#define PI 3.1415926535897932384626     
#define all(c) (c).begin(), (c).end()
#define clr(x) memset(x, 0, sizeof(x))  
#define MAX32 numeric_limits< int >::max() 
#define MIN32 numeric_limits< int >::min()
#define rall(c) (c).rbegin(), (c).rend()
#define deb(x) cerr << #x << " = " << x << endl
#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define for1(i, n) for(int i = 1; i <= (int) n; ++i)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = (int)(l); i < (int)(r); ++i)
#define tr(c, it) for(typeof(c).begin() it = c.begin(); it != c.end(); it++)
#define deb2(x, y) cerr << #x << " = " << x << "," << #y << " = " << y << endl

using namespace std;

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vill;
typedef pair < int, int > pi;
typedef unsigned long long int ull;

ll mypow(ll x, ll y) { 
    if (y == 0) 
        return 1; 
    ll p = mypow(x, y / 2) % mod; 
    p = (p * p) % mod; 
    if (!(y & 1)) 
        return p;
    return (p * x) % mod; 
} 

void plssolve() {
	int n; cin >> n;
	set< int > s;
	for(int it = 0; it < n; ++it) {
		int temp; cin >> temp;
		s.insert(temp);
	}
	if(sz(s) == n) 
		cout << "YES" << '\n';
	else
		cout << "NO" << '\n';
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    cout << fixed;
    int t = 1;
    //cin >> t;
    while(t--) {
        plssolve();
    }
    return 0;
}

Measured memory_bytes: 9600
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
	
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	int a,b,n;
	string s;
	cin >> a >> b;
	cout << a + b/2 << endl;
  	return 0;
}





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

typedef long long ll;

int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, x;
	cin>>n>>x;

	vector<ll> wow;
	wow.push_back(x);

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

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

	ll ans = wow[1] - wow[0];
	for(ll i=2;i<wow.size();i++) ans = __gcd(ans, wow[i] - wow[i-1]);
	cout<<ans<<endl;

}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    ll len = s.length();
    ll wcnt = 0;
    ll ans = 0;
    reverse(s.begin(), s.end());
    rep(i,len){
        if(s[i] == 'W') wcnt++;
        else ans += wcnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  ll n,k; cin >> n >> k;
  if(k == 0){
    std::cout << n*n << '\n';
    return 0;
  }
  ll ans = 0LL;
  rep(b, n+1){
    if(b <= k) continue;
    ans += (b-k)*(n/b);
    ans += max(n%b-k+1,0LL);
  }

  std::cout << ans << '\n';
}


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

typedef long long ll;

const ll MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> C(N - 1), S(N - 1), F(N - 1);
    rep(i, N - 1) cin >> C[i] >> S[i] >> F[i];
    rep(i, N) {
        int ans = 0;
        for (int j = i; j < N - 1; j++) {
            ans = max(S[j], (ans + F[j] - 1) / F[j] * F[j]) + C[j];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))

res=[0]*n

res[0] = sum(a) - 2*sum(a[1::2])

for i in range(1,n):
    res[i] = 2*a[i-1] - res[i-1]

print(*res)

Measured memory_bytes: 14108
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define readll(x) scanf("%I64d",&x)
#define mod 1000000007
#define eps 1e-6
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n,a;
deque<int> q;

int main(){
    readi(n);
    lp(i,1,n){
        readi(a);
        if(i&1) q.push_back(a);
        else q.push_front(a);
    }

    if(n&1) while(sz(q)) printf("%d ",q.back()), q.pop_back();
    else while(sz(q)) printf("%d ",q.front()), q.pop_front();
}

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);cin.tie(0);


Measured memory_bytes: 3072
#include<iostream>
#include<queue>
#include<vector>
#include<string>
#include<utility>

using namespace std;

int solve(const vector<string> mp, vector<pair<int,int>> points, int h, int w, int s, int e) {
    int cx,cy;
    int dx[] = {-1,0,1,0};
    int dy[] = {0,1,0,-1};
    vector<vector<int>> memo(w,vector<int>(h,0)); //(x,y)???????????¢
    queue<pair<int,int>> Q;
    Q.push(points[s]);
    while (!Q.empty()) {
        pair<int,int> q;
        q = Q.front();Q.pop();
        if (q == points[e]) {
            return memo[q.first][q.second];
        }
        for (int dir=0; dir<4; dir++) {
            cx = q.first + dx[dir];
            cy = q.second + dy[dir];
            if (cx<0 || cx>w-1 || cy<0 || cy>h-1 || mp[cy][cx] == 'X' || memo[cx][cy] != 0) continue;
            Q.push(make_pair(cx,cy));
            memo[cx][cy] = memo[q.first][q.second] + 1;
        }
    }
    return -1;
}

int main(){
    int h,w,n,num;
    int dx[] = {-1,0,1,0,};
    int dy[] = {0,1,0,-1,};
    long long sum=0;
    cin >> h >> w >> n;
    vector<string> mp;
    string tmp;
    vector<pair<int,int>> points(n+1);
    for (int i= 0; i<h; i++) {
        cin >> tmp;
        for (int j=0; j<w; j++) {
            if (tmp[j] == 'S') {
                points[0] = make_pair(j,i);
            } else if(tmp[j] != '.' && tmp[j] != 'X') {
                num = atoi(&tmp[j]);
                points[num] = make_pair(j,i);
            } 
        }
        mp.push_back(tmp);
    }
    for(int i = 1; i<= n ; i++) {
        sum += solve(mp,points,h,w,i-1,i);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 7764
#include <bits/stdc++.h>
//#include "./libb/lib.hpp"
 
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;
const uint64_t MOD = 1000000007;
const double PI = acos(-1);
 
int main()
{
	uint64_t samp = 10;
	uint32_t kk = 0;
	uint32_t ans = 1;

	cin >> kk;

	if(((kk % 2) == 0) || ((kk % 5) == 0))
	{
		cout << (-1) << endl;
		return 0;
	}

	kk = kk * 9;

	if ((kk % 7) == 0)
		kk = kk / 7;

	while(1)
	{
		samp = samp % kk;
		if (samp == 1)
			break;
		
		samp = samp * 10;
		ans++;
		if(ans >= 9000001)
		{
			cout << (-1) << endl;
			return 0;
		}
	}

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


Measured memory_bytes: 3588
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
using namespace std;
ll A[200005];
ll is[200005];

int main(){
	ll N,K;
	scanf("%lld%lld",&N,&K);
	for(ll i=1;i<=N;i++)
    {
        scanf("%lld",A+i);
    }
    ll now=1,times;
    if(K<=200000)
    {
        for(;K>0;K--)
            now=A[now];
        printf("%d",now);
        return 0;
    }
    for(times=0;;)
    {
        now=A[now];
        times++;
        if(times&&now==1)
        {
            K=K%times;
            for(;K>0;K--)
            {
                now=A[now];
            }
            break;
        }
        if(is[now])
        {
            K=(K-is[now])%(times-is[now]);
            for(;K>0;K--)
            {
                now=A[now];
            }
            break;
        }
        is[now]=times;
    }
    printf("%lld",now);
	return 0;
}


Measured memory_bytes: 6940
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;



int main() {
	int N;
	cin >> N;
	int v[3] = {3,5,7};


	int ans = 0;

	rep(dgt, 3, 10) {
		int ma = 1;
		rep(i, 0, dgt)ma *= 3;

		rep(msk, 0, ma) {
			int x = 0;
			int m = msk;
			int cn[3] = { 0,0,0 };
			rep(i, 0, dgt) {
				int d = m % 3;
				x = x * 10 + v[d];
				cn[d]++;
				m /= 3;
			}
			if (x <= N && cn[0] > 0 && cn[1] > 0 && cn[2] > 0)ans++;
		}
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    string s;
    cin >> n >> s;

    int cntw = 0;
    rep(i, n) {
        if (s[i] == 'W') cntw++;
    }
    if (cntw == 0) {
        cout << 0 << endl;
        return 0;
    }

    int cntr = n - cntw;
    int ans = cntw;
    
    int cnt = 0;
    rep(i, cntr) {
        if (s[i] == 'W') cnt++;
    }
    chmin(ans, cnt);

    cout << ans << endl;
}


Measured memory_bytes: 3768
package main

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

var (
	n     int
	m     = make(map[string]bool)
	tmp   int
	count int
)

func intOfString(s string) int {
	tmp, _ := strconv.Atoi(s)
	return tmp
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n = intOfString(sc.Text())
	for sc.Scan() {
		tmp = intOfString(sc.Text())
		if tmp >= 3200 {
			count++
		} else if tmp >= 2800 {
			m["red"] = true
		} else if tmp >= 2400 {
			m["orange"] = true
		} else if tmp >= 2000 {
			m["yellow"] = true
		} else if tmp >= 1600 {
			m["blue"] = true
		} else if tmp >= 1200 {
			m["l-blue"] = true
		} else if tmp >= 800 {
			m["green"] = true
		} else if tmp >= 400 {
			m["brown"] = true
		} else {
			m["gray"] = true
		}
	}

	if count == 0 {
		fmt.Printf("%[1]d %[1]d\n", len(m))
	} else {
		fmt.Printf("%d %d\n", max(len(m), 1), len(m)+count)
	}

}

func max(x, y int) int {
	if x < y {
		return y
	}

	return x
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,m;cin>>a>>b>>c;
  m=max(abs(b-a),abs(c-a));
  m=max(m,abs(c-b));
  cout<<abs(b-a)+abs(c-a)+abs(c-b)-m<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool is_palindrome(string s){
	string t(s.rbegin(),s.rend());
	return s==t;
}
int main() {
	// your code goes here
	string s;
	cin>>s;
	int n=(int)s.size();
	if(is_palindrome(s) && is_palindrome(s.substr(0,(n-1)/2)) &&is_palindrome(s.substr((n+1)/2))){
		cout<<"Yes"<<endl;
	}
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n,m,a;

    cin >> n >> m;

    for(int i=0;i<m;i++){
        cin >> a; n-=a;
    }

    if(n<0)cout <<"-1" <<endl;
    else cout << n <<endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>

using namespace std;

int cnt;
string s, t;

int main()
{
    cin>>s>>t;
    for(int i = 0; i < 3; i++)
    {
        if(s[i] == t[i]) cnt++;
    }
    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

"""
適切な回転に対して、x座標最大化の問題になる。
ということは、適当な半平面に入ってるものを全部足す
"""

import numpy as np

N = int(input())
X,Y = np.array([input().split() for _ in range(N)],dtype=np.int64).T

zero = (X==0)&(Y==0)
if(zero.all()):
    print(0)
    exit()

X = X[~zero]
Y = Y[~zero]
N = len(X)

# ソートして2周
angle = np.arctan2(Y,X)
i = angle.argsort()
X = X[i]; Y = Y[i]; angle = angle[i];
X = np.concatenate([X,X])
Y = np.concatenate([Y,Y])
angle = np.concatenate([angle,angle+2*np.pi])

# 区間和を全部計算してしまえ！

Xcum = X.cumsum()
Ycum = Y.cumsum()

items = np.arange(1,N+1)[None,:]
L = np.arange(N)[:,None]
dx = Xcum[L+items-1] - Xcum[L] + X[L]
dy = Ycum[L+items-1] - Ycum[L] + Y[L]

answer = (dx*dx+dy*dy).max()**.5
print(answer)

Measured memory_bytes: 12816
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll N,M;
    cin>>N>>M;
    string S;
    cin>>S;
    ll now = N;
    v ans;
    bool ok = true;
    while(now != 0){
       for(int i = max(now-M,ll(0)); i< now; i++){
           if(S[i] == '0'){
               ans.PB(now-i);
               now = i;
           }
           else{
               if(i == now-1){
                   ok = false;
                   now = 0;
                   break;
               }
           }
       }
    }
    if(!ok)cout<<-1;
    else{
        for(int i = ans.size()-1;i>=0;i--){
            cout<<ans[i]<<" ";
        }
    }

    return 0;
}

Measured memory_bytes: 1528
#include <iostream>
using namespace std;
int main(void){

    int alphabet[26];
    for(int i = 0; i < 26; i++) {
        alphabet[i] = 0;
    }

    char str;
    while(cin >> str) {
        int num = tolower(str) - 'a';
        alphabet[num]++;
    }

    for(int i = 0; i < 26; i++){
        str = i + 'a';
        cout << str << " : " << alphabet[i] << endl;
    }

}

Measured memory_bytes: 3048
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(input())
#上下左右隣接しない独立した#があるかどうかを調べる
#境界処理をしたくなので周囲に.追加
newS = ["." * (W+2)]
for rowS in S:
    newS.append("." + rowS + ".")
newS.append("." * (W+2))

for i in range(1, H+1):
    for j in range(1, W+1):
        if newS[i][j] == "#" and newS[i][j+1] != "#" and newS[i][j-1] != "#"\
        and newS[i+1][j] != "#" and newS[i-1][j] != "#":
            print("No", end = "")
            break
    else:
        continue
    break
else:
    print("Yes", end = "")



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define N 200005

using namespace std;
typedef pair<int,int> Pair;

inline int input() {
	int x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

int n, fa[N], f[N];
vector<int> T[N];

inline bool cmp(int x, int y) { return f[x] < f[y]; }

void dfs(int u) {
	for (int v : T[u]) dfs(v);
	sort(T[u].begin(), T[u].end(), cmp);
	for (int v : T[u]) f[u] = max(f[u], f[v]) + 1;
}

int main() {
	n = input();
	for (int i = 2; i <= n; ++i)
		fa[i] = input(), T[fa[i]].push_back(i);

	dfs(1);
	printf("%d\n", f[1]);
	return 0;
}


Measured memory_bytes: 15744
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, K: int):
    if K <= A:
        print(K)
    elif K <= A+B:
        print(A)
    else:
        print(A - (K-A-B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61876
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto A = RD;
	auto B = RD;
	auto C = RD;
	auto K = RD;

	auto c1 = min(A, K);
	K -= c1;
	auto ans = c1;
	auto c2 = min(B, K);
	K -= c2;
	auto c3 = min(C, K);
	ans -= c3;

	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 2716
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    String s = scanner.nextLine();
		    String[] a = s.split(",");
		    
		    System.out.println(a[0] + " " + a[1] + " " + a[2]);
		    
		    scanner.close(); }
		  }

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define mem(a) memset(a,0,sizeof(a))

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //////////////////////////////////////////
    int n,x,y,z,i,j,p,q;
    cin>>n;
    z=1234567879;
    for(i=1;i<=n/2;i++)
    {
        x=i;
        y=n-i;
        p=q=0;
        while(x)
        {
            p+=x%10;
            x/=10;
        }
        while(y)
        {
            q+=y%10;
            y/=10;
        }
        z=min(z,p+q);
    }
    cout<<z<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll extgcd(ll a,ll b,ll &x,ll &y){
  if(b == 0){
    x = 1;y = 0;
    return a;
  } else {
    ll d = extgcd(b,a%b,y,x);
    y -= a/b * x;
    return d;
  }
}
int main(){
  ll a,b,x,y;scanf("%lld%lld",&a,&b);
  extgcd(a,b,x,y);
  printf("%lld %lld\n",x,y);
}


Measured memory_bytes: 3220
#include <stdio.h>
#include <stdlib.h>

int kaijo(int nb){
	int sum = 1;
	while(nb > 0){
		sum *= nb;
		nb --;
	}
	return(sum);
}


int main(void){
	int N;
	scanf("%d", &N);
	int i = 1;
	
	int p[N +1], q[N+1];
	
	for(i = 0; i < N; i++){
		scanf("%d", &p[i]);
	}
	
	for(i = 0; i < N; i++){
		scanf("%d", &q[i]);
	}
	
	int ans1 = 1;
	int ans2 = 1;
	int j,pre1,pre2;
	
	for(i = 0; i < N -1; i++){
		pre1 = 0;
		pre2 = 0;
		for(j = 0; j < i;j++){
			if(p[j] < p[i]){
				pre1++;
			}
			if(q[j] < q[i]){
				pre2++;
			}
		}
		
		ans1 += kaijo(N-i-1) * (p[i]-1-pre1);
		ans2 += kaijo(N-i-1) * (q[i]-1-pre2);
	}
	printf("%d\n",abs(ans1 - ans2));
	return 0;
}




Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,x,y,d;
    int sum1=0,sum2=0,sum3=0;
    cin>>a>>b>>c;
    cin>>x>>y;
    sum1=x*a+y*b;
    int imin=min(x,y)*2;
   // cout<<imin<<endl;
    sum2=imin*c+(y-imin/2)*b+(x-imin/2)*a;
    int imax=max(x,y)*2;
    sum3=imax*c;
    cout<<min(min(sum1,sum2),sum3)<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	unsigned int a, b;
	unsigned int l, s;
	unsigned int gcd, lcm;
	
	while (scanf("%d %d", &a, &b) != EOF){
		l = a;
		s = b;
		if (l < s){
			l = b;
			s = a;
		}
		while (s){
			l %= s;
			l += s;
			s = l - s;
			l -= s;
		}
		gcd = l;
		lcm = a / gcd * b;
		
		printf("%d %d\n", gcd, lcm);
	}
	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, w, wt[200020], val[200020], dp[321][200020];
int main() {
	cin >> n >> w;
	for (int i = 0; i < n; i++) for(int j = 0; j <= w; j++) dp[i][j] = 0;
	for (int i = 0; i < n; i++) cin >> wt[i] >> val[i];
	
	for (int i = wt[0]; i <= w; i++) dp[0][i] = val[0];
	
	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= w; j++) {
			if (j-wt[i] >= 0) dp[i][j] = max(dp[i-1][j-wt[i]] + val[i], dp[i][j]);
			dp[i][j] = max(dp[i][j], dp[i-1][j]);
		}
	}
	cout << dp[n-1][w] << "\n";
	return 0;
}

Measured memory_bytes: 159232
import numpy as np
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
x,n = map(int,input().split())
b = 0
if n == 0:
  a = 1
else:
  b = [int(i) for i in input().split()]
  b.sort(reverse = True)
if b == 0:
  print(x)
else:
  c = [int(i) for i in range(102)]
  for i in b:
    c.pop(i)
  print(getNearestValue(c,x))

Measured memory_bytes: 27220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    string s;
    cin >> s;
    string ans;
    cout << s[0];
    rep (bit, 0, 1 << 3) {
        int sum = s[0] - '0';
        rep (i, 0, 3) {
            if (bit & 1 << i) {
                sum += s[i + 1] - '0';
            } else {
                sum -= s[i + 1] - '0';
            }
        }
        if (sum == 7) {
            rep (i, 0, 3) {
                if (bit & 1 << i) {
                    cout << '+';
                } else {
                    cout << '-';
                }
                cout << s[i + 1];
            }
            cout << "=7\n";
            return 0;
        }
    }
}

Measured memory_bytes: 256
import numpy as np
n = int(input())
a = np.array(list(map(int,input().split())))
bit = []
ans = 0
mod = 10**9+7
for i in range(60):
    bit.append(np.count_nonzero(a&1))
    a >>= 1
for i in range(60):
    ans += ((n-bit[i])*bit[i]) * pow(2,i,mod)
    ans %= mod
print(ans)

Measured memory_bytes: 49952
#include<stdio.h>
#define M 100000
#define INFTY 2000000000

struct Cards {
  char mark;
  int num;
};

void merge(struct Cards*,int ,int , int );
void mergeSort(struct Cards*,int , int );
int partition(struct Cards*,int ,int );
void quickSort(struct Cards*,int ,int );

struct Cards Left[M/2+2],Right[M/2+2];
int n;

int main(){
  int i,v;
  struct Cards X[M],Y[M];
  char C[10];
  int stable = 1;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%s %d",C,&v);
      X[i].mark = Y[i].mark = C[0];
      X[i].num = Y[i].num = v;
    }

  mergeSort(X,0,n);
  quickSort(Y,0,n-1);

  for(i=0;i<n;i++)
    {
      if(X[i].mark!=Y[i].mark)stable = 0;
    }

  if(stable==1)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n", Y[i].mark, Y[i].num);
  }
  return 0;
}
 

void merge(struct Cards S[],int l,int m , int r)
{
  int i,j,n1,n2,k;
   n1 = m - l;
   n2 = r - m;
   for(i=0;i < n1;i++)
     {
       Left[i]=S[l+i];
     }
 
   for(i=0;i < n2;i++)
     {
       Right[i]=S[m+i];
     }
   Left[n1].num=INFTY;
   Right[n2].num=INFTY;
   i=0;
   j=0;
   for(k=l;k < r;k++)
     {

       if(Left[i].num<=Right[j].num)
	 {
	   S[k] = Left[i];
	   i++;
	 }
       else 
	 {
	 S[k] = Right[j];
	 j++;
	 }
     }
}

void mergeSort(struct Cards S[],int l, int r)
{
  int mid=0;
  if(l+1 < r)
    {
      mid = (l+r)/2;
      mergeSort(S,l,mid);
      mergeSort(S,mid,r);
      merge(S,l,mid,r);
    }
}

int partition(struct Cards S[],int p,int r)
{
  int i,j;
  struct Cards x,tmp;
  x = S[r];
  i = p-1;
  for(j=p;j<r;j++)
    {
      if(S[j].num<=x.num)
	{
	  i = i+1;
	  tmp=S[i];
	  S[i]=S[j];
	  S[j]=tmp;
	}
    }
  tmp=S[i+1];S[i+1]=S[r];S[r]=tmp;
  return i+1;
}

void quickSort(struct Cards S[],int p,int r)
{
  int m;
  if(p<r)
    {
      m = partition(S,p,r);
      quickSort(S,p,m-1);
      quickSort(S,m+1,r);
    }
}


  

Measured memory_bytes: 2956
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    StringBuffer S = new StringBuffer(sc.next());
    StringBuffer T = new StringBuffer(sc.next());
    for (int i = 0; i < T.length(); i++) {
      char top = S.charAt(0);
      S = new StringBuffer(S.substring(1));
      S = S.append(top);
      if (S.toString().equals(T.toString())) {
        System.out.println("Yes");
        return;
      }
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	char c;
	cin >> c;
	
	if(c == 'A')
		cout << 'T' << endl;
	else if(c == 'T')
		cout << 'A' << endl;
	else if(c == 'G')
		cout << 'C' << endl;
	else
		cout << 'G' << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void)
{    
    string s;
    ll k;
    cin >> s >> k;
    ll r = 0, len = (ll)s.size(), p = 0;
    vll cnt(len+1, 0);
    char tmp = s[0];
    rep(i, len){
        if (s[i] == tmp) {
            cnt[p]++;
        } else {
            p++;
            cnt[p]++;
            tmp = s[i];
        }
    }
    
    if (p == 0) {
        r = len*k/2;
    } else {
        rep(i, p+1) r += cnt[i]/2;
        r *= k;
        if(s[0] == s[len-1]){
            r -= (cnt[0]/2 + cnt[p]/2 - (cnt[0] + cnt[p]) / 2) * (k-1);
        }
    }
    
    
    mes(r);
    
    
    
    
    
}

Measured memory_bytes: 3628
input_num = input().split()
dice_num = int(input_num[0])
border_socre = int(input_num[1])
ans_p = 0

for score in range(1,dice_num + 1):
    coin_counter = 0
    while score < border_socre:
        score = score * 2
        coin_counter += 1
    ans_p += (1 / dice_num ) * ((1/2 ) ** coin_counter)
    
print(round(ans_p, 12))

Measured memory_bytes: 3060