akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define N 200010
using namespace std;
int n,m,a[N],q[N<<2];
char s[N];

void work(int k){
	int l(1),r(n),tag(0);
	for (int i=1;i<=n;i++)
		q[i]=s[i-1]-'A';
	for (int i=1;i<=k;i++){
		if ((tag^q[l])==0)
			q[l]^=1;
		else{
			l++,tag^=1;
			q[++r]=tag;
		}
	}
	for (int i=1;i<=n;i++)
		a[i]=q[l+i-1]^tag;
}

int main(){
	scanf("%d%d",&n,&m);
	scanf("%s",s);
	if (m<=2*n)
		work(m);
	else
		if (m&1)
			work(2*n-1);
		else
			work(2*n);
	for (int i=1;i<=n;i++)
		printf("%c",(char)(a[i]+'A'));
	puts("");
	return 0;
}

Measured memory_bytes: 4480
#include <stdio.h>

int main(void){
	char S[4] = {};
	char T[4] = {};
	int a = 0;

	scanf("%s", &S);
	scanf("%s", &T);

	for (int i = 0; i < 3; i++)
	{
		if(S[i] == T[i])
			a++;
	}

	printf("%d\n", a);

	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    char s[150];
    scanf("%s",&s);
    long long k;
    cin>>k;
    long long i;
    for(i=0;s[i]=='1';i++);
    if(k<=i)
        cout<<"1"<<endl;
    else
        cout<<s[i]<<endl;
    return 0;
}

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

using namespace std;

int main(){
  int N;
  cin >> N;

  vector<long long> A(N), A_cnt(N + 1);
  for(auto& a: A){
    cin >> a;
    A_cnt[a]++;
  }

  long long all = 0;
  for(auto cnt: A_cnt){
    all += cnt * (cnt - 1) / 2;
  }

  for(int i = 0; i < N; i++){
    long long removed = A[i];
    long long ans = all - A_cnt[removed] * (A_cnt[removed] - 1) / 2 + (A_cnt[removed] - 1) * (A_cnt[removed] - 2) / 2;
    cout << ans << endl;
  }
}


Measured memory_bytes: 6912
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;

int main(){
	int n, ans = 0;
	cin >> n;
	vector<int> a(n+1);
	vector<int> b(n+1);
	vector<int> c(n+1);
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++){
		cin >> b[i];
	}
	for (int i = 1; i < n; i++){
		cin >> c[i];
	}
	for (int i = 1; i <= n; i++){
		ans += b[a[i]];
		if (i != 1 && a[i] - a[i-1] == 1){
			ans += c[a[i-1]];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    t: f64,
    x: f64
  }
  println!("{}", t / x)
}


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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

class unWSSSP {
public:

    ll INF = 1000000000;
    vector <ll> dist, visited, par;
    deque <ll> dq;

    unWSSSP(ll n, vector < vector <ll> > adj, ll src) {
        dist.clear(); f(i,1,n) dist.pb(INF); dist[src] = 0;
        visited.assign(n,0); visited[src] = 1;
        par.resize(n); par[src] = src;
        dq.pb(src);
        while(!dq.empty()) {
            ll u = dq[0]; dq.pop_front();
            f(i,0,sz(adj[u])-1) {
                ll v = adj[u][i];
                if(visited[v]) continue;
                dist[v] = dist[u] + 1;
                visited[v] = 1;
                par[v] = u;
                dq.pb(v);
            }
        }
        f(i,0,n-1) if(dist[i] == 1000000000) dist[i] = -1;
    }

};

int main()
{
    // Fast_IO();
    ll n, m; cin >> n >> m;
    vector < vector<ll> > adj(n);
    f(_,1,m) {
        ll u, v; cin >> u >> v;
        u--; v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    unWSSSP bfs(n,adj,0);
    bool impossible = false;
    f(i,0,n-1) if(bfs.dist[i] == -1) impossible = true;
    if(impossible) cout << "No";
    else {
        cout << "Yes" << endl;
        f(i,1,n-1) cout << bfs.par[i]+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 20748
/******************************************************************************

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

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

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

string Lex(string a,string b){
    int i;
    int x=a.length();
    int y=b.length();
    int z=(x<y)?x:y;
    for(i=0;i<z;i++){
        if(a[i]<b[i])
          return a;
        if(a[i]==b[i])
          continue;
        if(b[i]<a[i])
          return b;
    }
    if(z==x)
      return a;
    else
      return b;
}
int main()
{
    int n,j,k,l;
    string s;
    cin>>n;
    cin>>l;
    vector<string> v;
    for(j=0;j<n;j++){
         cin>>s;
         v.push_back(s);
    }
    sort(v.begin(),v.end());
    for(j=0;j<n;j++){
         
         cout<<v[j];
    }
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
H = [int(_) for _ in input().split()]
ans = 0
x = 0
h = H[0]
for i in range(1, N):
    if h >= H[i]:
        x += 1
    else:
        ans = max(ans, x)
        x = 0

    h = H[i]

ans = max(ans, x)
print(ans)



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

int main () {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

     int N; cin >> N;
     vector<int64_t> a(N);
     int64_t ans = 0;
     for (int i = 0; i < N; ++i)
        cin >> a[i];
     for (int i = 0; i < N-1; ++i) {
         if (a[i] > a[i+1]) {
             ans += a[i] - a[i+1];
             a[i+1] += a[i] - a[i+1];
         }
     }cout << ans << '\n';


    return 0;

}



Measured memory_bytes: 4756
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
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; }

ll MOD = 1000000007;
ll INF =1<<29;

int main(){
    int l,r;
    cin >> l >> r;
    int a = l/2019;
    int b = r/2019;
    int x = l%2019;
    int y = r%2019;
    if(x==0||y==0){
        cout << 0 <<endl;
        return 0;
    }
    if(a<b){
        cout << 0 << endl;
        return 0;
    }
    int mi= 1000000000;
    for(int i = x;i<=y-1;++i){
           for(int j = i+1;j<=y;++j){
               mi = min((i*j)%2019,mi);
           }
    }
    cout << mi << endl;
}

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

int main() {

    int n;
    cin >> n;
    int ans = 0;

    for(int i = 0; i < n; ++i){
        if(i+1 < 10)++ans;
        if(i+1 >= 100 && i+1 < 1000)++ans;
        if(i+1 >= 10000 && i+1 < 100000)++ans;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n;
cin >> n;
vector <int>num(0);
int count =1 ;
while(n>26){
num.push_back(n%26);
//cout <<"余りは"<< n % 26;
n =(n-1)/26;
count ++;
//cout <<"   nは"<<n <<endl;
}
num.push_back(n);

for(int i=count - 1 ;i>=0;i--){
//cout << num.at(i)<<endl;
char l;
if(num.at(i)==0){l = 'z';}
else{
l= 96+ num.at(i);
}
//cout <<"数字が"<<num.at(i) <<"の時文字は"<< l <<endl;
cout << l ;
}
  
cout<<endl;
}


Measured memory_bytes: 3608
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n = readline() |> chomp
	f = 0
	for i in 1:3
		if n[i]=='7'
			f = 1
		end
	end
	println(f==1 ? "Yes" : "No")
end

main()

Measured memory_bytes: 154884
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
ll INF = 1000000007;
using Graph = vector<vector<ll>>;

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する


int main() {
    ll a1,a2,a3;
    cin >> a1 >> a2 >> a3;

    if(a1+a2+a3 >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }


    


}


Measured memory_bytes: 256
use proconio::*;
use rand::*;

fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut res = 0;
    let mut last_helds = [0; 26];
    let mut ans = vec![0usize; d];
    let mut rng = thread_rng();
    for i in 0..d {
        ans[i] = rng.gen_range(1, 27);
    }

    // println!("{}", satisfaction(&ans, &c, &s, d));
    for a in ans {
        println!("{}", a);
    }
}

fn satisfaction(ans: &Vec<usize>, c: &Vec<i64>, s: &Vec<Vec<i64>>, d: usize) -> i64 {
    let mut last_helds = [0; 26];
    let mut res = 0;

    for day in 1..=d {
        res += s[day - 1][ans[day - 1] - 1];
        last_helds[ans[day - 1] - 1] = day as i64;
        for i in 0..26 {
            res -= c[i] * (day as i64 - last_helds[i]);
        }
    }

    res
}


Measured memory_bytes: 2696
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<complex>

using namespace std;


//ユークリッドの互除法　a,bは最大公約数を求めたい２つの数
long long int gcd(long long int a, long long int b) {
             long long int tmp;
             long long int r = 1;
             if (b > a) {
                           tmp = a;
                           a = b;
                           b = tmp;
             }
             r = a % b;
             while (r != 0) {
 
 
                           a = b;
                           b = r;
                           r = a % b;
 
             }
             return b;
}

const long long int mod=1000000007;
int main(){
	cout << fixed << setprecision(18);
	long long int n,m,k,t,a[201000],res=0,l,r;
	string str;
	char ch;
	cin>>n>>str>>k;
	ch=str[k-1];
	for(int i=0;i<str.length();i++){
		if(ch==str[i]){cout<<ch;}
		else{cout<<"*";}
	}
	
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int H1,M1,H2,M2,K;
int main() {
	scanf("%d%d%d%d%d",&H1,&M1,&H2,&M2,&K);
	printf("%d\n",(H2-H1)*60+M2-M1-K);
	return 0;
} 

Measured memory_bytes: 3212
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk

using namespace std;

inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    map<int, int> a;
    rep(i, 0, n) {
        int x;
        cin >> x;
        a[x]++;
    }
    if (sz(a) > 3) {
        cout << "No\n";
        return 0;
    }
    int v1 = a.begin()->fi;
    int v2 = (--a.end())->fi;
    int res[n];
    res[0] = v1;
    res[1] = v2;
    rep(i, 2, n) {
        res[i] = res[i - 1] ^ res[i - 2];
    }
    if (res[n - 1] != (res[n - 2] ^ res[0])) {
        cout << "No\n";
        return 0;
    }
    if (res[0] != (res[n - 1] ^ res[1])) {
        cout << "No\n";
        return 0;
    }
    map<int, int> aaa;
    rep(i, 0, n) {
        aaa[res[i]]++;
    }
    if (a == aaa) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N;
int A[20];
int x[20][20];
int y[20][20];

int main()
{
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        cin >> A[i];
        for (int j = 1; j <= A[i]; j++)
        {
            cin >> x[i][j] >> y[i][j];
        }
    }

    int ans = 0;
    for (int bit = (1<<N) - 1; bit >= 0; bit--)
    {
        bool ok = true;
        for (int j = 1; j <= N; j++)
        {
            if (!(bit & (1<<(j-1)))) continue;

            for (int k = 1; k <= A[j]; k++)
            {
                int xa = x[j][k];
                int ya = y[j][k];
                if (ya == 1)
                {
                    if (!(bit & (1<<(xa-1))))
                    {
                        ok = false;
                        break;
                    }
                }
                else
                {
                    if (bit & (1<<(xa-1)))
                    {
                        ok = false;
                        break;
                    }
                }
            }
        }
        int count = 0;
        if (ok)
        {
            for (int i = 0; i < N; i++)
            {
                if (bit & (1<<i))
                {
                    count++;
                }
            }
        }
        ans = max(ans, count);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    map<int, int>cnt;
    int ans = 0, N;
    cin >> N;
    for(int i = 0; i< N; i++){
        int a;
        cin >> a;
        cnt[a -1]++;
        cnt[a]++;
        cnt[a+1]++;
    }
    for(map<int, int>::iterator it = cnt.begin(); it != cnt.end(); it++){
        ans = max(ans, (*it).second);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <deque>
#include <vector>
#include <string>
#include <stdexcept>
using namespace std;

class Query {
  private:
    bool is_rev;
    string head;
    string tail;
  public:
    Query() {
      is_rev = true;
      head = "";
      tail = "";
    }

    Query(bool is_head, string t) {
      is_rev = false;
      if(is_head) {
	head = t;
	tail = "";
      } else {
	head = "";
	tail = t;
      }
    }

    bool is_reverse() {
      return is_rev;
    }
    bool is_head() {
      return head.size() > 0;
    }
    bool is_tail() {
      return tail.size() > 0;
    }

    char get_char() {
      if (is_rev)
	throw logic_error("rev");

      return is_head() ? head[0] : tail[0]; 
    }
};
deque<char> string_formation(string s, int q, Query queries[]) {
  bool is_rev = false;
  deque<char> dq;
  for(int i=0;i<s.size();i++) {
    dq.push_back(s[i]);
  }
  for(int i=0;i<q;i++) {
    //cout << "=====>" << i << " " << is_rev << " " << s << " " << endl;
    Query query = queries[i];
    if(query.is_reverse()) {
      is_rev = !is_rev;
      continue;
    }
    if(query.is_head()) {
      if(is_rev) {
	dq.push_back(query.get_char());
	continue;
      }
      dq.push_front(query.get_char());
      continue;
    }
    if(is_rev) {
      dq.push_front(query.get_char());
      continue;
    }
    dq.push_back(query.get_char());
  }
  // cout << "-->" << is_rev << " " << s << endl;
  if(!is_rev) {
    return dq;
  }
  deque<char> rev_dq;
  while(!dq.empty()) {
    rev_dq.push_back(dq.back());
    dq.pop_back();
  }
  return rev_dq;
}

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  Query queries[q];
  for(int i=0;i<q;i++) {
    int typ;
    cin >> typ;
    if(typ == 1) {
      queries[i] = Query();
      continue;
    }
    cin >> typ;
    string c;
    cin >> c;
    if(typ == 1) {
      queries[i] = Query(true, c);
      continue;
    }
    queries[i] = Query(false, c);
  }
  deque<char> ans = string_formation(s, q, queries);
  while(!ans.empty()) {
    cout << ans.front();
    ans.pop_front();
  }
}

Measured memory_bytes: 15104
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) int __VA_ARGS__; in(__VA_ARGS__)
//オーバーフロー対策
#define INL(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define next asdnext
#define prev asdprev
#pragma endregion RegionDefs

void solve()
{
    IN(n, k);
    int* h = new int[100100];
    rep(i, n) cin >> h[i];
    int* dp = new int[100100];
    fill(dp, dp+100100, INF);
    dp[0] = 0;
    rep(i, n)
    {
        reps(j, 1, k+1)
        {
            chmin(dp[i+j], dp[i]+abs(h[i] - h[i+j]));
        }
    }
    cout << dp[n-1] << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

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

using namespace std;
typedef long long ll;

const int INF = 1 << 30;
const int MOD = 1e9 + 7;


int main() {
    string s, t; cin >> s >> t;
    int n, m; n = s.size(); m = t.size();
    vector<vector<int>> dp(n+1, vector<int>(m+1, -INF));
    vector<vector<pair<int, int>>> rec(n+1, vector<pair<int, int>>(m+1));
    dp[0][0] = 0;
    rep(i, n+1) rep(j, m+1) {
        if (s[i] == t[j]) {
            if (i+1 <= n && j+1 <= m && dp[i+1][j+1] < dp[i][j] + 1) {
                dp[i+1][j+1] = dp[i][j] + 1;
                rec[i+1][j+1] = make_pair(i, j);
            }
        }
        if (i+1 <= n && dp[i+1][j] < dp[i][j]) {
            dp[i+1][j] = dp[i][j];
            rec[i+1][j] = make_pair(i, j);
        }
        if (j+1 <= m && dp[i][j+1] < dp[i][j]) {
            dp[i][j+1] = dp[i][j];
            rec[i][j+1] = make_pair(i, j);
        }
    }

    string ans = "";
    int i, j; i = n; j = m;
    while (i > 0 || j > 0) {
        int ni, nj;
        ni = rec[i][j].first;
        nj = rec[i][j].second;
        if (ni == i - 1 && nj == j - 1) ans += s[ni];
        i = ni; j = nj;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 105984
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static BufferedReader reader;
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		String[] strings = readLine();
		long H = Long.parseLong(strings[0]);
		long c = 0;
		while(H>0) {
			H/=2;
			c*=2;
			c++;
		}
		print(c);
		
		//String[] s = readLine();
		//print(num);
	}
	
	//functions here
	//note that all methods should be STATIC

	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
}

Measured memory_bytes: 22612
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

const int MX=511;

int a[MX][MX];
int main(){
	int W,H,w,h;
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if(H%h==0&&W%w==0)puts("No");
	else{
		puts("Yes");
		for(int i=1;i<=H;i+=h)
			for(int j=1;j<=W;j+=w)
				a[i][j]+=999999999;
		for(int i=h;i<=H;i+=h)
			for(int j=w;j<=W;j+=w)
				a[i][j]-=1000000000;
		for(int i=1;i<=H;i++){
			for(int j=1;j<=W;j++)printf("%d ",a[i][j]);
			puts("");
		}
	}
	return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int D;
  string S;
  cin >> D;
  switch (D) {
  case 25:
    S = "Christmas";
    break;
  case 24:
    S = "Christmas Eve";
    break;
  case 23:
    S = "Christmas Eve Eve";
    break;
  default:
    S = "Christmas Eve Eve Eve";
    break;
  }
  cout << S << "\n";
}

Measured memory_bytes: 256
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var c = int.Parse(line[2]);
        getAns(a, b, c);
    }
    static void getAns(int a, int b, int c)
    {
        var week = a * 7 + b;
        var nw = c / week;
        var nw2 = c - nw * week;
        var nw3 = Min(7, (nw2 + a - 1) / a);
        Console.WriteLine(7 * nw + nw3);
    }
}


Measured memory_bytes: 17948
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int N,H;cin>>N>>H;
  int a;
  int b[100005]={};
  int ma=0;
  int ans=0;
  for(int i=1;i<=N;i++){
    cin>>a>>b[i];
    ma=max(ma,a);
  }
  // ここまでOK
  sort(b+1,b+N+1);
  for(int i=N;i>=1;i--){
    if(H<=0 || b[i]<=ma)break;
    if(b[i]>ma){
      H-=b[i];
      ans++;
    }
  }
  if(H>0)ans+=(H+ma-1)/ma;
  P(ans);
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    
    string s;
    cin >> s;
    int ans = 700;
    rep(i,0,3)if(s[i] == 'o')ans +=100;
    P(ans);
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define log2(x) (31 - __builtin_clz(x))
#define lcm(x,y) (x*y) / __gcd(x,y)
int inf = (1e9) + 7;
int mod = 998244353;


int will[105][11];
int profit[105][11];
int main(){


	int n;
	sf1(n);

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 10; ++j)
		{
			sf1(will[i][j]);
		}
	}

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 11; ++j)
		{
			sf1(profit[i][j]);
		}
	}

	int mx = -inf;
	for (int i = 1; i < 1024; ++i)
	{

		int sum  = 0;
		for (int j = 0; j < n; ++j){
			int cont = 0;
			
			for (int k = 0; k < 10; ++k)
			{
				if(will[j][k] and ((1 << k) & i))
				{
					cont++;
				}
			}
			sum += profit[j][cont];
			if(j == n-1) mx = max(mx,sum);
		}
	}
	printf("%d\n",mx);
} 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<cmath>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<list>
#include<deque>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<chrono>


/*  auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
pr(duration.count());    */


#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define siz         100009
#define mp          make_pair
#define ll          long long int
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define pi          acos(-1.0)
#define all(x)      x.begin(),x.end()
#define ull		    unsigned long long int
#define m(a)	    memset(a,0,sizeof(a))
#define f(i,n)	    for(ll i=0;i<n;i++)
#define sc(a)	    scanf("%lld",&a)
#define pr(a)	    printf("%lld\n",a)
const ll inf = 1e15;
using namespace std;

int main()
{
	FastIO;
	ll a, co, b, t, i, j, k, n,d[10006];
	cin >> n;
	ll sum = 0;
	f(i, n)
	{
		cin >> a;
		a--;
		sum += a;
	}
	cout << sum << endl;
	return 0;
}

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

int main() {
   int n;
   cin >> n;
   
   vector<int> vec(n);
   
   for (int i=0; i<n; i++) {
       cin >> vec.at(i); 
   }
   
   sort(vec.begin(), vec.end());
   
   int alice = 0;
   int bob = 0;
   
   for (int i=0; i<n; i++) {
       if (i % 2== 0)  alice += vec.at(vec.size()-1);
       else  bob += vec.at(vec.size()-1);
       vec.pop_back();
   }
   
   cout << alice - bob << endl;
   
}

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


def solve(H: int, W: int, M: int, h: "List[int]", w: "List[int]"):
    from collections import defaultdict
    h = [hh - 1 for hh in h]
    w = [ww - 1 for ww in w]
    row_values, col_values = [0] * H, [0] * W
    for hh, ww in zip(h, w):
        row_values[hh] += 1
        col_values[ww] += 1
    max_row_value = max(row_values)
    max_col_value = max(col_values)
    max_rows = set(filter(lambda i: row_values[i] == max_row_value, range(H)))
    max_cols = set(filter(lambda i: col_values[i] == max_col_value, range(W)))
    intersections = defaultdict(set) # intersections[col]
    for hh, ww in zip(h, w):
        if ww not in max_cols:
            continue
        if hh not in max_rows:
            continue
        intersections[ww].add(hh)
    m = min([len(intersections[col]) for col in max_cols])
    return max_row_value + max_col_value - (1 if m == len(max_rows) else 0)

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    h = [int()] * (M)  # type: "List[int]"
    w = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        h[i] = int(next(tokens))
        w[i] = int(next(tokens))
    print(solve(H, W, M, h, w))

def test():
    import doctest
    doctest.testmod()

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


Measured memory_bytes: 225272
from itertools import permutations 

N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(M)]

answer = 0 
for path in permutations(range(2, N+1)):
    path = [1] + list(path)
    found = True 
    for i in range(1, len(path)):
        if not [path[i], path[i-1]] in a and not [path[i-1], path[i]] in a:
            found = False
            break
    if found:
        answer += 1
print(answer)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,w,i,j;
    cin>>n>>w;
    long long int wt[n],v[n];
    for(i=0;i<n;i++)
        cin>>wt[i]>>v[i];
    long long int dp[n][w+1];
    for(i=0;i<n;i++)
        dp[i][0]=0;
    for(j=1;j<=w;j++)
    {
        if(wt[0]<=j)
            dp[0][j]=v[0];
        else
            dp[0][j]=0;
    }
    for(i=1;i<n;i++)
    {
        for(j=1;j<=w;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(wt[i]<=j)
            {
                dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-wt[i]]);
            }
        }
    }
    cout<<dp[n-1][w];
    return 0;
}


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

 using namespace std;
 typedef long long ll;

 int main() {
   int N;

   cin >> N;

   vector<int> A(N);
   for (int i = 0; i < N; i++) cin >> A.at(i);

   vector<ll> A_toi(N);
   vector<ll> A_fromi(N);

   A_toi.at(0) = A.at(0);
   for (int i = 1; i < N; i++) {
     A_toi.at(i) = A_toi.at(i - 1) + A.at(i);
   }

   A_fromi.at(N - 1) = A.at(N - 1);
   for (int i = N - 2; i >= 0; i--) {
     A_fromi.at(i) = A_fromi.at(i + 1) + A.at(i);
   }

   ll min_gap = 2020202020;

   for (int i = 0; i < N - 1; i++) {
     min_gap = min(min_gap, abs(A_toi.at(i) - A_fromi.at(i + 1)));
   }

   cout << min_gap << endl;
 }


Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


int main(){
  int n, r;

  while(cin >> n >> r){
    if(n == 0 && r == 0) return 0;

    else{
    int hana[n];
    REP(i, n) hana[i]=n-i;

    REP(j, r){
      int p, c;
      cin >> p >> c;
      int tmp[c];
      REP(i, c) tmp[i] = hana[p+i-1];
      REP(i, p-1) hana[p-2-i+c] = hana[p-2-i];
      REP(i, c) hana[i] = tmp[i];
    }
    cout << hana[0] << endl;
  }
  }
return 0;
}

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

using namespace std;

int ans = 0;

int mod(int num, int k){
	int re;
	int a;
	a = num / k;
	re = num - k * a;
	return re;
}
void func(int num,int k){
	if(num % k == 0){
		ans++;
	}
	else if(ans < k * 2){
		num = mod(num,k);
		num = num * 10 + 7;
		ans++;
		
		//cout<<num<<endl;
		func(num,k);
	}
}
int main(void){
	int k;
	cin>>k;
	if(k % 2 == 0){
		cout<<"-1"<<endl;
		return 0;
	}
	else if(k == 1 || k == 7){
		cout<<"1"<<endl;
		return 0;
	}
	int pre_num = 7;
	func(pre_num,k);
	
	if(ans < k * 2){
		cout<<ans<<endl;
	}
	else cout<<"-1"<<endl;
	return 0;
}




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

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int64_t> A(N + 1);
    vector<int64_t> B(M + 1);
    A.at(0) = 0;
    B.at(0) = 0;
    for (int i = 1; i <= N; i++) {
        int64_t a;
        cin >> a;
        A.at(i) = A.at(i - 1) + a;
    }
    for (int i = 1; i <= M; i++) {
        int64_t a;
        cin >> a;
        B.at(i) = B.at(i - 1) + a;
    }
    int ans = 0, idx = M;
    for (int i = 0; i <= N && A.at(i) <= K; i++) {
        while (A.at(i) + B.at(idx) > K) {
            idx--;
        }
        ans = max(ans, i + idx);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6336
#include <cstdio>
#include <algorithm>

int a[5];

int main()
{
	scanf("%d%d%d",&a[1],&a[2],&a[3]);
	std::sort(a+1,a+4);
	int tmp=a[1],ans=0;
	for(int i=2; i<=3; i++)
		ans+=(a[i]-tmp),tmp=a[i];
	printf("%d",ans);
	return 0;
}

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

using namespace std;

int main(){
  int x;
  int n;
  cin >> x >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  p.push_back(100000);
  sort(p.begin(), p.end());
  int i=0;
  int min=1000;
  int ans=0;
  for(int a=0;a<=101;a++){
    if( a == p.at(i) ){
      i++;
      continue;
    }
    if( abs(a-x) < min ){
      min = abs(a-x);
      ans = a;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	string s;
	cin >> s;

	int ans = 0;
	for( int i = s.size()-1; i > 0; --i ) {
		if( s[i] != '9' && s[i-1] != '0' ) {
			s[i-1] -= 1;
		}

		ans += 9;
	}

	ans += s[0] - '0';
	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main()
{
    int n,count=0;
    cin>>n;
    int len[n];
    for(int i=0;i<n;i++)
    {
        cin>>len[i];
    }
    sort(len,len+n);
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if((len[i]+len[j])>len[k])
                {
                    count++;
                }
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    
    int num1,num2;
    for(int i = 0; ; i++){
        cin >> num1 >> num2;
        if(num1 == 0 && num2 == 0) break;
        if(num1 >= num2){
            cout << num2 << " " << num1 << endl;
        }
        else{
            cout << num1 << " " << num2 << endl;
        }
    }
    
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
    }

    sort(all(A));
    reverse(all(A));

    ll ans = A[0];    
    repd(i, 2, N) {
        ans += A[i / 2];
    }

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

Measured memory_bytes: 4052
# -*- coding: utf-8 -*-
from collections import defaultdict as dd
N = int(input())
a = [input() for _ in range(N)]
dic=dd(int)
for i,elem in enumerate(a):
    a[i] = tuple(sorted(elem))
    dic[a[i]] += 1
res = sum([val*(val-1)//2 for val in dic.values()])
print(res)

Measured memory_bytes: 25552
#include<stdio.h>
int main()
{
    int i,j=0,k=0,n;
    char a[100]={0},b[100]={0},c[200]={0};
    scanf("%d",&n);
    scanf("%s %s",&a,&b);
    for(i=0;i<2*n;i++){
        if(i%2==0){
            c[i]=a[j];
            j++;
        }else{
            c[i]=b[k];
            k++;
        }
    }
    printf("%s\n",c);
    return 0;
}

Measured memory_bytes: 128
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (a, b) = {
      let v: Vec<usize> = read_vec();
      (v[0], v[1])
    };
    let mut ans = 0;
    let mut count = 1;
    while count < b {
      ans += 1;
      count -= 1;
      count += a;
    }
    println!("{}", ans);
}


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

int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    if ((abs(b - a) <= d && abs(c - b) <= d) || abs(c - a) <= d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

var n, count int

func foundAll(s string) bool {
	found7 := false
	found5 := false
	found3 := false
	for _, r := range s {
		if r == '7' {
			found7 = true
			continue
		}
		if r == '5' {
			found5 = true
			continue
		}
		found3 = true
	}
	return found7 && found5 && found3
}

func search(base string, depth int) {
	if len(base) == depth {
		if !foundAll(base) {
			return
		}
		i, _ := strconv.Atoi(base)
		if i > n {
			return
		}
		count++
		return
	}
	search(base+"3", depth)
	search(base+"5", depth)
	search(base+"7", depth)
}

func main() {
	fmt.Scan(&n)

	for i := 1; i < 10; i++ {
		search("", i)
	}

	fmt.Println(count)
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;
int n;
int a[30];
int nn;
int q[300];
bool dp[30][3000];
bool al[30][3000];

void init1() {
    for (int i = 0; i < 30; i++) {
        for (int j = 0; j < 3000; j++) {
            al[i][j] = false;
        }
    }
}

bool solve(int i, int m) {
    if (al[i][m]) {
        return dp[i][m];
    }
    if (m == 0) {
        al[i][m] = true;
        dp[i][m] = true;
    } else if (i >= n) {
        al[i][m] = true;
        dp[i][m] = false;
    } else if (solve(i + 1, m - a[i])) {
        al[i][m] = true;
        dp[i][m] = true;
    } else if (solve(i+1,m)) {
        al[i][m] = true;
        dp[i][m] = true;
    } else {
        al[i][m] = true;
        dp[i][m] = false;
    }
    return dp[i][m];
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cin >> nn;
    for (int i = 0; i < nn; i++) {
        cin >> q[i];
    }
    for (int i = 0; i < nn; i++) {
        init1();
        bool t = solve(0, q[i]);
        if (t) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3236
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


A, B, K = MI()

ans = set(x for x in range(A, A + K) if A <= x <= B)
ans.update(set(x for x in range(B - K + 1, B + 1) if A <= x <= B))
for x in sorted(list(ans)):
    print(x)


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

int main() {
	int n;
	string s;
	cin >> n >> s;
	string k = s;
	char c = ' ';
	int x = 0;
	string d = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for(int i = 0;i < s.size();i++)
	{
		c = ' ';
		x = 0;
		while(c == ' ')
		{
			if(s.at(i) == d.at(x))
			{
				c = 'a';
			}
			x++;
		}
		k.at(i) = d.at(((x - 1) + n) % 26);
	}
    cout << k << endl;
}


Measured memory_bytes: 256
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

k_candidates = []
for i in range(0, 40):
    x = len(A)
    y = 2 * len([a for a in A if a & (2 ** i) > 0])
    if x <= y:
        pass
    else:
        k_candidates.append(2**i)

k = 0
for i in reversed(k_candidates):
    if K >= k + i:
        k += i


def f(k):
    return sum([k ^ a for a in A])


print(f(k))


Measured memory_bytes: 118544
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

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

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

type UnionFind struct {
	Par []int
}

func NewUnionFind(n int) *UnionFind {
	uf := &UnionFind{
		Par: make([]int, n),
	}
	uf.Init(n)
	return uf
}

func (uf *UnionFind) Init(n int) {
	for i := 0; i < n; i++ {
		uf.Par[i] = -1
	}
}

func (uf *UnionFind) Find(x int) int {
	if uf.Par[x] < 0 {
		return x
	}
	uf.Par[x] = uf.Find(uf.Par[x])
	return uf.Par[x]
}

func (uf *UnionFind) Unite(x, y int) {
	x, y = uf.Find(x), uf.Find(y)
	if x == y {
		return
	}

	if uf.Par[x] > uf.Par[y] {
		x, y = y, x
	}
	uf.Par[x] += uf.Par[y]
	uf.Par[y] = x
}

func (uf *UnionFind) Same(x, y int) bool {
	return uf.Find(x) == uf.Find(y)
}

// xの属する集合の要素数
func (uf *UnionFind) Size(x int) int {
	return -uf.Par[uf.Find(x)]
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m := nextInt(), nextInt()
	uf := NewUnionFind(n)
	for i := 0; i < m; i++ {
		a, b := nextInt()-1, nextInt()-1
		uf.Unite(a, b)
	}

	ans := 0
	for i := 0; i < n; i++ {
		ans = max(ans, uf.Size(i))
	}
	puts(ans)
}


Measured memory_bytes: 5852
program example
	implicit none

	integer :: N, P, i, wa=0
    integer,allocatable :: X(:)
    
    read(*,*) N
    
    allocate(X(N))
    
    read(*,*) X
    
    P=idnint(sum(X(:))/dble(N))
    
    do i=1,N
    	wa=wa+(X(i)-P)**2
	end do
    
    write(*,*) wa

end program example


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define pi pair<int,int>
#define ff first
#define ss second
#define int long long 
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)

const int N=2*1e5+1;
const int inf = 1e18;
int dp[N][3];
bool vis[N][3];

int n;
int a[N];

int solve(int id,int have){
	if(id>n){
		if(have<=1)
			return 0;
		return -inf;
	}
	
	int &tmp = dp[id][have];
	if(vis[id][have])
		return tmp;
	vis[id][have]=1;
	if(!have)
		tmp = solve(id+2,have)+a[id];
	else{
		tmp =solve(id+2,have)+a[id];
		tmp = max(tmp,solve(id+1,have-1));
	}
	return tmp;
}

int32_t main() { 
    boost;
    cin>>n;
    for(int i=1;i<=n;i++)
    	cin>>a[i];
    int ans ;
    if(n%2)
    	ans = solve(1,2);
    else
    	ans = solve(1,1);
    cout<<ans<<endl;
}           





Measured memory_bytes: 15172
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int d = scanner.nextInt();
        int e = scanner.nextInt();
        int x = 0;
        if (a > b) {
            x = a;
            a = b;
            b = x;
        }
        if (b > c) {
            x = b;
            b = c;
            c = x;
        }
        if (c > d) {
            x = c;
            c = d;
            d = x;
        }
        if (d > e) {
            x = d;
            d = e;
            e = x;
        }
        if (a > b) {
            x = a;
            a = b;
            b = x;
        }
        if (b > c) {
            x = b;
            b = c;
            c = x;
        }
        if (c > d) {
            x = c;
            c = d;
            d = x;
        }
        if (a > b) {
            x = a;
            a = b;
            b = x;
        }
        if (b > c) {
            x = b;
            b = c;
            c = x;
        }
        if (a > b) {
            x = a;
            a = b;
            b = x;
        }
        System.out.println(e + " " + d + " " + c + " " + b + " " + a);
    }
}



Measured memory_bytes: 26204
#include <iostream>
#include <algorithm>

using namespace std;

static const int N = 100;

int main()
{
    int n, p[N + 1], m[N + 1][N + 1];
    int i, l, j, k;

    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> p[i - 1] >> p[i];
    }

    for (i = 1; i <= n; i++) m[i][i] = 0;
    for (l = 2; l <= n; l++) {
        for (i = 1; i <= n - l + 1; i++) {
            j = i + l - 1;
            m[i][j] = (1 << 21);
            for (k = i; k <= j - 1; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }

    cout << m[1][n] << endl;

    return 0;
}


Measured memory_bytes: 3132