akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

	static long[] x, y;
	static long cnt = 0;
	static int [] perm; 
	public static double solve(int idx, int mask) {

		if(idx == perm.length) {
			double sum =0;
			for(int i=0;i<perm.length-1;i++) {
				sum += dist(perm[i], perm[i+1]);
			}
			cnt++;
			return sum;
		}
		double sum = 0;
		boolean b = false;
		for (int i = 0; i < x.length; i++) {
			if ((mask & (1 << i)) == 0) {
				perm[idx]=i;
				sum += solve(idx+1, mask | (1 << i));
				b = true;
			}
		}
		
		
		return sum;
	}

	public static double dist(int i, int j) {
		if (i == -1)
			return 0;
		long dx = x[i]-x[j];
		long dy = y[i]-y[j];
		return Math.sqrt(dx*dx + dy*dy);
	}
//	8
//	-406 10
//	512 859
//	494 362
//	-955 -475
//	128 553
//	-986 -885
//	763 77
//	449 310

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		x = new long[n];
		y = new long[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		perm = new int [n];
		double solve = solve(0, 0);
//		System.out.println(solve);
//		for(int i=1;i<=n;i++)
//			solve/=i;

		System.out.println(solve / cnt);
		
	}

}


Measured memory_bytes: 22356
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  lint h, w; std::cin >> h >> w;
  if (h%3==0 || w%3==0) {
    std::cout << 0 << std::endl;
    return 0;
  }
  lint ans = std::min(h,w);
  loop(2) {
    rep(x, h/3, h/3+2) {
      lint y = w/2;
      std::vector<lint> v = {
        x * w,
        (h-x) * y,
        (h-x) * (w-y)
      };
      lint min = *std::min_element(all(v));
      lint max = *std::max_element(all(v));
      lint d = max - min;
      assert(0 < d);
      debug(x,w,x*w);
      debug(h-x,y,(h-x)*y);
      debug(h-x,w-y,(h-x)*(w-y));
      debug("");
      cmn(ans, d);
    }
    std::swap(h,w);
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var s = ReadLine();
            for (int i = 0; i < 26; i++)
            {
                var c = (char)(i + 'a');
                bool f = s.Contains(c);
                if (!f)
                {
                    WriteLine(c);
                    return;
                }
            }
            WriteLine("None");
        }

        public class IO
        {
            #region Input
            public static string ReadString => ReadLine();
            public static int ReadInt => int.Parse(ReadLine());
            public static long ReadLong => long.Parse(ReadLine());
            public static double ReadDouble => double.Parse(ReadLine());

            public static List<string> ReadSplitString => ReadLine().Split().ToList();
            public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
            public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
            public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
            #endregion

            #region Output
            public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
            public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");

            #endregion
        }

        public class Mod
        {
            #region
            private readonly static long M = 1000000007;

            public static long Add(long a, long b) => (a * b) % M;
            public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
            public static long Multi(long a, long b) => (a * b) % M;
            #endregion
        }

        public static long GCD(long x, long y)
        {
            #region
            if (x < y)
            {
                var tmp = x;
                x = y;
                y = tmp;
            }
            while (true)

            {
                if (x % y == 0)
                {
                    return y;
                }
                else
                {
                    var tmp = x;
                    x = y;
                    y = tmp % y;
                }
            }
            #endregion
        }

        public static long Choice2(long n)
        {
            #region
            if (n <= 1)
                return 0;
            if (n == 2)
                return 1;
            else
                return n * (n - 1) / 2;
            #endregion
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000000 + 7
#define PI 3.14159265359

const long long INF = 100000;
typedef pair<int,int> P;
typedef long long ll;

using Graph = vector<vector<int>>;

vector<ll> v;

//K番目のlunlun数を返すbfs
void bfs(int K) {
	for (ll i = 1; i <= 9; i++) {
		v.push_back(i);
	}
	queue<ll> que;
	for (ll i = 1; i <= 9; i++) {
		que.push(i);
	}

	while (1) {
		ll iTop = que.front();
		que.pop();
		
		ll c = iTop % 10;// queの先頭の末尾の桁の数
		for (ll iMatubi/*付け加える末尾の数*/ = c - 1; iMatubi <= c + 1; iMatubi++) {
			
			if (iMatubi < 0 || iMatubi > 9) continue;
			
			ll iNext = iTop * 10 + iMatubi;//  queの先頭から得た新たなlunlun数
			que.push(iNext);
			v.push_back(iNext);
		}
		if (v.size() >= K) break;
	}
}


int main() {
    int K;
	cin >> K;
    bfs(K);
	cout << v[K-1] << endl;

}


Measured memory_bytes: 4628
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int MOD=1000000007;
const int nmax=201234;

ll h,w,n,r,c,res,fac[nmax],fac2[nmax],inv[nmax],a[3012];
vector<pair<ll,ll> > v2;

int main()
{
    scanf("%lld %lld %d",&h,&w,&n);
    v2.pb({0,0});
    for(ll i=1; i<=n; ++i)
    {
        scanf("%lld %lld",&r,&c);
        v2.pb({r,c});
    }
    sort(v2.begin(),v2.end());
    fac[0]=1;
    fac2[0]=1;
    inv[1]=1;
    for(ll i=2; i<200012; ++i)
        inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
    for(ll i=1; i<200012; ++i)
    {
        fac[i]=fac[i-1]*i%MOD;
        fac2[i]=fac2[i-1]*inv[i]%MOD;
    }
    for(ll i=1; i<=n; ++i)
    {
        a[i]=(a[i]+fac[v2[i].first+v2[i].second-2]*fac2[v2[i].second-1]%MOD*fac2[v2[i].first-1]%MOD)%MOD;
        if(a[i]<0)
            a[i]+=MOD;
        for(ll j=i+1; j<=n; ++j)
            if(v2[i].first<=v2[j].first && v2[i].second<=v2[j].second)
                a[j]=(a[j]-a[i]*fac[v2[j].first-v2[i].first+v2[j].second-v2[i].second]%MOD*fac2[v2[j].second-v2[i].second]%MOD*fac2[v2[j].first-v2[i].first]%MOD)%MOD;
    }
    res=fac[h+w-2]*fac2[w-1]%MOD*fac2[h-1]%MOD;
    for(ll i=1; i<=n; ++i)
        res=(res-a[i]*fac[h-v2[i].first+w-v2[i].second]%MOD*fac2[w-v2[i].second]%MOD*fac2[h-v2[i].first]%MOD)%MOD;
    if(res<0)
        res+=MOD;
    printf("%lld",res);
    return 0;
}


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

int N=0;//??°
int W=0;//?????§???
int v[100000], w[10000];

int main()
{
	cin >> N >> W;
	int DP[N+1][W+1];

	for (int j = 0; j < N; j++)
	{
		cin >> v[j];
		cin >> w[j];
	}

	for (int i = 0; i <= W ; i++)
	{
		for (int j = 0; j <= N; j++)
		{

		DP[j][i] = 0;
	}
}


	for (int i = 1; i <= N; i++)
	{
		for (int j = 0; j <= W; j++)
		{
			if (j < w[i-1]) {//??????????????????????\?(????????¶???)
				DP[i][j] = DP[i - 1][j];

			}
			else	if (DP[i - 1][j] > DP[i][j - w[i - 1]] + v[i-1])//???:???????¶????
			{
				DP[i][j] = DP[i - 1][j];
			
			}
			else
			{
				DP[i][j] = DP[i][j-w[i-1]] + v[i-1];//DP[i][j] ?????????????????´DP[i][j-w[i-1]],i?????????N????????§v[i-1]
			
			}

		}
	}



	



cout << DP[N][W] << endl;

return 0;
}

Measured memory_bytes: 7012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

const long long MAX = 2e5+100;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dp[1010][1010];

ll powmod(ll a, ll x){
	if(x == 0){return 1;}
	
	ll r = powmod(a, x/2);
	if(x%2){
		return ((r*r)%MOD)*a%MOD;
	}
	else{
		return r*r%MOD;
	}
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	COMinit();
	ll n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	
	//print(powmod(4, 1))
	memset(dp, 0, sizeof(dp));
	dp[a-1][0] = 1;
	rep(i, a, b){
		rep(k, 0, n){
			dp[i][k] += dp[i-1][k];
			dp[i][k] %=MOD;
		}
		
		for(ll j = c; j <= d && i*j <= n; j++){
			rep(k, 0, n){
				if(k+i*j <= n){
					ll tmp = COM(n-k, i*j)*fac[i*j]%MOD;
					tmp *= finv[j];
					tmp %= MOD;
					tmp *= powmod(finv[i], j);
					tmp %= MOD;
					//if(i == 2 && j == 2 && k == 0){print(tmp)}
					
					dp[i][k+i*j] += tmp*dp[i-1][k];
					dp[i][k+i*j] %= MOD;
				}
			}
			//print(tmp)
		}
	}
	//rep(i, a-1, b){rep(j, 0, n){cout << dp[i][j] << " ";}cout << endl;}
	
	print(dp[b][n])
	return 0;
}

Measured memory_bytes: 12928
from itertools import accumulate
N, Q = map(int, input().split())
S = "?" + input()
query = (tuple(map(int, input().split())) for _ in range(Q))

cnt = [0] * (N+1)
for i in range(N):
    if S[i] + S[i + 1] == "AC":
        cnt[i + 1] += 1

cnt = tuple(accumulate(cnt))

ans = (cnt[r] - cnt[l] for l, r in query)
print(*ans, sep="\n")


Measured memory_bytes: 12916
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int inf = 2e9;
#define MAXN 100005
int c[MAXN][4];
int dp[MAXN][4],used[MAXN][4];
int n;
int solve(int pos, int past){
	if(pos > n){
		return 0;
	}
	if(used[pos][past]) return dp[pos][past];
	used[pos][past] = 1;
	int ans = -1;
	for(int opc = 1; opc <=3; opc++){
		if(opc == past)continue;
		ans = max(ans, solve(pos+1, opc) + c[pos][opc]);
	}
	return dp[pos][past] = ans;
}

int main(){__
	cin >> n;
	for(int i =1; i <=n; i++){
		for(int j =1; j <=3; j++){
			cin >> c[i][j];
		}
	}
	cout << solve(1,0) << endl;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){ _;
  int n,tmp;
  for(;;){
    cin>>n;
    if(n==0)return 0;
    multiset<int> s;
    REP(i,n){
      cin>>tmp;
      s.insert(tmp);
    }
    long long int sum=0;
    for(int i:s){
      sum+=i;
    }
    sum-=*(s.begin());
    sum-=*(s.rbegin());
    cout<<sum/(s.size()-2)<<endl;
  }
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define int long long

#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##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
inline void Yes (bool condition) { if(condition) { cout << "Yes" << endl; } else { cout << "No" << endl;} }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
signed main(){
	int n,k;
	cin>>n>>k;
	if((n-2)*(n-1)/2<k)cout<<-1<<endl;
	else{
		cout<<(n-1)*n/2-k<<endl;
		for(int i=2;i<=n;i++){
			cout<<1<<" "<<i<<endl;
		}
		int l=(n-1)*(n-2)/2-k;
		for(int i=2;i<=n;i++){
			if(l==0)break;
			for(int j=i+1;j<=n;j++){
				cout<<i<<" "<<j<<endl;
				l--;
				if(l==0)break;
			}
		}
	}
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl

typedef pair<int, int> P;
typedef long long ll;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, p; cin>>n>>p;
    ll ans = 1;
    if (n ==1) ans = p;
    else { 
        for (int j = 1; pow(j,n)<=p; j++){
            ll testnum = pow(j,n);
            if(p%testnum == 0){
                ans = j;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
#define MAX  1000000000
#define ll long long int

int main()
{
	int n;
	int bit = 1;
	cin >> n;

	while (bit <= n) {
		bit = bit * 2;
	}

	cout << bit / 2 << endl;

	return (0);
}

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

using namespace std;

int main(void) {
    string S;
    cin >> S;
    if(S == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (S == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
    return 0;
}

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

using namespace std;

const int N = 200000;

int n;
long long res;
int a[N + 1];
long long S[N + 1];

map<long long, int> mp;

int main() {
	scanf("%d", &n);
	mp[0] = 1;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		S[i] = S[i - 1] + a[i];
		res += mp[S[i]];
		mp[S[i]]++;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

int powmod(int x, int y, int mod)
{
    int res = 1;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

void solve()
{
}

int main()
{
    // freopen("filename.in","r",stdin);
    // freopen("filename.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    string s;
    cin >> s;
    ll tot = 0;
    for (auto x : s)
    {
        tot += (x - '0');
    }

    if (tot % 9 == 0)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}

Measured memory_bytes: 3716
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
    int n;
    char s[10010];
    string S;
    cin >> n >> S;
    rep(i,S.size()){
        s[i] = S[i];
        int x = s[i] - 'A';
        x = (x+n)%26;
        char ans = 'A' + x;
        cout << ans;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
alise=0
bob=0
a_list=list(map(int,input().split()))
a_sort=sorted(a_list)
for i in range(N,0,-2):
    alise+=a_sort[i-1]
for i in range(N-1,0,-2):
    bob+=a_sort[i-1]
print(alise-bob)


Measured memory_bytes: 38256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int ans;
	int f=0;
	for(int i=0;i<s.length()-2;i++){
		int p=0;
		for(int j=i;j<i+3;j++){
			p=p*10+s[j]-'0';
		}
		if(f==0){
			ans=fabs(p-753);
			f=1;
		}
		else{
			if(fabs(p-753)<ans)
				ans=fabs(p-753);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int x, k, d;
// main solution goes here:
void execute(int test_number)
{
    cin>>x>>k>>d;
    x = abs(x);
    int q = x/d, r = x%d;
    if (q>=k) {
        cout<<x - k*d;
    } else if ((q+k)%2==0) {
        cout<<r;
    } else {
        cout<<d-r;
    }
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

Measured memory_bytes: 3612
h,w = map(int,input().split())
a = [input() for _ in range(h)]

cnt = 0
for x in range(h):
    for y in range(w):
        cnt += (a[x][y]=='#')
if(cnt > h+w-1):
    print('Impossible')
    exit()


x,y = 0,0
while(x+y<h+w-2):
    dx,dy=0,0

    if(x!=h-1):
        if(a[x+1][y]=='#'):
            dx = 1
    if(y!=w-1):
        if(a[x][y+1]=='#'):
            dy = 1
    if(dx+dy!=1):
        print('Impossible')
        exit()

    x += dx
    y += dy

print('Possible')


Measured memory_bytes: 38256
import java.util.Scanner;
class Main {
 public static void main(String[] args){
 
  Scanner scan = new Scanner(System.in);
  
  int x= scan.nextInt(),h=x/3600,m,s;
  x%=3600;
  m=x/60;
  x%=60; 
  s=x;
 
  System.out.println(h+":"+m+":"+s);
 }
}

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

using namespace std;

int main() {
    int h, w;
    vector<vector<int>> in, res;
    cin >> h >> w;

    in.resize(h);
    for (int i = 0; i < h; i++) {
        in[i].resize(w);
        for (int j = 0; j < w; j++) {
            cin >> in[i][j];
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w - 1; j++) {
            if (in[i][j] % 2 == 1) {
                in[i][j] -= 1;
                in[i][j + 1] += 1;
                res.push_back({i, j, i, j + 1});
            }
        }
    }

    for (int i = 0; i < h - 1; i++) {
        if (in[i][w-1] % 2 == 1) {
            in[i][w-1] -= 1;
            in[i+1][w-1] += 1;
            res.push_back({i, w-1, i+1, w-1});
        }
    }

    cout << res.size() << "\n";
    for (int i = 0; i < res.size(); i++) {
        cout << res[i][0] + 1 << " " << res[i][1] + 1 << " " << res[i][2] + 1 << " " << res[i][3] + 1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 9904
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()


int main()
{
	ll d, g;
	cin >> d >> g;

	vector<pair<ll, ll>> p(d);
	for (int i = 0; i < d; i++)
	{
		ll a, b;
		cin >> a >> b;

		p.at(i).first = a;
		p.at(i).second = b;
	}

	ll res = inf;
	for (int bit = 0; bit < (1 << d); bit++)
	{
		ull s = 0;
		ll cnt = 0;
		for (int i = 0; i < d; i++)
		{
			if (bit & (1 << i))
			{
				cnt += p.at(i).first;
				s += 100 * (i + 1) * p.at(i).first + p.at(i).second;
			}
		}

		if (s >= g)
		{
			res = min(res, cnt);
		}
		else
		{
			for (int i = d - 1; i >= 0; i--)
			{
				if (bit & (1 << i))
				{
					continue;
				}
				else
				{
					for (int j = 0; j < p.at(i).first; j++)
					{
						if (s >= g)
						{
							break;
						}
						s += 100 * (i + 1);
						cnt++;
					}
				}
			}
			res = min(res, cnt);
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<ll> a(n);
  bool win = false;
  rep(i,n) {
    cin >> a[i];
    if (a[i] % 2 == 1) win = true;
  }
  cout << (win ? "first" : "second") << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    string X;
    cin >> N >> X;

    reverse(X.begin(), X.end());
    vector<int> cnt(N + 5);
    cnt[0] = 0;
    for (int i = 1; i < N + 5; ++i) {
        int nxt = i % __builtin_popcount(i);
        cnt[i] = cnt[nxt] + 1;
    }

    int pcnt = 0;
    for (int i = 0; i < N; ++i)
        pcnt += (X[i] == '1');

    static ll modx[2];
    vector<vector<ll>> a(N + 5, vector<ll>(2));
    {
        a[0][0] = a[0][1] = 1;
        for (int i = 0; i < N; ++i) {
            if (X[i] == '1') {
                if (pcnt - 1)
                    (modx[0] += a[i][0]) %= (pcnt - 1);
                (modx[1] += a[i][1]) %= (pcnt + 1);
            }
            if (pcnt - 1)
                a[i + 1][0] = (a[i][0] * 2) % (pcnt - 1);
            a[i + 1][1] = (a[i][1] * 2) % (pcnt + 1);
        }
    }

    for (int i = N - 1; i >= 0; --i) {
        if (pcnt == 1 && X[i] == '1') {
            cout << 0 << '\n';
            continue;
        }

        int tmp = 0;
        if (X[i] == '1') {
            tmp = (modx[0] - a[i][0]) % (pcnt - 1);
            if (tmp < 0)
                tmp += (pcnt - 1);
        } else
            tmp = (modx[1] + a[i][1]) % (pcnt + 1);

        if (X[i] == '1')
            cout << cnt[tmp] + 1 << '\n';
        else
            cout << cnt[tmp] + 1 << '\n';
    }

    return 0;
}


Measured memory_bytes: 15232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int h, w;
int f(int i, int j) {
    return j + i * w + 1;
}
template <typename T>
vector<T> Dijkstra(int s, vector<vector<pair<int, T>>> &g) {
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>>
        que;
    int n = sz(g);
    vector<T> d(n);
    rep(i, n) d[i] = INF;
    d[s] = 0;
    que.push(make_pair(0, s));
    while (!que.empty()) {
        pair<T, int> p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (auto e : g[v]) {
            if (chmin(d[e.first], d[v] + e.second)) {
                que.push(make_pair(d[e.first], e.first));
            }
        }
    }
    return d;
}
int main() {
    cin >> h >> w;
    int n = h * w;
    auto v = make_vec<char>(h, w);
    rep(i, h) rep(j, w) cin >> v[i][j];
    vector<vector<pair<int, int>>> g(n + 1);
    rep(i, h) rep(j, w) {
        if (i + 1 < h) {
            if (v[i][j] == '.' && v[i + 1][j] == '#') {
                g[f(i, j)].emplace_back(f(i + 1, j), 1);
            } else {
                g[f(i, j)].emplace_back(f(i + 1, j), 0);
            }
        }
        if (j + 1 < w) {
            if (v[i][j] == '.' && v[i][j + 1] == '#') {
                g[f(i, j)].emplace_back(f(i, j + 1), 1);
            } else {
                g[f(i, j)].emplace_back(f(i, j + 1), 0);
            }
        }
    }
    if (v[0][0] == '#') {
        g[0].emplace_back(1, 1);
    } else {
        g[0].emplace_back(1, 0);
    }
    auto d = Dijkstra(0, g);
    cout << d[n] << endl;
}


Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var direction = 1;
            var ans = new int[s.Length];

            var count = 1;

            for (int i = 0; i < s.Length - 1; i++)
            {
                if (direction == 1)
                {
                    if (s[i + 1] == 'R')
                    {
                        count++;
                    }
                    if (s[i + 1] == 'L')
                    {
                        if (count % 2 == 0)
                        {
                            ans[i] += count / 2;
                            ans[i + 1] += count / 2;
                        }
                        else
                        {
                            ans[i] += count / 2 + 1;
                            ans[i + 1] += count / 2;
                        }
                        count = 1;
                        direction *= -1;
                    }
                }
                else if (direction == -1)
                {
                    if (s[i + 1] == 'L')
                    {
                        count++;
                    }
                    if (s[i + 1] == 'R')
                    {
                        if (count % 2 == 0)
                        {
                            ans[i - count] += count / 2;
                            ans[i - count + 1] += count / 2;
                        }
                        else
                        {
                            ans[i - count] += count / 2;
                            ans[i - count + 1] += count / 2 + 1;
                        }
                        count = 1;
                        direction *= -1;
                    }
                }
            }

            if (count % 2 == 0)
            {
                ans[s.Length - count - 1] += count / 2;
                ans[s.Length - count] += count / 2;
            }
            else
            {
                ans[s.Length - count - 1] += count / 2;
                ans[s.Length - count] += count / 2 + 1;
            }
            for(int i = 0; i < s.Length - 1; i++)
            {
                Console.Write("{0} ", ans[i]);
            }
            Console.Write(ans[s.Length - 1]);
        }
    }
}

Measured memory_bytes: 29064
use std::str::FromStr;
use std::collections::HashMap;

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

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let v : Vec<usize> = get_vec();
    let n = v[0];
    let k = v[1];
    let w : Vec<i32> = get_vec();
    let mut score : HashMap<char,i32> = HashMap::new();
    score.insert('s', w[0]);
    score.insert('p', w[1]);
    score.insert('r', w[2]);
    let rsp : String = get_one();
    let rsp_i : Vec<char> = rsp.chars().collect();
    let mut ans = 0;
    for i in 0..k {
        let mut j = 0;
        let mut prev = rsp_i[i];
        let mut same_cnt = 0;
        while j*k+i < n {
            //println!("{} {} {}", i, j, j*k+i);
            let cur = rsp_i[j*k+i];
            //println!("{} {} {} {}", prev, cur, same_cnt, ans);
            if cur == prev {
                same_cnt += 1;
            }
            else {
                ans += ((same_cnt+1) / 2) * score[&prev];
                same_cnt = 1;
            }
            prev = cur;
            j+=1;
        }
        ans += ((same_cnt + 1) / 2) * score[&prev];
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
using System;

class Program {
  static void Main(string[] args) {
    string s = Console.ReadLine();
    for (int i=0; i<s.Length/2; i++) {
      if (s[i] != s[s.Length-1-i]) {
        Console.WriteLine("No");
        return;
      }
    }
    Console.WriteLine("Yes");
  }
}

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

void main_()
{
    ll N, M;
    cin >> N >> M;

    bitset<(ll)1e6 + 1> broken;
    for (ll i = 0; i < M; ++i) {
        ll a;
        cin >> a;
        broken.set(a);
    }

    array<ll, 2> dp;
    dp[0] = 1;
    dp[1] = broken[1] ? 0 : 1;
    for (int i = 2; i <= N; ++i) {
        auto dp_n = broken[i] ? 0 : dp[0] + dp[1];
        dp_n %= (ll)1e9 + 7;
        dp[0] = dp[1];
        dp[1] = dp_n;
    }

    cout << dp[1] << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
int main(){    
double x1, y1, x2, y2, distance;    
scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);    
distance=sqrt((pow(x2-x1, 2)+pow(y2-y1, 2)));    
printf("%f\n", distance);    
return 0;}


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

int main() {
    string s;
    cin >> s;
    int res = 114514;
    for(int i = 0;i < s.size() - 2;i++) {
        int x = (s[i] - '0')*100;
        int y = (s[i + 1] - '0')*10;
        int z = s[i + 2] - '0';
        res = min(abs(x + y + z - 753), res);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int arr=2e6+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;

///---program start---///

main()
{
    #ifdef Barik
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    fast;

    int h,w,n;
    cin>>h>>w>>n;
    int x,y;
    cin>>x>>y;
    vector<pair<int,int>> vecx(0); /// pair(who(0 || 1),where(-1 || +1))
    vector<pair<int,int>> vecy(0); /// pair(who(0 || 1),where(-1 || +1))
    string s,t;
    cin>>s>>t;
    for (int i=0;i<n;i++){
        int who;

        who=0;
        if (s[i]=='L'){
            vecy.pb(mp(who,-1));
        }
        if (s[i]=='R'){
            vecy.pb(mp(who,+1));
        }
        if (s[i]=='U'){
            vecx.pb(mp(who,-1));
        }
        if (s[i]=='D'){
            vecx.pb(mp(who,+1));
        }

        who=1;
        if (t[i]=='L'){
            vecy.pb(mp(who,-1));
        }
        if (t[i]=='R'){
            vecy.pb(mp(who,+1));
        }
        if (t[i]=='U'){
            vecx.pb(mp(who,-1));
        }
        if (t[i]=='D'){
            vecx.pb(mp(who,+1));
        }
    }
    auto solve=[&](const vector<pii>& vec,int N,int s)
    {
//        cout<<"solve :: "<<"\n";
//        cout<<"N s :: "<<N<<" "<<s<<"\n";
//        for (auto i:vec){
//            cout<<i.fir<<" "<<i.sec<<"\n";
//        }
        int cur;

        /// if +
            cur=s;
            for (auto i:vec){
                if (i.fir==0&&i.sec==+1){
                    cur++;
                }
                if (i.fir==1&&i.sec==-1&&cur>1){
                    cur--;
                }
                if (cur>N){
                    return 1;
                }
            }

        /// if -
            cur=s;
            for (auto i:vec){
                if (i.fir==0&&i.sec==-1){
                    cur--;
                }
                if (i.fir==1&&i.sec==+1&&cur<N){
                    cur++;
                }
                if (cur<=0){
                    return 1;
                }
            }

        return 0;
    };
    if (solve(vecx,h,x)||solve(vecy,w,y)){
        cout<<"NO"<<"\n";
    }
    else{
        cout<<"YES"<<"\n";
    }
}


Measured memory_bytes: 10748
#include <bits/stdc++.h>
#define ll long long
#define M 1000000007 
#define MM 998244353
#define PI 3.14159265 
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;

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

	long long int dp[n]; 

	for (int i = 0; i<n ; i++)
	{
		dp[i] = M;
	}

	dp[0] = 0;

	dp[1] = abs(h[1] - h[0]);

	for (int i = 2; i < n; i++)
	{
		for (int j = k; j > 0; j--)
		{
			if (i - j >= 0)
			{
				dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
			}
		}
	}

	cout << dp[n-1];
	
  	return 0;
}

Measured memory_bytes: 4728
N = int(input())

kisu = 0
gusu = 0

for i in range(1,N+1):
  if i % 2 == 1:
    kisu += 1
  else:
    gusu += 1
    
kakuritsu = kisu / (gusu + kisu)

print('{:.10f}'.format(kakuritsu))



Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
class Dijkstra{
    private:
        struct edge{
            ll to,cost;
        };
        vector<vector<edge>> G;
        vector<ll> d;
        ll siz;
    public:
        Dijkstra(int n){
            G.resize(n);
            siz = n;
        }
        void add_edge(int from,int to,int cost){
            G[from].push_back(edge{to,cost});
        }
        vector<ll> dijkstra(int s){
            priority_queue<P,vector<P>,greater<P>> q;
            d.assign(siz,INF);
            d[s] = 0;
            q.push(P(0,s));
            while(!q.empty()){
                P p = q.top();q.pop();
                int v = p.second;
                if (d[v] < p.first) continue;
                for(edge &e:G[v]){
                    if (chmin(d[e.to],d[v]+e.cost)){
                        q.push(P(d[e.to],e.to));
                    }
                }
            }
            return d;
        }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    Dijkstra g(n);
    ll a,b,c;
    rep(i,n-1){
        cin >> a >> b >> c;
        a--;
        b--;
        g.add_edge(a,b,c);
        g.add_edge(b,a,c);
    }
    ll q,k;
    cin >> q >> k;
    k--;
    vector<ll> d = g.dijkstra(k);
    ll x,y;
    rep(i,q){
        cin >> x >> y;
        x--;
        y--;
        PRINT(d[x]+d[y]);
    }
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;

int main() {
	int result = 0;
	int N = 0;
	cin >> N;

	vector<int> B(N, 0);
	vector<int> Ans(N, 0);

	for (int i = 0; i < N - 1; i++) {
		cin >> B[i];
	}

	Ans[0] = B[0];
	for (int i = 1; i < N - 1; i++) {
		Ans[i] = min(B[i-1], B[i]);
	}
	Ans[N-1] = B[N-2];

 	cout << accumulate(Ans.begin(), Ans.end(), 0) << endl;
	return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

struct train{
  string s,t;
};

struct Comp{
  bool operator()(pair<string,string> a,pair<string,string> b)const{
    return a.fi < b.fi;
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  ll n;
  while(cin >> n && n){
    vector<train> ans;
    vector<pair<string,string>> v(n);
    rep(i,n){
      cin >> v[i].fi >> v[i].se;
    }
    sort(all(v),Comp());
    ans.push_back({v[0].fi,v[0].se});
    REP(i,1,n){
      bool f = false;
      rep(j,ans.size()){
        if(ans[j].t <= v[i].fi){
          ans[j] = {v[i].fi,v[i].se};
          f = true;
          break;
        }
      }
      if(!f) ans.push_back({v[i].fi,v[i].se});
    }
    cout << ans.size() << endl;
  }
  return 0;
}

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

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

    if(((a+b)==c) || ((b+c)==a) || ((a+c)==b))  cout << "Yes\n";
    else    cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
                int seven[1000001];
                int K,i;

                scanf("%d",&K);

                if(K % 2 == 0){
                        printf("-1");
                        return 0;
                }
                seven[1] = 7 % K;

                for(i = 2; i <= K; i++){
                        seven[i] = (seven[i-1] * 10 + 7) % K;
                        if(seven[i]==0)break;
                }

                for (i = 1;i <= K ; i++){
                        if(seven[i]==0){
                                printf("%d",i);
                                return 0;
                        }
                }
                /* if(i<=K)printf("%d",i); */
                /* else printf("-1"); */
                printf("-1");
                return 0;
}

Measured memory_bytes: 5568
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    long long n, h;
    cin >> n >> h;

    vector<pair<long long, long long>> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data[i].second >> data[i].first;
    }
    sort(data.begin(), data.end(), greater<pair<long long, long long>>());

    long long ans = 100000000000000;
    long long b_accum = 0;
    long long a_max = 0;
    for (long long i = 1; i <= n; i++) {
        b_accum += data[i - 1].first;
        a_max = max(a_max, data[i - 1].second);
        long long rest = h - b_accum;
        if (rest <= 0) {
            ans = min(ans, i);
            continue;
        }
        long long kaisu = rest / a_max;
        if (rest % a_max)
            kaisu++;
        ans = min(ans, i + kaisu);
    }

    cout << ans << endl;


    return 0;
}

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

int main(){
  string S,T;
  cin>>S>>T;
  string ans;
  ans="Yes";
  for(int i=0; i<S.size(); i++){
    if(S[i]!=T[i]){ ans="No"; break;}
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(){
	int a[5],ned[5],mxned=0,sum=0;
	for(int i=0;i<5;i++){
		cin>>a[i];
		ned[i]=10-a[i]%10;
		if(ned[i]==10){
			continue;
		}
		mxned=max(ned[i],mxned);
	}
	for(int i=0;i<5;i++){
		if(ned[i]==mxned ){
			sum+=a[i];
			mxned=-1;
			continue;
		}
		else if(ned[i]==10){
			sum+=a[i];
		}
		else{
			sum+=a[i];
			sum+=ned[i];
		}
	}
	cout<<sum;
}
//FELAROSSO 2019

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1L<<32;
ll fac[MAX], finv[MAX], inv[MAX];
//ワーシャルフロイド法、o(v^3)
int main(){
  ll v,e,ans=0;cin>>v>>e;
  ll g[10][10];
  rep(i,0,10){
    rep(j,0,10){
      cin>>g[i][j];
    }
  }
  bool ok=true;
  rep(k,0,10){
    rep(i,0,10){
      if(g[i][k]==MOD)continue;
      rep(j,0,10){
        if(g[k][j]==MOD)continue;
        g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
      }
      if(g[i][i]<0)ok=false;//負の閉回路の検出
    }
  }
  rep(i,0,v){
    rep(j,0,e){
      ll a;
      cin>>a;
      if(a==-1)continue;
      ans+=g[a][1];
    }
  }
  out(ans);
  
}




Measured memory_bytes: 256