akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

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

const int INF = 1e9 + 7;

int main()
{
	IO_OP;
	
	int n, d;
	cin >> n >>d;
	cout << (n + 2 * d) / (2 * d + 1) << endl;
	
}



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

int main()
{
  int nNum;
  cin >> nNum;

  int64_t nFact = 1;
  for (int n = 1; n <= nNum; n++)
  {
    nFact *= n;
    nFact %= 1000000007;
  }

  cout << nFact << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;

int main() {
  int a;
  int b;
  int ans=0;

  cin >> a >> b;

  if(a>=b){
    ans+=a;
    a--;
  }
  else{
    ans+=b;
    b--;
  }

  if(a>=b){
    ans+=a;
    a--;
  }
  else{
    ans+=b;
    b--;
  }  



  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

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

int main(){
    long k;
    cin >> k;
    long ans = 0;
    for(int a=1;a<=k;a++){
        for(int b=1;b<=k;b++){
            for(int c=1;c<=k;c++){
                ans += gcd(gcd(a,b),c);
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    if(0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1156
n = int(input())
number_list = list(map(int,input().split()))

a = n-1
step = -2
ans = []

for i in range(n):
    ans.append(number_list[a])
    
    a += step
    
    if a == -1:
        a=0
        step=2
    elif a == -2:
        a=1
        step=2
    
print(' '.join(map(str,ans)))
    

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

int main(){
    int k;
    cin >> k;
    int a = k / 1000;
    int b = (k % 1000) / 100;
    int c = (k % 100) / 10;
    int d = k % 10;
    if (a == b && b == c || b == c && c == d){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

Measured memory_bytes: 256
(let* ((n (read)))
  (defun collatz (k)
    (if (oddp k)
        (1+ (* 3 k))
        (/ k 2)))
  (defun collatzp (lst k)
    (if (find k lst)
        (1+ (length lst))
        (collatzp (cons k lst) (collatz k))))
  (princ (collatzp nil n)))

Measured memory_bytes: 13668
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	string output="";
	for(int i=0;i<s.size();i++){
		if(s[i]=='0'){
			output+="0";
		}
		else if(s[i]=='1'){
			output+="1";
		}
		else{
			if(output.size()!=0)
				output.pop_back();
		}
	}
	cout << output;
}

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

int main(void) {
	int h, w, i = 0, j = 0;
	cin >> h >> w;
	vector<string> s(h);
	for (; i < h; i++)
		cin >> s[i];
	for (; j < h; j++) {
		for (i = 0; i < w; i++) {
			if (s[j][i] == '#') {
				if (!((j > 0 && s[j - 1][i] == '#') || (j < h - 1 && s[j + 1][i] == '#') || (i < w - 1 && s[j][i + 1] == '#')))
					break;
				while (i < w && s[j][i] == '#')
					i++;
			}
		}
		if (i < w)
			break;
	}
	if (j < h)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
# flag = [False] * N

# # 一致している場所を探す
# count = 0
# for i in range(N):
#     if P[i] == i + 1:
#         flag[i] = True
#         count += 1

# if count == 0:
#     print(0)
#     exit()

# # 前から順番にスワップ
# # よく分からない
# # print(P, count)

# ans = 0
# i = 0
# while i < N:
#     if not flag[i]:
#         ans += 1
#         i += 2
#     else:
#         i += 1
# print(ans)

res = 0
for i in range(N):
    if P[i] == i + 1:
        if P[i] == N:
            P[i - 1], P[i] = P[i], P[i - 1]
        else:
            P[i], P[i + 1] = P[i + 1], P[i]
        res += 1
print(res)

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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;


void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif
	string str;
	cin >> str;

	
	cout << (str.substr(0,4) == "YAKI" ? "Yes" : "No") << endl;
}



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

	solve();
#ifdef _WIN32
	system("PAUSE");
#endif
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

ll solve(int N) {

  static ll dp[2][1<<16]; zero(dp);

  rep(i, N) {
    int M; ll L; cin >> M >> L;

    int bit = 0;
    rep(_, M) {
      int s, t; cin >> s >> t;
      REP(j, s-6, t-6) {
        bit |= 1<<j;
      }
    }

    rep(S, 1<<16) dp[(i+1)&1][S] = dp[i&1][S];

    rep(S, 1<<16) {
      if((S ^ bit) == (S + bit)) {
        int nS = S ^ bit;
        maximize(dp[(i+1)&1][nS], dp[i&1][S] + L);
      }
    }
  }

  return *max_element(dp[N&1], dp[N&1]+(1<<16));
}

int main() {

  for(int N; cin >> N && N;) {
    cout << solve(N) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4120
#include <bits/stdc++.h>
#define MAXN 505
using namespace std;

struct e
{
	int a,b,c,d;
	e(){}
	e(int x,int xx,int xxx,int xxxx):a(x),b(xx),c(xxx),d(xxxx){}
	void print(){printf("%d %d %d %d\n",a,b,c,d);}
};

int n,m,h,a[MAXN][MAXN];
vector <e> p;

inline void read(int &x)
{
	x=0;char ch=getchar();bool f=false;
	while (ch<'0'||ch>'9'){if (ch=='-') f=true;ch=getchar();}
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	if (f) x=-x;return ;
}

int main()
{
	read(n);read(m);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			read(a[i][j]);
	for (int i=1;i<=n;i++)
		for (int j=1;j<m;j++)
			if (a[i][j]&1){p.push_back(e(i,j,i,j+1));--a[i][j];++a[i][j+1];}
	for (int i=1;i<n;i++)
		if (a[i][m]&1){p.push_back(e(i,m,i+1,m));--a[i][m];++a[i+1][m];}
	h=p.size();
	printf("%d\n",h);
	for (int i=0;i<h;i++) p[i].print();
	return 0;
}

Measured memory_bytes: 5232
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int a,b;

  cin>>a>>b;

  if((a+b)%2==0){
    cout<<(a+b)/2<<endl;
  }else{
    cout<<((a+b)/2)+1<<endl;
  }
  
  return 0;

}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
typedef long long lint;
using namespace std;

int main()
{
	lint N,A,x[55]={};
	lint sum=0;
	lint dp[55][55][2510]={};//50,50,50*50
	lint ans=0;
	
	cin >> N >> A;
	for(lint i=0;i<N;i++)
	{
		cin >> x[i];
		sum+=x[i];
	}
	
	dp[0][0][0]=1;
	for(lint i=0;i<N;i++)
	{
		for(lint j=0;j<N;j++)
		{
			for(lint k=0;k<=sum;k++)
			{
				if(dp[i][j][k]==0)continue;
				//do not use x[i]
				dp[i+1][j][k]+=dp[i][j][k];
				//use x[i]
				dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
			}
		}
	}
	
	for(lint i=1;i<=N;i++)
		ans+=dp[N][i][i*A];
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 59520
def main():
    N = int(input())
    A = [0] * N
    B = [0] * N
    C = [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
        C[i] = A[i] + B[i]

    C.sort(reverse=True)
    ans = -sum(B)
    for i, c in enumerate(C):
        if i % 2 == 0:
            ans += C[i]
    
    print(ans) 

    
    



if __name__ == "__main__":
    main()

Measured memory_bytes: 77836
import math
N,D = map(int,input().split())
X = [0] * N
Y = [0] * N
for i in range(N):
    X[i],Y[i] = map(int,input().split())

ans = 0
tmp = 0
for i in range(N):
    tmp = math.sqrt(X[i]**2+Y[i]**2)
    if tmp <= D:
        ans +=1
    tmp = 0
print(ans)

Measured memory_bytes: 24572
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/lexical_cast.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define mp make_pair
#define endl '\n'
#define PI acos(-1)
typedef tree<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

long mod=1e9+7;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k;
	cin>>n>>k;
	cout<<((n-k+1>0)?n-k+1:0);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100000 + 1000;

int n;
vector<int> edg[MAXN];
int f[MAXN];

int dp(int x)
{
	vector<int> v;
	for(int i = 0; i < edg[x].size(); i++)
		v.push_back(dp(edg[x][i]));
	sort(v.begin(), v.end());
	f[x] = 1;
	for(int i = 0; i < v.size(); i++)
		f[x] = max(f[x], v[i]) + 1;
	return f[x];
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;
	for(int i = 2; i <= n; i++)
	{
		int x;
		cin >> x;
		edg[x].push_back(i);
	}

	int ans = dp(1) - 1;
	cout << ans << endl;

	return 0;
}


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

int main() {
	string s;
	cin>>s;
	
	int x;
	
	x=s.size()-2;
	
	char y=s.at(s.size()-1);
	
	cout << s.at(0) << x << y << endl;
	
	
	
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner scan = new Scanner(System.in);
		String cu = "A";
		while(scan.hasNext())
		{	
			String str[] = scan.next().split(",");
			if(cu.equals(str[0]))
				cu = str[1];
			else if(cu.equals(str[1]))
				cu = str[0];
		}
		System.out.println(cu);
	}
}

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


int main() {
  int a , b , c ;
  cin >> a >> b >> c;
  
  int x=1;
  for(int i=0;i<10;i++){
    x=a*c-b;
    cout <<x <<endl;
    c=x;
  }
    
    
}
    

Measured memory_bytes: 256
# ABC104C - All Green
import sys
input = sys.stdin.readline

def ans(g, i, L):
    # Assume the case using question no.i
    if i == 0:  # base case
        return float("inf")

    n = min(g // (i * 100), L[i][0])  # n:count
    s = n * i * 100  # s:score

    # add bonus if available
    if n == L[i][0]:
        s += L[i][1]

    # make up for the shortage
    if s < g:
        n += ans(g - s, i - 1, L)

    # compare to other cases without question no.i recursively
    return min(n, ans(g, i - 1, L))


def main():
    d, g = list(map(int, input().rstrip().split()))
    arr = [0] + [list(map(int, input().rstrip().split())) for _ in range(d)]
    print(ans(g, d, arr))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> cnt(N);
    for(int i=0;i<N-1;i++){
        int a;
        cin >> a;
        a--;
        cnt[a]++;
    }
    for(int i=0;i<N;i++) cout << cnt[i] << "\n";
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;
const int MOD = 1e9 + 7;

signed main(){

  int n, q; cin >> n >> q;
  dsu uf(n);
  for(int i = 0; i < q; i++){
    int t, u, v; cin >> t >> u >> v;
    if(t == 0){
      uf.merge(u, v);
    }else{
      cout << uf.same(u, v) << endl;
    }
  }

  return 0;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define unordered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using unordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MaxN = 2e5 + 100;

vector<int> adj[MaxN];

int dists[MaxN];

void DfsDist(int v, int p) {
  for (int s : adj[v]) {
    if (s != p) {
      dists[s] = dists[v] + 1;
      DfsDist(s, v);
    }
  }
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);

  int N;
  cin >> N;

  for (int i = 0; i < N - 1; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].PB(v);
    adj[v].PB(u);
  }

  dists[1] = 1;
  DfsDist(1, -1);

  const int v = max_element(dists, dists + N + 1) - dists;

  fill_n(dists, N + 1, 0);
  DfsDist(v, -1);

  const int len = *max_element(dists, dists + N + 1);

  if (len % 3 == 1) {
    cout << "Second\n";
  } else {
    cout << "First\n";
  }
}



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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define in2(x, y) int x,y;cin>>x>>y
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)

#define lim5 100002
#define lim9 1000000002

int main(){
	in(n);

	cout << (n - (n / 2)) / (double)n << endl;

	return 0;
}


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

using namespace std;

long long w,h,x,y;
double ans;

int main(){
	cin >> w >> h >> x >> y;
	ans = w * 1.0 / 2.0 *  h * 1ll * 1.0;
	printf("%.6lf ",ans);
	if(x * 2 == w && y * 2 == h) cout << 1;
	else cout << 0;
	return 0;
}

Measured memory_bytes: 256
/*********************************
*include
*********************************/
#include <stdio.h>

/*********************************
*function prototype
*********************************/
int areaOfRectangle( int hight, int width );
int lengthOfRectangle( int hight, int width );

/*********************************
*function
*********************************/
int main( void )
{
	int input_hight;
	int input_width;

	scanf( "%d %d", &input_hight, &input_width );

	/* ????????¢?????¢????????¨??????????????¨????????? */
	printf( "%d %d\n", areaOfRectangle( input_hight, input_width ),
					lengthOfRectangle( input_hight, input_width ) );

	return ( 0 );
}

/*  ????????¢?????¢???????¨??????????*/
int areaOfRectangle( int hight, int width )
{
	return ( hight * width );
}

/*  ????????¢?????¨?????????????¨?????????? */
int lengthOfRectangle( int hight, int width )
{
	return ( 2 * ( hight + width ) );
}

Measured memory_bytes: 596
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
  public static void main(String[] args) {
    try {
      BufferedReader stdReader =
        new BufferedReader(new InputStreamReader(System.in));
      String line;
      while ((line = stdReader.readLine()) != null) { 
    	  int x = Integer.parseInt(line);
        System.out.println(x*x*x);
      }
      stdReader.close();
    } catch (Exception e) {
      e.getStackTrace();
      /*?????´??????0??????*/
      System.exit(0); 
    }
  }
}

Measured memory_bytes: 24184
from sys import stdin

a = []
for line in stdin:
    a.append(line.rstrip())

N, A, B, C = a


def split(X):
    arr = []
    for i in X:
        arr.append(i)
    return arr


def diff(X, Y, Z):
    sum = 0
    for i in range(0, int(N)):
        if(X[i] != Y[i] and X[i] != Z[i] and Y[i] != Z[i]):
            sum += 2
        elif(X[i] == Y[i] and X[i] == Z[i] and Y[i] == Z[i]):
            next
        elif(X[i] == Y[i] or X[i] == Z[i] or Y[i] == Z[i]):
            sum += 1
    return sum


spA = split(A)
spB = split(B)
spC = split(C)

diffSum = diff(A, B, C)

print(diffSum)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b(a);
  sort(b.begin(), b.end());
  rep(i, n){
    if (b[n-1] == a[i]) cout << b[n-2] << endl;
    else cout << b[n-1] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4736
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int32_t V[200010];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (int32_t i = 0; i < N; i++)
	{
		in >> V[i];
	}
	for (int32_t i = 0; i < N; i++)
	{
		if (V[i] > i) {
			out << -1 << endl; return 0;
		}
	}

	int64_t res = 0;
	int32_t max_v = 0;
	for (int32_t i = N-1; i >= 0; --i)
	{
		if (V[i] < max_v) {
			out << -1 << endl; return 0;
		}
		if (V[i] > max_v) {

			res += V[i];
			max_v = V[i];

		}

		if (max_v > 0) { --max_v; }
	}
	out << res << endl;


	return 0;
}
#endif


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

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using ld = long double;
template <typename T, typename A>
ostream& operator<<(ostream& os, const vector<T, A>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

constexpr ll MOD = 1000000007LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> a(N);
    vector<int> odd;
    vector<int> even;
    ll oddsum = 0;
    ll evensum = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (a[i] > 0) {
            if (i % 2 == 0) {
                even.push_back(i);
                evensum += a[i];
            } else {
                odd.push_back(i);
                oddsum += a[i];
            }
        }
    }
    const vector<int> ind = (oddsum > evensum ? odd : even);
    if (ind.empty()) {
        const int maxind = max_element(a.begin(), a.end()) - a.begin();
        cout << a[maxind] << endl;
        vector<int> op;
        for (int i = N - 1; i > maxind; i--) {
            op.push_back(i);
        }
        for (int i = 0; i < maxind; i++) {
            op.push_back(0);
        }
        cout << op.size() << endl;
        for (const int e : op) {
            cout << e + 1 << endl;
        }
    } else {
        cout << max(oddsum, evensum) << endl;
        const int size = ind.size();
        vector<int> op;
        for (int i = N - 1; i > ind[size - 1]; i--) {
            op.push_back(i);
        }
        for (int i = size - 1; i >= 1; i--) {
            const int half = (ind[i] + ind[i - 1]) / 2;
            for (int j = half; j >= ind[i - 1] + 1; j--) {
                op.push_back(j);
            }
        }
        for (int i = ind[0] - 1; i >= 0; i--) {
            op.push_back(0);
        }
        cout << op.size() << endl;
        for (const int e : op) {
            cout << e + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;


int main() {
	cout << fixed << setprecision(18);

	long long int N,M,K,A[200005];
	cin>>N>>M;
	if(N>=M){
		for(int i=0;i<N;i++){
			cout<<M;
		}
	}else{
		for(int i=0;i<M;i++){
			cout<<N;
		}
	}
} 

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int N;
	std::cin >> N;
	std::vector<double> value(N);
	for (auto& v : value)
	{
		std::cin >> v;
	}
	boost::sort(value);
	double result = (value[0] + value[1]) / 2;
	for (auto i : boost::irange(2, N))
	{
		result = (result + value[i]) / 2;
	}
	std::cout << result << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

int main() {
  string s; cin >> s;
  long long int cnt = 0, sum = 0;
  for (long long int i = 0; i < s.length(); i++) {
    if (s[i] == 'B')
      cnt++;
    else
      sum += cnt;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int main()
{
  cin>>s1;
  cin>>s2;
  int l1=s1.length();
  int l2=s2.length();
  int dp[l1+1][l2+1];
  int i,j;
  for(i=0;i<=l1;i++)
  	for(j=0;j<=l2;j++)
  		{
  			if(i==0|j==0)
  			    dp[i][j]=0;
  		    else if(s1[i-1]==s2[j-1])
  		    	dp[i][j]=dp[i-1][j-1]+1;
  		    else
  		    	dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
  		}
  	int idx=dp[l1][l2];
  	char ans[idx+1];
  	i=l1;
  	j=l2;
  	ans[idx]='\0';
  	idx--;
  	while(i>0&&j>0)
  	{
  		if(s1[i-1]==s2[j-1])
  		{
  			ans[idx]=s1[i-1];
  			i--;
  			j--;
  			idx--;
  		}
  		else if(dp[i-1][j]>dp[i][j-1])
  			i--;
  		else
  			j--;
  	}
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    set<int> s;
    map<int, int> m;
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        s.insert(A[i]);
        m[A[i]]++;
    }

    if ((int)s.size() == 1) {
        if (A[0] == N - 1) {
            cout << "Yes\n";
        } else {
            if (A[0] <= N / 2) {
                cout << "Yes\n";
            } else {
                cout << "No\n";
            }
        }
    } else if ((int)s.size() == 2) {
        int a = *s.begin();
        if (s.count(a + 1)) {
            if (a + 1 - (m[a]) >= 1 && 2 * (a + 1 - (m[a])) <= m[a + 1]) {
                cout << "Yes\n";
            } else {
                cout << "No\n";
            }
        } else {
            cout << "No\n";
        }
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 9984
#include <stdio.h>

int main(void)
{
	int bucket[101];
	int i;
	int max;
	
	for (i = 0; i <= 100; i++){
		bucket[i] = 0;
	}
	
	while (scanf("%d", &i) != EOF){
		bucket[i]++;
	}
	
	max = 0;
	for (i = 0; i <= 100; i++){
		if (bucket[i] > bucket[max]){
			max = i;
		}
	}
	
	for (i = 0; i <= 100; i++){
		if (bucket[i] == bucket[max]){
			printf("%d\n", i);
		}
	}
	
	return (0);
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll kai[300001];
ll mokai[300001];

ll mod_pow (ll x, ll y) {
    ll ret = 1;
    while (y) {
        if (y&1) ret = ret*x%MOD;
        x = x*x%MOD;
        y /= 2;
    }
    return ret;
}

void init (int _n) {
    kai[0] = 1;
    for (int i = 1; i <= _n; i++) kai[i] = kai[i-1]*i%MOD;
    for (int i = 0; i <= _n; i++) mokai[i] = mod_pow(kai[i],MOD-2);
}

ll conb (ll x, ll y) {
    ll z = x-y;
    ll ret = kai[x]*mokai[y]%MOD;
    ret = ret*mokai[z]%MOD;
    return ret;
}


ll n, a, b, k;

int main() {
    init(300000);
    cin >> n >> a >> b >> k;
    ll ans = 0;
    for (ll i = 0; i <= n; i++) {
        ll j = k-a*i;
        if (j < 0 || j%b != 0) continue;
        j /= b;
        if (j > n) continue;
        ans = (ans + conb(n, i) * conb(n, j)) % MOD;
    }
    cout << ans << endl;
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int total;
  total = N * A;

  if (total > B) {
    cout << B << endl;
  }
  else if (total < B){
    cout << total  << endl;
  }
  else{
    cout << total << endl;
  }
}


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

using namespace std;

size_t gcd(size_t a, size_t b) {
    if (b == 0)
        return a;
    auto c = a % b;
    return gcd(b, c);
}

vector<pair<size_t, size_t>> f(size_t n) {
    vector<pair<size_t, size_t>> r;
    for (size_t i = 2; i * i < n; ++i) {
        if (n % i == 0) {
            r.emplace_back(i, 0);
            while (n % i == 0) {
                n /= i;
                ++r.back().second;
            }
        }
    }
    if (n != 1)
        r.emplace_back(n, 0);
    return r;
}

int main() {
    size_t a, b;
    cin >> a >> b;
    auto c = gcd(a, b);
    auto d = f(c);
    cout << d.size() + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), x = in.nextInt(), y = in.nextInt();

            int result = Math.min(x, y) * (Math.min(a + b, 2 * c));
            int sub = Math.min(x, y);
            x -= sub;
            y -= sub;

            result += Math.min(2 * c, a) * x;
            result += Math.min(2 * c, b) * y;
            out.println(result);
        }

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(a==0)
        cout<<1<<endl;
    else if(b==0)
        cout<<2<<endl;
     else if(c==0)
        cout<<3<<endl;
       else if(d==0)
        cout<<4<<endl;
         else if(e==0)
        cout<<5<<endl;


}


Measured memory_bytes: 3472
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void debug() { std::cerr << '\n'; }
template <class H, class... T> void debug(H &&head, T &&... args) {
    std::cerr << head;
    sizeof...(args) == 0 ? std::cerr << "" : std::cerr << ' ';
    debug(std::forward<T>(args)...);
}
template <class T> void debug(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cerr << v[i];
        i == v.size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
    }
}
template <class T> void debug(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cerr << v[i][j];
            j == v[i].size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
        }
    }
}

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

    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> v(N);
    REP(i, Q) {
        int a;
        cin >> a;
        v[a - 1]++;
    }
    REP(i, N) {
        int point = K - Q + v[i];
        if (0 < point)
            print("Yes");
        else
            print("No");
    }

    return 0;
}

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

int main(void){
    int n,m;
    cin >> n >> m;
    vector<string> c(m);
    vector<int> s(m);
    for(int i=0;i<m;i++){
        cin >> s[i] >> c[i];
    }

    //nけたの数字
    string nu;
    if(n==1) nu = "0";
    else if(n==2)nu = "10";
    else nu = "100";

    bool is_right = true;
    for(int i=0;i<m;i++){
        nu.replace(s[i]-1, 1, c[i]);
        //cout << nu << endl;

        //矛盾チェック
        if(nu[0] == '0' && nu.size() > 1)is_right = false;
    }
    //矛盾チェック
    for(int i=0;i<m;i++){
        for(int j=i;j<m;j++){
            if(s[i] == s[j] && c[i] != c[j])is_right=false;
        }
    }
    if(is_right)cout << nu << endl;
    else cout <<-1 << endl;
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        String ans = "No";
        
        if((a<c && c<b) || (a>c && c>b)){
            ans = "Yes";
        }
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 35816
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define FOR(i, to) for (int i = 0; i < (to); ++i)
#define Nmax 200100
#define vmax 1000000000
#define MOD 998244353
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pair<int, int> > vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
 
int N;
int a[510][510], rm[510][510];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
 
bool ok(int x) {
  return x >= 0 && x < N;
}

int calc(int x, int y) {
  int ret = a[x][y];
  for(int k=0;k<4;++k) {
    int nx = x+dx[k], ny = y+dy[k];
    if(ok(nx) && ok(ny)) ret = min(ret, a[nx][ny] + 1-rm[nx][ny]);
  }
  return ret;
}
 
void upd(int r, int c) {
  rm[r][c] = 1;
  queue<pii> q;
  q.push(mp(r,c));
  while(q.size()) {
    pii p = q.front(); q.pop();
    int x = p.fs, y = p.sc;
    
    for(int k=0;k<4;++k) {
    
    
      int nx = x+dx[k], ny = y+dy[k];
      if(ok(nx) && ok(ny) && calc(nx, ny) < a[nx][ny]) {
        a[nx][ny] = calc(nx,ny);
        q.push(mp(nx, ny));
      }
    }
  }
}
 
void displ() {
  for(int i=0;i<N;++i) {
    for(int j=0;j<N;++j) {
      cout<<a[i][j]<<" ";
    }
    cout<<endl;
  }
  cout<<endl;
}
 
int main() {
  cin>>N;
  
  for(int i=0;i<N*N;++i) {
    int r = i/N, c = i%N;
    a[r][c] = min(min(r, c), min(N-1-r, N-1-c));
  }
 
  int ret = 0;
  for(int i=0;i<N*N;++i) {
    int x; cin>>x; --x;
    int r = x/N, c = x%N;
    
    //cout<<r<<" "<<c<<" "<<a[r][c]<<"\n";
    ret += a[r][c];
    upd(r,c);
    //displ();
  }
  cout<<ret<<"\n";
  return 0;
}

Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W));
    vector<pair<int, int>> odd;
    rep(h, H) rep(w, W) {
        cin >> a[h][w];
    }

    vector<vector<int>> ans;
    int stack = 0;
    rep(h, H) rep(wt, W) {
        if (h == H - 1 && wt == W - 1) break;
        int w = wt;
        if (h % 2 == 1) {
            w = W - wt - 1;
            if (a[h][w] % 2 == 1) {
                if (wt == W - 1) {
                    ans.push_back({h + 1, w + 1, h + 2, w + 1});
                    a[h + 1][w]++;
                } else {
                    ans.push_back({h + 1, w + 1, h + 1, w});
                    a[h][w - 1]++;
                }
            }
        } else {
            if (a[h][w] % 2 == 1) {
                if (wt == W - 1) {
                    ans.push_back({h + 1, w + 1, h + 2, w + 1});
                    a[h + 1][w]++;
                } else {
                    ans.push_back({h + 1, w + 1, h + 1, w + 2});
                    a[h][w + 1]++;
                }
            }
        }
    }

    cout << ans.size() << endl;
    for (auto e : ans)
        printf("%d %d %d %d\n", e[0], e[1], e[2], e[3]);
}

Measured memory_bytes: 9904
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(void){

	int m,g,n,a[8],b[8],dp[9][1001];
	
	while(cin >> m,m){
		
		fill(a,a+8,0);
		fill(b,b+8,0);
		
		for(int i=1;i<=m;i++){
			cin >> a[i] >> b[i];
		}
		
		fill(dp[0],dp[9],0);
		
		dp[0][0]=1;
		for(int i=0;i<=m;i++){
			for(int j=0;j<1001;j++){
				for(int k=0;k<=b[i];k++){
					if(j-k*a[i]>=0)dp[i+1][j]+=dp[i][j-k*a[i]];
				}
			}
		}

		cin >> g;
		while(g--){
			cin >> n;
			cout << dp[m+1][n] << endl;
		}
			
	}
	
return 0;
}

Measured memory_bytes: 1196
using System;
using System.Linq;

namespace ConsoleApp3
{
    class Program2
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select((c => long.Parse(c))).ToArray();

            var dp = new long[N - 1, 2];
            dp[0, 0] = A[0];
            dp[0, 1] = -A[0];

            for (int i = 1; i < N - 1; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    var k = A[i] * (j == 0 ? 1 : -1);
                    var c = dp[i - 1, 0] + k;
                    c = Math.Max(c, dp[i - 1, 1] - k);
                    dp[i, j] = c;
                }

//                Console.WriteLine(dp[i, 0]);
//                Console.WriteLine(dp[i, 1]);
            }

//            Console.WriteLine(dp[N - 2, 0]);
//            Console.WriteLine(dp[N - 2, 1]);

            dp[N - 2, 0] += A[N - 1];
            dp[N - 2, 1] -= A[N - 1];
            Console.WriteLine(Math.Max(dp[N - 2, 0], dp[N - 2, 1]));
        }
    }
}



Measured memory_bytes: 32092
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList <Number> list = new ArrayList<>();
        int count = 1;
        int ans = 0;
        
        for(int i = 0; i < N; i++){
            int x = sc.nextInt();
            if(x == count){
                ans++;
                count++;
            }
            list.add(x);
        }
        
        if(ans == 0){
            System.out.println("-1");
        }else{
            System.out.println(N-ans);
        }
   }
}

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

int main() {
    int a, b, c, x, y, ans=0;
    cin >> a >> b >> c >> x >> y;
    if(a+b<=2*c) ans=a*x+b*y;
    else if(a+b>2*c){
        if(x>y) {
            if(a>2*c) ans=2*c*x;
            else ans=y*2*c+(x-y)*a;
        }
        else {
            if(b>2*c) ans=2*c*y;
            else ans=x*2*c+(y-x)*b;
        }
    }
    cout << ans << endl;
}

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

int64_t res=0,len,mul[15];

void FindLen()
{
    mul[0]=1;
    for(int i=1;i<=10;i++)
        mul[i]=mul[i-1]*10LL;
    char c;
    int rs=1,l=2,r=10;
    bool check=false;
    while(l<=r)
    {
        int mid=(l+r)/2;
        cout<<"? "<<mul[mid-1]<<"\n";
        fflush(stdout);
        cin>>c;
        if(c=='Y')
        {
            rs=mid;
            l=mid+1;
        }
        else
        {
            check=true;
            r=mid-1;
        }
    }
    if(check==true)
        len=rs;
    else
    {
        l=1,r=9;
        while(l<=r)
        {
            int mid=(l+r)/2;
            cout<<"? "<<mul[mid]-1<<"\n";
            fflush(stdout);
            cin>>c;
            if(c=='Y')
            {
                rs=mid;
                r=mid-1;
            }
            else
                l=mid+1;
        }
        len=rs;
    }
}

int Binary(int l,int r)
{
    char c;
    int rs;
    while(l<=r)
    {
        int mid=(l+r)/2;
        cout<<"? "<<res*10+mid<<"\n";
        fflush(stdout);
        cin>>c;
        if(c=='Y')
        {
            rs=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    return rs;
}

int main()
{
    FindLen();
    for(int i=1;i<=len-1;i++)
    {
        int tmp;
        if(i==1)
            tmp=Binary(1,9);
        else
            tmp=Binary(0,9);
        res=res*10+tmp;
    }
    int tt=0;
    if(len==1)
        tt=1;
    for(int i=tt;i<=9;i++)
    {
        char c;
        cout<<"? "<<res*100+i*10<<"\n";
        fflush(stdout);
        cin>>c;
        if(c=='Y')
        {
            res=res*10+i;
            break;
        }
    }
    cout<<"! "<<res;
}


Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll                long long int
#define ld                long double
#define pb                push_back
#define mk                make_pair
#define in(i,a,n)         for(ll i=0;i<n;++i) cin>>a[i];
#define out(i,a,n)        for(ll i=0;i<n;++i) cout<<a[i]<<" ";
#define sz                size()
#define all(c)            c.begin(), c.end()
#define rall(c)           c.rbegin(), c.rend()
#define loop(i,a,b)       for(ll i=a;i<b;i++)
#define rloop(i,a,b)      for(ll i=a;i>b;i--)
#define T                 int t;scanf("%lld",&t);while(t--)
#define F                 first
#define S                 second
#define deb(x) cout << #x << " " << x << endl
#define inf INT_MAX
const ll N = 200010;
const ll MOD = 998244353;
ll mod(ll n) {
    return (n % MOD + MOD) % MOD;
}
 

 
 
int main(){
//T{
  
    int n;
    cin >> n;
    n = n%10;
    if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
        cout << "hon";
    else if(n == 0 || n == 1 || n == 6 || n == 8)
        cout << "pon";
    else cout << "bon";

    
//}

}

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

using namespace std;

int main(void){
	double n, m, d;

	cin >> n >> m >> d;

	double res;
	if (d != 0)	
		res = (m-1)*(2*d/n/n+(n-2*d)/n/n*2);
	else 
		res = (m-1)/n;

	printf("%.10lf\n", res);
}


Measured memory_bytes: 256
//Keep Working Hard
  // I__Like__Food  
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast") 
  #pragma GCC optimize("unroll-loops")
  using namespace std;
  using namespace __gnu_pbds;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int mod = 1e9 + 7;
  const int N = 100005;
  const int INF = 1e16;
  const double PI = acos(-1);


int dp[10005][105][2];

int32_t main()
{
       

    IOS


    string s;
    cin >> s;

    int d;
    cin >> d;

    dp[0][0][0] = 1;

    

    for(int i = 0; i < s.length(); i++)
    {
      // i is terating over the string
      trace1(i);

      for(int j = 0; j < d; j++)
        {
          // j is iterating over the digit sum modulo d

          for(int k = 0; k < 2; k++)
          {
            /*
            if k is zero then we did'nt place a digit so far which 
            is less significant than the digit in the string so 
            */

            /*
            if k is one then we have placed placed a digit earlier 
            such that is less significant than the digit in the string 
            */
            for(int x = 0; x < 10; x++)
            {
              // x iterating over the digits we are placing at the ith position
              if(k == 0 and x > s[i]-'0')
              {
                continue;
                // if k is zero we can only place digits from 0 to the corresponding digit
                //in the string
              }
              int kk = k;
              if(x < s[i]-'0')
              {
                kk = 1;
                // if kk is one now we can only place digits from 0 to 9 due to the less significant digit placed before
              }
              dp[i+1][(j+x)%d][kk] += dp[i][j][k]%mod;
              dp[i+1][(j+x)%d][kk]%=mod;
            }
          }
        }
    }



    cout << (dp[s.length()][0][0]%mod + dp[s.length()][0][1]%mod - 1 + mod)%mod;
  return 0;
} 

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

int main(){
  string s;
  cin >> s;
  string hitachi = "";
  bool flag = false;
  while(hitachi.length() <= s.length()){
    hitachi += "hi";
    if(hitachi == s) {
      flag = true;
      break;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc179/tasks/abc179_e

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

int main(){
  ll n, x, m;
  cin >> n >> x >> m;
  vector<int> id(m, -1);
  vector<int> a;
  int len = 0;
  ll tot = 0;
  while(id[x]==-1){
    a.push_back(x);
    id[x]=len;
    len++;
    tot += x;
    x=(x*x)%m;
  }
  int c = len-id[x];//周期
  ll s = 0;//周期の1ループ分の和
  for(int i=id[x];i<len;++i)s+=a[i];
  ll ans = 0;
  //2周目にくるまでよりも短い場合
  if(n<=len){
    rep(i, n)ans+=a[i];
  }else{
    ans += tot;
    n -= len;
    ans += s*(n/c);
    n%=c;
    rep(i, n)ans += a[id[x]+i];
  }

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


Measured memory_bytes: 4048
def main():
    N, M = map(int, input().split())
    g = [[] for _ in range(N + 1)]
    INF = -1 * 10 ** 9 * 1000
    d = [INF] * (N + 1)
    d[1] = 0
    for _ in range(M):
        a, b, c = map(int, input().split())
        g[a].append((b, c))
    for i in range(2 * N):
        for x, r in enumerate(g):
            for y, c in r:
                if d[x] != INF and d[x] + c > d[y]:
                    d[y] = d[x] + c
                    if y == N and i > N:
                        print("inf")
                        exit()

    print(d[-1])


main()


Measured memory_bytes: 3364