akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int MOD = 1000000007;

int n, i, j, res, ind, act, last;
VI beg, fin;
bool inv;
char t[200005];

bool get(int ind, bool inv) {
	if (inv) return t[ind] == 'W';
	return t[ind] == 'B';
}

int main() {
scanf("%d", &n);
scanf("%s", t);
if (t[0] == 'W' || t[2 * n - 1] == 'W') {
	printf("0\n");
	return 0;
}
beg.clear();
fin.clear();
beg.pb(0);
last = 0;
for (i=1;i<2*n;i++) {
	if (t[i] != t[i - 1]) {
		if (last == 0) beg.pb(i); else fin.pb(i);
	} else {
		if (last == 0) fin.pb(i); else beg.pb(i);
		last = 1 - last;
	}
}

if (beg.size() != fin.size()) {
	printf("0\n");
	return 0;
}
sort(beg.begin(), beg.end());
sort(fin.begin(), fin.end());
res = 1;
ind = n; 
for (i = n - 1;i >= 0;i--) {
	while (ind - 1 >= 0 && fin[ind - 1] > beg[i]) ind--;
	act = i - ind + 1;
	res = (res * 1LL * act) % MOD;
}
for (i=2;i<=n;i++) res = (res * 1LL * i) % MOD;
printf("%d\n", res);
return 0;
}

Measured memory_bytes: 1912
N = int(input())
S = input()

R_count = S.count("R")
B_count = S.count("B")
G_count = S.count("G")

distance_1To2 = 0
t = 0
for i in range(N-2):
    for j in range(i+1,N):
        if j+(j-i) >= N:
            break
        if S[j] != S[i]:
            if S[j] != S[j+(j-i)] and S[i] != S[j+(j-i)]:
                t += 1

print((R_count*B_count*G_count) - t)

Measured memory_bytes: 9148
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <limits>
#include <iomanip>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) { if(b==0) return a; else return GCD(b, a%b); }
ll LCM(ll a, ll b) { return a/GCD(a,b)*b; }

class CHAndV {
public:
	void solve(std::istream& in, std::ostream& out) {
        int h,w,k;in>>h>>w>>k;
        vector<string> c(h);
        rep(i,h) in>>c.at(i);

        int ans=0;
        int res=0;
        for(int i = 0;i < (1 << h); ++i){
            for(int j = 0;j<(1<<w); ++j){
                res = 0;
                rep(ii, h){
                    rep(jj, w){
                        if(c.at(ii).at(jj)=='#' && ((1 << ii) & i) && ((1 << jj) & j) ) ++res;
                    }
                }
                if(res==k) ++ans;

            }
        }
        out<<ans<<endl;

	}
};


int main() {
	CHAndV solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vectors<decltype(inner)>(x, inner); }
template<class T> void show_with_brank(T a){ int cnt = 0; for(auto itr :a){ if(cnt++ != 0) cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
signed main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    if((abs(a-b) <=d &&abs(b-c)<=d) || abs(a-c)<=d)
        return puts("Yes")*0;
    else
        return puts("No")*0;
}





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

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

    int x,y;
    while(cin >> x >> y){
        if(x == 0 && y == 0)
            return 0;

        if(x < y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    }
}

Measured memory_bytes: 3004
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>
#include <cassert>

using lli = long long int;
int inf = 1000000007;
using namespace std;

vector<lli> in_vec(int n) {
	vector<lli> vec(n);
	for (int i = 0; i < n; i++)cin >> vec[i];
	return vec;
}

void solve()
{
	int N, L;
	cin >> N >> L;
	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	sort(S.begin(), S.end());
	for (int i = 0; i < N; i++) { cout << S[i]; }
	cout << endl;
}

int main()
{
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}

int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	if (a == 1) {
		ans += 300000;
	}
	else if (a == 2) {
		ans += 200000;
	}
	else if (a == 3) {
		ans += 100000;
	}

	if (b == 1) {
		ans += 300000;
	}
	else if (b == 2) {
		ans += 200000;
	}
	else if (b == 3) {
		ans += 100000;
	}

	if (a*b == 1) {
		ans += 400000;
	}

	cout << ans << endl;
}



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

#define MN 1001000

using namespace std;
typedef long long ll;

#define MOD 1000000007

ll n, ans, a[MN], f[26];
char s[MN]; string str;

ll solve(int c, ll ways) {
    if(c == 26) return ways;
    return (solve(c + 1, ways) + solve(c + 1, ways * f[c] % MOD)) % MOD;
}

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

    for(int i = 0; i < n; i++) {
        f[s[i]-'a']++;
    }

    printf("%lld\n", (solve(0, 1) - 1 + MOD) % MOD);
    return 0;
}


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

using namespace std;

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

int main()
{
    int no_of_numbers, desired_number;
    scanf("%d %d", &no_of_numbers, &desired_number);

    int array_gcd, largest_number = 0;
    for(int i = 1; i <= no_of_numbers; i++)
    {
        int number_i;
        scanf("%d", &number_i);

        array_gcd = (i == 1 ? number_i : gcd(array_gcd, number_i));
        largest_number = max(number_i, largest_number);
    }

    printf(desired_number%array_gcd == 0 && desired_number <= largest_number ? "POSSIBLE\n" : "IMPOSSIBLE\n");
    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d){
    cout << "Left" << endl;
  }
  if (a + b < c + d){
    cout << "Right" << endl;
  }
  if (a + b == c + d){
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
import collections
s = set(list(input()))
ans = 'Yes'
if 'N' in s and not 'S' in s or 'S' in s and not 'N' in s:
    ans = 'No'
elif 'W' in s and not 'E' in s or 'E' in s and not 'W' in s:
    ans = 'No'
print(ans)

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] arr = sc.nextLine().split(" ");
		int a =Integer.parseInt(arr[0]);
		int b = Integer.parseInt(arr[1]);
		sc.close();

		int x = a+b;
		int y = a-b;
		int z = a*b;
		if (x>=y && x>=z)
			System.out.println(x);
		else if (y>=x && y>=z)
			System.out.println(y);
		else
			System.out.println(z);
	}
}


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

int N, K;
vii bingos = {{0, 3, 6},{1, 4, 7},{2, 5, 8},{0, 1, 2},{3, 4, 5},{6, 7, 8},{0, 4, 8},{2,4,6}};
int A[9];
vector<bool> A_hit(9, false);

int main(){
    int a;
    for(int i=0; i < 9; ++i){
        cin >> a;
        A[i] = a;
    }
    int N;
    cin >> N;
    int b;
    for(int i=0; i < N; ++i){
        cin >> b;
        for (int j = 0; j < 9; j++)
        {
            if(b == A[j]) A_hit[j] = true;
        }
    }
    for(int i=0; i < 8; ++i){
        vi bingo = bingos[i];
        if(A_hit[bingo[0]] && A_hit[bingo[1]] && A_hit[bingo[2]]){
            cout << "Yes"; return 0;
        }
    }
    cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define iii pair<int,pair<int,int> >
#define mp make_pair
#define x first
#define y second
bool vis[100003][3];
int n,m,s,t;
vector<int>v[100003];
void dfs(int x,int z,int times){
	vis[x][z]=1;
	cout<<x<<' '<<z<<' '<<times<<endl;
	if(x==t&&z==0){
		cout<<times;
		exit(0);
	}
	for(int i=0;i<v[x].size();i++)
		if(!vis[v[x][i]][(z+1)%3])
			dfs(v[x][i],(z+1)%3,times+(z+1)/3);
}
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		v[--a].push_back(--b);
	}
	cin>>s>>t;t--;
	--s;
	queue<iii>q;
	q.push(mp(0,mp(s,0)));
	while(q.size()){
		iii now=q.front();q.pop();
		if(now.y.x==t&&now.y.y==0){
			cout<<now.x;
			return 0;
		}
		for(int i=0;i<v[now.y.x].size();i++)
			if(!vis[v[now.y.x][i]][(now.y.y+1)%3]){
				vis[v[now.y.x][i]][(now.y.y+1)%3]=1;
				q.push(mp(now.x+(now.y.y+1)/3,mp(v[now.y.x][i],(now.y.y+1)%3)));
			}
	}
	cout<<-1;
}

Measured memory_bytes: 6016
# coding: utf-8
# Your code here!

s=input()
t=input()
b=[]

if len(s)-len(t)<0:
    flg=False
else:
    for i in range(len(s)-len(t)+1):
        ans=s
        for j in range(len(t)):
            flg=True
            if s[i+j]=='?' or s[i+j]==t[j]:
                #print(ans)
                ans=ans[:i+j]+t[j]+('' if i+j+1>len(s) else ans[i+j+1:])
            else:
                flg=False
                break
        if flg==True:
            b.append(ans.replace('?','a'))
#print(b)
b.sort()

print(b[0] if len(b)>0 else 'UNRESTORABLE')


Measured memory_bytes: 38384
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

void sputs(){}
template <class Head, class... Tail>
void sputs(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(Tail) == 0) { cout << endl; }
  else { cout << " "; }
  sputs(std::move(tail)...);
}

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n;cin>>n;
  vvi g(n);
  rep(i, n-1){
    int a,b;cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }

  int x = 0;
  int max_d = 0;
  auto dfs = [&](const auto& dfs, auto& d, int u, int cost) -> void {
    each(v, g[u]){
      if (d[v]<INF) continue;
      d[v] = cost+1;
      if (d[v]>max_d){
        chmax(max_d, d[v]);
        x = v;
      }
      dfs(dfs, d, v, cost+1);
    }
  };

  vi d0(n, INF); d0[0] = 0;
  dfs(dfs, d0, 0, 0);

  vi dx(n, INF); dx[x] = 0;
  max_d = 0;
  dfs(dfs, dx, x, 0);
  dump(max_d);

  vi dp(n+1);

  dp[0] = 1;
  dp[1] = 0;
  rep(i, 2, n+1){
    if (dp[i-1]==0 || dp[i-2]==0) dp[i] = 1;
  }
  cout << (dp[max_d]?"First":"Second") << endl;

  return 0;
}


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

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    
    ll k = min(b-1, n);
    cout << (a * k) / b - a * (k / b)  << endl;
    return 0;
}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll a,b,c;
    cin >> a >> b >> c;
    if(a<b){
        if(a<c && c<b) cout << "Yes" << "\n";
        else cout << "No" << "\n";
    }else{
        if(b<c && c<a) cout << "Yes" << "\n";
        else cout << "No" << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#define INF 1e8
#define MAX_N 110
using namespace std;
int t[MAX_N];
int start[MAX_N];
int dp[MAX_N][MAX_N];
int max_day, T, N;
int solve(int i, int j)
{
    if(i == max_day + 1) return 0;
    if(dp[i][j] != -1) return dp[i][j];
    int ret = INF;
    for(int k = 0; k < T; k++)
    {
        if(t[j] <= start[i])
        {
			ret = min(ret, solve(i + 1, (j + 1) % T));
		}
		ret = min(ret, solve(i + 1, 1) + 1);
	}
	return dp[i][j] = ret;
}
int main()
{
	while(cin >> T, T)
	{
		for(int i = 0; i < T; i++) cin >> t[i];
		memset(dp, -1, sizeof(dp));
		cin >> N;
		int d, m;
		for(int i = 0; i < MAX_N; i++) start[i] = INF;
		for(int i = 0; i < N; i++)
		{
			cin >> d >> m;
			d--;
			start[d] = min(start[d], m);
			max_day = max(d, max_day);
		}
		int ans = solve(0, 0);
		cout << ans << endl;
	}
	return 0;
}


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

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	int n, m;
	cin >> n >> m;
	vector<vector<int>> a(n, vector<int>(m, 0));
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			char x;
			cin >> x;
			a[i][j] = x == '#';
		}
	}

	vector<vector<int>> best(n, vector<int>(m, 1e9));
	queue<pair<int, int>> q;
	q.push({0, 0});
	best[0][0] = a[0][0];
	while(!q.empty()){
		int x, y;
		tie(x, y) = q.front();
		q.pop();

		if(x + 1 < n && best[x][y] + (a[x][y] ^ a[x + 1][y] && a[x + 1][y]) < best[x + 1][y]){ // down
			best[x + 1][y] = best[x][y] + (a[x][y] ^ a[x + 1][y] && a[x + 1][y]);
			q.push({x + 1, y});
		}
		if(y + 1 < m && best[x][y] + (a[x][y] ^ a[x][y + 1] && a[x][y + 1]) < best[x][y + 1]){ // right
			best[x][y + 1] = best[x][y] + (a[x][y] ^ a[x][y + 1] && a[x][y + 1]);
			q.push({x, y + 1});
		}
	}

	cout << best[n - 1][m - 1] << endl;
	
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N, L;
  cin >> N >> L;

  vi A(N);
  for (int i=0; i<N; i++) {
    A[i] = L+i+1-1; // 単調増加
  }

  if (A[N-1] <= 0) {
    A[N-1] = 0;
  } else if (A[0] <= 0) {
    // delete 0
  } else {
    A[0] = 0;
  }

  cout << accumulate(begin(A), end(A), 0) << endl;

  return 0;
}


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

int main() {
  vector<int> vec(3);
  cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
  
  if (vec.at(0) == vec.at(1) && vec.at(1) != vec.at(2)) {
    cout << "Yes" << endl;
  }
   else if (vec.at(0) == vec.at(2) && vec.at(1) != vec.at(2)) {
    cout << "Yes" << endl;
  }
   else if (vec.at(2) == vec.at(1) && vec.at(0) != vec.at(2)) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  
}

 





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

using ll = long long;

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

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

	if(a % 3 == 0 || b % 3 == 0 || (a+b)%3 == 0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;


	return 0;
}

Measured memory_bytes: 256
import math
def sosuu(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i = 3
    while i <= math.sqrt(x):
        if x % i ==0:
            return False
        i = i + 2
    return True
    
c = 0
while True:
    try:
        x = int(input())
    except:
        break
    if sosuu(x) == True:
        c += 1
print(c)


Measured memory_bytes: 5672
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}

long long  best(int w, int h)
{
	long long best_diff = (long long)w * h;
	for (long long j = 1; j < w; j++)
	{
		vector<long long> pcs;
		pcs.push_back(j * h);

		long long rem_w = (w - j);
		long long rem_h = h;
		long long sq2 = 0;
		if (rem_w % 2 == 0 || rem_h % 2 == 0)
		{
			pcs.push_back((rem_w * rem_h) / 2LL);
		}
		else
		{
			if (rem_w < rem_h)
				swap(rem_w, rem_h);
			 sq2 = rem_w / 2;
			sq2 *= rem_h;
			pcs.push_back(sq2);
			pcs.push_back((rem_w * rem_h) - sq2);
		}
		sort(pcs.begin(), pcs.end());
		best_diff = min(best_diff, abs(pcs.back() - pcs[0]));

	}
	return best_diff;
}

int main() {

#if defined(_DEBUG) 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int w, h;
	cin >> w >> h;
	cout << min(best(w, h), best(h, w));

	return 0;
}


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

int findMin(int arr[], int n) 
{ 
    int sum=0;
    for(int i=0;i<n;i++) sum = sum+arr[i];
   
    int diff = INT_MAX;
    int t=0;
    for(int i=0;i<n;i++){
        t = t+arr[i];
        diff = min(abs(t-(sum-t)),diff);
    }
    
    return diff; 
} 
  

int main() 
{ 
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    cout<<findMin(arr,n);
    return 0; 
} 

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)


typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
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;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
//////////////////////////


ll SOLVE(){
    ll n,m,r;cin>>n>>m>>r;
    ll a[r];rep(i,0,r-1){cin>>a[i];a[i]--;}
    vector<l_l>v[n];
    rep(iz,1,m){
        ll x,y,z;cin>>x>>y>>z;x--;y--;
        v[x].pb({y,z});
        v[y].pb({x,z});
    }
    
    ll d[n][n];
    rep(i,0,n-1)rep(j,0,n-1)d[i][j]=(i==j?0:inf);
    rep(i,0,n-1){
        for(auto x:v[i]){
            ll j=x.fi;
            d[i][j]=d[j][i]=x.se;
        }
    }
    for (int k = 0; k < n; k++){       // 経由する頂点
      for (int i = 0; i < n; i++) {    // 始点
        for (int j = 0; j < n; j++) {  // 終点
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }
    /*
    rep(i,0,n-1){
        rep(j,0,n-1)cout<<d[i][j]<<" ";cout<<endl;
    }*/
    
    ll dp[1<<r][r];rep(i,0,(1<<r)-1)rep(j,0,r-1)dp[i][j]=inf;
    rep(i,0,r-1){
        dp[1<<i][i]=0;
    }
    rep(i,1,(1<<r)-1){
        rep(j,0,r-1){
            if(((i>>j)&1)==0)continue;
            rep(k,0,r-1){
                if((i>>k)&1)continue;
                chmin(dp[i+(1<<k)][k],dp[i][j]+d[a[j]][a[k]]);
            }
        }
    }
    ll ans=inf;
    rep(j,0,r-1)chmin(ans,dp[(1<<r)-1][j]);
    cout<<ans<<endl;
    
    
    return 0;
}

int main(){fastio
    
    clock_t start = clock();
    SOLVE();
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    cerr<<endl<<time<<"ms"<<endl;
    
    return 0;
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef bitset<61> Bitset;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const int INF = INT_MAX;
const int MAX = 300000;
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); }
//------------------------------------------------------------------------------------------------------------------------------
int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;cin>>N>>M;
    vector<int>H(N);
    vector<vector<int>>G(N);
    map<int,bool>mp[N];
    for(int i = 0; i < N; i++) cin>>H[i];
    for(int i = 0; i < M; i++) {
        int a,b;cin>>a>>b;a--;b--;
        if(mp[a][b]) continue;
        mp[a][b] = 1;
        G[a].push_back(b);G[b].push_back(a);
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        bool f = 1;
        for(auto nv : G[i]){
            if(H[i]<=H[nv]){
                f = 0;
            }
        }
        if(f) ans++;
    }   
    cout << ans << endl;
}


Measured memory_bytes: 18244
#include <iostream>
#include <cmath>
 
using namespace std;
 
int main (void) {
  double x1, y1, x2, y2, x3, y3, x4, y4;
  int n;
    
  cin >> n;
   
  for(int i = 0; i < n; i++) {
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
    double t1 = (y1-y2)/(x1-x2);
    double t2 = (y3-y4)/(x3-x4);
    //cout << t1 << " " << t2 << endl;
    if ( t1 == t2 ) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
   
  return 0;
}

Measured memory_bytes: 1224
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>

using std::cout;
using std::endl;
using std::cin;

int main() {
	double a, b, C;			// ??\???
	double S, L, h, x, c;	// ??????

	// ??\???
	cin >> a >> b >> C;

	C = (C*M_PI) /180;
	h = b*sin(C);

	S = a * h / 2;

	x = b * cos(C);
	c = sqrt(pow(h, 2.0) + pow((a-x), 2.0));
	L = a + b + c;

	// ??????
	cout << std::fixed << std::setprecision(10) << S << endl;
	cout << std::fixed << std::setprecision(10) << L << endl;
	cout << std::fixed << std::setprecision(10) << h << endl;

	return 0;
}

Measured memory_bytes: 3508
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  int n,x;
  cin>>n>>x;
  vi m(n);
  rep(i,n)cin>>m[i];
  int MIN=INF;
  rep(i,n){
    x-=m[i];
    MIN=min(MIN,m[i]);
  }
  cout<<n+x/MIN<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int a[] = new int[n];
    int b[] = new int[n];
    Data []d = new Data[n];
    
    for (int i=0; i<n; i++){
      a[i] = Integer.parseInt(sc.next());
      b[i] = Integer.parseInt(sc.next());
    }
    
    for(int i= 0; i < n; i++) {
      d[i] = new Data(b[i], a[i]);
    }
    
    Arrays.sort(d, new Comparator<Data>() {
      public int compare(Data d1, Data d2) {
        return d1.getA() - d2.getA();
      }
    });
 
    int t=0;
    for(int i=0; i<n; i++){
      t += d[i].getB();
      if(t > d[i].getA()){
        System.out.println("No");
        return;
      }
    }
    
    System.out.println("Yes");
    
  }
  
  public static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    } else {
      return gcd(b,a%b);
    }
  }
}

class Data{
    private int a;
    private int b;
    public Data(int a, int b) {
        this.a = a;
        this.b = b;
    }
    public int getA() {
        return a;
    }
    public int getB() {
        return b;
    }
}

Measured memory_bytes: 71504
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int n;
    cin>>n;
    deque<int> q;
    rep(i, n) {
        int p, d, x;
        cin>>p;
        switch (p)
        {
        case 0:
            cin>>d>>x;
            if (d) q.push_back(x);
            else q.push_front(x);
            break;
        case 1:
            cin>>d;
            cout<<q[d]<<endl;
            break;
        default:
            cin>>d;
            if (d) q.pop_back();
            else q.pop_front();
            break;
        }
    }
}


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

int main(){
    int N,X = 0,Y = 0;
    cin >> N;

    vector<int> V(N);
    vector<int> C(N);
    
     for (int i = 0; i < N; i++) {
    cin >> V.at(i);
  }
     for (int i = 0; i < N; i++) {
    cin >> C.at(i);
  }

for (int i = 0; i < N; i++) {
    if( V.at(i) > C.at(i) ){
        X = X + V.at(i);
        Y = Y + C.at(i);
    }
  }
    cout << X - Y << endl;

}

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

int main(){
  int64_t N,a=0;
  cin >> N;
  vector<int64_t> b(N-1);
  for(int i=0; i<N-1; i++){
    cin >> b[i];
  }
  for(int i=0; i<N-2; i++){
    if(b[i]>b[i+1])
      a += b[i+1];
    else
      a += b[i];
  }
  cout << a+b[0]+b[N-2] << endl;
}

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

using namespace std;

int main(){
    int N, M;
    while(cin >> N >> M){
        vector<vector<int>> A(N, vector<int>(M));
        for(auto& v : A){
            for(auto& t : v){
                cin >> t;
                --t;
            }
        }
        vector<int> ok(M, 1);
        int best = N;
        for(int i=0;i<M;i++){
            vector<int> cnt(M, 0);
            for(auto& v : A){
                for(int j=0;j<M;j++){
                    if(!ok[v[j]]) continue;
                    cnt[v[j]]++;
                    break;
                }
            }
            int mIdx = 0;
            for(int j=0;j<M;j++){
                if(cnt[j] > cnt[mIdx]) mIdx = j;
            }
            best = min(best, cnt[mIdx]);
            ok[mIdx] = 0;
        }
        cout << best << endl;
    }
}

Measured memory_bytes: 640
L=input()
MOD=10**9+7
pre=[]
temp=0
for i in range(len(L)):
    if L[i]=='1':
        temp+=1
    pre+=[temp]
ans=pow(3,len(L)-1,MOD)
for i in range(1,len(L)):
    if L[i]=='1':
        
        ans+=(pow(2,pre[i]-1,MOD)*pow(3,len(L)-1-i,MOD))%MOD
        ans%=MOD
print((ans+pow(2,pre[-1],MOD))%MOD)



Measured memory_bytes: 7156
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        String s = sc.next();
        if (s.equals("zyxwvutsrqponmlkjihgfedcba")) {
            System.out.println(-1);
        } else {
            String ans = "";
            if (s.length() == 26) {
                char min = 'z';
                for (int i = 25; i >= 1; i--) {
                    if (s.charAt(i) > s.charAt(i-1)) {
                        for (int j = i; j < 26; j++) {
                            if (s.charAt(j) < min && s.charAt(j) > s.charAt(i-1)) {
                                min = s.charAt(j);
                            }
                        }
                        for (int k = 0; k < i-1; k++) {
                            ans += s.charAt(k);
                        }
                        break;
                    }
                }
                System.out.println(ans+min);
            } else {
                char[] alpha = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
                'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
                int[] used = new int[s.length()];
                for (int i = 0; i < s.length(); i++) {
                    for (int j = 0; j < 26; j++) {
                        if (s.charAt(i) == alpha[j]) {
                            used[i] = j;
                        }
                    }
                }
                int minint = 0;
                char min = 'z';
                for (int i = 0; i < 26; i++) {
                    boolean flag = true;
                    for (int j = 0; j < used.length; j++) {
                        if (i == used[j]) {
                            flag = false;
                        }
                    }
                    if (flag) {
                        if (alpha[i] < min) {
                            min = alpha[i];
                            minint = i;
                        }
                    }
                }
                System.out.println(s + alpha[minint]);
            }
        }
    }

}


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

const int MAX = 8;
int field[MAX][MAX][MAX];

int dx[] = {0,1,0,-1,1,1,-1,-1};
int dy[] = {1,0,-1,0,1,-1,-1,1};
int X[] = {0,1,0,-1,1,1,-1,-1,  0,1,0,-1,1,1,-1,-1,0};
int Y[] = {1,0,-1,0,1,-1,-1,1,  1,0,-1,0,1,-1,-1,1,0};
int Z[] = {1,1,1,1,1,1,1,1,     -1,-1,-1,-1,-1,-1,-1,-1,1};

int n,m,p;
int flag,ball;

void solve(){
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      for(int k=0; k<n; k++){
	//x and y
	for(int d=0; d<8; d++){
	  int nx = i + dx[d], ny = j + dy[d], nz = k;
	  if(nx >= 0 && ny >= 0 && nz >= 0 &&
	     n > nx && n > ny && n > nz){
	    if(field[i][j][k] != field[nx][ny][nz] ||
	       field[i][j][k] == 0)continue;
	    int color = field[i][j][k];
	    int cnt = 2;

	    while(field[nx][ny][nz]){
	      if(cnt == m){
		flag = ball;
		goto end;
	      }
	      nx += dx[d], ny += dy[d];

	      if(nx >= 0 && ny >= 0 && nz >= 0 &&
		 n > nx && n > ny && n > nz){
		if(color == field[nx][ny][nz])cnt++;
		else break;
	      } 
	      else break;
	    }

	  }
	}

	//z
	for(int d=0; d<17; d++){
	  int nx = i + X[d], ny = j + Y[d], nz = k + Z[d];
	  if(nx >= 0 && ny >= 0 && nz >= 0 &&
	     n > nx && n > ny && n > nz){
	    if(field[i][j][k] != field[nx][ny][nz] ||
	       field[i][j][k] == 0)continue;
	    int color = field[i][j][k];
	    int cnt = 2;

	    while(field[nx][ny][nz]){
	      if(cnt == m){
		flag = ball;
		goto end;
	      }
	      nx += X[d], ny += Y[d], nz += Z[d];

	      if(nx >= 0 && ny >= 0 && nz >= 0 &&
		 n > nx && n > ny && n > nz){
		if(color == field[nx][ny][nz])cnt++;
		else break;
	      } 
	      else break;
	    }

	  }
	}



      }
    }
  }
 end:;
}

int main(){
  while(cin >> n >> m >> p,n|m|p){
    flag = 0;
    ball = 1;
    vector<pair<int,int> >v;
    memset(field,0,sizeof(field));
    int turn = 1;

    for(int i=0; i<p; i++){
      int x,y;
      cin >> x >> y;
      v.push_back(make_pair(x,y));
    }



    for(int i=0; i<v.size() && turn <= p; i++,turn++){
      int x,y,z;
      x = v[i].first, y = v[i].second;
      x--,y--;
      z = 0;

      while(field[x][y][z]){
	z++;
      }

      if(z >= n) continue;

      field[x][y][z] = ball;

      solve();
      if(flag)break;
      ball++;
      if(ball == 3) ball = 1;
    }
  
    if(!flag) cout << "Draw" << endl;
    else if(flag == 1) cout << "Black " << turn << endl;
    else cout << "White " << turn << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
//JSD
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#define ll long long 
using namespace std;
int main(){
	int n,a;
	cin>>n>>a;
	if(n<a) cout<<"0\n";
	else cout<<"10\n";
	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n, w;
    cin >> n >> w;
    vector<LL> wei[4];
    LL weight, value;
    cin >> weight >> value;
    wei[0].pb(value);

    for(int i = 1; i < n; ++i) {
        int we;
        cin >> we >> value;
        wei[we - weight].pb(value);

    }

    for(int i = 0; i < 4; ++i) {
        wei[i].pb(INF);
        sort(all(wei[i]), greater<LL>());
        wei[i][0] = 0;
        for(int j = 1; j < wei[i].size(); ++j) {
            wei[i][j] += wei[i][j - 1];

        }
    }

    LL res = 0;
    for(int i = 0; i < wei[0].size(); ++i) {
        for(int j = 0; j < wei[1].size(); ++j) {
            for(int k = 0; k < wei[2].size(); ++k) {
                for(int l = 0; l < wei[3].size(); ++l) {
                    if(i * weight + j * (weight + 1) + k * (weight + 2) + l * (weight + 3) > w) {
                        continue;

                    }
                    res = max(res, wei[0][i] + wei[1][j] + wei[2][k] + wei[3][l]);
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    using R = double;

    int n; cin >> n;
    R rsum = 0.0;
    vi a(n); for(auto& e : a) cin >> e, rsum += (1.0 / e);

    R res = 1 / rsum;
    cout.precision(20);
    cout << fixed << res << endl;

    return 0;
}


Measured memory_bytes: 256
n = input().split()

n.sort()
n1 = int(n[0])
n2 = int(n[1])
n3 = int(n[2])

if n1 == n2 and n1 == n3:
    print(str(0))
else:
    ans = abs(n1-n2) + abs(n2-n3)
    print(str(ans))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll           long long int
#define pb           push_back
#define F            first
#define S            second
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    ll p[n+1]={0};
    for(int i=1;i<=n;++i)
        cin>>a[i];
    int cur=1;
    for(int i=1;k>0;++i)
    {
        cur=a[cur];
        --k;
        if(p[cur])
        {
            ll j=i-p[cur];
            k%=j;
            break;
        }
        else
            p[cur]=i;
    }
    while(k>0)
    {
        cur=a[cur];
        --k;
    }
    cout<<cur;
	return 0;
}

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

typedef long long                   ll;
typedef long double                 ld;
typedef pair<ll,ll>                 pll;
typedef pair<ld,ld>                 pld;


#define all(x)          (x).begin(),(x).end()
#define Sort(x)         sort(all(x))
#define sep             ' '

#define endl            '\n'
#define tab             '\t'
#define X               first
#define Y               second
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define set_random      mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll MOD = 1e9 + 7,
         MAXN= 1e6+10,
         INF=1e18;
ll dp[MAXN][3],a[MAXN][3],n;
int main()
{
    fast_io;
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    for(ll i=0;i<n;i++){
        for(ll j=0;j<3;j++){
            for(ll k=0;k<3;k++){
                if(k!=j){
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
                }
            }
        }
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
    return 0;
}


Measured memory_bytes: 8448
import sys
import os
import math


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B = list(map(int, sys.stdin.readline().split()))
    print(math.ceil((B - A) / (A - 1)) + 1)


if __name__ == '__main__':
    main()


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

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

using namespace std;

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

    int N;
    cin >> N;
    while (N >= 100 && N % 10 == 0) N /= 10;
    int ans = 0;
    if (N < 100 && N % 10 == 0) {
        ans += N;
    } else {
        while (N > 100) {
            ans += N % 10;
            N /= 10;
        }
        ans += N / 10 + N % 10;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
a = list(input())
while len(a) != 0:
    if "".join(a[-5:]) == "dream" or "".join(a[-5:]) == "erase":
        del a[-5:]
    elif "".join(a[-6:]) == "eraser":
        del a[-6:]
    elif "".join(a[-7:]) == "dreamer":
        del a[-7:]
    else:
        print("NO")
        break
if len(a) == 0:
    print("YES")

Measured memory_bytes: 3956
local read = io.read
local max = math.max
local min = math.min
local insert = table.insert

local n = read("n")

local a_max = 0
local a_t = {}
for i = 1, n do
	local a_i = read("n")
	a_t[i] = a_i
	a_max = max(a_i, a_max)
end


local function gcd(x, y)
	if y == 0 then
		return x
	else
		return gcd(y, x % y)
	end
end

local is_setwise_coprime = false
local pre_gcd_num = a_t[1]
for i = 2, n do
	pre_gcd_num = gcd(max(pre_gcd_num, a_t[i]), min(pre_gcd_num, a_t[i]))
	if pre_gcd_num == 1 then
		is_setwise_coprime = true
	end
end


local dust_t = {}
for i = 2, a_max do
	if dust_t[i] == nil then
		local j = 2 * i
		while j <= a_max do
			if dust_t[j] == nil then
				dust_t[j] = i
			end
			j = j + i
		end
	end
end

local is_pairwise_coprime = true
local prime_factor_t = {}
for i = 1, n do
	local divided = a_t[i]
	local a_i_prime_t = {}
	while true do
		if prime_factor_t[divided] and divided ~= 1 then
			is_pairwise_coprime = false
			break
		elseif dust_t[divided] then
			insert(a_i_prime_t, divided)
			insert(a_i_prime_t, dust_t[divided])
			divided = divided // dust_t[divided]
		else
			insert(a_i_prime_t, divided)
			break
		end
	end
	for j = 1, #a_i_prime_t do
		prime_factor_t[a_i_prime_t[j]] = true
	end
	if not is_pairwise_coprime then
		break
	end
end

print(is_pairwise_coprime and "pairwise coprime" or (is_setwise_coprime and "setwise coprime" or "not coprime"))


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

int main(){
	int i,j,k;
  	vector<int> dp;
  	for(i=1,j=0;i<=999;i++){
      j+=i;
      dp.push_back(j);
    }
  cin>>j>>k;
  //k=k-j;
  for(i=0;i<dp.size()-1;i++){
    if(dp[i]>j&&dp[i]-j==dp[i+1]-k){
        //cout<<dp[i]<<" ";
      cout<<dp[i]-j<<endl;break;
    }
  }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc=new Scanner(System.in);
		boolean a[] =new boolean[10001];
		Arrays.fill(a, true);
		a[0]=a[1]=false;
		for(int i=2; i*i<=10000; i++)
		{
			for(int j=i*2; j<=10000; j+=i)
				a[j]=false;
		}
		while(sc.hasNext())
		{
			int n=sc.nextInt();
			if(n==0)
				return;
			int sum=0;
			int ans=0;
			for(int i=2; i<=n; i++)
			{
				sum =0;
				if(a[i])
					for(int j=i; j<=n; j++)
					{
						if(a[j])
						{
							sum+=j;
							if(n==sum)
								ans++;
						}
						if(sum>=n)
							break;
					}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
import math
a, b = map(int, input().split())
a1 = a+1
b1 = b+1
A = a/0.08
A1=a1/0.08
B = b/0.1
B1 = b1/0.1

ans1 = set(i for i in range(math.ceil(A), math.floor(A1)))
ans2 = set(j for j in range(math.ceil(B), math.floor(B1)))

if ans1 & ans2 == set():
    print(-1)
else:
    ans = ans1&ans2
    print(min(list(ans)))

Measured memory_bytes: 3188