akhauriyash/Code-Regression huggingface dataset:
//2018年  3月 24日 土曜日 02:36:27 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll A[MAX_N];
ll L;
int nex[20][MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	cin >> L;
	int at = 0;
	rep(i, 0, N) {
		while(at < N && A[at] - A[i] <= L) at++;
		nex[0][i] = at - 1;
		// debug(i, nex[0][i]);
	}
	rep(i, 0, 19) {
		rep(j, 0, N) {
			nex[i + 1][j] = nex[i][nex[i][j]];
			// debug(i + 1, j, nex[i + 1][j]);
		}
	}
	int Q;
	cin >> Q;
	while(Q--) {
		int a, b;
		cin >> a >> b; a--; b--;
		if(a > b) swap(a, b);
		int res = 0, at = a;
		for(int i = 19; i >= 0; i--) {
			if(nex[i][at] < b) {
				res |= (1 << i);
				at = nex[i][at];
			}
		}
		res += 1;
		cout << res << "\n";
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 16384
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
using namespace std;

int main(){
 ll m,d;
 ll ans=0;
 cin>>m>>d;
ll tmp,tmp1;
 for(ll i=1;i<=m;i++){
   for(ll j=1;j<=d;j++){
     tmp=j%10;
     tmp1=j/10;
     if(tmp1>1&&tmp>1&&(tmp*tmp1==i))
     ans++;
   }
 }


cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b ? "true" : "false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vector<bool> v) {
	string res;
	for(int i = 0; i < (int) v.size(); i++)
		res += char('0' + v[i]);
	return res;
}
 
template<size_t S> string to_string(bitset<S> b) {
	string res;
	for(int i = 0; i < S; i++)
		res += char('0' + b[i]);
	return res;
}

template<class T> string to_string(T v) {
    bool f = 1;
    string res;
    for(auto& x : v) {
		if(!f)
			res += ' ';
		f = 0;
		res += to_string(x);
	}
    return res;
}
 
void DBG() {
	cerr << "]" << endl;
}

template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h);
	if(sizeof...(t))
		cerr << ", ";
	DBG(t...);
}

#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};

void solve() {
	int n;
	cin >> n;
	long long mx = 0, ans = 0;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		if(x < mx && i != 0){
			ans += mx - x;
		}
		else mx = x;
	}
	cout << ans << '\n';
}	
 
int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
 	
	int t = 1;
	//cin >> t;
	for(int i = 1; i <= t; i++) {
		//cout << "Case #" << i << ": ";
		solve();
	}
}

Measured memory_bytes: 3616
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>

using namespace std;

int main()
{
    int n, r;
    
    cin >> n >> r;
    
    if (n >= 10) {
        cout << r << endl;
    } else {
        cout << r + 100 * (10 - n) << endl;
    }
    return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  char s[100];
  char t[100];
  scanf("%s",s);
  scanf("%s",t);
  int i;
  int a=0;
  for(i=0;i<3;i++){
    if(s[i]==t[i]){
      a++;
    }
  }

  printf("%d",a);
  return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

ll maxAbsValExpr(vector<ll> &x, vector<ll> &y) {
    ll res = 0, n = x.size(), smallest, cur;
    for (ll p : {1, -1}) {
        for (ll q : {1, -1}) {
            smallest = p * x[0] + q * y[0] + 0;
            for (ll i = 1; i < n; ++i) {
                cur = p * x[i] + q * y[i];
                res = max(res, cur - smallest);
                smallest = min(smallest, cur);
            }
        }
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> x(n), y(n);
    rep(i, n) { cin >> x[i] >> y[i]; }
    cout << maxAbsValExpr(x, y) << endl;
    return 0;
}



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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#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 all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
void yesOrNo(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

void solve(ll D, ll T, ll S) {
  if (S * T >= D) {
    yes();
  } else
    no();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll D;
  scanf("%lld", &D);
  ll T;
  scanf("%lld", &T);
  ll S;
  scanf("%lld", &S);
  solve(D, T, S);
  return 0;
}


Measured memory_bytes: 3716
//S：場に出す、M：手札にする、L：場を回収する。シュミレーション。
//実装のポイント：実は、今までに引いた手札や場にある手札を使うことがないので、今引いた札、枚数だけ覚えておけば十分である。

#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;

int N[100];
int ans[100][10];	//プレイヤーjの札の枚数
int ans_ba[100];	//場の札の枚数

int main(){
	int i,j,slen;
	char str[102];

	for(i = 0;  ;i++){
		cin >> N[i];

		if(N[i] == 0)
			break;
		cin >> str;
		slen = strlen(str);

		//趣味レート
		for(j = 0 ;j < slen ;j++){
			int player = j%N[i];

			if(str[j] == 'S'){
				ans_ba[i] += ans[i][player] + 1;
				ans[i][player] = 0;
			}
			if(str[j] == 'L'){
				ans[i][player] += ans_ba[i] + 1;
				ans_ba[i] = 0;
			}
			if(str[j] == 'M'){
				ans[i][player]++;
			}
		}
	}

	for(j = i-1; j >= 0; j--){
		sort(ans[j],ans[j]+N[j]);
	}
	for(j = 0;j < i;j++){
		for(int k = 0;k < N[j];k++)
			cout << ans[j][k] << " ";
		cout << ans_ba[j] << endl;
	}
	return 0;
}

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

int main() {
  char a ;
  cin >> a;
  if(a=='a'){
  cout << "vowel" <<endl; 
  }
  else if(a=='e'){
  cout << "vowel" <<endl; 
  }
  else if(a=='i'){
  cout << "vowel" <<endl; 
  }
  else if(a=='o'){
  cout << "vowel" <<endl; 
  }
  else if(a=='u'){
  cout << "vowel" <<endl; 
  }
  else{
  cout<< "consonant"<< endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
using namespace std;
 
int main() {
    int ans=0;
    long long n; cin >> n;
    for (long long a = 1; a < n; a++)
    {
        for (long long b = 1; b < (n+a-1)/a; b++)
        {
            if (a*b<n)
            {
                ans = ans + 1;
            }
            
                
            
            
        }
        
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;


int main() {
    int n;
    string s;
    cin >> n >> s;

    map<char, vector<int>> cnt;
    rep(i, n) cnt[s[i]].push_back(i);

    ll ans = 0;
    int r_size = cnt['R'].size();
    int g_size = cnt['G'].size();
    int b_size = cnt['B'].size();

    rep(i, r_size) rep(j, g_size) {
        int tmp = b_size;

        if (cnt['R'][i] < cnt['G'][j]) {
            int sa = cnt['G'][j] - cnt['R'][i];
            int sa2 = -1;
            if (sa % 2 == 0) sa2 = sa / 2;

            if (cnt['G'][j] + sa < n)  if (s[cnt['G'][j] + sa] == 'B') --tmp;
            if (cnt['R'][i] - sa >= 0) if (s[cnt['R'][i] - sa] == 'B') --tmp;

            if (sa2 > 0) if (s[cnt['R'][i] + sa2] == 'B') --tmp;
            ans += tmp;
        } else {
            int sa = cnt['R'][i] - cnt['G'][j];
            int sa2 = -1;
            if (sa % 2 == 0) sa2 = sa / 2;

            if (cnt['R'][i] + sa < n)  if (s[cnt['R'][i] + sa] == 'B') --tmp;
            if (cnt['G'][j] - sa >= 0) if (s[cnt['G'][j] - sa] == 'B') --tmp;
            if (sa2 > 0) if (s[cnt['G'][j] + sa2] == 'B') --tmp;
            ans += tmp;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3644
#include <stdio.h>

/*
	10^6のオーダーは大丈夫
*/

int main(void){
	int N,Y;
	scanf("%d %d",&N,&Y);
	int x,y,z;
	int i,j,flag=0;
	
	for(i=0;i<=N;i++){
		x = i;
		for(j=0;j<=N-i;j++){
			y = j;
			z = N-i-j;
			int m = 10000*x + 5000*y + 1000*z;
			if(m==Y){flag = 1;break;}
		}
		if(flag==1)break;
	}	
	if(flag==1)	printf("%d %d %d",x,y,z);
	else printf("-1 -1 -1");
	
	return 0;
}

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

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  for(;;){
    int n,m,s,g1,g2;
    cin >> n >> m >> s >> g1 >> g2;
    if(!n&&!m&&!s&&!g1&&!g2) return 0;
    int wf[128][128];
    REP(i,n+1) REP(j,n+1) wf[i][j]=(1<<25);
    REP(i,n+1) wf[i][i]=0;
    REP(i,m){
      int b1,b2,c;
      cin >> b1 >> b2 >> c;
      wf[b1][b2]=c;
    }
    REP(k,n+1) REP(i,n+1) REP(j,n+1)
      wf[i][j]=min(wf[i][j],wf[i][k]+wf[k][j]);
    int answer=(1<<25);
    REP(i,n+1)
      answer=min(answer,wf[s][i]+wf[i][g1]+wf[i][g2]);
    cout << answer << endl;
  }
}

Measured memory_bytes: 1212
#include<iostream>
using namespace std;
int main()
{
	int a[]={1,2,3,4,5,6,7,8,9};
	for(int i=0;i<9;i++)
	{
		for(int j=0;j<9;j++)
		{
			cout<<a[i]<<'x'<<a[j]<<'='<<a[i]*a[j]<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3112
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  vector<int> b;

  for(int i=1;i<=n;i++){
    for(int j=0;j+i<n;j++){
      int tmp=0;
      for(int l=j;l<=j+i;l++)tmp+=a[l];
      b.push_back(tmp);
    }
  }

  sort(b.begin(),b.end(),greater<int>());

  int aa=0;
  for(int i=0;i<b.size();i++)aa=max(aa,b[i]);
  int keta=1;
  while(aa>0){
    keta++;
    aa/=2;
  }

  for(int kt=keta;kt>=0;kt--){
    vector<int> ch;
    for(int i=0;i<b.size();i++){
      if(b[i]&(1ull<<kt))ch.push_back(b[i]);
    }
    if((int)ch.size()>=k)b=ch;
  }

  int ans=b[0];
  for(int i=1;i<k;i++)ans&=b[i];
  cout<<ans<<endl;

}


Measured memory_bytes: 6516
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
A = readInts()
mi = float('inf')
for a,b in combinations(A,2):
    mi = min(mi, a+b)
print(mi)


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

const int MOD = 1000000007;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];

  long long res = 0;
  long long two_factor = 1;
  for (int d = 0; d < 60; ++d) {
    long long even = 0, odd = 0;
    for (int i = 0; i < N; ++i) {
      if (A[i] & (1LL << d))
        ++odd;
      else
        ++even;
    }
    long long add = (odd * even) % MOD * two_factor % MOD;
    res = (res + add) % MOD;
    two_factor = (two_factor * 2) % MOD;
  }
  cout << res << endl;
}

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

//-----------------------
const int MOD = (int)1e9 + 7;
struct mint { int n; mint(int n_ = 0) : n(n_ % MOD) { if (n < 0) n += MOD; } };
mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.n; }
mint operator*(mint a, mint b) { return 1LL * a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
ostream &operator<<(ostream &os, mint a) { return os << a.n; }
istream &operator>>(istream &is, mint& a) { return is >> a.n; }
mint inv(mint x) { long long a = x.n, b = MOD, u = 1, v = 0;
    while (b) { long long t = a/b; swap((a -= t*b), b); swap((u -= t*v), v); }
    return mint(u); }
mint operator^(mint a, long long n) { mint r = 1;
    while (n) { if (n & 1) r *= a; a *= a; n >>= 1; } return r; }
bool operator<(const mint &a, const mint &b) { return a.n < b.n; }
//-----------------------

mint dp[10101][101][2];
int main() {
    string s; cin >> s;
    int M; cin >> M;
    int n = s.size();
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) for (bool lt: {true, false}) {
        for (int r = 0; r < M; r++) {
            int cur = s[i] - '0';
            for (int d = 0; d < 10; d++) if (lt || d <= cur) {
                dp[i + 1][(r + d) % M][lt | (d < cur)] += dp[i][r][lt];
            }
        }
    }
    cout << dp[n][0][0] + dp[n][0][1] - 1 << endl;  // 0 を除く
    return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int w[100];

int main() {
  int n;
  cin >> n;
  int s_1 = 0, s_2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
    s_2 += w[i];
  }
  int min_diff = abs(s_2 - s_1);
  for (int i = 0; i < n; i++) {
    s_1 += w[i];
    s_2 -= w[i];
    int tmp = abs(s_2 - s_1);
    if (min_diff > tmp) {
      min_diff = tmp;
    }
  }
  cout << min_diff << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
    cin>>n;long long a[n+1],b[n];for(int i=0;i<n+1;i++)cin>>a[i];for(int i=0;i<n;i++)cin>>b[i];
    long long ans=0, f1, f2=0;
    for(int i=0;i<n;i++){
            f1=min(a[i]-f2,b[i]);
            f2=min(a[i+1],b[i]-f1);
            ans+=(f1+f2);
    }
    cout<<ans<<endl;
}

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

int N;
int A[102];
int max_A = INT_MIN;
int min_A = INT_MAX;

int main(){
    cin >> N;
    for(int i=0;i<N;++i) cin >> A[i];
    for(int i=0;i<N;++i){
        if(max_A < A[i]) max_A = A[i];
        if(min_A > A[i]) min_A = A[i];
    }
    cout << max_A - min_A;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll n,a,b[200005],ans;
int main()
{
    ans=0;
    memset(b,0,sizeof(b));
    scanf("%lld",&n);
    for(int i=0;i<n;i++)
    {scanf("%lld",&a);
      if(i!=0)
        b[i]=b[i-1]+a;
      else
        b[i]=a;
    }
    sort(b,b+n);
    for(ll i=0;i<n-1;i++)
    {
        ll k;k=1;
       // printf("%lld ",b[i]);

        while(b[i]==b[i+1]&&i<n-1)
        {
            k=k+1;
            i=i+1;
        }
        //printf("%lld  ",k);
        k=k*(k-1)/2;
            ans+=k;
    }
    for(ll i=0;i<n;i++)
    if(b[i]==0)
            ans+=1;
    printf("%lld",ans);

}


Measured memory_bytes: 1792
using System;
using System.Diagnostics.CodeAnalysis;

namespace ChokudaiScanner
{
    class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();

            int N = cin.NextInt();
            int Y = cin.NextInt();
            for(int i = 0; i <= N; i++)
            {
                for(int j = 0; i+j <= N; j++)
                {
                    int k = N - (i + j);
                    int sum = i * 10000 + j * 5000 + k * 1000;
                    if (sum == Y)
                    {
                        Console.WriteLine("{0} {1} {2}", i, j, k);
                        return;
                    }
                }
            }
            Console.WriteLine("-1 -1 -1");
        }
    }

    class Scanner
    {
        string[] s;
        int i;

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

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

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayNext(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Next();
            }
            return Array;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}



Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>

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

ll INF = 1LL << 60;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> a(N), b(N);
	for (int i = 0; i < N; i++) cin >> a[i];

	ll ans = INF;
	for (int bit = 0; bit < (1 << N); bit++) {
		b = a;
		ll cost = 0;
		int M = b[0];
		int color = 1;
		for (int i = 0; i < N; i++) {
			if (i == 0) continue;
			if (bit & (1 << i)) {
				color++;
				if (M >= b[i]) {
					cost += (M + 1) - b[i];
					b[i] = M + 1;
				}
			}
			M = max(M, b[i]);
		}
		if (color >= K) ans = min(ans, cost);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3576
N = int(input())
order = len(str(N))

if order == 2:
  print(9)
  
elif order == 4:
  print(909)
  
elif order == 6:
  print(90909)
  
elif order == 1:
  a = int(N)
  print(a)

elif order == 3:
  b = int(N) - 90
  print(b)

elif order == 5:
  c = 909 + int(N) - 10000 + 1
  print(c)

Measured memory_bytes: 3064
from fractions import gcd
from functools import reduce


def lcm(x,y):
    return (x*y)//gcd(x,y)


def lcm_list(nums):
    return reduce(lcm,nums,1)

mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
num=lcm_list(A)
cnt=0
for i in A:
    cnt +=num//i
print(cnt%mod)

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

ll n, ans = 10000000;

ll f(ll a, ll b) {
	int ad = 1, bd = 1;
	while (a >= 10) {
		a /= 10;
		ad++;
	}
	while (b >= 10) {
		b /= 10;
		bd++;
	}
	return max(ad, bd);
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (ll i = 1; i * i <= n; i++) {
		if (!(n % i)) {
			ans = min(ans, f(i, n / i));
		}
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, x, y;
  cin >> A >> B;
  
  x = (A + B) % 2;
  if(x == 1) {
    y = (A + B) / 2 + 1; 
  }
  else {
    y = (A + B) / 2;
  }
  cout << y << endl;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

void solve() {
  double n, k;
  cin >> n >> k;
  double ans = 0;
  for (double i = 1; i <= n; i++) {
    ans += (1.0 / n) * pow(0.5, ceil(log(ceil(k / i)) / log(2)));
  }
  cout << fixed << setprecision(20) << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 4304
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    set<string> ans;
    for (int i = 0; i < N; i++) {
        string tmp;
        cin >> tmp;
        ans.insert(tmp);
    }
    int res = ans.size();
    printf("%d\n", res);
}


Measured memory_bytes: 19184
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD (int)1e9 + 7
#define atoi(x) ((x)-'0')
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;

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

int n, m, a, b;
vi dis(100010, INF), ans(100010);
vector<vi> graph(100010);
queue<int> Q;

int main() {
	cin >> n >> m;
	FOR(i, m) {
		cin >> a >> b;
		graph[a].pb(b);
		graph[b].pb(a);
	}
	for (int i = 1; i <= n; i++) sort(all(graph[i]));
	dis[1] = 0;
	Q.push(1);
	while (!Q.empty()) {
		int t = Q.front(); Q.pop();
		for (int i = 0; i < graph[t].size(); i++) {
			int v = graph[t][i];
			if (dis[v] == INF) {
				dis[v] = dis[t] + 1;
				ans[v] = t;
				Q.push(v);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		if (dis[i] == INF) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes" << endl;
	for (int i = 2; i <= n; i++) {
		cout << ans[i] << endl;
	}
}

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

int main(){
int n,c=0;
cin >> n;
int a[n];
for(int i=1;i<=n;i++)
  cin >> a[i]; 

for(int i=1;i<=n;i++)
  if(a[i]!=i && c==0)
  {	c=1;
    int t= a[i];
    a[i] = a[t];
	a[t] = t;
    
  }

for(int i=1;i<=n;i++)
  if(a[i]!=i){cout << "NO"; return 0;}
    
cout << "YES";
return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int h,w,s,t,m,min,ans;
int main(){
    while(1){
        scanf("%d%d", &h, &w);
        if(h==0&&w==0) break;
        min=h*h+w*w;
        ans=150*150;
        for(int i=1;i<=150;i++)
            for(int j=i+1;j<=150;j++){
                m = i*i+j*j;
                if(min<=m&&m<ans&&(i!=h||j!=w)){
                    if(min==m&&i<h)continue;
                    ans=m;
                    s=i;
                    t=j;
                }
            }
        printf("%d %d\n",s,t);
    }
    return 0;
}



Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string S;
  cin >> S;
int sum=0;
  for(int i=0;i < 4;i++){
  if(S.at(i) == '+'){
  sum++;
  }
  if(S.at(i) == '-'){
  sum--;
  }
  }
  cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const int MOD = 1000000007;

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
  vector<string> W={ "Sunny", "Cloudy", "Rainy" , "Sunny" };
  string S,ans;
  cin >> S;
  rep(i,3){
    if(S==W[i]) ans = W[i+1];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3472
import numpy as np
Nmax = 10**5

N = int(input())
h = [int(x) for x in input().split()]

dp = [0] * (Nmax + 1)

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

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]))

print(int(dp[N-1]))


Measured memory_bytes: 23072
import math
n, d  = map(int, input().split())
c = [0] * n
for i in range(n):
    c[i] = list(map(int, input().split()))

ans = 0
for i in range(n):
    for j in range(i+1, n):
        dis = 0
        for k in range(d):
            dis += (c[i][k] - c[j][k])**2
        if math.sqrt(dis) % 1 == 0:
            ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#define N 2005
using namespace std;

typedef long long ll;
ll n, x, mn, s, a[N], b[N];
int main()
{
	ll i, j;
	cin >> n >> x;
	for (i = 0; i < n; i++) scanf("%lld", &a[i]), b[i] = a[i], mn += a[i];
	for (i = 1; i < n; i++) {
		s = x * i;
		for (j = 0; j < n; j++) {
			b[j] = min(b[j], a[(j - i + n) % n]);
			s += b[j];
		}
		mn = min(mn, s);
	}
    cout << mn << endl;
    return 0;
}

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

int n;
string s;
short dp[2002][2002];

int main(){
  while(cin >> s){
    n = s.length();
    memset(dp, 0, sizeof(dp));

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

    for(int i = 1; i < n; i++){
      for(int j = 0; j + i < n; j++){
        int k = i + j;

        if(s[j] == s[k] && dp[j][k] < dp[j + 1][k - 1] + 2){
          dp[j][k] = dp[j + 1][k - 1] + 2;
        }

        if(dp[j][k] < dp[j + 1][k]){
          dp[j][k] = dp[j + 1][k];
        }
        if(dp[j][k] < dp[j][k - 1]){
          dp[j][k] = dp[j][k - 1];
        }
      }
    }

    string ans = "";
    int x = n - 1;
    int y = 0;

    while(y < x){
      if(dp[y][x] == dp[y + 1][x]){
        y = y + 1;
      }
      else if(dp[y][x] == dp[y][x - 1]){
        x = x - 1;
      }
      else if(s[y] == s[x] && dp[y + 1][x - 1] + 2 == dp[y][x]){
        ans += s[x];
        x = x - 1;
        y = y + 1;
      }
    }

    string rev = ans;
    reverse(rev.begin(), rev.end());

    if(dp[0][n - 1] % 2 == 0){
      ans += rev;
    }
    else{
      ans += s[x];
      ans += rev;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 9032
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Product[] products = new Product[n];
		for (int i = 0; i < n; i++) {
		    products[i] = new Product(sc.nextInt(), sc.nextInt(), sc.next().charAt(0), sc.nextLong(), sc.next());
		}
		Arrays.sort(products);
		StringBuilder sb = new StringBuilder();
		for (Product p : products) {
		    sb.append(p).append("\n");
		}
		System.out.print(sb);
	}
	
	static class Product implements Comparable<Product> {
	    int value;
	    int weight;
	    char type;
	    long datetime;
	    String name;

	    public Product(int value, int weight, char type, long datetime, String name) {
    	    this.value = value;
    	    this.weight = weight;
    	    this.type = type;
    	    this.datetime = datetime;
    	    this.name = name;
	    }
	    
	    public int compareTo(Product another) {
	        if (value != another.value) {
	            return value - another.value;
	        } else if (weight != another.weight) {
	            return weight - another.weight;
	        } else if (type != another.type) {
	            return type - another.type;
	        } else if (datetime != another.datetime) {
	            if (datetime < another.datetime) {
	                return -1;
	            } else {
	                return 1;
	            }
	        } else {
	            return name.compareTo(another.name);
	        }
	    }
	    
	    public String toString() {
	        return value + " " + weight + " " + type + " " + datetime + " " + name;
	    }
	}
}



Measured memory_bytes: 196092
n, m = map(int, input().split())
edges = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)


def get_first_cycle(n, edges):
    seen = [-1] * n  # seen: -1: 未確認, 0: 非cycleのnode, 1: cycle候補
    for start in range(n):
        if seen[start] == 0:
            continue
        seen[start] = 1
        path = [start]
        while path:
            now = path[-1]
            if not edges[now]:
                path.pop()
                seen[now] = 0
                continue

            next_node = edges[now].pop()
            if seen[next_node] == -1:
                path.append(next_node)
                seen[next_node] = 1

            elif seen[next_node] == 1:
                idx = path.index(next_node)
                cycle = path[idx:]
                return cycle
    return False


cycle = get_first_cycle(n, edges)
if not cycle:
    print(-1)
    exit()

nodes = set(cycle)
length = len(cycle)
i = 0
while i < length:
    now = cycle[i]
    routes = edges[now]
    while routes:
        to = routes.pop()
        if to in nodes:
            update = True
            idx = cycle.index(to)
            cycle = cycle[:i+1] + cycle[idx:]
            nodes = set(cycle)
            length = len(cycle)
            break
    i += 1

print(len(cycle))
for node in cycle:
    print(node+1)


Measured memory_bytes: 3444
# -*- coding: utf-8 -*-
# map(int, input().split())
X,K,D = map(int, input().split())

# 移動仕切れるか
max_move = K*D
if abs(X) >= max_move:
    print(abs(X)-max_move)
else:
    # ギリギリを狙う
    giri_kaisuu = int(abs(X)/D)
    nokori = K - giri_kaisuu
    if nokori%2 == 0:
        print(abs(X)-(giri_kaisuu*D))
    else:
        print(-(abs(X)-((giri_kaisuu+1)*D)))

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

int N, K;
int64 fact[101];
int64 dp[101][100001];

int rec(int idx, int add)
{
  if(idx == 0) return (0);
  if(~dp[idx][add]) return (dp[idx][add]);
  long long ret = 0;
  for(int i = 0; i <= K; i++) {
    if(i <= idx && idx <= add + i) {
      int sqr = (add + i) % idx;
      (ret += 1LL * fact[idx - 1] * sqr % mod) % mod;
      (ret += rec(idx - 1, add + (add + i) / idx)) %= mod;
    } else {
      (ret += 1LL * fact[idx - 1] * (i + add) % mod) %= mod;
      (ret += rec(idx - 1, add)) %= mod;
    }
  }
  return (dp[idx][add] = ret);
}

int main()
{
  cin >> N >> K;
  fact[0] = 1;
  for(int i = 1; i <= N; i++) {
    (fact[i] = fact[i - 1] * (K + 1)) %= mod;
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(N, 0) << endl;
}

Measured memory_bytes: 79104
n=int(input())
a=0;b=0;ab=0;res=0
for i in range(n):
    s=input()
    res+=s.count("AB")
    if s[0]=="B":
        if s[-1]=="A":
            ab+=1
        else:
            b+=1
    elif s[-1]=="A":
        a+=1
if ab>0:
    res+=ab-1
    if a>0:
        res+=1
        a-=1
    if b>0:
        res+=1
        b-=1
res+=min(a,b)
print(res)

Measured memory_bytes: 43880
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

int get(){
	char c=getchar();
	int x=0;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string s;
int q;
char c;
bool r;
int t,f;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>s;
	cin>>q;
	string p,h;
	while(q--){
		cin>>t;
		t%=2;
		if(t){
			r^=1;
			continue;
		}
		cin>>f;
		f%=2;
		cin>>c;	 
		f^=r;
		if(f){
			p+=c;
		}else
		h+=c;
	}
	if(r){
		for(int i=sz(h)-1;i>=0;i--)
		cout<<h[i];
		for(int i=sz(s)-1;i>=0;i--)
		cout<<s[i];
		cout<<p;
	}else{
		for(int i=sz(p)-1;i>=0;i--)
		cout<<p[i];
		cout<<s;
		cout<<h;
	}
	re 0;
}

Measured memory_bytes: 1040
program abc167d
      implicit none
      integer(8)::n
      integer(8),allocatable,dimension(:)::a,s,flag,flag_turn
      integer(8)::k
      integer(8)::i
      integer(8)::num_to_loop,num_loop

         read *, n,k
         allocate(a(n),s(0:n),flag(n),flag_turn(n))
         read *, a(1:n)

         s(0)=1; flag=0; flag(1)=1; flag_turn=0; flag_turn(1)=0
         do i=1,n
            s(i)=a(s(i-1))
            if (flag(s(i))/=1) then  ! if not visited
               flag(s(i))=1          ! marking 'visited'
               flag_turn(s(i))=i
            else             
               num_to_loop=i
               num_loop=i-flag_turn(s(i))
               exit
            end if
         end do

         if (num_to_loop>=k) then
            print *, s(k)
         else
            print *, s( mod( k - num_to_loop, num_loop ) + &
                     ( num_to_loop - num_loop) )
         end if

   end program abc167d

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

const int N = 100, VMAX = 100000;
long long v[N], wt[N], f[N+1][VMAX + 1], INF = 2e9;

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

	for(int i = 0; i < n; i++) cin >> wt[i] >> v[i];

	for(int i = 0; i <= N; i++)
		for(int j = 0; j <= VMAX; j++)
			f[i][j] = INF;

	f[0][v[0]] = wt[0];
	f[0][0] = 0;
	for(int i = 1; i < n; i++){
		for(int j = 0; j <= VMAX; j++){
			f[i][j] = f[i-1][j];
			if(j-v[i] >= 0) f[i][j] = min(f[i][j],f[i-1][j-v[i]]+wt[i]);
		}
	}

	int ans = 0;
	for(int i = 0; i <= VMAX; i++){
		if(f[n-1][i] <= w) ans = max(i,ans);
	}

	cout << ans;
}

Measured memory_bytes: 82508
from math import factorial

M, N = map(int, input().split())

if N > 1 and M > 1:
	a = factorial(N) / factorial(2) / factorial(N - 2)
	b = factorial(M) / factorial(2) / factorial(M - 2)
elif N <= 1 and M > 1:
	b = factorial(M) / factorial(2) / factorial(M - 2)
	a = 0
elif M <= 1 and N > 1:
	a = factorial(N) / factorial(2) / factorial(N - 2)
	b = 0
else:
	a, b = 0, 0


print(int(a+b))

Measured memory_bytes: 3064
#include <stdio.h>
int main(void) {
	long long n, a=2,i,j;
	scanf("%lld", &n);
	for (i = 1; i <= n; i++) {
		if (n < i * i) {
			break;
		}
		if (n % i == 0) {
			j = i;
		}
	}
	printf("%lld\n", n/j+j-a);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    ll cur = 0;
    while (A%2==0 and B%2==0 and C%2 ==0){
        if (cur > pow(10,8)){
            cout << -1 << endl;
            return 0;
        }
        int tmpA, tmpB, tmpC;
        tmpA = A/2;
        tmpB = B/2;
        tmpC = C/2;

        A += tmpB + tmpC;
        B += tmpA + tmpC;
        C += tmpA + tmpB;
        cur++;
    }
    cout << cur << endl;

}

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

int main() {
  int N;
  cin >> N;
  vector<int> s(N);
  for(int i=0; i<N; i++)
    cin >> s[i];
  sort(s.begin(),s.end());
  int answer;
  answer = s[N/2]-s[N/2 -1];
  cout << answer;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>

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

using namespace std;

int visit[20][20][16][4];
char field[20][20];
const int N = 16;
int w, h;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

struct state{
	int x, y, mem, dir;
	state(int x, int y, int m, int d):x(x), y(y), mem(m), dir(d){}
};

void move(state &s){
	s.x = (s.x + dx[s.dir] + w)%w;
	s.y = (s.y + dy[s.dir] + h)%h;
}

void operate(state &s, char x){
	rep(i, 4){
		if(x == "<>^v"[i]){
			s.dir = i;
			return;
		}
	}

	rep(i, 2){
		if(x == "_|"[i]){
			s.dir = i*2;
			if(!s.mem) s.dir++;
			return;
		}
	}

	if('0' <= x && x <= '9'){
		s.mem = x-'0';
		return;
	}

	if(x == '+'){
		s.mem++;
	}else if(x == '-'){
		s.mem--;
	}
	s.mem = (s.mem+N)%N;
}

int main(){
	cin >> h >> w;
	rep(i, h) rep(j, w) cin >> field[i][j];

	state start(0, 0, 0, 1);
	bool ans = false;
	queue<state> q;
	q.push(start);
	while(!q.empty()){
		state s = q.front();
		q.pop();

		if(visit[s.y][s.x][s.mem][s.dir]) continue;
		visit[s.y][s.x][s.mem][s.dir] = 1;

		//cout << s.x << ' ' << s.y << ' ' << s.mem << ' ' << "LRUD"[s.dir] << endl;

		if(field[s.y][s.x] == '@'){
			ans = true;
			break;
		}

		if(field[s.y][s.x] == '?'){
			rep(i, 4){
				state next = s;
				next.dir = i;
				move(next);
				q.push(next);
			}
		}else{
			operate(s, field[s.y][s.x]);
			move(s);
			q.push(s);
		}
	}
	cout << (ans?"YES":"NO") << endl;

	return 0;
}

Measured memory_bytes: 1376
A, V = map(int, input().split())  # 鬼
B, W = map(int, input().split())

T = int(input())

# 鬼のほうが足が遅いと捕まらない
# すれ違うだけでもアウト
if W >= V:
    ans = 'NO'
else:
    # T秒以内に捕まる？
    d = abs(A - B)
    av = abs(V - W)
    if d / av <= T:
        ans = 'YES'
    else:
        ans = 'NO'

print(ans)


Measured memory_bytes: 9204
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 998244353
#define F first
#define S second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)

bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}
int power(int x, unsigned int y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
signed main()
{
    int n,m;
    cin>>n>>m;
    if(n==m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    }



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int N, A, B;
  cin >> N >> A >> B;

  int ans = (max(A, B)-min(A, B));
  if(ans%2 == 0){
    cout << ans/2 << endl;
    return 0;
  }

  ans = min(A, B)-1;
  ans = min(ans, N-max(A, B));

  ans += (max(A, B)-min(A, B)+1)/2;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 1005
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) printf("Case %lld:\n",i)
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,ll>mpp;
map<pair<ll,ll>,bool>mb;
map<ll,bool>mp;
ll itr,n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,ok=0;
bool flag=0;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>adj[MAX+19];
bool visited[MAX+19];
ll start_time[MAX+10],finish_time[MAX+10],deep[MAX+10],parent[MAX+12];
ll dp[MAX][MAX];
char grid[MAX][MAX];
int main()
{
    fast;
    cin>>n>>m;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
           cin>>grid[i][j];
        }
    }
    memset(dp,0,sizeof dp);
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            if(grid[i][j]=='#')dp[i][j]=0;
            else
            {
                if(i==1 and j==1) dp[i][j]=1;
                else dp[i][j]=(dp[i][j-1]+dp[i-1][j])%mod;
            }
        }
    }
    cout<<dp[n][m]%mod<<endl;
    return 0;
}
 /*1 10 9 9
 6 9 9 9
 6 9 9 9
 8 9 9 9
 1 2 5 10 3 4 6 7 8 9
10 4 9 10 3 4 9 7 9 9*/


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#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 rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
typedef pair<long long, long long> P;

int main(){
    long long n;
    cin>>n;
    vector<long long>a(n);
    rep(i,n){
        cin>>a[i];
    }
    long long sum=0;
    rep(i,n){
        sum+=a[i];
    }
    
    cout<<sum-n<<endl;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

ll dp[1010][100100] = {0};
int main(void){
    int h, n;
    cin >> h >> n;

    for(int i = 0; i < 1010; i++){
        for(int j = 0; j < 100100; j++){
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    vector<int> w(n);
    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i] >> w[i];

    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= h; j++){
            dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            //if(j >= v[i]){ 
            dp[i][min(j + v[i - 1], h)] = min(dp[i][min(j + v[i - 1], h)], dp[i][j] + w[i - 1]);
            //}
            //cout << i << "-" << j << " " << dp[i][j] << endl;
        }
    }

    cout << dp[n][h] << endl;

}

Measured memory_bytes: 790144