akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <iterator>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <utility>
#include <functional>
#include <stack>
#include <deque>
#include <sstream>
using namespace std;

#define ll long long
#define mod 1000000007
#define ld long double
#define infinity (ll)1e18+1
#define PI 3.14159265358979

#define pdd pair<ld,ld>
#define pll pair<ll, ll>
#define pii pair<int,int>

#define MP make_pair
#define SZ size()
#define PB push_back

#define vi vector<int>//ll
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define vch vector<char>
#define vb vector<bool>
#define vld vector<ld>
#define vs vector<string>

#define FOR(i,a,b) for(ll i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(ll i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define ALL(a) a.begin(), a.end()
#define X first
#define Y second
#define MAXN 100001

ll power(ll n, ll to, ll modulo = mod)
{
	if (to == 0) return 1;
	if (to == 1) return n%modulo;
	int exp = 1;
	ll ans = n;
	while (2 * exp <= to)
	{
		ans *= ans;
		ans %= modulo;
		exp *= 2;
	}
	return ((ans*power(n, to - exp, modulo)) % modulo);
}

bool check(string s)
{
	FOR(i, 1, s.size())
		if (s[i] != s[0])
			return false;
	return true;
}

int toOne(string s, char top)
{
	int ans = 0;
	while (!check(s))
	{
		string ns;
		FOR(i, 0, s.size() - 1)
		{
			if (s[i] == top || s[i + 1] == top)
				ns += top;
			else
				ns += s[i];
		}

		s = ns;
		ans++;
	}

	return ans;
}

int solve(string s)
{
	int best = 1000;
	FOR(i, 0, s.size())
		best = min(best, toOne(s, s[i]));
	return best;
}

int main()
{
	srand(time(NULL));
	clock_t startTime = clock();
	ios_base::sync_with_stdio(false), cin.tie(0);
	//ifstream in("In.txt");

	string s;
	cin >> s;

	cout << solve(s);
	return 0;
}
//don't forget about MAXN

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> os;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> os_pair;

ll power(ll x, ll n) {ll res = 1; while (n > 0) {if (n % 2 == 1) {res = res * x;} x = x * x; n = n / 2;} return res;}
ll powm(ll a, ll b) {ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod; a = a * a % mod;} return res;}

//cout<< fixed << setprecision(10)
ll m, n, k, i, j;
ll pa[200005];
ll pb[200005];
int foo(ll x)
{
	ll t = 0;
	for (i = 0; i <= min(x, n); i++)
	{
		if (x - i > m)
		{
			continue;
		}
		t = pa[i] + pb[x - i];
		if (t <= k)
		{
			return 1;
		}

	}
	return 0;
}

int main() {

	fast;

	cin >> n >> m >> k;
	ll a[n + 1];
	ll b[m + 1];

	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	for (i = 1; i <= m; i++)
	{
		cin >> b[i];
	}
	mem(pa, 0);
	mem(pb, 0);
	for (i = 1; i <= n; i++)
	{
		pa[i] = pa[i - 1] + a[i];
	}
	for (i = 1; i <= m; i++)
	{
		pb[i] = pb[i - 1] + b[i];
	}
	ll lr = 0, r = n + m;
	while (r >= lr)
	{
		ll mid = (lr + r) / 2;
		if (foo(mid))
		{
			lr = mid + 1;
		}
		else
		{
			r = mid - 1;
		}
	}
	cout << r;


}


Measured memory_bytes: 9828
#include<stdio.h>
#include<stdlib.h>
int main() {
	int n, i, j, a[11111],b[11111], m = 0, g[111], t = 0;
	scanf("%d", &n);
	if (n % 2 == 0) {
		for (i = 1; i <= n / 2; i++) {
			g[i] = t;
			g[n - i + 1] = t;
			t++;
		}
		for (i = 1; i <= n; i++) {
			for (j = i + 1; j <= n; j++) {
				if (g[i] != g[j]) {
					a[m] = i;
					b[m] = j;
					m++;
				}
			}
		}
	}
	else {
		for (i = 1; i <= n / 2; i++) {
			g[i] = t;
			g[n - i] = t;
			t++;
		}
		g[n] = t;
		for (i = 1; i <= n; i++) {
			for (j = i + 1; j <= n; j++) {
				if (g[i] != g[j]) {
					a[m] = i;
					b[m] = j;
					m++;
				}
			}
		}
	}
	printf("%d\n", m);
	for (i = 0; i < m; i++)
		printf("%d %d\n", a[i], b[i]);
		return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  
  string s,t;
  cin >> s >> t;
  t.pp();
  if(s==t)Yes
    No
	return 0;
}

Measured memory_bytes: 3644
N = int(input())
e = [0] * (N+1)
for i in range(2, N+1):
    cur = i
    for j in range(2, i+1):
        while cur%j == 0:
            e[j] += 1
            cur //= j

def num(m):
    return len(list(filter(lambda x:x >= m-1, e)))

print (num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) + num(5) * (num(5) - 1) * (num(3) - 2)//2)

Measured memory_bytes: 3064
#include <cstdio>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
int main() {
	int D;
	int T;
	int S;
	scanf("%d", &D);
	scanf("%d", &T);
	scanf("%d", &S);
    if(D <= T*S){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}


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

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	// freopen("in.txt", "r", stdin);
	int n;
	cin >> n;
	string s;
	cin >> s;
	char cur = s[0];
	int ans = 1;
	for(int i=1; i<s.length(); i++){
		if(s[i] != cur){
			cur = s[i];
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<int> v(3);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    if(v.size() == 2) puts("Yes");
    else puts("No");
    return 0;
}

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

using namespace std;

    struct data_t {
      string S;
      int P;
      int number;
      bool operator<( const data_t& right ) const {
      return S == right.S ? P > right.P : S < right.S;
      }
    };

int main() {
    int n;
    cin >> n;
    vector<data_t> data_array(n);

    vector<pair <char,int>>SP(n);
	for(int i=0;i<n;i++){
	cin >> data_array[i].S >> data_array[i].P;
    data_array[i].number=i+1;
	}
  sort(data_array.begin(), data_array.end());
  for(int i=0;i<n;i++){
    cout << data_array[i].number << endl;
  }
  
}

Measured memory_bytes: 256
using System.Collections.Generic;
using static System.Console;

class Program
{
    static void Main()
    {
        var s = NextString();
        var ans = new List<char>();

        foreach (char v in s)
        {
            if (v == 'B')
            {
                if (ans.Count != 0)
                    ans.RemoveAt(ans.Count - 1);
            }
            else
                ans.Add(v);
        }
        WriteLine(string.Join("", ans));
    }

    static string NextString()
    {
        var result = new List<char>();
        while (true)
        {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	int a, b, c, k;
	cin >> a >> b >> c >> k;

	int sum;
	sum = min(k, a);
	k -= min(k, a);

	if (k > 0) {
		k -= min(k, b);

		if (k > 0) {
			sum -= min(k, c);
			k -= min(k, c);
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint MOD = 998244353;

lint modpow(lint m, lint n){
  if(n == 0) return 1;
  else if(n % 2 == 0) return modpow(m * m % MOD, n/2);
  else{
    return modpow(m, n - 1) * m % MOD;
  }
}

signed main(){
  lint N; cin >> N;
  vector<lint> a(N), num(N);
  for(lint i = 0; i < N; i++) {cin >> a[i]; num[a[i]]++;};
  if(a[0] != 0 || num[0] != 1){
    cout << 0 << endl;
    return 0;
  }
  lint ans = 1;
  for(lint i = 2; i < N; i++){
     ans *= modpow(num[i - 1], num[i]);
     ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main()
{
  string s, t;
  cin >> s >> t;
  
  string s2 = s + t;
    
    if(t == s + t[s.size()])
      printf("Yes");
  
   else
     printf("No");
}

int main()
{
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

Measured memory_bytes: 3692
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    vector<mint> dp(13, 0);
    dp[0] = 1;
    rep(i,n){
        vector<mint> ndp(13, 0);
        int val = (s[i] == '?' ? -1 : s[i] - '0');
        rep(j,13){
            if(val == -1){
                rep(k,10){
                    int nex = (j*10 + k) % 13;
                    ndp[nex] += dp[j];
                }
            }
            else{
                int nex = (j * 10 + val) % 13;
                ndp[nex] += dp[j];
            }
        }
        dp = move(ndp);
    }
    cout << dp[5].x << endl;
    return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  lvector D(n);rep(i,n) cin>>D[i];sort(ALL(D));
  ll ans=D[n/2]-D[n/2-1];
  print(ans);
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

string func(int a){
   string num;
   if(a<100)
      num+='0';
   else
      num+=to_string(a/100);
   if(a<10)
      num+='0';
   else
      num+=to_string(a/10%10);
   num+=to_string(a%10);
   return num;
}

int main(){
   int n;
   cin >> n;
   string s;
   cin >> s;
   int ans=0;
   for(int i=0;i<1000;i++){
      int ncnt=0;
      string now = func(i);
      // cout << now << endl;
      for( int j=0;j<s.size();j++){
         if(now[ncnt]==s[j])
            ncnt++;
         if(ncnt==3){
            ans++;
            break;
         }
      }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    string s; cin >> s;
    ll ans = 0;
    int ss = 0;
    int tt = 0;
    rep(i,s.size()){
        if(s[i]=='S'){
            ss++;
        }else{
            if(ss==0){
                ans++;
            }else{
                ss = max(0,ss-1);
            }
        }
    }


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


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll gcd(ll a, ll b)
{
    if(b==0)
        return a;
    else return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
    return a/gcd(a, b) * b;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll a, b;
    cin>>a>>b;
    cout<<lcm(a, b);
    
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=sum(b)

for i in range(n-1):
    if a[i+1] == a[i]+1:
        ans += c[a[i]-1]
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <set>
#include <fstream>
#include <cstring>
#include <climits>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long
#define mod 1000000007

int main() {

	int n;
	cin >> n;
	int ans[n];
	memset(ans, 0, sizeof(ans));
	for (int i = 1; i < n; ++i) {
		int x;
		cin >> x;
		ans[x - 1]++;
	}
	for (int i = 0; i < n; ++i)
		cout << ans[i] << '\n';

	return 0;
}

Measured memory_bytes: 4428
#include <iostream> 
using namespace std;
int main(){
    int n;cin>>n; 
    string s;cin>>s; 
    for(int i=0;i<(int)s.length();++i){
        if(i<n)cout<<s[i];else break;
    }
    if(n<s.length()) cout<<"...";
}

Measured memory_bytes: 3604
//package AtCoder;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
class Main {

	public static void solve() {
		long a = s.nextLong(), b = s.nextLong(), c = s.nextLong(), d = s.nextLong();
		out.println(Long.max(Long.max(a * c, a * d), Long.max(b * c, b * d)));
	}

	public static void main(String[] args) {
		new Thread(null, null, "Thread", 1 << 27) {
			public void run() {
				try {
					out = new PrintWriter(new BufferedOutputStream(System.out));
					s = new FastReader(System.in);
					solve();
					out.close();
				} catch (Exception e) {
					e.printStackTrace();
					System.exit(1);
				}
			}
		}.start();
	}

	public static PrintWriter out;
	public static FastReader s;

	public static class FastReader {

		private InputStream stream;
		private byte[] buf = new byte[4096];
		private int curChar, snumChars;

		public FastReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (snumChars == -1) {
				throw new InputMismatchException();
			}
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException E) {
					throw new InputMismatchException();
				}
			}
			if (snumChars <= 0) {
				return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int number = 0;
			do {
				number *= 10;
				number += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return number * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			long sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long number = 0;
			do {
				number *= 10L;
				number += (long) (c - '0');
				c = read();
			} while (!isSpaceChar(c));
			return number * sgn;
		}

		public int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextLong();
			}
			return arr;
		}

		public String next() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndofLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndofLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}

	
}


Measured memory_bytes: 32736
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int> pii32;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 2e5+10;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

set <pair<int,pii>> st;
int seg[3][maxn * 4], pos[3][maxn * 4];
int p[maxn];
int N;

void pull (int idx, int id) {
	if (seg[idx][id * 2 + 0] < seg[idx][id * 2 + 1])
		pos[idx][id] = pos[idx][id * 2 + 0];
	else
		pos[idx][id] = pos[idx][id * 2 + 1];
	seg[idx][id] = min(seg[idx][id * 2 + 0], seg[idx][id * 2 + 1]);
	return;
}

pii pull (pii x, pii y) {
	if (x.F < y.F)
		return x;
	else
		return y;
}

void build (int idx, int l = 0, int r = N, int id = 1) {
	if (r - l == 1) {
		seg[idx][id] = IN;
		pos[idx][id] = -1;
		if (idx == 2 || (idx == 0 && l % 2 == 0) || (idx == 1 && l % 2 == 1)) {
			seg[idx][id] = p[l];
			pos[idx][id] = l;
		}
		return;
	}
	int mid = (l + r) >> 1;
	build(idx, l, mid, id * 2 + 0);
	build(idx, mid, r, id * 2 + 1);
	pull(idx, id);
	return;
}

pii getmn (int idx, int st, int en, int l = 0, int r = N, int id = 1) {
	if (st >= r || en <= l)
		return MP( IN, -1 );
	if (st <= l && en >= r)
		return MP( seg[idx][id], pos[idx][id] );
	int mid = (l + r) >> 1;
	return pull(getmn(idx, st, en, l, mid, id * 2 + 0), getmn(idx, st, en, mid, r, id * 2 + 1));
}

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> p[i];
	build(0); build(1); build(2);
	st.insert( MP( getmn(0, 0, N - 1).F, MP( 0, N - 1 ) ) );
	while (sz(st)) {
		pair<int,pii> x = *st.begin();
		st.erase(x);
		int l, r, ps, f;
		l = x.S.F;
		r = x.S.S;
		ps = getmn(l % 2, l, r).S;
		f = getmn(1 - ps % 2, ps + 1, r + 1).S;
		if (ps - l > 1)
			st.insert( MP( getmn(l % 2, l, ps - 1).F, MP( l, ps - 1 ) ) );
		if (f - ps > 1)
			st.insert( MP( getmn(1 - ps % 2, ps + 1, f - 1).F, MP( ps + 1, f - 1 ) ) );
		if (r - f > 1)
			st.insert( MP( getmn(1 - f % 2, f + 1, r).F, MP( f + 1, r ) ) );
		cout << p[ps] << " " << p[f] << " ";
	} cout << "\n";
}


Measured memory_bytes: 22528
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

ll f(vector<ll> &a, ll b) {
  ll sum = 0;
  int len = a.size();
  REP(i, len) {
    sum += abs(a[i] - b);
  }
  //    cout << b << " " << sum << endl;                                                                 
  return sum;
}

int main() {
  int N; cin>>N;
  vector<ll> a(N);
  ll sum = 0;
  ll min_v = 1LL<<60;
  ll max_v = -min_v;
  ll ans = 1LL<<60;
  REP(i,N) {
    cin>>a[i];
    a[i] -= (ll)(i+1);
    min_v = min(min_v, a[i]);
    max_v = max(max_v, a[i]);
  }
  ll av_v = (max_v + min_v) /2LL;
  sort(a.begin(), a.end());
  int pos = lower_bound(a.begin(), a.end(), av_v) - a.begin();
  int d	= 500;
  for(int i = max(0, pos - d); i < min(N, pos+d+1); i++) {
    ll work = f(a, a[i]);
#ifdef DEBUG
    cout << i << "," << work << endl;
#endif
    ans = min(ans, work);
  }
#ifdef DEBUG
          cout <<  "Answer = ";
#endif
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N = INT()
	ab = [LIST() for _ in range(N-1)]

	graph = defaultdict(list)

	# edge = [[0]*N for _ in range(N)]
	edge = defaultdict(int)
	for a, b in ab:
		graph[a-1].append(b-1)
		graph[b-1].append(a-1)

	K = 0
	for v in graph.values():
		K = max(K, len(v))
	color = list(range(1, K+1))

	q = deque()
	q.append((0, None))

	while q:
		i, color_from = q.popleft()
		tmp = -1
		for node in graph[i]:
			str_ = "{},{}".format(i, node)
			if not edge[str_]:
				use_color = color[tmp]
				if use_color == color_from:
					use_color = color[tmp-1]
					tmp -= 1
				tmp -= 1
				edge[str_] = use_color
				edge["{},{}".format(node, i)] = use_color
				q.append((node, use_color))
	print(K)
	for a, b in ab:
		print(edge["{},{}".format(a-1, b-1)])


if __name__ == "__main__":
	main()


Measured memory_bytes: 122476
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

# def printA(A):
#     for i, n in enumerate(A):
#         print(n, end='')
#         if i != N-1:
#             print(' ', end='')
#     print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

while True:
    N = int(input())
    A = []

    if N == 0:
        break

    for i in range(N):
        A.append([int(x) for x in input().split()])

    for i in range(N):
        A[i].append(sum(A[i]))

    B = []

    for i in range(N+1):
        temp = 0
        for j in range(N):
            temp += A[j][i]
        B.append(temp)
    A.append(B)

    for row in A:
        for i in row:
            s = str(i)
            print(s.rjust(5, ' '), end='')
        print()
        pass




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

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    int time[101];
    memset(time,0,sizeof(time));
    for (int i=A+1; i<=B; i++) {
        time[i]++;
    }
    for (int i=C+1; i<=D; i++) {
        time[i]++;
    }
    int ans=0;
    for (int i=0; i<101; i++) {
        ans+=(time[i]==2?1:0);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

vector<vector<ll> > memo(11,vector<ll>(11,INF));
int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    ll N,M; cin>>N>>M;
    ll ans=0;
    vector<vector<char> > field_A(N,vector<char>(N));
    vector<vector<char> > field_B(M,vector<char>(M));
    rep(i,N){
        string tmp; cin>>tmp;
        rep(j,N) field_A[i][j]=tmp[j];
    }
    rep(i,M){
        string tmp; cin>>tmp;
        rep(j,M) field_B[i][j]=tmp[j];
    }
    
    //(i,j)
    rep(i,N-M+1)rep(j,N-M+1){
        bool c=true;
        rep(k,M)rep(l,M){
            if(field_B[k][l]!=field_A[i+k][j+l]) c=false;
        }
        
        if(c){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}



Measured memory_bytes: 3632
# -*- coding:utf-8

A = []
while True:
    a,b = map(int,input().split())
    if a == 0 and b == 0:
        break
    else:
        if a > b:
            a,b = b,a
        else:
            pass
        A.append((a,b))


for i in range(len(A)):
    a,b = A[i]
    print(a,b)



Measured memory_bytes: 6176
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30
#define MAX_P 1000000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;


int p[MAX_P], n, sum[MAX_P];

int main(){
  p[0] = p[1] = 1;
  REP(i, 2, MAX_P){
    sum[i] = sum[i-1];
    if(!p[i]){
      sum[i]++;
      for(int j = i+i; j < MAX_P; j += i) p[j] = 1;
    }
  }
  //  rep(i, 100) printf("%d ", sum[i]); puts("");

  while(scanf("%d", &n) && n){
    int ip, m, res = 0;
    rep(i, n){
      scanf("%d%d", &ip, &m);
      //      int c = 0;
      //      REP(j, (ip-m)>0?(ip-m):0, (ip+m+1)>MAX_P?MAX_P:(ip+m+1)) if(!p[j]) c++;
      int top = (ip+m)>MAX_P-1?MAX_P-1:(ip+m);
      int under = (ip-m-1)>0?(ip-m-1):0;
      int c = sum[top] - sum[under];
      if(c) res += c-1;
      else res--;
    }
    printf("%d\n", res);
  }
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  double sum = 0;
  double a;
  string b;
  double c = 380000;
  for(int i=0;i<N;++i){
    cin >> a >> b;
    if(b=="BTC"){
      sum += a*c;
    }
    else{
      sum += a;
    }
  }
  cout << sum <<endl;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = str(input())
LR = [list(map(int, input().split())) for _ in range(Q)]
# 累積和をもとめておく
count = [0]*(N)
for i in range(1, N):
    if S[i]=='C' and S[i-1]=='A':
        count[i] = count[i-1] + 1
    else:
        count[i] = count[i-1]
for l, r in LR:
    print(count[r-1]-count[l-1])

Measured memory_bytes: 30664
import math

K = int(input())

sum = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):

            if i==j and j==k and k==i:
                sum += i

            else:
                ans = i
                ans = math.gcd(ans,j)
                ans = math.gcd(ans,k)

                if i!=j and j!=k and k!=i:
                    sum += 6*ans
                else:
                    sum += 3*ans
print(sum)

Measured memory_bytes: 9204
using System.Collections.Generic;
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = Array.ConvertAll(line, long.Parse);
            var k = (n+2) /2;
            var d = new Dictionary<long, int>();
            for (int i = 0; i < n; i++)
                if (d.ContainsKey(a[i])) d[a[i]]++;
                else d[a[i]] = 1;
            var dm = d.Values.Max();
            var ans = d.First(x => x.Value == dm).Key;
            if (dm >= k) Console.WriteLine(ans);
            else Console.WriteLine("NO COLOR");
        }
    }
}

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



int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int x,y;
    cin>>x>>y;

    cout<<x+y/2<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

template<typename T>
struct Matrix{
public:
    int Hei, Wid;
    vector<vector<T>> Mat;
    Matrix(vector<vector<T>> v) : Hei((int)v.size()), Wid((int)v[0].size()), Mat(v) {}
    Matrix(int h, int w) : Hei(h), Wid(w), Mat(vector<vector<T>>(h, vector<T>(w))) {}
    inline vector<T>& operator [] (int i){ return Mat[i]; }
    inline Matrix operator + (Matrix Mat2){ Matrix res = *this; return res += Mat2; }
    inline Matrix& operator += (Matrix Mat2){
        assert(Hei == Mat2.Hei && Wid == Mat2.Wid);
        for(int i = 0; i < Hei; ++i)for(int j = 0; j < Wid; ++j)Mat[i][j] += Mat2[i][j];
        return *this;
    }
    inline Matrix operator - (Matrix Mat2){ Matrix res = *this; return res -= Mat2; }
    inline Matrix& operator -= (Matrix Mat2){
        assert(Hei == Mat2.Hei && Wid == Mat2.Wid);
        for(int i = 0; i < Hei; ++i)for(int j = 0; j < Wid; ++j)Mat[i][j] -= Mat2[i][j];
        return *this;
    }
    inline Matrix operator * (Matrix Mat2){ Matrix res = *this; return res *= Mat2; }    
    inline Matrix& operator *= (Matrix Mat2){
        assert(Wid == Mat2.Hei);
        Matrix res(Hei, Mat2.Wid);
        for(int i = 0; i < Hei; ++i)for(int j = 0; j < Mat2.Wid; ++j)for(int k = 0; k < Wid; ++k){
            res[i][j] += Mat[i][k] * Mat2[k][j];
        }
        return *this = res;
    }
    inline Matrix operator * (T scalar){ Matrix res = *this; return res *= scalar; }
    inline Matrix& operator *= (T scalar){
        for(int i = 0; i < Hei; ++i)for(int j = 0; j < Wid; ++j)Mat[i][j] *= scalar;
        return *this;
    }
    inline Matrix pow(long long pow){
        assert(Hei == Wid);
        Matrix res(Hei, Wid), tmp = *this;
        for(int i = 0; i < Hei; ++i)res[i][i] = 1;
        for(; pow; pow >>= 1){ if(pow & 1)res *= tmp; tmp *= tmp; }
        return res;
    }
};

int main() {

    long long n, a, b;
    cin >> n >> a >> b;

    Matrix<long long> s({ { a, b } }), t({ { 1, 0 }, { -1, 1 } }), u({ { 1, 1 }, { 0, 1 } });
    Matrix<long long> v = t * u;

    Matrix<long long> w = v.pow(n / 2);
    if(n % 2 == 1) w *= t;
    s *= w;

    cout << s[0][0] << ' ' << s[0][1] << '\n';

}



Measured memory_bytes: 3180
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
		long N = input[0];
		long T = input[1];
		var t = Console.ReadLine().Split().Select(long.Parse).ToArray();
		
		long ans = 0;
        for(var i = 0; i < N; i++)
		{
			if (i == N - 1) { ans += T; }
			else if (t[i + 1] - t[i] > T) { ans += T; }
			else { ans += t[i + 1] - t[i]; }
		}
		Console.WriteLine(ans);
	}
}


Measured memory_bytes: 32928
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define long long long
#define filein freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

int main() {
    //filein
    long n,k,c;
    string s;

    cin>>n>>k>>c>>s;
    vector<long> v,v1;
    long count=0;
    long i=0;
    while (count<k){
        while (s[i]=='x')i++;
        v.push_back(i);
        count++;
        i+=(c+1);
    }
    count=0;
    i=n-1;
    while (count<k){
        while (s[i]=='x')i--;
        v1.push_back(i);
        count++;
        i-=(c+1);
    }
    reverse(v1.begin(),v1.end());


    for (long j = 0; j <k ; ++j) {
        if (v[j]==v1[j])
            cout<<v[j]+1<<endl;
    }










}


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

const int INF=1001001001;
int ddy[]={-1,0,1,0};
int ddx[]={0,-1,0,1};

int main(){
    int h,w,ch,cw,dh,dw;
    cin>>h>>w>>ch>>cw>>dh>>dw;
    ch--; cw--; dh--; dw--;
    vector<string>s(h);
    rep(i,h)cin>>s[i];
    queue<P>q,q2;
    vector<vector<int>>dist(h,vector<int>(w,INF));
    q.emplace(P(ch,cw));
    dist[ch][cw]=0;
    //BFS
    while(!q.empty()){
        while(!q.empty()){
            int y=q.front().first;
            int x=q.front().second;
            q.pop();
            //4方向
            rep(dir,4){
                int vy=y+ddy[dir];
                int vx=x+ddx[dir];
                if(vy<0||vy>=h||vx<0||vx>=w)continue;
                if(dist[vy][vx]<=dist[y][x])continue;
                if(s[vy][vx]=='#'){
                    q2.emplace(P(y,x));
                    continue;
                }
                dist[vy][vx]=dist[y][x];
                q.emplace(P(vy,vx));
            }
        }
        while(!q2.empty()){
            //5*5マス
            int y=q2.front().first;
            int x=q2.front().second;
            q2.pop();
            for(int dy=-2; dy<=2; ++dy){
                for(int dx=-2; dx<=2; ++dx){
                    int vy=y+dy;
                    int vx=x+dx;
                    if(dy==0&&dx==0)continue;
                    if(vy<0||vy>=h||vx<0||vx>=w)continue;
                    if(dist[vy][vx]<=dist[y][x]+1)continue;
                    if(s[vy][vx]=='#')continue;
                    dist[vy][vx]=dist[y][x]+1;
                    q.emplace(P(vy,vx));
                }
            }
        }
    }
    if(dist[dh][dw]!=INF)cout<<dist[dh][dw]<<endl;
    else cout<<-1<<endl;
}

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

#include <iostream>
#include <fstream>

#include<bits/stdc++.h>
using namespace std;

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

template<class T> bool chmin(T& a,T b){
    if(a > b){ a = b; return true; }else return false;
}
template<class T> bool chmax(T& a,T b){
    if(a < b){ a = b; return true; }else return false;
}

class CFolia {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);

        typedef long long ll;

        int64_t n;cin >> n;
        vector<int64_t> a(n + 1);rep(i,n + 1)cin >> a[i];

        int64_t sum = 0;
        rep(i,n+1)sum += a[i];

        int64_t ans = 0;
        int64_t f = 0;

        if(n == 0){
            if(a[0] == 1){
                cout << 1 << '\n';
            }else{
                cout << -1 << '\n';
            }
            return;
        }

        for(int i = 0;i <= n;i++){
            if(i == 0){
                if(a[i] == 1){
                    if(n == 0){
                        cout << 1 << '\n';
                    }else{
                        cout << -1 << '\n';
                    }
                    return;
                }else{
                    f = 1;
                    ans += 1;
                }
            }else if(i == n){
                if(2 * f < a[n]){
                    cout << -1 << '\n';
                    return;
                }else ans += a[n];
            }else{
                sum -= a[i];
                f = min(2 * f - a[i] , sum);
                if(f < 0){
                    cout << -1 << '\n';
                    return;
                }else ans += f + a[i];
            }
        }
        cout << ans << '\n';
    }
    void main2(istream& cin,ostream& cout){

    }
};


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


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

int main(){
	int h,m,s,dt,dtt,dh,dm,ds,dth,dtm,dts;
	const int mt = 120 * 60;
	while(cin >> h >> m >> s){
		if(h == -1) break;
		dt = mt - (3600 * h + 60 * m + s);
		dtt = 3 * dt;
		dh = dt / 3600;
		dt -= 3600 * dh;
		dm = dt / 60;
		dt -= 60 * dm;
		ds = dt;
		dth = dtt / 3600;
		dtt -= dth * 3600;
		dtm = dtt / 60;
		dtt -= dtm * 60;
		dts = dtt;
		printf("%02d:%02d:%02d\n",dh,dm,ds);
		printf("%02d:%02d:%02d\n",dth,dtm,dts);
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
             int num = 0;

        // 割れる限り割り続ける
        while (n % p == 0) {
            ++num;
            n /= p;
        }

        // その結果を push
        res.push_back(make_pair(p, num));
    }

    // 最後に残った数について
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    long long N;
    cin >> N;
    auto pf = prime_factorize(N);
    long long res = 0;
    for (auto p : pf) {
        long long e = p.second;
        long long tmp = 0, cur = 1;
        while (e >= cur) e -= cur++, ++tmp;
        res += tmp;
    }
    cout << res << endl;
}

Measured memory_bytes: 3640
/*
	Name: D-机场大巴 
	Author: RoseKey
	Date: 14/02/19 16:48
	Description: 贪心+模拟 
*/

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
#define LL long long
#define Rg register
#define RI register int
#define RC register char
#define ed puts("") 
#define pair pair<LL,LL>
#define space putchar(' ')
using namespace std;
    
template <typename tp> inline void read(tp & x)
{	
    x=0;
    RI f=1;
    RC c=getchar();
    while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar(); }
    while(c>='0' && c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();} 
 	x*=f;
} 	
    
template <typename Tp> inline void print(Tp x)
{		
    if(x<0) x=-x,putchar('-');
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

int n,c,k;
int temp;
LL ans;
LL t[1000005];
int s[1000005];
bool vis[1000005];
bool flag=1;
LL kk;

int main()
{
	read(n),read(c),read(k);
	for(RI i=1;i<=n;++i)
		read(t[i]);
	stable_sort(t+1,t+n+1);
	for(RI i=1;i<=n;++i)
	{
//		int kk=t[i]+k;
//		ans++;
//		temp=c-1;
//		int flag=i;
//		for(RI j=flag+1;j<=n;++j)
//		{
//			if(t[j]<=kk && t[j]+k>=kk)
//			{
//				temp--;
//				if(temp==0)
//					break;	
//			}	
//		}	
//		int hh=c-temp;//多接了几个人
//		i+=hh-1;
		if(flag)
        {
            ++ans,++temp;
            kk=t[i]+k;
            flag=0;
        }
        else if(t[i]<=kk) 
			++temp;
        else if(t[i]>kk)
        {
            flag=true;
			temp=0;
            --i;
        }
        if(temp==c) 
        {
            flag=true;
			temp=0;
        }
	}	
	print(ans);		
	return 0;
}

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

int main() {
	ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = a * c;
    ans = max(ans, b * d);
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int n,memo[100001],k;
vector<int>vec;
int solve(int idx){
    if(idx==n-1)
        return 0;
    if(idx>=n)
        return 2e9;
    int &cur=memo[idx];
    if(cur!=-1)
        return cur;
    cur=2e9;
    for(int i=1;i<=k;i++){
        if(idx+i<n)
            cur=min(cur,abs(vec[i+idx]-vec[idx])+solve(i+idx));
    }
    return cur;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    memset(memo,-1,sizeof(memo));
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        vec.push_back(a);
    }
    cout<<solve(0);
}

Measured memory_bytes: 7416