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

public class Main {


  private static void solve() {
    long n = nl();
    long[] a = nal(5);
    long min = Arrays.stream(a).min().getAsLong();
    long ret = 4 + (n + min - 1) / min;
    System.out.println(ret);
    
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 27472
fun main(args:Array<String>){
    val mod = 1000000007
    val line1 = readLine()!!.split(" ").map { it.toInt() }
    //nは最上段の数,mは壊れている床の数
    val n = line1[0]
    val m = line1[1]
    val list= mutableListOf<Int>()
    for(i in 1..m){
        list.add(readLine()!!.toInt())
    }
    //pnはn段目にたどり着く場合の数,pn1はn-1段目にたどり着く場合の数
    var pn1 = if(list.contains(1)) 0L else 1L
    var pn = if(list.contains(2)) 0L else pn1+1L
    if(pn1==0L && pn ==0L){
        println(0)
        return
    }
    
    when(n){
        1->
        {println(1)
            return 
        }
        2->{
            println(pn)
            return
        }
    }
    
    var count = if(pn==2L) 0 else 1
    for(i in 3..n){
        val pnext = if(count<list.size && list[count] == i)
        {
            count +=1
            0L
        }
        else pn+pn1

        pn1 = pn % mod
        pn = pnext % mod
    }
    println(pn)
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N, M;
  cin >> N >> M;
  int X;
  cin >> X;
  vector<int> A(M);
  rep(i, 0, M) { cin >> A[i]; }
  sort(all(A));
  cout << min(M - (lower_bound(all(A), X) - A.begin()),

              (lower_bound(all(A), X) - A.begin()))
       << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
//#include<bits/stdc++.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#define  si(a)       scanf("%d",&a)
#define  sl(a)       scanf("%lld",&a)
#define  sii(a,b)    scanf("%d%d",&a,&b)
#define  sll(a,b)    scanf("%lld%lld",&a,&b)
#define  queues      priority_queue
#define mod 1000000007
#define mem(a)  memset(a,0,sizeof(a));
#define def(a) ((a)&(-a))
typedef long long ll;
//priority_queue<int,vector<int >,greater<int > >q;
const int INF=0x3f3f3f3f;
//const double E=exp(1);
//const double PI=acos(-1);
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&a==c)cout<<"Yes";
  else cout<<"No";
}
/******************************************
**        **             ********       **
**       ** **           **             **
**      **   **          **             **
**     **     **         **             **
**    ***********        **             **
**   **         **       ********       **
******************************************/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = a; i<n; i++)
#define per(i,a,n) for (int i = n-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define all(now) (now).begin(),(now).end()
#define fi first
#define se second
#define SZ(now) ((int)(now).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod = 1000000007;
inline int read(int &n){char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+(c-'0');c=getchar();}return n = x*f;}
ll powmod(ll a,ll b,ll mod) {ll res = 1; a%=mod; assert(b>=0); for(;b; b>>=1){if(b&1)res = res*a%mod; a = a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N = 1e5+7;
int T,n,m;
char str[3];
int main()
{
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    scanf("%d", &n);
    int num = (n/100);
    num = num * 100 + num * 10 + num;

    if(num<n){
        num += 111;
    }
    printf("%d\n", num);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

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

    int now = 0;
    int ans = 0;
    while(now < n) {
        while(now+1 < n && s[now] == s[now+1]) { 
            now++;
        }
        ans++;
        now++;
    }
    cout << ans << endl;
    return 0;
} /*atcoder*/



Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll dp[101][100010];
int main(){
    ll n,w;
    cin>>n>>w;
    pair<ll,ll>A[n+2];
    for(int i=1;i<=n;i++)
    cin>>A[i].first>>A[i].second;
    for(int i=0;i<=w;i++)
    dp[0][i]=0;
    for(int i=0;i<=n;i++)
    dp[i][0]=0;
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
           ll w=A[i].first;
           ll v=A[i].second;
           if(w<=j)
           dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v);
           else
           {
               dp[i][j]=dp[i-1][j];
           }
           
        }
    }
  /*  for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++)
        cout<<dp[i][j]<<" ";
        cout<<endl;
    }
    */
    cout<<dp[n][w]<<endl;

    
}

Measured memory_bytes: 79104
from collections import deque
n = int(input())
A = [*map(int, input().split())]
# print(n)
# print(A)

A.sort(reverse=True)

# print(A)

q = deque([A[0]])
B = []
for a in A[1:]:
    x = q.popleft()
    B.append(x)
    q.append(a)
    q.append(a)
# print(q)
# print(B)
print(sum(B))


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    set<int> s;
    rep(i, n) {
        s.insert(a[i]);
    }
    if (int(s.size()) == n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 10368
import java.util.Scanner;

class Main
{
    static int[][]M = new int[100][100];

    static int prim(int n)
    {
	int u, minv;
	int sum = 0;
	int[]d = new int[100];
	int[]f = new int[100];
	int[]cl = new int[100];

	for(int i = 0; i < n; i++)
	    {
		d[i] = 200000;
		f[i] = -1;
		cl[i] = 0;
	    }

	d[0] = 0;

	while(true)
	    {
		minv = 200000;
		u = -1;

		for(int i = 0; i < n; i++)
		    {
			if(minv > d[i] && cl[i] != 2)
			    {
				u = i;
				minv = d[i];
			    }
		    }

		if(u == -1) break;
		cl[u] = 2;

		for(int j = 0; j < n; j++)
		    {
			if(cl[j] != 2 && M[u][j] != 200000)
			    {
				if(d[j] > M[u][j])
				   {
				       d[j] = M[u][j];
				       f[j] = u;
				       cl[j] = 1;
				   }
			    }
		    }
	    }
		for(int i = 0; i < n; i++)
		    {
			if(f[i] != -1) sum += M[i][f[i]];
		    }
	    
	return sum;
    }

    public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);

	int n = In.nextInt();

	for(int i = 0; i < n; i++)
	    {
		for(int j = 0; j < n; j++)
		    {
			int e = In.nextInt();
			M[i][j] = ((e == -1) ? 200000 : e);
		    }
	    }

	System.out.println(prim(n));

    }
}

Measured memory_bytes: 41516
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val K = scn.nextInt()
    var list = intArrayOf(1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51)

    println(list[K-1])
}


Measured memory_bytes: 29596
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second
main(){
  int a[5],sum=0;
  r(i,5)a[i]=0;
  int n;
  cin>>n;
  r(i,n){
    string s;
    cin>>s;
    if(s[0]=='M')a[0]++;
    if(s[0]=='A')a[1]++;
    if(s[0]=='R')a[2]++;
    if(s[0]=='C')a[3]++;
    if(s[0]=='H')a[4]++;
  }
  for(int i=0;i<5;i++){
    for(int j=i+1;j<5;j++){
      for(int k=j+1;k<5;k++){
        sum+=a[i]*a[j]*a[k];
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
'''
Created on 2020/08/17

@author: harurun
'''

import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write

mod=1000000000000000000
A,B,C,K=map(int,pin().split())
if abs(A-B)>mod:
  print("Unfair")
elif K%2==0:
  print(A-B)
else:
  print(B-A)


Measured memory_bytes: 9112
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
using namespace std;

#define bll long long
#define dou double
#define For(i,a,b) for (int i=(a),_##i=(b); i<=_##i; ++i)
#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; --i)
#define Mem(a,b) memset(a,b,sizeof(a))
#define Cpy(a,b) memcpy(a,b,sizeof(b))

const int maxn=1e5+100;
int N,M,u[maxn],link[maxn];
int dlt[maxn];

int get_u(int x,int &ret)
{
    if (x==u[x]) return x;
    u[x]=get_u(u[x],ret);
    ret+=dlt[x];
    dlt[x]=ret;
    return u[x];
}

bool check(int x,int y,int d)
{
    int rx=0,ry=0;
    int a=get_u(x,rx),b=get_u(y,ry);
    if (a==b) return (dlt[y]-dlt[x]==d);
    if (link[a]<link[b]) swap(a,b),swap(x,y),d=-d;
    u[b]=a;
    link[a]+=(link[a]==link[b]);
    dlt[b]=dlt[x]-dlt[y]+d;
    return 1;
}

int main()
{
    for (; scanf("%d%d",&N,&M)!=EOF; )
    {
        bool flag=1;
        For(i,1,N) u[i]=i,link[i]=0,dlt[i]=0;
        For(i,1,M)
        {
            int x,y,d;
            scanf("%d%d%d",&x,&y,&d);
            if (flag) flag=check(x,y,d);
        }
        if (flag)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2040
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = Integer.parseInt(scan.next());
		int b = Integer.parseInt(scan.next());
		System.out.println("a " + ((a < b) ? "<" : (a > b) ? ">" : "==") + " b");
		scan.close();
	}
}


Measured memory_bytes: 26116
S = input()
counta = 0
countb = 0
for i in range(len(S)):
    if(i % 2 == 0 and S[i] == '0'):
        counta += 1
    if(i % 2 == 0 and S[i] == '1'):
        countb += 1
    if(i % 2 == 1 and S[i] == '1'):
        counta += 1
    if(i % 2 == 1 and S[i] == '0'):
        countb += 1
print(min(counta,countb))

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

using ll = long long int;


int main(){
    string s, ans = "";
    cin >> s;
    for(auto c : s){
        if(c == '0' || c == '1') ans.push_back(c);
        else if(!ans.empty()) ans.pop_back();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[int(input()) for _ in range(N)]

Asorted=sorted(A)
Amax1=Asorted[-1]
Amax2=Asorted[-2]

for a in A:
	if a!=Amax1:
		print(Amax1)
	else:
		print(Amax2)


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

signed main(){
  unsigned long h,w;
  cin >> h >> w;
  if(h == 1 || w == 1){
    cout << 1 << endl;
    return 0;
  }
  unsigned long evenNum = w / 2 + ((w % 2 == 0) ? 0 : 1);
  unsigned long oddNum = w / 2;
  unsigned long result = (evenNum * (h / 2 + ((h % 2 == 0) ? 0 : 1)) + oddNum * (h / 2));
  cout << result << endl;
}

Measured memory_bytes: 256
h,n = map(int,input().split())
a_list = []
b_list = []
for i in range(n):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
    
dp=[[float('inf') for i in range(h+1)]for i in range(n+1)]#i番めの魔法までを使って体力j減らすのに必要な魔力の最小値
dp[0][0]=0

for i in range(1,n+1):
  for j in range(h+1):
    if j>=a_list[i-1]:
      ai=a_list[i-1]
      bi=b_list[i-1]
      dp[i][j]=min(dp[i][j-ai]+bi,dp[i-1][j])
    else:
      dp[i][j]=min(dp[i-1][j],b_list[i-1])
ans=dp[n][h]
print(ans)

Measured memory_bytes: 305288
#include <stdio.h>
int main(void)
{
	int c1,c5,c10,c50,c100,c500,a;
	scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
	a=c1+c5*5+c10*10+c50*50+c100*100+c500*500;
	if(a>=1000){
	printf("1\n");
	}
	else{
	printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N, A, B, num=0, a=0;
    cin >> N >> A >> B;
    num=N;
    while(num){
        a+=num%10;
        num=num/10;
    }
    if(N%a==0){
        cout << "Yes" << endl; 
    }
    else cout << "No" << endl;
    
}

Measured memory_bytes: 256
N = int(input())
s = input()

keep = 0
ans = ''
for i in range(N):
    if s[i] == '(':
        ans += '('
        keep += 1
    else:
        if keep > 0:
            ans += ')'
            keep -= 1
        else:
            ans = ('(' + ans + ')')
print(ans + ')' * keep)


Measured memory_bytes: 9140
import math
N,M = map(int,input().split())
List = list(map(int,input().split()))
a = 0
b = 0
for i in range(0,N):
    a = a + List[i]
for j in range(0,N):
    if List[j] >= math.ceil(a/(4*M)):
        b = b+1
if b <  M:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c && c <= b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 384
import sys

from collections import deque


def main():
    def input(): return sys.stdin.readline()[:-1]
    H, W = map(int, input().split())

    graph = [input() for _ in range(H)]

    dist = [[-1] * W for _ in range(H)]
    queue = deque()

    H -= 1
    W -= 1
    
    # initialize
    queue.append((0, 0))
    dist[0][0] = 0
    cnt = 0
    for g in graph:
        cnt += g.count(".")

    while queue:
        vx, vy = queue.popleft()

        if (vx, vy) == (W, H):
            break

        dxdy = [(1,0), (0, 1), (-1, 0), (0, -1)]
        for dx, dy in dxdy:
            if (vx + dx > W) or (vy + dy > H): continue
            elif (vx + dx < 0) or (vy + dy < 0): continue

            elif graph[vy + dy][vx + dx] == ".":
                if dist[vy + dy][vx + dx] == -1:
                    queue.append((vx + dx, vy + dy))
                    dist[vy + dy][vx + dx] = dist[vy][vx] + 1
                    

            elif graph[vy + dy][vx + dx] == "#": continue
            else: continue

    # can't goal
    if dist[H][W] == -1:
        print(-1)
    else:
        # the number of "." - min(dist) - "." of start
        print(cnt - dist[H][W] - 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9432
#include "bits/stdc++.h"
using namespace std;

int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((abs(c-a)<=d)||
    ((abs(b-a)<=d)&&(abs(c-b)<=d)))printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
from collections import deque

if __name__ == '__main__':
    n, q = map(int, input().split())
    Q = deque()
    for i in range(n):
        name,time = input().split()
        Q.append([name, int(time)])
    runtime = 0
    while Q:
        qt = Q.popleft()
        if qt[1] > q:
            runtime += q
            qt[1] -= q
            Q.append(qt)
        else:
            runtime += qt[1]
            print(qt[0],runtime)

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

void	dfs(int	index, int size, string &standard)
{
	if (index == size) {
		cout << standard << endl;
		return;
	}
	char	c = 'a';
	for (int i = 0; i < index + 1; ++i) {
		c = 'a' + i;
		if (c != 'a' && standard.find(c - 1) == string::npos)
			break;
		standard.push_back(c);	
		dfs(index + 1, size, standard);
		standard.erase(index, 1);
	}
}

int	main()
{
	int	N;
	cin >> N;
	string standard("");
	dfs(0, N, standard);
}


Measured memory_bytes: 1536
#include <algorithm>
#include <iostream>
#include <numeric>

using namespace std;

int main() {
  int p[8];
  for (int i = 0; i < 8; i++)
    cin >> p[i];
  cout << max(accumulate(p, p+4, 0), accumulate(p+4, p+8, 0)) << endl;
  return 0;
}

Measured memory_bytes: 0
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
const ll mod = 1000000007;
const ll maxn = 200005;
const ll mm = 1e+18;
void solve()
{
    int k;
    cin>>k;
    int a,b;
    cin>>a>>b;
    repp(i,a,b+1){
        if(i%k==0){
            cout<<"OK";
            return;
        }
    }
    cout<<"NG";
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <vector>
#include <array>
#include <algorithm>
#include <tuple>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

int main(int argc, char const* argv[])
{
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    int a, b, c;
    a = b = c = 0;
    char turn = 'a';
    while(true) {
        if(turn=='a') {
            if(a==sa.size()) break;
            turn = sa[a];
            a++;
        } else if(turn=='b') {
            if(b==sb.size()) break;
            turn = sb[b];
            b++;
        } else {
            if(c==sc.size()) break;
            turn = sc[c];
            c++;
        }
    }
    cout << static_cast<char>(toupper(turn)) << endl;
    return 0;
}


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

#define pb(s) push_back(s)
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))

typedef long long ll;


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

    int w,h,n;
    cin>>w>>h>>n;
    int xmin=0,ymin=0,ymax=h,xmax=w;
    for(int i=0;i<n;++i){
        int x,y,a;
        cin>>x>>y>>a;
        if(a==1){
            xmin=max(xmin,x);
        }
        else if(a==2){
            xmax=min(xmax,x);
        }
        else if(a==3){
            ymin=max(ymin,y);
        }
        else{
            ymax=min(ymax,y);
        }
    }
    if(ymax-ymin<=0||xmax-xmin<=0){
        cout<<0;
    }
    else cout<<(ymax-ymin)*(xmax-xmin);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 4e2+1;
int n;
ll DP[N][N], a[N], s[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    cin >> a[i];
    s[i+1] = s[i] + a[i];
  }
  FOR(i, 0, n)FOR(j, 0, n-i){
    if(i==0){
      DP[j][j+1] = a[j];
    }else{
      DP[j][j+i+1] = LINF;
      FOR(k, j+1, j+i+1) mins(DP[j][j+i+1], DP[j][k]+DP[k][j+i+1]+s[j+i+1]-s[j]);
    }
  }
  cout << DP[0][n]-s[n] << endl;
}

Measured memory_bytes: 1536
#include<iostream>

using namespace std;

typedef long long ll;

int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	ll dp[n][3];
	
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];

	for (int i = 1; i < n; ++i)
	{
		/* code */
		dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][1], dp[i-1][0]);
	}

	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<'\n';

	return 0;
}

Measured memory_bytes: 3840
#include<stdio.h>

#define nMIN 2
#define nMAX 200000
#define RtMIN 1
#define RtMAX 1000000000


int main(){
int n[nMAX],Time,i,max=0,sub;

scanf("%d",&Time);
if(nMIN<=Time&&Time<=nMAX){
for(i=0;i<Time;i++){
scanf("%d",&n[i]);
if(RtMIN>n[i]||n[i]>RtMAX)exit(1);
}
max=n[i-1];
sub=n[i-1]-n[i-2];
for(i=Time-2;i>=0;i--){

if(max<n[i]&&i!=0){
max=n[i];
}
if(sub<max-n[i]&&n[i]!=max){
sub=max-n[i];
}
}
}
 else exit(1);

printf("%d\n",sub);
return 0;
}



Measured memory_bytes: 2548
#include<stdio.h>
//#include<math.h>
int ifcl(int p0[2],int p1[2],int p2[2],int p3[2]){
  long long x0=p1[0]-p0[0],x1=p2[0]-p0[0],x2=p3[0]-p0[0],x3=x2-x1,x4=x0-x1,x5=-x1;
  long long y0=p1[1]-p0[1],y1=p2[1]-p0[1],y2=p3[1]-p0[1],y3=y2-y1,y4=y0-y1,y5=-y1;
  long long x7=x2-x0,y7=y2-y0/*,y3=y2-y1,y4=y0-y1,y5=-y1*/;
  
  long long c1=(x0*y1-y0*x1)*(x0*y2-y0*x2),c2=(x3*y4-y3*x4)*(x3*y5-y3*x5);
  long long d1=x1*x4+y1*y4,d2=x2*x7+y2*y7,d3=x1*x2+y1*y2,d4=x4*x7+y4*y7;
  if(c1==0&&c2==0)return (d1<0&&d2>0&&d3>0&&d4<0)?0:1;
  return (c1<=0&&c2<=0)?1:0;
}
int main(){
  int p[4][2],n,i;
  scanf("%d",&n);
  while(n--){
    for(i=0;i<8;i++)scanf(" %d",&p[i/2][i%2]);
    printf("%d\n",ifcl(p[0],p[1],p[2],p[3]));
  }
  return 0;
}

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

typedef long long ll; 
#define sz(a) ((int)(a.size()))

const int mod=1e9+7; 
int mul(int a, int b){
  return (ll)a*b%mod; 
}
void add_self(int &a, int b){
  a+=b; 
  if(a>= mod) a-=mod; 
}
void mul_self(int &a, int b){
  a=(ll)a*b%mod; 
}
void sub_self(int &a, int b){
  a-=b; 
  if(a<0) a+=mod;
}
int exp(int a, int b){
  int ret=1; 
  while(b){
    if(b%2){
      mul_self(ret,a); 
    }
    mul_self(a,a); 
    b/=2; 
  }
  return ret; 
}
//--------------------------------------------------
const int nax=1e5+5; 
int nextt[nax][30]; 

bool notpos(string a, string b){
  set<char> aa,bb; 
  for(char c:a){
    aa.insert(c); 
  }
  for(char c:b){
    if(aa.find(c)==aa.end()){
      return 1; 
    }
  }
  return 0; 
}

void solve(){ 
  string s,t; cin>>s>>t; 
  if(notpos(s,t)){
    cout<<-1<<endl; return;
  }
  memset(nextt,-1,sizeof(nextt)); 
  for(int i=sz(s)-2;i>=0;i--){
    for(int j=0;j<26;j++){
      nextt[i][j]=nextt[i+1][j]; 
    }
    nextt[i][s[i+1]-'a']=i+1;
  }
  ll ans=0; 
  int j=0; 
  int i=0; 
  if(s[0]!=t[0]) i=nextt[0][t[0]-'a']; 
  while(j<sz(t)){
    j++;  
    if(j==sz(t)){
      ans+=i; 
    }
    else {
      i=nextt[i][t[j]-'a']; 
      if(i==-1){
        ans+=sz(s); 
        if(s[0]==t[j]) i=0; 
        else i=nextt[0][t[j]-'a']; 
      }
    }
  }
  cout<<ans+1<<endl; 
}

int main(){
  clock_t beg=clock(); 
  solve(); 
  clock_t end=clock(); 
  fprintf(stderr,"%.2lf sec\n",(double)(end-beg)/CLOCKS_PER_SEC); 
}

Measured memory_bytes: 12416
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
p = list(map(int,input().split()))

ans = []
num = 0
while ans == []:
  if x + num in p and x - num in p:
    num+=1
  else:
    if x + num not in p and x - num not in p:
      ans = x - num
    elif x + num not in p:
      ans = x + num
    else:
      ans = x - num
print(ans)

Measured memory_bytes: 9116
n, W = [int(_) for _ in raw_input().split()]

wvs = [[int(_) for _ in raw_input().split()] for i in xrange(n)]

p = {0: 0}

for w, v in wvs:
    for d, dv in p.items():
        p[d + w] = max(p.get(d + w, 0), dv + v)
    m = -1
    for d, dv in sorted(p.items()):
        if dv <= m:
            del p[d]
            continue
        m = max(m, dv)

ans = 0
for d, dv in sorted(p.items()):
    if d > W:
        break
    ans = dv

print(ans)

Measured memory_bytes: 2820
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i=0; i<n; i++) cin >> l[i];

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

    int ans = 0;
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            for (int k=j+1; k<n; k++) {
                if (l[i]==l[j] || l[j]==l[k] || l[i]+l[j]<=l[k])
                    continue;
                ans++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3196
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<lli> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

void solve()
{

    lli x;
    cin>>x;
    for(lli i = -1000; i <= 1000; i ++) {
        for(lli j = -1000; j <= 1000; j ++) {
            lli ans = i * i * i * i * i - j * j * j * j * j;
            if(ans == x) {
                cout<<i<<' '<<j<<endl;
                return ;
            }
        }
    }
    cout<<"\n";
    return ;
}

/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3540
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    println!("? {}", (1..(N + 1)).map(|i| i.to_string()).collect::<Vec<_>>().join(" "));
    let s: String = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    };

    let mut ok = N + 1;
    let mut ng = 1;

    while ok - ng > 1 {
        let mid = (ok + ng) / 2;
        let query = (mid..(mid + N)).map(|i| i.to_string()).collect::<Vec<_>>().join(" ");
        println!("? {}", query);
        let T: String = {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        };
        if T == s {
            ng = mid;
        } else {
            ok = mid;
        }
    }
    let mut q = vec![0; N];
    for i in 0..(N - 1) {
        q[i] = ok + i;
    }

    let mut res = vec!['?'; 2 * N];
    for i in 1..(2 * N + 1) {
        if !q.contains(&i) {
            q[N - 1] = i;
            let query = q.iter().map(|&x| x.to_string()).collect::<Vec<_>>().join(" ");
            println!("? {}", query);
            let T: String = {
                let mut line: String = String::new();
                std::io::stdin().read_line(&mut line).unwrap();
                line.trim().to_string()
            };
            res[i - 1] = if T.as_str() == "Red" {
                'R'
            } else {
                'B'
            };
        }
    }
    let mut r = 0;
    let mut b = 0;
    for i in 0..(2 * N) {
        if res[i] == 'R' && r < N / 2 {
            q[r + b] = i + 1;
            r += 1;
        } else if res[i] == 'B' && b < N / 2 {
            q[r + b] = i + 1;
            b += 1;
        }
    }
    for i in ok..(ok + N - 1) {
        q[N - 1] = i;
        let query = q.iter().map(|&x| x.to_string()).collect::<Vec<_>>().join(" ");
        println!("? {}", query);
        let T: String = {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        };
        res[i - 1] = if T.as_str() == "Red" {
            'R'
        } else {
            'B'
        };
    }

    let ans = res.iter().map(|&c| c.to_string()).collect::<Vec<_>>().join("");
    println!("! {}", ans);

}

Measured memory_bytes: 4816
#include<iostream>
using namespace std;
int main()
{
  int L,R,d,count=0;
  cin>>L>>R>>d;
  while(L<=R)
  {
  	if(L%d==0)
  		count++;
  	L++;	
  }
  cout<<count<<endl;
  return 0;
} 

Measured memory_bytes: 3636
raw_input = input().split()

takahashi_hp = int(raw_input[0])
takahashi_ak = int(raw_input[1])
aoki_hp = int(raw_input[2])
aoki_ak = int(raw_input[3])

while 1:
    aoki_hp -= takahashi_ak
    if aoki_hp <= 0:
        print('Yes')
        break
    takahashi_hp -= aoki_ak
    if takahashi_hp <= 0:
        print('No')
        break


Measured memory_bytes: 9172
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.HashMap;

public class Main
{
    String s;
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	int bg = s.indexOf("A");
	int ed = s.lastIndexOf("Z");

	out(ed - bg + 1);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	s = sc.next();
    }

    void out()
    {
	
    }
    
    void out(int n)
    {
	System.out.println(n);
    }

    void out(char c)
    {
	System.out.print(c);
    }
    
    void out(String s)
    {
	System.out.println(s);
    }
}


Measured memory_bytes: 25868
class StructuredProgramming:
    def call(self, n):
        s = ""
        i = 1
        while i <= n:
            x = i
            if x % 3 == 0:
                s += " %d" % (i)
            else:
                while x:
                    if x % 10 == 3:
                        s += " %d" % (i)
                        break
                    x /= 10
            i += 1
        print s

if __name__ == "__main__":
    sp = StructuredProgramming()
    n = int(raw_input())
    sp.call(n)

Measured memory_bytes: 6448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int A, B, K;
    cin >> K >> A >> B;
    for (int i = A; i <= B; i++)
    {
        if (i % K == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;

    return 0;
}

Measured memory_bytes: 3636
N,M = map(int,input().split())
S = input()[::-1]

if M >= N:
    print(N)
    exit()

p = -1
for i in reversed(range(1,M+1)):
    if S[i] == "0":
        p = i
        break

if p == -1:
    print(-1)
    exit()

ps = [p]
while 1:
    tmp = -1
    for i in reversed(range(ps[-1]+1,ps[-1]+M+1)):
        try:
            if S[i] == "0" or i == N:
                ps.append(i)
                tmp = i
                break
        except:
            pass
    if tmp == -1:
        print(-1)
        exit()
    if ps[-1] == N:
        break

pp = ([ps[i+1]-ps[i] for i in range(len(ps)-1)])[::-1] + [ps[0]]
print(*pp)

Measured memory_bytes: 10340
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;
const int Maxn = 505;
typedef int arr[Maxn];
//ll Add(ll x, ll y) { return (x += y) >= Mod ? x - Mod : (x < 0 ? x + Mod : x); }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int n;
arr posn;
int ans[Maxn * Maxn];
struct str
{
	int pos, cnt;
	bool operator<(str A) const { return pos < A.pos; }
} a[Maxn];
pair<int, int> q[Maxn];
int main()
{
	rg int tmp;
	cin >> n;
	for (int i = 1; i <= n; i++)
		a[i] = {read(), i};
	sort(a + 1, a + n + 1);
	for (int i = 1, j = 0; i <= n; i++)
	{
		tmp = a[i].cnt - 1;
		if (tmp)
		{
			for (j++; j < a[i].pos; j++)
				if (!ans[j])
				{
					ans[j] = a[i].cnt;
					if (!--tmp)
						break;
				}
		}
		if (tmp)
		{
			puts("No");
			return 0;
		}
		ans[a[i].pos] = a[i].cnt;
	}
	rg int h = 1, t = 0;
	for (int i = 1, j = 1; i <= n * n; i++)
		if (a[j].pos == i)
		{
			if (n - a[j].cnt > 0)
				q[++t] = mp(a[j].cnt, n - a[j].cnt);
			j++;
		}
		else if (!ans[i])
		{
			if (h > t)
			{
				puts("No");
				return 0;
			}
			ans[i] = q[h].first;
			q[h].second--;
			if (!q[h].second)
				h++;
		}
	puts("Yes");
	for (int i = 1; i <= n * n; i++)
		cout << ans[i] << ' ';
	putchar('\n');
	return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    if(a==b) cout<< 2*a<< endl;
    else cout << max(a,b)*2-1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100;
const int MAX_M = 100000;
int n, m;
int dp[MAX_N + 1][MAX_M + 1];
int a[MAX_N + 1];
const int M = 1000000007;

void solve()
{
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        dp[i][0] = dp[i - 1][0];
        for (int j = 1; j <= m; j++)
        {
            dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % M;
            if (j > a[i])
            {
                dp[i][j] = (dp[i][j] - dp[i - 1][j - a[i] - 1] + M) % M;
            }
        }
    }
    cout << dp[n][m] << endl;
}

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

Measured memory_bytes: 39296
#include "bits/stdc++.h"
using namespace std;
void solve(){
    int x;
    cin >> x;
    int ans = 1;
        for(int i = 2; i < 32; i++){
            int memo = i;
        while(memo * i <= x){
            memo *= i;
        ans = max(ans, memo);
        }
    }
    cout << ans << endl;
}
int main(){
    solve();
    return 0;
}

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

namespace AtCoder_solve
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            var cnt = 0;
            
            for(int i=0;i<n-2; i++)
            {
                if (s[i] == 'A' & s[i + 1] == 'B' & s[i + 2] == 'C')
                {
                    cnt++;
                }
            }

            Console.WriteLine(cnt);
        }
    }
}


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

vals = [[0, 0, 0] for i in range(N)]

for i in range(N):
    v1, v2, v3 = map(int, input().split())
    vals[i][0] = v1
    vals[i][1] = v2
    vals[i][2] = v3

dp = [[0 for i in range(3)] for j in range(N)]

dp[0][0] = vals[0][0]
dp[0][1] = vals[0][1]
dp[0][2] = vals[0][2]

for i in range(1, N):
    for activity in range(3):
        for pastActivity in range(3):
            if activity == pastActivity: continue
            
            dp[i][activity] = max(dp[i][activity],
                                  dp[i-1][pastActivity] + vals[i][activity])

print(max(dp[-1]))


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

namespace ProblemB
{
    class Program
    {
        static void Main()
        {
            var buff = GetIntArray();
            int N = buff[0];
            int K = buff[1];

            var list = GetIntList();
            list.Sort();

            int ans = 0;
            for(int i = 0; i < K; i++)
            {
                ans += list[i];
            }
            Console.WriteLine(ans);
        }

        public static int[] GetIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static List<int> GetIntList() => Console.ReadLine().Split().Select(int.Parse).ToList();
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static double[] GetDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray();
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static long[] GetLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray();

    }
}


Measured memory_bytes: 28672
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int d[101];
int main(){
    int n,ai;
    cin>>n;
    rep(i,n){
        cin>>ai;
        ++d[ai];
    }
    int mx=0;
    rep(i,n+1){
        if(d[i]>0) mx=i;
    }
    if(mx==1&&n>2){
        cout<<"Impossible"<<endl;
        return 0;
    }
    bool flag=true;
    if(mx%2==1){
        rep(i,mx+1){
            if(i<(mx+1)/2&&d[i]>0) flag=false;
            if(i>=(mx+1)/2&&d[i]<2) flag=false;
            if(i==(mx+1)/2&&d[i]!=2) flag=false;
        }
    }
    else{
        rep(i,mx+1){
            if(i<mx/2&&d[i]>0) flag=false;
            if(i>mx/2&&d[i]<2) flag=false;
            if(i==mx/2&&d[i]!=1) flag=false;
        }
    }
    if(flag) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
}

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

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    ppi                      pair <int , pii>               
#define    sp(x)                    setprecision(x)
  
int32_t main()
{
    speed upp
    int n,m,v,p,ans,sum=0;
    cin>>n>>m>>v>>p;
    int a[n+1];
    f(i,1,n)
        cin>>a[i];
    sort(a+1,a+n+1);
    v=v-p;
    v=max((int)0,v);
    int l=1,r=n-p;
    ans=r+1;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(a[mid]+m<a[n-p+1])
            l=mid+1;
        else
        {
            sum=0;
            f(i,1,n-p+1)
            {
                if(i==mid)
                    continue;
                int x=a[mid]+m-a[i];
                x=min(m,x);
                sum+= x;
                
            }
            
            if ( v*m  <= sum )
            {
                r=mid-1;
                ans=mid;
            }
            else    
                l=mid+1;
        }
    }
    
    cout<<n-ans+1;
}

Measured memory_bytes: 1024
s = input()
a = 10000
for i in range(0, 26):
  n = 0
  t = 0
  b = True
  for j in range(0, len(s)):
    if s[j] != chr(ord("a")+i):
      t += 1
    elif b:
      n = max(n, t)
      t = 0
    else:
      n = max(n, (t+1)//2)
      t = 0
  n = max(n, t)
  a = min(a, n)
print(a)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
int main(void)
{
    int m1,d1,m2,d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    if(m1!=m2)
    {
        cout << 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256