akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int a[]=new int[n];
			for(int i=0;i<n;i++)
				a[i]=in.nextInt();
			int cnt=32;
			int i=0;
			while(cnt>0)
			{
				cnt-=(cnt-1)%5;
				System.out.println(cnt>0 ? cnt:0);
				cnt-=a[(i++)%n];
				System.out.println(cnt>0 ? cnt:0);
			}
		}
	}
	
	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

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

int main () {
   while (1) {
      int i, j, h, w;
      cin >> h >> w;

      if ( h == 0 && w == 0 ) break;

    for ( i = 0; i < h; i++ ){
          for ( j = 0; j < w; j++ ) cout << "#"; 
        cout << endl;
        }
cout << endl;
  }
 return 0;
}  

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

int main()
{
	int a, b, k;
	cin >> a >> b >> k;
	int cnt = 0;
	for (int i = 100; i >0; i--) {
		if (a % i == 0 && b % i == 0)
			cnt++;
		if (cnt == k) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 384
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
using namespace std;
#define fastestiointhewest   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll          long long
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define mii         map<int,int>
#define vi          vector<int>
#define vll         vector<long long>
#define all(a)      (a).begin(),(a).end()
#define clz(a)      __builtin_clz(a) // count leading zeroes
#define ctz(a)      __builtin_ctz(a) // count trailing zeroes
#define popc(a)     __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define SIZE        1000005
#define F           first
#define S           second
#define debug(x)    cerr << #x << " = " << x << endl;
#define mod         998244353

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define endl        '\n'
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void solve()
{ 
  int n,m; cin>>n>>m;
  int lbnd=1,ubnd=n;
  rep(i,0,m)
  {
    int l,r; cin>>l>>r;
    lbnd=max(lbnd,l);
    ubnd=min(ubnd,r);
  }
  cout<<max(ubnd-lbnd+1,0);
} 
int main()
{   
    fastestiointhewest;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

struct edge {
    int from, to, cost;
    edge(int to): to(to), cost(1) {}
};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL n,m,s,t,u,v;
    cin >> n >> m;
    vector<vector<edge>> es(n*3);
    REP(i,0,m) {
        cin >> u >> v;
        --u; --v;
        REP(j,0,3) {
            es[u*3+j].pb(v*3+(j+1)%3);
        }
    } 
    cin >> s >> t;
    --s; --t;
    VI d(n * 3, -1);
    deque<PII> q;
    q.pb(s * 3,0);
    d[s * 3] = 0;
    while (!q.empty()) {
        auto p = q.front();
        q.pop_front();
        int index = p.first;
        for (auto &&e: es[index]) {
            if (d[e.to] > -1) continue;
            d[e.to] = p.second + 1;
            q.pb(e.to, d[e.to]);
        }
    }
    if (d[t*3] > -1) d[t*3] /= 3;
    cout << d[t * 3] << endl;
}

int main() {
    solve();
    
    return 0;
}


Measured memory_bytes: 17792
[N, M] = map(int, input().split())
a = [list(map(int, input().split())) for i in range(N)]
def value(xyz, sign):
	return sum([xyz[i]*(1 - 2*((sign & (1 << i)) >> i)) for i in range(3)])
print(0 if M == 0 else max([sum([value(a[j], sign) for j in sorted([i for i in range(N)], key = lambda index : value(a[index], sign))[-M:]]) for sign in range(8)]))

Measured memory_bytes: 3384
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
/* void swap(int* a, int* b) { */
/*   int tmp; */
/*   tmp = *a; */
/*   *a = b; */
/*   *b = tmp; */
/* } */
int compare_int(const void *a, const void *b)
{
    return *(long long int*)a - *(long long int*)b;
}

int main(){
  //long long int N, M,i,j,Q,k, A, B, T;
  long long int x[20] ={0};
  long long int v[20] ={0};
  long long int ans[20] ={0};
  //int flag = 0;
  //long long int K, S, cnt=0, cnt2=0;
  char str[120] = {0};
  long long int len[120];
  int lenstr;
  long long int L[200000];
  long long int c[200000];
  long long int t[100000];
  int i;
  char S[300000] = {0};
  int SS[300000] = {0};
  //long long int A[100000];
  long long int cnt = 0;
  int max, min, min_cost=9999;

  for (i = 0; i < 3; i++) {
    scanf("%d", &x[i]);
  }

  qsort(x, 3, sizeof(long long int), compare_int);
  for (i = 0; i < 3;i++) {
    //   printf("%d", x[i]);
  }
  double a = (float)x[0];
  double b = (float)x[1];
  printf("%d\n", x[0]*x[1]/2);
  //printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
typedef long long ll;

using namespace std;

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

    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i=0; i<n; i++)
        cin >> arr[i];
    vector<int> smn,smx;
    smn.push_back(0);
    smx.push_back(0);
    ll tot=1000;
    int i=0;
    while(true) {
        if(i==n-1)
            break;
        while(i!=n-1 && arr[i]>arr[i+1])
            i++;
        ll mn=arr[i];
        while(i!=n-1 && arr[i]<=arr[i+1])
            i++;
        ll mx=arr[i];
        ll cnt=tot/mn;
        tot-=cnt*mn;
        tot+=cnt*mx;
    }
    cout << tot;

    return 0;
}


Measured memory_bytes: 3660
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")

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

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;


long long mod = int(1e9) + 7;

int main() {
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	string s;
	cin >> s;
	int n = s.length();
	long long dp[100000][13];
	memset(dp, 0, sizeof(dp));
	if (s[0] == '?') {
		for (int i = 0; i < 10; i++)
			dp[0][i] = 1;

	}
	else {
		dp[0][s[0] - '0'] = 1;
	}
	for (int i = 1; i < n; i++) {
		if (s[i] != '?') {
			int t = s[i] - '0';
			for (int j = 0; j < 13; j++) {
				dp[i][(j * 10 + t) % 13] += dp[i - 1][j];
				dp[i][(j * 10 + t) % 13] %= mod;
			}
		}
		else {
			for (int t = 0; t < 10; t++) {
				for (int j = 0; j < 13; j++) {
					dp[i][(j * 10 + t) % 13] += dp[i - 1][j];
					dp[i][(j * 10 + t) % 13] %= mod;
				}
			}
		}
	}
	cout << dp[n - 1][5] << endl;
	return 0;
}


Measured memory_bytes: 10624
#include<stdio.h>
long long max(long long a,long long b,long long c,long long d){
if(a>=b&&a>=c&&a>=d)return a;
  else if(b>=a&&b>=c&&b>=d)return b;
  else if(c>=b&&c>=a&&c>=d)return c;
  else if(d>=a&&d>=b&&d>=c)return d;
}
int main(){
long long a,b,c,d;
  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
  long long ac=a*c,ad=a*d,bc=b*c,bd=b*d;
  if(max(ac,ad,bc,bd)==ac){printf("%lld",ac);
                           return 0;
                          }
  if(max(ac,ad,bc,bd)==bc){printf("%lld",bc);
                           return 0;
                          }
  if(max(ac,ad,bc,bd)==ad){printf("%lld",ad);
                           return 0;
                          }
  if(max(ac,ad,bc,bd)==bd){printf("%lld",bd);
                           return 0;
                          }
  return 0;
}

Measured memory_bytes: 1716
#include <cstdio>
#include <algorithm>
using namespace std;
const int NN = 505, NLEN = 500 * 500 + 5;
int A[NN], N, ans[NLEN], id[NN];
bool cmp(int u, int v) { return A[u] < A[v]; }
int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", &A[i]);
		ans[A[i]] = i;
		id[i] = i;
	}
	sort(id + 1, id + N + 1, cmp);
	//这需要给 A[i]排序
	int p = 1;
	for (int i = 1; i <= N; ++i) {
		int cnt = 0;
		for (int j = 1; j < A[id[i]]; ++j) {
			if (ans[j] == 0) {
				if (cnt == id[i] - 1)
					break ;
				++cnt;
				ans[j] = id[i];
			}
		}
		if (cnt < id[i] - 1) {
			printf("No\n");
			return 0;
		}
	}
	for (int i = 1; i <= N; ++i) {
		int cnt = 0;
		for (int j = A[id[i]] + 1; j <= N * N; ++j) {
			if (cnt == N - id[i])
				break ; //这句话得放在前面，不能放在后面
			if (!ans[j]) {
				ans[j] = id[i];
				++cnt;
			}
		}
		if (cnt != N - id[i]) { //记得判这个
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	for (int i = 1; i <= N * N; ++i)
		printf("%d ", ans[i]);
	printf("\n");
	return 0;
}
/*
4
3 4 16 9
*/

Measured memory_bytes: 4208
# デバッグ用
GBN_DEBUG = False
GBN_DEBUG = True
def dprn(s, i):
    if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
    if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
    if GBN_DEBUG: print(i, end=" ")
def endl(): 
    if GBN_DEBUG: print('')
def puts(s): print(s)

#本体ここから

#S = input()
#N = int(input())
#S, T = input().split()
N, K = map(int, input().split())
#W = [input() for _ in range(N)]
l = list(map(int, input().split()))

l.sort(reverse=1)
ans = 0
for i in range(K):
    ans += l[i]
print(ans)


Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
public class Main
{
	static final int mod=(int)1e9+7;
	static final int inf=(int)1e9;
	static final int INF=(int)1e18;
	public static void main(String[] args)
	{
		FastScanner fs=new FastScanner();
		char arr[]=fs.next().toCharArray();
		int c=0,max=0;
		for(int i=0;i<arr.length-1;i++)
		{
			if(arr[i]==arr[i+1] && arr[i]=='R')
			{
				c++;
			}
			else if(arr[i]=='R')
			{
				max=Math.max(max,c+1);
				c=0;
			}
		}
		if(arr[2]=='R')
		max=Math.max(max,c+1);
		System.out.println(max);
	}
}
class FastScanner 
{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		public String next() 
		{
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		long pow(long x,long n)
		{
			long res=1;
			while(n>0)
			{
			   	if(n%2!=0)
			   	{
			   		res=(res*x);n--;
			   	}
			   	else
			   	{
			   		x=(x*x);n/=2;
			   	}
			}
			return res;
		}
		int gcd(int a,int b)
		{
			if(b==0)
			{
				return a;
			}
			return gcd(b,a%b);
		}
		long longgcd(long a,long b)
		{
			if(b==0)
			{
				return a;
			}
			return longgcd(b,a%b);
		}
		int[] sort(int arr[])
		{
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		char[] charsort(char arr[])
	        {
	    	ArrayList<Character> list = new ArrayList<>();
	    	for(char c:arr)list.add(c);
	    	Collections.sort(list);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		arr[i]=list.get(i);
	    	}
	    	return arr;
	        }
		long[] longsort(long arr[])
		{
			ArrayList<Long> list = new ArrayList<Long>();
			for(long i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		public int nextInt() 
		{
			return Integer.parseInt(next());
		}
		public int[] readArray(int n)
		{
			int[] arr=new int[n];
			for (int i=0; i<n; i++) arr[i]=nextInt();
			return arr;
		}	
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		public double nextDouble()
		{
			return Double.parseDouble(next());
		}
		public long[] longreadArray(int n) 
		{
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
}

Measured memory_bytes: 32708
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int p[] = new int[M];
		String S[] = new String[M];
		Set correctSet = new HashSet<Integer>();
		Set wrongSet = new HashSet<Integer>();
		Set submitAnswer = new HashSet<Integer>();
		int correct = 0;
		int wrong = 0;

		for (int i = 0; i < M; i++) {
			p[i] = sc.nextInt();
			S[i] = sc.next();
			if ("AC".equals(S[i])) submitAnswer.add(p[i]);
		}

		for (int i = 0; i < M; i++) {
			if (submitAnswer.contains(p[i])) {
				if ("WA".equals(S[i])  && !correctSet.contains(p[i])) {
					wrongSet.add(p[i]);
					wrong++;
				} else if ("AC".equals(S[i]) && !correctSet.contains(p[i])) {
					correctSet.add(p[i]);
					correct++;
				}
			}
		}

		System.out.println(correct + " " + wrong);
	}
}

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

int findSumOfDisits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; i++){
    int sum = findSumOfDisits(i);
    if (A <= sum && sum <= B){
      total += i;
    }
  }
  cout << total << endl;
}


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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;

ll n,k,Mtipe=0;
vector <pair<ll,ll>> as; // jumlah,tipe
vector <ll> tp[100005]; // sushi pertipe

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

    cin >> n >> k;

    for (int i=0;i<n;i++){
        ll t,d;
        cin >> t >> d;
        as.pb(mp(d,t));
        tp[t].pb(d);
        Mtipe=max(Mtipe,t);
    }

    sort(as.begin(),as.end(),greater<pair<ll,ll>>());
    ll cek[Mtipe+1];
    ll tot=0,picked=0;
    for (int i=0;i<=Mtipe;i++) cek[i]=0;
    for (int i=0;i<k;i++){
        if (cek[as[i].se]==0){
            picked++;
        }
        cek[as[i].se]++;
        tot+=as[i].fi;
    }

    vector <ll> alt;
    for (int i=1;i<=Mtipe;i++){
        if (cek[i]==0 && !tp[i].empty()){
            ll maks=0;
            for (auto x : tp[i]){
                maks=max(maks,x);
            }
            alt.pb(maks);
        }
    }

    sort(alt.begin(),alt.end(),greater<ll>());

    auto ite=alt.begin();
    ll id=k-1,ans=tot+picked*picked;

    while (id>=0 && ite!=alt.end()){
        while (cek[as[id].se]==1 && id>0) id--;
        if (cek[as[id].se]<=1) break;

        cek[as[id].se]--;
        tot-=as[id].fi;
        tot+=*ite;
        picked++;
        ans=max(ans,tot+picked*picked);

        ite++;
        id--;
    }

    cout << ans << el;

    return 0;
}

Measured memory_bytes: 8944
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int ans = 1;
      
      	while(sc.hasNextInt()){
			 ans *= sc.nextInt();
        }
		sc.close();

		System.out.println(ans);
	}
}

Measured memory_bytes: 35748
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final int NONE = -1;
        final int HONEST = 1;
        final int UNKIND = 0;

        Scanner sc = new Scanner(System.in);
        try {
            final int n = sc.nextInt();
            int [][] shogen = new int[n][n];
            for (int i=0; i<n; i++) {
                for (int j=0; j<n; j++) {
                    shogen[i][j] = NONE;
                }
            }
            for (int i=0; i<n; i++) {
                int m = sc.nextInt();
                for (int j=0; j<m; j++) {
                    int x = sc.nextInt();
                    int y = sc.nextInt();
                    shogen[i][x-1] = y;
                }
            }

            int maxCount = 0;
            int n2 = 1 << n;
            for (int i=1; i<n2; i++) {
                int [] assumption = new int[n];
                int tmp = i;
                for (int j=0; tmp != 0; j++) {
                    if (tmp % 2 == 1) {
                        assumption[j] = HONEST;
                    } else {
                        assumption[j] = UNKIND;
                    }
                    tmp >>= 1;
                }

                boolean ok = true;
                for (int j=0; j<n; j++) {
                    if (assumption[j] == HONEST) {
                        for (int k=0; k<shogen[j].length; k++) {
                            if ((shogen[j][k] == HONEST && assumption[k] == UNKIND)
                                    || (shogen[j][k] == UNKIND && assumption[k] == HONEST)) {
                                ok = false;
                            }
                        }
                    }
                }
                if (ok) {
                    maxCount = Math.max(maxCount,  Integer.bitCount(i));
                }
            }

            System.out.println(maxCount);

        } finally {
            sc.close();
        }
    }
}



Measured memory_bytes: 25120
#include<iostream>                  
using namespace std;
int main(){
   
   int a,b,i,ans;
   char op;

   for(i=1;i<=100000000;i++){
	    ans=0;
   cin>>a>>op>>b;
if(op=='?')break;
else if (op=='+'){ans=a+b;}
   else if(op=='-'){ans=a-b;}
   else if(op=='*'){ans=a*b;}
   else if(op=='/'){ans=a/b;}

cout<<ans<<endl;

   
   }

   
   return 0;
   }


Measured memory_bytes: 3120
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

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

Measured memory_bytes: 256
N, M = map(int, input().split())

Lmax = 0
Rmin = N

for i in range(M):
  L, R = map(int, input().split())
  Lmax = max(L, Lmax)
  Rmin = min(R, Rmin)
  
if (Lmax > Rmin):
  print(0)
else:
  print(Rmin - Lmax + 1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N = 55;
int n,k,v[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
        cin >> v[i];
    vector<int> t;
    int ans = 0;
    for (int l = 0; l <= min(n,k); ++l)
        for (int r = 0; l + r <= min(n,k); ++r) {
            t.clear();
            for (int i = 0; i < l; ++i)
                t.push_back(v[i]);
            for (int i = 0; i < r; ++i)
                t.push_back(v[n-1-i]);
            sort(begin(t),end(t),greater<int>());
            for (int i = 0; i < k - l - r; ++i)
                if (t.size() && t.back() < 0)
                    t.pop_back();
            ans = max(ans, accumulate(begin(t),end(t),0));
        }
    cout << ans << endl;
}


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

int main () {
	int n;
	scanf("%d", &n);

	long long ans = 0;
	for (int i = 0, x; i < n; i++) {
		scanf("%d", &x);

		ans += x - 1;
	}

	printf("%lld\n", ans);
	return 0;
}

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

#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) for(int i=int(n-1);i>=0;i--)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
typedef pair<int,int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    
    int n,x,y; cin >> n >> x >> y, x--, y--;
    vi ans(n-1);
    forn(i, n) forsn(j, i+1, n) {
        int a = abs(i - x) + 1 + abs(y - j);
        int b = abs(i - y) + 1 + abs(x - j);
        int v = min(abs(i - j), min(a, b));
        ans[v-1]++;
    }
    forn(i, n-1) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	while(1){int n;cin>>n;
int p=6;int a[]={6,9,36,81,216,729,1296,6561,7776,46656,59049};
int dp[n+1];
dp[0]=0;
for(int i=1;i<=n;i++){
	dp[i]=dp[i-1]+1;
	for(int j=0;j<11;j++){
		if(i>=a[j]){dp[i]=min(dp[i],dp[i-a[j]]+1);}
	}//2-th for
}//for
cout<<dp[n]<<endl;
	
	
	return 0;
	
	}
}


Measured memory_bytes: 640
import java.util.Scanner;


public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		new A().doIt();
	}
	
	
	class A{
		
		int[][] price;
		int[][] rePrice;
		
		void setPrice(){
			price = new int[101][20000];
			rePrice = new int[101][1001];
			for(int i=1;i<100;i++)for(int s=1;s<=1000;s++){
				double afterPrice = (int) s * (100.0 + i) / 100.0;
				price[i][(int)afterPrice] = s;
				rePrice[i][s] = (int)afterPrice;
			}
		}
		
		void doIt(){
			setPrice();
			while(true){
				int x = in.nextInt(), y = in.nextInt(), s = in.nextInt();
				if(x + y + s ==0)return;
				solve(x, y, s);
			}
		}
		
		void solve(int x,int y,int s){
			int max = -1;
			for(int a=1;a<s;a++){
				int b = s-a;
				int before_a = price[x][a];
				int before_b = price[x][b];
				int sum = rePrice[y][before_a] + rePrice[y][before_b];
				max = Math.max(max, sum);
			}
			System.out.println(max);
		}
		
	}

}

Measured memory_bytes: 31508
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>

int main(){
 
  int n;
  cin>>n;
  
  vi data(n-1);
  rep(i,n-1){
    int tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  int answer=0;
  
  answer+=data.at(0);
  
  answer+=data.at(n-2);
  
  for (int i=1;i<n-1;i++){
    answer+=min(data.at(i),data.at(i-1));
  }
  
  cout<<answer<<endl;

  


  
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int P[10010];
int N, M, A[10010], B[10010], COST[10010];
pair<int,int> bridge[10010];

void init(int N) {
	for (int i=0; i<N; ++i) { P[i] = i; }
}

int root(int a) {
	if (P[a] == a) return a;
	return (P[a] = root(P[a]));
}

bool is_same_set(int a, int b) {
	return root(a) == root(b);
}

void unite(int a, int b) {
	P[root(a)] = root(b);
}

int main() {
	
	while(cin >> N >> M) {
		int costs=0;
		if (N == 0 && M == 0) { break; }
		init(N);
		
		for (int i=0; i<M; i++) {
			cin >> A[i] >> B[i] >> COST[i];
			bridge[i].first = COST[i];
			bridge[i].second = i;
		}
		sort(bridge,bridge+M);
		
		for (int i=0; i<M; i++) {
			int cost = bridge[i].first;
			int machiID = bridge[i].second;
			if (!is_same_set(A[machiID], B[machiID])) {
				unite(A[machiID],B[machiID]);
				costs+=cost;
			}
		}
		cout << costs << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
n,k=map(int,input().split())
lists=[]
for _ in range(k):
  d=int(input())
  a=list(map(int,input().split()))
  lists.append(a)
num=[0]*n
for list in lists:
  for __ in range(len(list)):
    num[list[__]-1]+=1
count=0
for nn in num:
  if nn==0:
    count+=1
print(count)

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

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

	bool color_P = false;
	bool color_W = false;
	bool color_G = false;
	bool color_Y = false;
	int type = 0;

	vector<char> color(n);
	for (int i = 0; i < n; i++) {
		cin >> color[i];
		if (color[i] == 'P' && color_P == false) {
			color_P = true;
			type++;
		}
		else if (color[i] == 'W' && color_W == false) {
			color_W = true;
			type++;
		}
		else if (color[i] == 'G' && color_G == false) {
			color_G = true;
			type++;
		}
		else if (color[i] == 'Y' && color_Y == false) {
			color_Y = true;
			type++;
		}
	}

	if (type == 4) cout << "Four" << endl;
	else if (type == 3) cout << "Three" << endl;

	return 0;
}

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

int main() {
	string s, t;
	cin >> s >> t;
	bool ng = false;

	rep(i, s.size()) {
		if (s.at(i) != t.at(i)) {
			ng = true;
		}
	}

	if (ng) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

map<int, bool> mp;
int cost[20][20];
int main(){
	int n, a, b, c;
	int cnt;
	while(cin >> n && n){
		mp.clear();
		cnt = 0;
		fill(&cost[0][0], &cost[19][19] + 1, INF);
		rep(i, n){
			cin >> a >> b >> c;
			if(!mp[a]){
				mp[a] = true;
				cnt++;
				cost[a][a] = 0;
			}
			if(!mp[b]){
				mp[b] = true;
				cnt++;
				cost[b][b] = 0;
			}
			cost[a][b] = cost[b][a] = min(cost[a][b], c);
		}
		rep(k, cnt)rep(i, cnt)rep(j, cnt) cost[i][j] = min(cost[i][k]+cost[k][j], cost[i][j]);
		int id = 0;
		int best = INF;
		rep(i, cnt){
			int c = 0;
			rep(j, cnt)c+=cost[i][j];
			if(c < best){
				best = c;
				id = i;
			}
		}
		cout << id << " " << best << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <set>
#include <cstdio>
#include <numeric>
#include <algorithm>
#include <queue>

inline int getInt(){ int s; scanf("%d", &s); return s; }

typedef long long ll;

using namespace std;

int check(int a, int m){
  vector<int> visit(m);
  int now = 0;

  while(!visit[now]){
    visit[now] = 1;
    now = (now + a) % m;
  }

  return accumulate(visit.begin(), visit.end(), 0);
}

int main(){
  int m = getInt();
  int n = getInt();
  int a = getInt();
  int b = getInt();
  int c = getInt();
  int d = getInt();

  a %= m;
  b %= n;
  c %= m;
  d %= n;

  int acnt = check(a, m);
  int bcnt = check(b, n);

  ll ans1 = ((ll)acnt * bcnt) / __gcd(acnt, bcnt);
  ll ans2 = 0;

  vector<int> h(m, -1);
  int hh = 0;
  int xx = 0;
  int yy = 0;

  while(h[xx] == -1){
    h[xx] = yy;
    xx = (xx + a) % m;
    yy = (yy + b) % n;
    hh++;
  }

  int ym = ans1 / hh;
  int yd = n / ym;

  xx = c;
  yy = d;

  while(true){
    ans2++;

    if(ans2 == 30 * n){
      int ccnt = check(c, m);
      int dcnt = check(d, n);
      ans2 = ((ll)ccnt * dcnt) / __gcd(ccnt, dcnt);
      break;
    }

    if(h[xx] != -1){
      if((yy - h[xx] + n) % yd == 0)
        break;
    }

    xx = (xx + c) % m;
    yy = (yy + d) % n;
  }

  printf("%lld\n", ans1 * ans2 - 1);

  return 0;
}

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

int main()
{
	int s,t,sp=0,tp=0;
	for(int i=0;i<4;i++){
		cin >> s;
		sp += s;
	}
	for(int i=0;i<4;i++){
		cin >> t;
		tp += t;
	}
	cout << max(sp,tp) << endl;
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M, K;

int way[21][21];

ll dp[2][(1 << 20)];

void solve() {
	cin >> N >> M >> K;
	memset(way, -1, sizeof(way));

	rep(i, 0, K) {
		int a, b, c; cin >> a >> b >> c; a--; b--;
		way[a][b] = c;
	}
	dp[0][0] = 1;
	int now = 0, nex = 1;
	rep(i, 0, M) {
		rep(j, 0, N - 1) {
			memset(dp[nex], 0, sizeof(dp[nex]));
			rep(bit, 0, (1 << (N - 1))) {
				if(!dp[now][bit]) continue;
				// debug(i, j, bit, dp[now][bit]);
				if(way[i][j] != 1) { //do zero
					if(!(bit & (1 << j))) {
						ADD(dp[nex][bit], dp[now][bit]);
					}
				}
				if(way[i][j] != 0) { //do one
					if(bit & (1 << j)) {
						ADD(dp[nex][bit], dp[now][bit]);
					}
					else {
						ADD(dp[nex][((bit - (1 << j)) & bit) | (1 << j)], dp[now][bit]);
					}
				}
			}
			swap(now, nex);
		}
		// debug(i, vi(dp[now], dp[now] + (1 << (N - 1))));
	}
	ll res = 0;
	rep(bit, 0, (1 << (N - 1))) ADD(res, dp[now][bit]);
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

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



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

using namespace std;

int main(){
  
 // freopen("input.txt","r",stdin);
 // freopen("outputu.txt","w",stdout);
  int i,n,x;
  cin>>n;
  vector<int> v;
  for(i=0;i<n;i++){
    cin>>x;
    v.push_back(x);
  }
  sort(v.begin(),v.end());
  for(i=0;i<n;i++){
    //cout<<v[i];
    if(v[i]==v[i-1]){
    cout<<"NO";
    return 0;
  }
    
  }
  cout<<"YES";
  


  
 
 
 
    
 
return 0;
}

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

#define ls tree[node].l
#define rs tree[node].r

mt19937 rnd( time(NULL) );

const int maxN = 4e5 + 10;

struct Treap
{
	int l, r;
	int key, val, size;
}tree[maxN + 1];

int n, cnt, m, lim;
int a[maxN + 1], mx[maxN * 4 + 1];
int root[maxN + 1];

vector<int> t;

inline int read()
{
	int num = 0, f = 1;
	char ch = getchar();
	while( !isdigit( ch ) ) { if(ch == '-') f = -1; ch = getchar(); }
	while( isdigit( ch ) ) num = (num << 3) + (num << 1) + (ch ^ 48), ch = getchar();
	return num * f;
}

inline int new_Node(int v)
{
	tree[++ cnt] = (Treap){0, 0, (int)rnd(), v, 1};
	return cnt;
}

inline void pushup(int node)
{
	tree[node].size = tree[ls].size + tree[rs].size + 1;
}

inline void split(int node, int k, int &u, int &v)
{
	if(!node) { u = v = 0; return; }
	if(tree[node].val <= k) u = node, split(rs, k, tree[u].r, v);
	else v = node, split(ls, k, u, tree[v].l);
	pushup(node);
}

inline int merge(int u, int v)
{
	if(!u || !v) return u | v;
	if(tree[u].key < tree[v].key)
	{
		tree[u].r = merge(tree[u].r, v);
		pushup(u);
		return u;
	}
	else
	{
		tree[v].l = merge(u, tree[v].l);
		pushup(v);
		return v;
	}
}

inline int find(int node)
{
	while(rs) node = rs;
	return node ? tree[node].val : 0;
}

inline void change(int node, int l, int r, int x, int num)
{
	if(l == r) { mx[node] = num; return; }
	int mid = (l + r) >> 1;
	if(x <= mid) change(node << 1, l, mid, x, num);
	else change(node << 1 | 1, mid + 1, r, x, num);
	mx[node] = max(mx[node << 1], mx[node << 1 | 1]);
}

inline int query(int node, int l, int r, int v)
{
	if(mx[node] < v) return v;
	if(l == r) { t.push_back(l); return mx[node]; }
	int mid = (l + r) >> 1, res = v;
	if(res < mx[node << 1]) res = query(node << 1, l, mid, res);
	if(res < mx[node << 1 | 1]) res = query(node << 1 | 1, mid + 1, r, res);
	return res;
}

int main()
{
	n = read(); lim = 2 * n;
	for(int i = 1; i <= n; i++) a[i] = read();

	m = 1;
	for(int i = 1; i <= n; i++)
	{
		if(a[i] < a[i - 1]) m ++;
		root[m] = merge(root[m], new_Node(a[i]));
	}

	for(int i = 1; i <= m; i++) change(1, 1, lim, i, find(root[i]));

	for(int i = 0; i < n; i++)
	{
		t.clear();
		query(1, 1, lim, 0);
		m ++;
		int val = 0;
		for(int j = 0; j < t.size(); j++)
		{
			int x = t[j], u = 0, v = 0;
			split(root[x], val, u, v);
			root[m] = merge(root[m], v);
			root[x] = u;
			change(1, 1, lim, x, find(u));
			if(v) val = find(v);
		}
		change(1, 1, lim, m, find(root[m]));
		if(tree[ root[m] ].size == n)
		{
			printf("%d\n", i);
			break;
		}
	}
	return 0;
}


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

#define LL long long int
#define inp_s ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define mod 1000000007

LL q, h, s, d, n;

int main(){
      inp_s;
      cin >> q >> h >> s >> d;
      cin >> n;
      LL ans = (n * s);
      ans = min(ans, (n * 4 * q));
      ans = min(ans, (n * 2 * h));
      LL rem = (n % 2), m = (n / 2);
      if(rem == 0){
            ans = min(ans, (m * d));
      } else {
            ans = min(ans, (m * d) + (rem * s));
            ans = min(ans, (m * d) + (rem * 4 * q));
            ans = min(ans, (m * d) + (rem * 2 * h));
      }
      cout << ans;
      return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;


signed main(){
    while(true){
        string s;
        cin >> s;
        if(s == "-"){
            break;
        }
        string t = s;
        cin >> n;
        int cnt=0;
        REP(i,n){
            int t;
            cin >> t;
            cnt += t;
        }
        cnt %= s.size();
        REP(i,s.size()){
            t[i] = s[(i+cnt)%s.size()];
        }
        print(t);
    }
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}





Measured memory_bytes: 3128
import sys
input = sys.stdin.buffer.readline
MOD = 10**9+7

MAXN = 2*10**5+5
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

n, k = map(int, (input().split()))
ans = 0
for m in range(min(n-1,k)+1):
    ans += nCr(n,m) * nCr(n-1, n-m-1) % MOD
    ans %= MOD
print(ans)


Measured memory_bytes: 52720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
    int n, k, a, q, com, m, i;
    cin >> n;
    vector<bitset<64> > bit(n);
    bitset<64> b;
    bitset<64> c;
    rep(j, n)
    {
        cin >> k;
        rep(l, k)
        {
            cin >> a;
            bit[j].set(a, 1);
        }
    }
    
    cin >> q;
    rep(j, q)
    {
        cin >> com;
        switch(com)
        {
            case 0:
                cin >> i;
                if (b.test(i)) cout << 1 << endl;
                else cout << 0 << endl;
                break;
            case 1:
                cin >> m;
                b |= bit[m];
                break;
            case 2:
                cin >> m;
                b &= ~bit[m];
                break;
            case 3:
                cin >> m;
                b ^= bit[m];
                break;
            case 4:
                cin >> m;
                c = b & bit[m];
                if (c == bit[m]) cout << 1 << endl;
                else cout << 0 << endl;
                break;
            case 5:
                cin >> m;
                c = b & bit[m];
                if (c.any()) cout << 1 << endl;
                else cout << 0 << endl;
                break;
            case 6:
                cin >> m;
                c = b & bit[m];
                if (c.none()) cout << 1 << endl;
                else cout << 0 << endl;
                break;
            case 7:
                cin >> m;
                c = b & bit[m];
                cout << c.count() << endl;
                break;
            case 8:
                cin >> m;
                c = b & bit[m];
                cout << c.to_ulong() << endl;
                break;
        }
    }
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<long long> h(n);
    long long MIN;
    for(int i = 0;i < n;i++)cin >> h[i];
    reverse(h.begin(),h.end());
    MIN = h[0];
    for(int i = 0;i <= n;i++){
        if(i == n)cout << "Yes" << endl;
        else if(MIN < h[i]){
            if(h[i]- MIN == 1);
            else{
                cout << "No" << endl;
                break;
            }
        }else{
            MIN = h[i];
        }
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    // A*1 ~ A*Bの間で探す
    for (int b = 1; b <= B; ++b)
    {
        if (A * b % B == C)
        {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<char,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;




int main(){
    string N;
    cin >> N;
    ll n=N.size();
    ll ans=0;
    vector<ll> keta(n,0);
    for(ll i=0;i<n;i++){
        keta[i]=N[i]-'0'
    ;}
    for(ll i=n-1;i>=0;i--){
        if(keta[i]==10){
            if(i>0){
                keta[i-1]++;
                keta[i]=0;
            }
            else ans+=1;
        }
        else if(keta[i]<=4){
            ans+=keta[i];
        }
        else if(keta[i]>=6&&keta[i]<=9){
            ans+=10-keta[i];
            if(i>0){
                keta[i-1]++;
            }
            else ans+=1;
        }
        else if(keta[i]=5){
            if(i==0){
                ans+=5; 
            }
            else if(keta[i-1]<=4){
                ans+=5;
            }
            else if(keta[i-1]>=5){
                ans+=5;
                keta[i-1]+=1;
            }
        }
    ;}
    cout<<ans<<endl;
    
    return 0;
}


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

typedef long long ll;

int main(){
    ll n,i,j,k,l,r;
    cin>>n;
    ll ans=0;
    ans+=(n/500)*1000;
    n=n-(n/500)*500;
    ans+=(n/5)*5;
    cout<<ans;
    
    
}

Measured memory_bytes: 256
using System;

namespace c
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            string[] A = Console.ReadLine().Split(' ');
            int N = int.Parse(NK[0]);
            int K = int.Parse(NK[1]);
            if (K - 1 == 1)
            {
                Console.WriteLine(N - 1);
            }
            else
            {
                int count = 0;
                N = N - 1;
                while (N > 0)
                {
                    N = N - (K - 1);
                    count++;
                }


                Console.WriteLine(count);
            }
        }
    }
}

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

using namespace std;

#define int long long
#define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Printv(v)                                                              \
    {                                                                          \
        REP(x, v.size()) { cout << v[x] << (x == v.size() - 1 ? "\n" : " "); } \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
const ll LINF = 1e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

ll a[300];
double dp[301][301][301];
ll N;

double calcdp(VL n) {
    if(dp[n[3]][n[2]][n[1]]) return dp[n[3]][n[2]][n[1]];
    if(n[0] == N) return 0;
    double &res = dp[n[3]][n[2]][n[1]];
    double p = 0, tmp = 0;
    FOR(i, 1, 4) {
        if(n[i]) {
            p += (double)n[i] / N;
            n[i]--;
            n[i-1]++;
            tmp += (double)(n[i]+1.0) / N * calcdp(n);
            n[i]++;
            n[i-1]--;
        }
    }
    return res = (1.0 + tmp) / p;
}

signed main() {
    cin >> N;
    VL num(4);
    REP(i, N) num[IN()]++;
    double ans = calcdp(num);
    cout << scientific << setprecision(12) << ans << "\n";
}


Measured memory_bytes: 426368
#include <bits/stdc++.h>
using namespace std;
using tii = tuple<int, int, int>;
using pit = pair<int, tii>;

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

const int INF = 1e9;

int main()
{
	int w, h;
	while (cin >> w >> h, w | h) {
		vector<vector<int>> s(h, vector<int>(w));
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> s[i][j];
			}
		}
		vector<int> cost(4);
		for (int i = 0; i < 4; i++) {
			cin >> cost[i];
		}
		vector<vector<vector<int>>> d(h, vector<vector<int>>(w, vector<int>(4, INF)));
		priority_queue<pit, vector<pit>, greater<pit>> pq;
		pq.emplace(0, make_tuple(0, 0, 0));
		while (!pq.empty()) {
			auto p = pq.top(); pq.pop();
			int c = p.first, x = get<0>(p.second), y = get<1>(p.second), dir = get<2>(p.second);
			if (d[x][y][dir] != INF) continue;
			d[x][y][dir] = c;
			for (int i = 0; i < 4; i++) {
				int com = (i + 4 - dir) % 4, tx = x + dx[i], ty = y + dy[i], tc = c + (com == s[x][y] ? 0 : cost[com]);
				if (0 <= tx && tx < h && 0 <= ty && ty < w && d[tx][ty][i] == INF) {
					pq.emplace(tc, make_tuple(tx, ty, i));
				}
			}
		}
		int res = INF;
		for (int i = 0; i < 4; i++) {
			res = min(res, d[h - 1][w - 1][i]);
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3256