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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

int main(int argc, char const* argv[])
{
    string s;
    cin >> s;

    bool truth=true;
    for (char i = 'a'; i <= 'z'; i++) {
        // cout << i << endl;
        if (s.find(i) != string::npos) {
            continue;
        }else{
            truth=false;
            cout << i << endl;
            break;
        }

    }
    if (truth) {
        cout << "None" << endl;
    }

    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int n;
long long int a[100010];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  long long int dis = 0, cmp;
  for (int i = 1; i <= n + 1; i++) {
    dis += abs(a[i] - a[i - 1]);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i - 1] <= a[i] && a[i] <= a[i + 1])
      cmp = 0;
    else if (a[i - 1] >= a[i] && a[i] >= a[i + 1])
      cmp = 0;
    else {
      cmp = 2 * min(abs(a[i - 1] - a[i]), abs(a[i] - a[i + 1]));
    }
    cout << dis - cmp << endl;
  }
  return 0;
}

Measured memory_bytes: 2048
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		LL n = -1;
		cin >> n;
		if (n < 0) return 0;
		set<LL> s;
		for (LL x = 1; x * x <= n; ++x) {
			if ((n % x) == 0) {
				if (x > 1) {
					LL y = n;
					while ((y % x) == 0) {
						y /= x;
					}
					if (y % x == 1) {
						s.insert(x);
					}
				}
				LL d = n / x;
				LL y = n;
				while ((y % d) == 0) {
					y /= d;
				}
				if (y % d == 1) {
					s.insert(d);
				}
			}
		}
		--n;
		for (LL x = 1; x * x <= n; ++x) {
			if ((n % x) == 0) {
				if (x > 1) {
					s.insert(x);
				}
				s.insert(n / x);
			}
		}
		s.erase(1);
		LL ans = s.size();
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;

#define REPP(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)
#define PER(i,a) for(int i = (a) - 1; i >= 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair

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

int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}


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

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define b_e(a) a.begin(),a.end() //sort(b_e(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll)(n) ; i++ )
#define DREP(i,m,n) for(ll i=(ll)(m) ; i > (ll)(n) ; i-- )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define p_b push_back
#define SZ(x) ((ll)(x).size()) //size()がunsignedなのでエラー避けに
#define endk '\n'


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //


// --------- library end - //



int main(){
  ll N = il();

  ll ans = 1;

  // 10
  rep(i, N){
    ans *= 10;
    if (ans >= INF) ans %= INF;
  }

  ll minu = 1;
  rep(i, N){
    minu *= 9;
    if (minu >= INF) minu %= INF;
  }

  ll plu = 1;
  rep(i, N){
    plu *= 8;
    if (plu >= INF) plu %= INF;
  }

  ans += plu;
  if (ans >= INF) ans -= INF;

  ans = ans - minu;
  if ( ans < 0 ) ans += INF;
  ans = ans - minu;
  if ( ans < 0 ) ans += INF;

  cout << ans << endk;




}



Measured memory_bytes: 3692
#include <cstdio>
#include <iostream>
using namespace std;
int N, M, Count = 1;

int main()
{
    scanf("%d %d", &N, &M);
    for(int i = 0; i < M; i++)
    {
        Count *= 2;
    }
    printf("%d", Count * 1900 * M + Count * 100 * (N - M));
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  string s;
  cin >> s;

  if (sz(s) <= n) {
    cout << s << '\n';
  } else {
    cout << s.substr(0,n) << "...\n";
  }
}

Measured memory_bytes: 3656
#include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std;

int n,tot,p[1030];
bool b[10010];

int main(){
	scanf("%d",&n); p[0]=p[(n<<1)+1]=1;
	for (int i=2; tot<(n<<1)+1; i++){
		if (!b[i]) p[++tot]=i;
		for (int j=1; j<=tot && i*p[j]<=10000; j++){
			b[i*p[j]]=1;
			if (!(i%p[j])) break;
		}
	}
	rep(x,0,n-1){
		rep(y,0,n-1){
			int s=(x+y)>>1,d=(x-y)>>1;
			if ((x^y)&1) printf("%d ",p[s+1]*p[d+n+(n>>1)+1]);
				else printf("%lld ",1ll*p[s+1]*p[s]*p[d+n+(n>>1)+1]*p[d+n+(n>>1)]+1);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3072
#include <stdio.h>

int main(void){
  int s;
  int h,m,sec;

  scanf("%d",&s);
  sec=s%60;  s=s/60;
  m=s%60;  s=s/60;
  h=s%60;
  printf("%d:%d:%d\n",h,m,sec);

  return 0;
}

Measured memory_bytes: 592
import java.awt.geom.Point2D;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

public class Main {
	static int n;
	
	static ArrayList<Point2D.Double> xy1, xy2;
	
	private static double cross(Point2D.Double a, Point2D.Double b)
	{
		return (a.x * b.y - a.y * b.x);
	}
	
	// a + b
	private static Point2D.Double add(Point2D.Double a, Point2D.Double b)
	{
		return new Point2D.Double(a.x + b.x, a.y + b.y); 
	}
	
	// a - b
	private static Point2D.Double sub(Point2D.Double a, Point2D.Double b)
	{
		return new Point2D.Double(a.x - b.x, a.y - b.y); 
	}
	
	// a * t
	private static Point2D.Double mul(Point2D.Double a, double t)
	{
		return new Point2D.Double(a.x * t, a.y * t);
	}
	
	private static Boolean isCrossing(Point2D.Double a1, Point2D.Double a2, Point2D.Double b1, Point2D.Double b2)
	{
		return (cross(sub(a2, a1), sub(b1, a1)) * cross(sub(a2, a1), sub(b2, a1)) < 1e-10) &&
			   (cross(sub(b2, b1), sub(a1, b1)) * cross(sub(b2, b1), sub(a2, b1)) < 1e-10);
	}
	
	private static Point2D.Double crosspoint(Point2D.Double a1, Point2D.Double a2, Point2D.Double b1, Point2D.Double b2)
	{
		Point2D.Double b = sub(b2, b1);
		double d1 = Math.abs(cross(b, sub(a1, b1)));
		double d2 = Math.abs(cross(b, sub(a2, b1)));
		double t = d1 / (d1 + d2);
		
		return add(a1, mul(sub(a2, a1), t));
	}
	
	public static void main(String[] args)
	{
		Scanner sca = new Scanner(System.in);
		
		while(true)
		{
			n = sca.nextInt();
			if(n == 0) break;
			
			int i, j, k;
			
			xy1 = new ArrayList<Point2D.Double>();
			xy2 = new ArrayList<Point2D.Double>();
			
			for(i = 0;i < n;i++)
			{
				double x1 = sca.nextDouble();
				double y1 = sca.nextDouble();
				double x2 = sca.nextDouble();
				double y2 = sca.nextDouble();
				
				Point2D.Double p;
				
				p = new Point2D.Double(x1, y1);
				xy1.add(p);
				p = new Point2D.Double(x2, y2);
				xy2.add(p);
			}
			
			int area = 2;
			for(i = 1;i < n;i++)
			{
				ArrayList<Point2D.Double> store = new ArrayList<Point2D.Double>();
				Point2D.Double a1 = xy1.get(i);
				Point2D.Double a2 = xy2.get(i);
				
				for(j = 0;j < i;j++)
				{
					Point2D.Double b1 = xy1.get(j);
					Point2D.Double b2 = xy2.get(j);
					
					if(!isCrossing(a1, a2, b1, b2)) continue;
					
					Point2D.Double cross = crosspoint(a1, a2, b1, b2);
					
					// 正方形の辺上にあるときcontinue
					double dx = Math.abs(Math.abs(cross.x) - 100);
					double dy = Math.abs(Math.abs(cross.y) - 100);
					if(dx < 1e-10 || dy < 1e-10) continue;
					
					// 今までの点で一致しているものが無いか探す
					for(k = 0;k < store.size();k++)
					{
						Point2D.Double sp = store.get(k);
						dx = Math.abs(sp.x - cross.x);
						dy = Math.abs(sp.y - cross.y);
						if(dx < 1e-10 && dy < 1e-10) break;
					}
					if(k == store.size())
					{
						store.add(cross);
					}
				}
				
				area += store.size() + 1;
			}
			
			System.out.println(area);
		}
	}
}

Measured memory_bytes: 63556
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define mod(cans) cans%10**9+7
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define cin_pl(n,x) rep(i,n){cin>>x[i];}
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define prians(Answer) cout<<Answer<<"\n"
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > matrix;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef greater<int> gi;
typedef vector<unsigned> vu;


ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
bool is_prime(const unsigned n){
    switch(n){
        case 0:
        case 1: return false;
        case 2: return true;
    }
 
 
    for(unsigned i=2;i<n;++i){
        if(n%i == 0) return false;
    }
 
    return true;
}

int main()
{
    int n;cin>>n;
    vi p(n);cin_pl(n,p);
    int sum=0;
    rep(i,n)sum+=p[i];
    int ave=sum/n+1;
    int ans=0,ans1=0;
    rep(i,n)
    {
        ans+=pow(abs(p[i]-ave),2);
    }
   rep(i,n)
    {
        ans1+=pow(abs(p[i]-ave+1),2);
    } 
    cout<<min(ans,ans1);

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#pragma warning (disable: 4996)

long long L, Q, A[1 << 20], dp0[1 << 20], dp1[1 << 20];

void init() {
	for (int i = 0; i < (1 << L); i++) { dp0[i] = A[i]; dp1[(1 << L) - i - 1LL] = A[i]; }

	for (int i = 0; i < L; i++) {
		for (int j = 0; j < (1 << L); j++) {
			if ((j&(1 << i)) != 0) { dp0[j] += dp0[j - (1 << i)]; }
		}
	}
	for (int i = 0; i < L; i++) {
		for (int j = 0; j < (1 << L); j++) {
			if ((j&(1 << i)) != 0) { dp1[j] += dp1[j - (1 << i)]; }
		}
	}
}

int A1[1 << 20], A2[1 << 20], cnts;

void enumerate(vector<int>I) {
	cnts = 0; int N = I.size();

	int sum = 0, cnt = 0;
	for (int i = 0; i < (1 << I.size()); i++) {
		A1[cnts] = sum; A2[cnts] = ((N - cnt) & 1); cnts++;

		int cx = i, ss = 0;
		while ((cx & 1) == 1) {
			cx >>= 1; sum -= (1 << I[ss]); ss++; cnt--;
		}
		if (ss < N) { sum += (1 << I[ss]); cnt++; }
	}
}

int main() {
	cin >> L >> Q;
	for (int i = 0; i < (1 << L); i++) { char c; cin >> c; A[i] = (c - '0'); }

	init();

	for (int i = 1; i <= Q; i++) {
		char c[22]; scanf("%s", c);
		for (int j = 0; j < L; j++) { if (j < (L - 1 - j)) swap(c[j], c[L - 1 - j]); }
		
		vector<int>v0, v1, v2;
		for (int j = 0; j < L; j++) {
			if (c[j] == '0') v0.push_back(j);
			if (c[j] == '1') v1.push_back(j);
			if (c[j] == '?') v2.push_back(j);
		}

		int ans = 0;
		if (v2.size() <= 7) {
			enumerate(v2);
			int BASE = 0; for (int j = 0; j < v1.size(); j++) BASE += (1 << v1[j]);
			for (int j = 0; j < cnts; j++) {
				ans += A[BASE + A1[j]];
			}
		}
		else if (v0.size() <= v1.size()) {
			enumerate(v0);
			int BASE = 0; for (int j = 0; j < v2.size(); j++) BASE += (1 << v2[j]);

			for (int j = 0; j < cnts; j++) {
				if (A2[j] == 0) ans += dp1[BASE + A1[j]];
				if (A2[j] == 1) ans -= dp1[BASE + A1[j]];
			}
		}
		else {
			enumerate(v1);
			int BASE = 0; for (int j = 0; j < v2.size(); j++) BASE += (1 << v2[j]);

			for (int j = 0; j < cnts; j++) {
				if (A2[j] == 0) ans += dp0[BASE + A1[j]];
				if (A2[j] == 1) ans -= dp0[BASE + A1[j]];
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


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

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D(x)         cout << #x << " - " << x << endl;
  #define  D2(x)        cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  all(x)       (x).begin(), (x).end()
  #define  D2p(x)       cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
	ll n,d;
	cin >> n >> d;
	int ans=0;
	for(int i=0;i<n;i++){
		ll x,y;
		cin >> x >> y;
		ans += ((x*x +y*y) <= d*d);
	}
	cout << ans;
  }

  int main(){
    IOS
    solve();
    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 3784
use proconio::input;
use rand::Rng;

pub fn get_time() -> f64 {
    static mut STIME: f64 = -1.0;
    let t = std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)
        .unwrap();
    let ms = t.as_secs() as f64 + t.subsec_nanos() as f64 * 1e-9;
    unsafe {
        if STIME < 0.0 {
            STIME = ms;
        }
        ms - STIME
    }
}

pub struct State {
    max_day: usize,
    sat: isize,
    out: Vec<usize>,
    last: Vec<usize>,
    c: Vec<isize>,
    s: Vec<Vec<isize>>,
}

impl State {
    fn calclate_score(&mut self) -> isize {
        self.sat = 0;
        self.last = vec![0; 26];
        let mut s: isize = 0;
        for i in 0..26 {
            s += self.c[i];
        }
        let mut temp_minus = 0;
        for d in 0..self.max_day {
            temp_minus += s;
            assert!(0 <= self.out[d] && self.out[d] <= 25);
            let j = self.out[d as usize] as usize;
            temp_minus -= self.c[j] * (d + 1 - self.last[j]) as isize;
            self.sat -= temp_minus;
            self.last[j] = d + 1;
            self.sat += self.s[d][j];
        }
        self.sat
    }
    fn initialize_output(&mut self) {
        for i in 0..self.max_day {
            let mut max = 0;
            for j in 0..26 {
                max = if self.s[i][max] < self.s[i][j] {
                    j
                } else {
                    max
                };
            }
            self.out[i] = max;
        }
        for i in 0..self.max_day {
            let mut max = self.out[i];
            let mut max_score = self.calclate_score();
            for j in 0..26 {
                self.out[i] = j;
                let temp = self.calclate_score();
                if max_score < temp {
                    max = j;
                    max_score = temp;
                }
            }
            self.out[i] = max;
        }
        eprintln!("{}", self.calclate_score());
    }
}

fn main() {
    input! {
        max_day: usize,
        c: [isize; 26],
        s: [[isize; 26]; max_day],
    }
    let mut plan = State {
        max_day: max_day,
        sat: 0,
        out: vec![0; max_day],
        last: vec![0; 26],
        c,
        s,
    };
    plan.initialize_output();
    let mut rng = rand::thread_rng();
    let mut max_score = plan.calclate_score();
    let mut loop_cnt = 0;
    while get_time() < 1.9 {
        // eprintln!("{}", max_score);
        let d: usize = rng.gen_range(0, max_day);
        let q: usize = rng.gen_range(0, 26);
        let old = plan.out[d];
        plan.out[d] = q;
        let score = plan.calclate_score();
        if max_score < score {
            max_score = score;
        } else {
            plan.out[d] = old;
        }
        loop_cnt += 1;
    }
    for x in plan.out {
        println!("{}", x + 1);
    }
    eprintln!("score:{}, loop:{}", max_score, loop_cnt);
}


Measured memory_bytes: 2764
#include <cstdio>

int main()
{
    int a,b,c,d,e;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (a > b)
    {
        printf("%d", b * c + (a - b) * d);
    }
    
    else
    {
        printf("%d", a * c);
    }
    
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

int64_t gcd(const int64_t& lhs, const int64_t& rhs)
{
  if (rhs == 0)
  {
    return lhs;
  }
  return gcd(rhs, lhs % rhs);
}
int main()
{
  int n;
  std::cin >> n;
  int64_t lcm = 1;
  for (int i = 0; i < n; ++i)
  {
    int64_t t;
    std::cin >> t;
    lcm = lcm / gcd(lcm, t);
    lcm = lcm * t;
  }
  std::cout << lcm << std::endl;
  return 0;
}

Measured memory_bytes: 256
require "prime"

q = gets.to_i
lr = q.times.map {gets.split.map(&:to_i)}

prime = Prime.each(10 ** 5).to_a
prime -= prime.reject {|pr| ((pr + 1) / 2).prime?}

lr.each do |l, r|
  l_idx = prime.bsearch_index {|pr| pr >= l}
  r_idx = prime.bsearch_index {|pr| pr > r}
  result = if !l_idx
    0
  elsif !r_idx
    prime.size - l_idx
  else
    r_idx - l_idx
  end
  puts result
end

Measured memory_bytes: 21872
n = int(input())
a = [int(input()) for _ in range(n)]

maximum = max(a)
ans = [maximum]*n
if a.count(maximum) ==1:
    maximum_index = a.index(maximum)
    ans[maximum_index] = max(
        a[:maximum_index]+a[maximum_index+1:]
    )
for i in range(n):
    print(ans[i])

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

using namespace std;
typedef long long ll;
struct chara{
    ll h, a, d, s, t;
    bool operator < (const chara& c) const {
        return t * c.a < c.t * a;
    }
};
ll solve(int n){
    chara me;
    cin >> me.h >> me.a >> me.d >> me.s;

    vector<chara> rival(n);
    for(chara& c : rival){
        cin >> c.h >> c.a >> c.d >> c.s;
        c.a = max(0ll, c.a - me.d);
    }

    for(chara& c : rival){
        if(me.a <= c.d){
            if(c.a > 0){
                return -1;
            }else{
                c.d = 0;
            }
        }
    }

    for(chara& c : rival){
        c.t = (c.h + me.a - c.d - 1) / (me.a - c.d);
    }

    ll sum = 0;
    for(const chara& c : rival){
        if(c.s < me.s){
            sum -= c.a;
        }
    }

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

    ll time = 0;
    for(const chara& c : rival){
        time += c.t;
        sum += c.a * time;
        if(sum >= me.h) {
            return -1;
        }
    }

    return sum;
}

int main(){
    int n;
    while(cin >> n){
        cout << solve(n) << endl;
    }
    return 0;
}

Measured memory_bytes: 2580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, k;
    cin >> n >> k;
    ll a[n];
    rep(i, 0, n) cin >> a[i];
    rep(i, k, n) {
        if (a[i] > a[i - k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e,f,g;
  cin>>a>>b>>c>>d;
  e=max(a,b)-min(a,b);
  f=max(a,c)-min(a,c);
  g=max(b,c)-min(b,c);
  if(f<=d) cout<<"Yes";
  else if(e<=d&&g<=d) cout<<"Yes";
  else cout<<"No";
}

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

long fact(int n){
    long ans=1;
    for(int i=1; i<=n; ++i){
        ans=(ans*i)%1000000007;
    }
    return ans;
}

int main() {
	int N, M; cin >> N >> M;
	if(abs(N-M)>1) cout << 0 << endl;
	else{
	    long P=(fact(N)*fact(M))%1000000007;
	    if(N==M) P=(2*P)%1000000007;
	    cout << P << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LL long long int 
const LL MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//            When something is important enough, you do it even if the odds are not in your favor.

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LL k,i;cin>>k;
      LL r=0,x=7;
      fo(i,0,1e6){
        r+=x%k;
        r%=k;x%=k;
        if(r==0) break;
        x*=10;
      }
      if(i==1e6) cout<<-1;
      else cout<<i+1;
    }
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define ll long long
#define faltu ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define binary(x) std::string binary = std::bitset<25>(x).to_string(); //to binary
#define inf 1000000007
#define mod 1000000007
#define pi pair<int,int>
#define lpi pair<int,int>
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define lvi vector<long long int>
#define pie 3.14159265358979323846
ll int MMM=inf;
int pw(int x,int y){int z=1;for(;y;y>>=1,x=1ll*x*x%MMM)if(y&1)z=1ll*z*x%MMM;return z;}
using namespace std;
vi pm;
void prm(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
              prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p]) pm.pb(p);
}
bool sortbysecdesc(const pair<ll int,ll int> &a,const pair<ll int,ll int> &b)
{
    return a.first>b.first;
}
bool cmp(int x,int y){return x>y;}
int main()
{
	faltu;
	int n,ans=0;
	cin>>n;
	int a[n+1];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=1;i<n-1;i++)
	{
		if((a[i]>=a[i-1]&&a[i]<a[i+1])||(a[i]>a[i-1]&&a[i]<=a[i+1]))ans++;
		else if((a[i]<a[i-1]&&a[i]>=a[i+1])||(a[i]<=a[i-1]&&a[i]>a[i+1]))ans++;
	}
	cout<<ans<<endl;
}








Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int bottom, top, i, count = 0;
  int time[100] = {};
  scanf("%d %d", &bottom, &top);
  for(i = bottom; i < top; i++) {
    time[i]++;
  }
  scanf("%d %d", &bottom, &top);
  for(i = bottom; i < top; i++) {
    time[i]++;
  }
  for(i = 0; i < 100; i++) {
    if(time[i] == 2) {
      count++;
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
// Best practice

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// #include <functional> // for less

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;
// using namespace __gnu_pbds;

// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

// #define fbo find_by_order
// #define ook order_of_key

// Code from Here -------------------------------------------------------------------------------


signed main() {
	tezz

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, m, p, q;
	cin >> n >> m;
	vi c(n + 1);
	vector<vi> adj(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> c[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> p >> q;
		adj[p].pb(q);
		adj[q].pb(p);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int maxx = -1;
		for (auto it : adj[i]) {
			maxx = max(maxx, c[it]);
		}
		if ( c[i] > maxx )ans++;
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 9800
import copy
x,y = map(int,input().split())
color = 1
za = [0,0]
n = 0
m = 1
l = 1
d = 1
X = 0
Y = 0
while True:
    if za[0] <= x and za[0]+l-1 >= x and za[1] >= y and za[1]-l+1 <= y:
        print(color)
        break
    m = copy.deepcopy(l)
    l += n
    n = m
    color += 1
    if color > 3:
        color = 1
    if d == 1:
        za[0] += n
        za[1] = Y
        d = 2
    #print(za)
    elif d == 2:
        za[0] = X
        za[1] += l
        Y = za[1]
        d = 3
    elif d == 3:
        za[0] -= l
        za[1] = Y
        X = za[0]
        d = 4
    elif d == 4:
        za[0] = X
        za[1] -= n
        d = 1
    #print(za,X,Y,l,color)


Measured memory_bytes: 6344
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }

  pair<long long,int> p[m];
  int b;
  long long c;
  for(int i=0;i<m;i++){
    cin >> b >> c;
    p[i] = make_pair(c,b);
  }

  sort(a,a+n);
  sort(p,p+m);

  long long f[n];
  int count = 0;
  for(int i=0;i<n;i++) f[i] = 0;
  for(int i=m-1;i>=0;i--){
    c = p[i].first;
    b = p[i].second;
    for(int j=count;j<min(n,count+b);j++){
      f[j] = c;
    }
    count += b;
    if(count > n-1) break;
  }

  long long g[2*n];
  for(int i=0;i<n;i++){
    g[i] = a[i];
  }

  for(int i=n;i<2*n;i++){
    g[i] = f[i-n];
  }

  sort(g,g+2*n);

  long long ans = 0;
  for(int i=n;i<2*n;i++) ans += g[i];
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
using namespace std;

int main(){
  vi v(32);
  v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << v[K-1] << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}
int main(){
    int A, B;
    cin >> A >> B;
    int count = 0;
    for(int i = A; i <= B; i++){
        if(is_palindrome(to_string(i))) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <map>

using namespace std;

#define R register

const int MAXN=2e5+10;

int n;
int a[MAXN];

map<int,int> mp;

inline bool chk(int k)
{
	mp.clear();
	for(R int i=2;i<=n;i++)
	{
		if(a[i-1]<a[i]) continue;
		if(k==1) return 0;
		while(!mp.empty())
		{
			int p=mp.rbegin()->first;
			if(p>a[i]) mp.erase(p);
			else break;
		}
		int j=a[i];
		while(j>0&&mp[j]+1==k)
		{
			mp.erase(j);
			j--;
		}
		if(j==0) return 0;
		mp[j]++;
	}
	return 1;
}

int main()
{
	scanf("%d",&n);
	for(R int i=1;i<=n;i++) scanf("%d",&a[i]);
	int l=1,r=n,mid,res=n;
	while(l<=r)
	{
		int mid=l+r;mid>>=1;
		if(chk(mid)) r=mid-1,res=mid;
		else l=mid+1;
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 1024
# frozen_string_literal: true

n = gets.chomp.to_i
w = []
n.times do
  w.push gets.chomp
end
if w.size != w.uniq.size
  puts 'No'
else
  (n - 1).times do |i|
    if w[i][-1] != w[i + 1][0]
      puts 'No'
      exit 0
    end
  end
  puts 'Yes'
end


Measured memory_bytes: 3836
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Solve(int N, string[] S)
        {
            int a = 0, b = 0, c = 0, m = 0;
            foreach (string s in S)
            {
                for (int i = 0; i + 1 < s.Length; ++i)
                {
                    if (s[i] == 'A' && s[i + 1] == 'B') { ++c; }
                }
                int flag = 0;
                if (s.Last() == 'A') { flag |= 1; }
                if (s.First() == 'B') { flag |= 2; }
                switch (flag)
                {
                case 1: ++a; break;
                case 2: ++b; break;
                case 3: ++m; break;
                }
            }
            if (m > 0)
            {
                c += m - 1;
                if (a > 0)
                {
                    ++c;
                    --a;
                }
                if (b > 0)
                {
                    ++c;
                    --b;
                }
            }
            return c + Math.Min(a, b);
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            var S = new string[N];
            for (int n = 0; n < N; ++n) { S[n] = Read(); }
            Console.WriteLine(Solve(N, S));
        }
    }
}


Measured memory_bytes: 13344
n,k=map(int,input().split())
ans=[0]*n #0がn個ある配列(すぬけ君の配列)

for i in range(k): #k種類のお菓子を順に見て行く
    d=int(input())  #参照しなくていい数
    a=list(map(int,input().split()))
    for j in a:    #そのお菓子を持っていれば配列の要素を1にする
        ans[j-1]=1 #すぬけ君0はいないので配列の番値は-1にならない

print(n-sum(ans)) #(全集合)-(お菓子を持っている人)
                  #n-(0+1+1+1+0+0+...)


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    std::deque<int> deq;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a;
        deq.emplace_back(a);
    }
    int count = 0;
    int flag = 1;
    while (flag==1) {
        flag = 0;
        for (int j=n-1;0<j;j--) {
        if (deq[j]<deq[j-1]) {
            int tmp = deq[j];
            deq[j] = deq[j-1];
            deq[j-1] = tmp;
            count++;
            flag = 1;
        }
    }
    }
    for (int k=0;k<deq.size();k++) {
        if (k==deq.size()-1) {
            cout << deq[k] << endl;
        } else {
            cout << deq[k] << " ";
        }
    }
    cout << count << endl;
}



Measured memory_bytes: 3112
#include<iostream>
#include<string>

using namespace std;
int main(void){
  string s;
  bool flag = true;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    for(int j = i + 1; j < s.size(); j++){
      if(s[i] == s[j]){
        cout << "no" << endl;
        flag = false;
        break;
      }
      if(flag == false) break;
    }
  }
  if(flag){
    cout << "yes" << endl;
  }
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> w(n);
  for(int i=0; i < n; i++){
     cin >> w[i];
  }
  
  int ans  =  100000;
  for(int i=1; i<n; i++){
    int l=0,r=0;
  for(int j=0; j<i; j++)  l += w[j];
  for(int j=i; j<n; j++)  r += w[j];
    ans=min(ans,abs(l-r));
  }
  cout << ans << endl;
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;

int kaizyou(int n){
  int a=1;
  for(int i=1;i<=n;i++){
    a *= i;
  }
  return a;
}
int main() {
  int n;
  cin >> n;
  vector<pii> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i).first >> p.at(i).second;
  }
  double d = 0;
  sort(p.begin(),p.end());
  do{
    for(int i=0;i<n-1;i++){
      d += sqrt(pow(p.at(i+1).first-p.at(i).first,2.0) + pow(p.at(i+1).second-p.at(i).second,2.0));
    }
  }while(next_permutation(p.begin(),p.end()));
  cout << fixed << setprecision(10);
  cout << d/(double)kaizyou(n) << endl;
}

Measured memory_bytes: 3856
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
import math

sys.setrecursionlimit(1000000)

MOD = 10 ** 9 + 7


# INF = float('inf')
# N = int(input())
# A = [int(x) for x in input().split()]
# A = [int(input()) for _ in range(N)]
# dp = [[0] * 100 for _ in range(100)]
# dp = defaultdict(lambda: float('inf'))
# print('hoge', file=sys.stderr)


# 組み合わせの総数
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N, K = [int(x) for x in input().split()]
r = N - K
b = K

for i in range(1, b + 1):
    if r + 1 >= i and b >= i:
        ans = comb(r + 1, i) * comb(b - 1, i - 1)
        print(ans % MOD)
    else:
        print(0)


Measured memory_bytes: 3948
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Pipes;
using System.Runtime.InteropServices.ComTypes;

namespace cswork
{
    class Program
    {
        public Program() { }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        void Omame()
        {
            cin = new Scanner();
            int N = cin.nextInt();
            int W = cin.nextInt();
            List<int> w = new List<int>();
            List<int> v = new List<int>();
            for (int i = 0; i < N; i++)
            {
                w.Add(cin.nextInt());
                v.Add(cin.nextInt());
            }

            long[,] dp = new long[N + 1, W + 1];
            for (int i = 0; i < N; i++)
            {
                for (int sumW = 0; sumW <= W; sumW++)
                {
                    if (w[i] <= sumW)
                    {
                        dp[i + 1, sumW] = dp[i, sumW - w[i]] + v[i];
                    }
                    dp[i + 1, sumW] = Math.Max(dp[i + 1, sumW], dp[i, sumW]);
                }
            }

            Console.WriteLine(dp[N, W]);
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

Measured memory_bytes: 89056
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    n = ii()
    print(n**3)


main()


Measured memory_bytes: 13796
# ABC 58 C

import numpy as np

def resolve():
    n = int(input())
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    ans = {}

    for i in range(n):
        s = input()
        sdic = {}
        for a in alphabet:
            sdic[a] = 0
        for c in s:
            sdic[c] += 1

        if i == 0:
            ans = sdic
        else:
            for c in alphabet:
                ans[c] = min(ans[c], sdic[c])

    for c in alphabet:
        for i in range(ans[c]):
            print(c, end="")
    print("")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 12496
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline int read(){
	char ch=getchar();
	int o=0,f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		o=(o<<3)+(o<<1)+(ch^48);
		ch=getchar();
	}
	return o*f;
}
int b[1000],ans;
int main(){
	int n=read();
	for(register int i=1;i<=n-1;i++) cin>>b[i];
	ans+=b[1];
	for(register int i=1;i<=n-1;i++){
		ans+=min(b[i],b[i+1]);
	}
	ans+=max(b[n-1],b[n]);
	cout<<ans<<endl;
}

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

#define MAX_SIZE (100000 + 10)

int P[3];
int T[MAX_SIZE];
int DP[MAX_SIZE][3];

int main()
{
  int N, K;
  std::cin >> N >> K;
  for (int i = 0; i < 3; ++i)
  {
    std::cin >> P[i];
  }

  for (int i = 0; i < N; ++i)
  {
    char t;
    std::cin >> t;
    switch (t)
    {
    case 'r': T[i] = 2; break;
    case 's': T[i] = 0; break;
    case 'p': T[i] = 1; break;
    }
  }

  int ans = 0;
  for (int k = 1; k <= K; ++k)
  {
    int dpi = 0;
    DP[0][0] = DP[0][1] = DP[0][2] = 0;
    for (int i = k - 1; i < N; i += K)
    {
      ++dpi;
      DP[dpi][0] = DP[dpi][1] = DP[dpi][2] = 0;
      for (int cur = 0; cur < 3; ++cur)
      {
        for (int prev = 0; prev < 3; ++prev)
        {
          int point = 0;
          if (T[i] == cur && cur != prev) point = P[cur];
          DP[dpi][cur] = std::max(DP[dpi][cur], DP[dpi - 1][prev] + point);
        }
      }        
    }

    int maxp = 0;
    for (int i = 0; i < 3; ++i)
    {
      maxp = std::max(maxp, DP[dpi][i]);
    }
    ans += maxp;
  }

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

  return 0;
}


Measured memory_bytes: 1792
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import sys
def input():
	return sys.stdin.readline()[:-1]

n, m, l = map(int, input().split())
dist = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
	a, b, c = map(int, input().split())
	dist[a-1][b-1] = c
	dist[b-1][a-1] = c

fw = floyd_warshall(csr_matrix(dist))

num = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
	for j in range(n):
		if fw[i][j] <= l:
			num[i][j] = 1

ans = floyd_warshall(csr_matrix(num))

q = int(input())
for _ in range(q):
	s, t = map(int, input().split())
	if ans[s-1][t-1] > n:
		print(-1)
	else:
		print(int(ans[s-1][t-1])-1)

Measured memory_bytes: 21124
s = input()
s_len = len(s)
ans = '-1 -1'

for i in range(s_len):
    if i+1 < s_len and s[i] == s[i+1]:
        ans = '{} {}'.format(i+1, i+2)
        break
    elif i+2 < s_len and s[i] == s[i+2]:
        ans = '{} {}'.format(i+1, i+3)
        break
print(ans)

Measured memory_bytes: 3188
#include "iostream"
using namespace std;
 
int main(){

  long int A,B,n;
  int i=1;
  long int N;
  
  cin >> A >> B;

  if(A<B){
   	n=A;
    A=B;
    B=n;
  }
  
 
 while(1){
    
    if((A*i)%B==0){
     N=A*i; 
     break;
    }
   
   i++;
    
  }
  
  cout << N;
  
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n1,n2,count,check;

    while(1){
        cin >> n1 >> n2;
        if(cin.eof()){
            break;
        }
        count = 1;
        check = n1 + n2;
        while(1){
            check /= 10;
            if(check == 0){
                cout << count << endl;
                break;
            }
            else {
                count++;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3072
h, n = map(int, input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i], b[i] = map(int, input().split())

dp = [[float("inf")]*(h+1) for i in range(n+1)]
for i in range(n+1):
    dp[i][0] = 0
for i in range(n):
    for j in range(h):
        if j+1-a[i] >= 0:
            dp[i+1][j+1] = min(dp[i][j+1], dp[i][j]+b[i], dp[i+1][j+1-a[i]]+b[i])
        else:
            dp[i+1][j+1] = min(dp[i][j+1], dp[i][j]+b[i], b[i])

print(dp[n][h])

Measured memory_bytes: 296216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll INF = 1LL << 60;
const ll MOD = (ll) 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] == i + 1) {
            if (i == n - 1) {
                swap(v[i], v[i - 1]);
                ans++;
            }
            else {
                swap(v[i], v[i + 1]);
                ans++;
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"math"
)

func main(){
	var s, t []byte
	fmt.Scan(&s, &t)

	ans := 1000
	for i := 0;i < len(s); i++ {
		cnt := 0
		if i + len(t) > len(s) {
			break
		}
		for j := i; j < i+ len(t); j++ {
			if s[j] != t[j-i] {
				cnt++
			}
		}

		ans = min(ans, cnt)
	}
	fmt.Println(ans)
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N,M;
  cin >> N >> M;
  int A[M];
  long sum_day;
  sum_day = 0;

  for (int i = 0; i < M; i++) {
    cin >> A[M];
    sum_day += A[M];
  }
  
    if (N-sum_day >= 0){
        cout << N-sum_day << endl;
    }else{
        cout << -1 << endl;  
  }
}

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

int calc(pair<int, int> stu, pair<int, int> check) {
  return abs(stu.first - check.first) + abs(stu.second - check.second);
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> stu(n), check(m);
  for (int i = 0; i < n; i++) {
    cin >> stu[i].first >> stu[i].second;
  }
  for (int i = 0; i < m; i++) {
    cin >> check[i].first >> check[i].second;
  }

  for (int i = 0; i < n; i++) {
    int min = 999999999;
    for (int j = 0; j < m; j++) {
      min = std::min(min, calc(stu[i], check[j]));
    }
    for (int j = 0; j < m; j++) {
      int temp = calc(stu[i], check[j]);
      if (min == temp) {
        cout << j + 1 << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    long long N, D, X;
    cin >> N >> D >> X;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        for (int j = 1; j <= D; j+=A) {
            X++;
        }
    }
    cout << X << endl;
}

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

using namespace std;

long long qtd[26];

int main(){
    string s;
    cin >> s;
    long long n = s.size();
    for(int i = 0; i < n; i++){
        qtd[s[i]-'a']++;
    }
    long long tot = n*(n-1)/2;

    for(int i = 0; i < 26; i++){
        tot -= (qtd[i]*(qtd[i]-1))/2;
    }

    cout << tot+1 << endl;
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long double DB;

DB d,x,n;
int main() {
	cin>>n>>d>>x; DB ans=0;
	for(int i=n;i>=1;i--) {
		DB sum=(d*2*n+n*(2*n-1)*x);
		ans+=sum/2/n;
		DB d2=(d*(2*n-2)+d+2*x+3*d+3*x)/2/n;
		sum=sum-(4*d+4*n*x-2*x)/2/n;
		n-=1;
		DB x2=(sum-2*n*d2)/n/(2*n-1);
		d=d2; x=x2;
	} printf("%.15f\n",(double)ans);
}

Measured memory_bytes: 256