akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
#include <cctype>
using namespace std;
string S;
int cur;
char readchar()
{
    assert(cur<S.size());
    char ret=S[cur];
    cur++;
    return ret;
}
char peek()
{
    assert(cur<S.size());
    return S[cur];
}
int digit()
{
    assert(isdigit(peek()));
    int n=readchar()-'0';
    return n;
}
int number()
{
    int n=digit();
    while(cur < S.size() && isdigit(peek()))
    {
        n=n*10+digit();
    }
    return n;
}
//-----------------
int factor();
int term()
{
    int a=factor();
    while(cur<S.size()&&(peek()=='*'||peek()=='/'))
    {
        char op=readchar();
        int b=factor();
        if(op=='*')
            a*=b;
        else
            a/=b;
    }
    return a;
}

int expression()
{
    int a=term();
    while(cur<S.size()&&(peek()=='+'||peek()=='-'))
    {
        char op=readchar();
        int b=term();
        if(op=='+')a+=b;
        else a-=b;
    }
    return a;
}

int factor()
{
    if(peek()!='(')return number();
    cur+=1;
    int n=expression();
    assert(peek()==')');
    cur+=1;
    return n;
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cur=0;
        cin>>S;
        cout<<expression()<<endl;
        S.erase(S.begin(),S.end());
    }
    return 0;
}

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


int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p.at(i);
  int ans;
  int curMin = 1e9;
  
  rep(i, n){
    curMin = min(curMin, p.at(i));
    if (curMin ==p.at(i)) ans++;
  }
  cout << ans << endl;


}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		List<String> sList = new ArrayList<String>();

		for (int i = 0; i < n; i++) {
			sList.add(sc.next());
		}
		Collections.sort(sList);

		int listSize = sList.size();

		StringBuilder sss = new StringBuilder();
		for (int i = 0; i < listSize; i++) {
			sss.append(sList.get(i));
		}
		System.out.println(sss);
		sc.close();
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
int main () {
  int n;
  int a[10000] = {} ;
  scanf("%d",&n);
  while(n > 0){
    for(int i = 0 ; i < n ; i ++) {
      scanf("%d",&a[i]);
    }
    int sum = 0 ;
    for(int i = 0 ; i < n ; i ++){
      sum=sum + a[i];
    }
    int cnt=0;
    for(int i = 0 ; i < n ; i ++){
      if(a[i]*n <= sum){
        cnt++;
      }
    }
    printf("%d\n" ,cnt);
    scanf("%d",&n);
  }
  return 0;
}


Measured memory_bytes: 2108
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
using namespace std;
typedef long long ll;


int main(void) {
	map<string, int> mp;
	int n, cnt=0; cin >> n;
	rep(i, n) {
		string s; cin >> s;
		mp[s]++;
		cnt = max(cnt, mp[s]);
	}
	vector<string> ans;
	for (auto s = mp.begin(); s != mp.end(); s++) {
		if (s->second == cnt) {
			ans.push_back(s->first);
		}
	}
	sort(ans.begin(), ans.end());
	rep(i, ans.size()) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 26868
s = int(input())

def func(n):
    if n % 2 == 0:
        return int(n / 2)
    else:
        return 3*n + 1

i = 1
num_list = [s]
while True:
    num_list.append(func(num_list[i-1]))
    if num_list[i] in num_list[:i-1]:
        print(i+1)
        break
    i += 1

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

#define mp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;


int main()
{
  vector<int> v(3);
  for (auto &e : v)
    scanf("%d", &e);
  sort(v.begin(), v.end());
  vector<int> ans({5, 5, 7});
  puts(ans==v?"YES":"NO");
}


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

const int inf = 1000000000;

int h, w;
int maze[1000][1000];

queue<pair<int, int>> bfs_q;
queue<pair<int, int>> dfs_q;

bool boundary_check(int i, int j) {
  return 0 <= i && i < h && 0 <= j && j < w;
}

void dfs(int i, int j)
{
  bfs_q.emplace(i, j);

  const int di[] = {0, 1, 0, -1};
  const int dj[] = {1, 0, -1, 0};

  int m = maze[i][j];

  for (int ii = 0; ii < 4; ii++) {
    int ni = i + di[ii];
    int nj = j + dj[ii];
    if (boundary_check(ni, nj)) {
      if (maze[ni][nj] > m) {
        maze[ni][nj] = m;
        dfs(ni, nj);
      }
    }
  }
}

int main()
{
  int si, sj, gi, gj;

  cin >> h >> w;
  cin >> si >> sj;
  cin >> gi >> gj;

  si--; sj--; gi--; gj--;

  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      maze[i][j] = s[j] == '#' ? -1 : inf;
    }
  }

  maze[si][sj] = 0;
  dfs_q.emplace(si, sj);

  while (!empty(dfs_q) || !empty(bfs_q)) {
    while (!empty(dfs_q)) {
      auto [i, j] = dfs_q.front();
      dfs_q.pop();
      dfs(i, j);
    }
    while (!empty(bfs_q)) {
      auto [i, j] = bfs_q.front();
      bfs_q.pop();
      for (int di = -2; di <= 2; di++) {
        for (int dj = -2; dj <= 2; dj++) {
          int ni = i + di;
          int nj = j + dj;
          if (!boundary_check(ni, nj)) continue;
          int m = maze[i][j];
          if (maze[ni][nj] > m + 1) {
            maze[ni][nj] = m + 1;
            dfs_q.emplace(ni, nj);
          }
        }
      }
    }
  }
  if (maze[gi][gj] == inf) maze[gi][gj] = -1;
  cout << maze[gi][gj] << endl;
}


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

int a[100];
int main() {
	int b;
	while (cin >> b, b) {
		for (int c = 0; c<b; c++)scanf("%d", &a[c]);
		int sum = 0;
		for (int d = 0; d < b - 1; d++) {
			for (int e = d + 1; e < b; e++) {
				if (a[d] > a[e])sum++;
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3112
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskD   {
public   static   final int MAX = 1_00_100;
public   static long[] fac = new long[MAX];
public   static long[] inv = new long[MAX];
public   static long[] finv = new long[MAX];

public void solve(int testNumber, Scanner in, PrintWriter out) {
        int N = in.nextInt();
        int M = in.nextInt();
        int mod = 1_000_000_007;
        setnck(mod);
        int[] fac = factor(M);
        long ans = 1;
        for(int i : fac) ans = ans*nck(i + N - 1, i, mod)%mod;
        out.println(ans);
    }

public   static void setnck(int MOD) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i-1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i-1] * inv[i] % MOD;
        }
    }

static long nck(int n, int k, int MOD) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

public   static int[] factor(long n) {
        int[] ret = new int[50];
        int pos = 0;
        for(int i = 2; i*i <= n; i++){
            while(n%i == 0){
                n/=i;
                ret[pos] += 1;
                if(n%i!=0) pos++;
            }
        }
        if(n!=1) ret[pos++] = 1;
        return Arrays.copyOf(ret, pos);
    }

}
}



Measured memory_bytes: 25428
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::string S;

  std::cin >> S;

  int size = S.size();

  std::vector<int> a;

  for (int i = 0; i < size; i ++)
    a.push_back(S[i] - '0');

  long long s = 0;

  for (int i = 0; i < (1 << (size - 1)); i ++) {
    long long x = a[0];
    
    for (int j = 1, b = 1; j < size; j ++, b <<= 1)
      if (b & i) {
        s += x;

        x = a[j];
      }
      else {
        x = x * 10 + a[j];
      }

    s += x;
  }
  
  std::cout << s << std::endl;

  return 0;
}


Measured memory_bytes: 256
A, B, K = map(int, input().split())
lst1 = list(range(A, min(A+K, B+1)))
lst2 = list(range(max(B-K+1, A), B+1))
ans = set(lst1 + lst2)
ans = list(sorted(ans))
for i in ans:
  print(i)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
	#define D(x...) printf(x)
#else
	#define D(x...)
#endif
int amperrow[110][110], n, m, upto, seen[210], ismatched[210], matchedto[210];
vector<int> adj[210];
int match(int a)
{
	if (seen[a] == upto) return 0;
	seen[a] = upto;
	for (auto b : adj[a])
	{
		if (!ismatched[b])
		{
			ismatched[b] = ismatched[a] = 1;
			matchedto[b] = a;
			return 1;
		}
		else if (match(matchedto[b]))
		{
			ismatched[a] = 1;
			matchedto[b] = a;
			return 1;
		}
	}
	return 0;
}
int moved[110][110], val[110][110];
pair<int, int> movedto[110][110];
int rowitwants(int a)
{
	a--;
	return a/m;
}	
void dobpmthing(int jmovingto)
{
	D("starting new %d\n", jmovingto);
	for (int i = 0; i < n+n; i++) adj[i].clear();
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (amperrow[i][j]) adj[i].push_back(n+j), adj[n+j].push_back(i);
			D("%d ", amperrow[i][j]);
		}
		D("\n");
	}
	fill_n(ismatched, 2*n, 0);
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		upto++;
		if (match(i))
		{
			ans++;
			D("yay %d\n", i);
		}
		else
		{
			D("rip %d\n", i);
		}
	}
	assert(ans == n);
	for (int i = n; i < 2*n; i++)
	{
		bool done = 0;
		for (int j = 0; j < m; j++)
		{
			if (rowitwants(val[matchedto[i]][j]) == i-n && !moved[matchedto[i]][j])
			{
				done = 1;
				moved[matchedto[i]][j] = 1;
				movedto[matchedto[i]][j] = { matchedto[i], jmovingto };
				break;
			}
		}
		assert(done);
		amperrow[matchedto[i]][i-n]--;
	}
}
int nowhere[110][110];
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			scanf("%d", &val[i][j]);
			amperrow[i][rowitwants(val[i][j])]++;
		}
	}
	for (int i = 0; i < m; i++)
	{
		dobpmthing(i);
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			nowhere[movedto[i][j].first][movedto[i][j].second] = val[i][j];
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++) printf("%d ", nowhere[i][j]);
		printf("\n");
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			int done = 0;
			for (int k = 0; k < n; k++)
			{
				if (rowitwants(nowhere[k][j]) == i) printf("%d ", nowhere[k][j]), done++;
			}
			assert(done == 1);
		}
		printf("\n");
	}
}

Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<functional>
#include<cstring>

int main() {
	int n;
	bool used[10000];
	while (std::cin >> n) {
		int str[4] = { (n / 1000),(n / 100) % 10,(n / 10) % 10,n % 10 };
		if (n % 1111 == 0) {
			if (str[0] == 0)
				break;
			else
				std::cout << "NA" << std::endl;

		}
		std::memset(used, false, sizeof(used));
		used[n] = true;
		int cnt = 0;
		while(n!=6174) {
			++cnt;
			std::sort(str, str + 4, std::greater<int>());
			int l = str[0] * 1000 + str[1] * 100 + str[2] * 10 + str[3];
			std::sort(str, str + 4);
			int	s = str[0] * 1000 + str[1] * 100 + str[2] * 10 + str[3];
			n = l - s;
			if (used[n])
				goto a;
			used[n] = true;
			str[0] = n / 1000;
			str[1] = (n / 100) % 10;
			str[2] = (n / 10) % 10;
			str[3] = n % 10;
		}
		std::cout << cnt << std::endl;
	a:;
	}
	return 0;
}

Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main()
{
	int A,B;
	char op;
	cin>>A>>op>>B;
	switch(op) 
	{
		case '+': cout<<A+B<<endl;break;
		case '-': cout<<A-B<<endl;break;
	 } 
	 return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

const int MOD = 1e9+7;
int n, alp[26];

int main(void){
        scanf("%d", &n); getchar();
        for(int i=0; i<n; i++) alp[getchar()-'a']++;
        long ans = 1;
        for(int i=0; i<26; i++) ans = (ans * ++alp[i]) % MOD;
        printf("%ld\n", ans-1);
        return 0;
}

Measured memory_bytes: 128
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0))
for y in range(H):
    for x in range(W):
        if s[y][x] == '#':
            flag = True
        else:
            continue
        for dy, dx in moves:
            ny = y + dy
            nx = x + dx
            if 0 <= ny < H and 0 <= nx < W:
                if s[ny][nx] == '#':
                    flag = False
                    break
        if flag:
            print('No')
            exit()

print('Yes')

Measured memory_bytes: 39536
#include<stdio.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
typedef long long lint;
const int mod=1000000007;
int k,n=-1,cnt=13;
char c[15];
lint fact[2000010],inv[2000010];
int main(){
	while(true){
		*c=getchar_unlocked();
		if(*c=='\n')break;
		k*=10;
		k+=*c-'0';
	}
	while(getchar_unlocked()!=-1)n++;
	fact[0]=1;
	for(int i=1;i<=n+k;i++)fact[i]=fact[i-1]*i%mod;
	inv[n+k]=1;
	lint now=fact[n+k];
	int b=mod-2;
	while(b){
		if(b&1){
			inv[n+k]*=now;
			inv[n+k]%=mod;
		}
		b>>=1;
		now*=now;
		now%=mod;
	}
	for(int i=n+k-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
	lint ans=1;now=1;
	for(int i=1;i<=k;i++){
		now*=25;
		now%=mod;
		ans+=fact[n+k]*inv[n+k-i]%mod*inv[i]%mod*now;
		ans%=mod;
	}
	*(c+14)='\n';
	while(ans){
		*(c+cnt)=ans%10+'0';
		ans/=10;
		cnt--;
	}
	fwrite(c+cnt+1,1,14-cnt,stdout);
	return 0;
}

Measured memory_bytes: 32776
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A, B, K;
  cin >> A >> B >> K;
  if ( K >= A+B)
    cout << 0 << " " << 0 << endl;
  else if (K <= A)
    cout << A-K << " " << B <<endl;
  else
    cout << 0 << " " << B- (K-A) << endl; 
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int cnt = 0;
      int f = 1;
      int r = 0;
      int min = 10000;
      if(s.length()==1){
      	System.out.println(0);
        return;
      }
      for(char c = 'a';c<='z';c++){
        r = 0;
        for(int i = 0;i < s.length();i++){
      	  if(s.charAt(i)!=c)break;
          else r++;
        }
        if(r==s.length()){
        	System.out.println(0);
            return;
        }
      }
      for(char c = 'a';c <= 'z';c++){
        String t = s;
      	while(true){
          StringBuilder sb = new StringBuilder();
          f = 0;
          for(int i = 0;i < t.length()-1;i++){
        	if(t.charAt(i)==c)sb.append(c);
            else if(t.charAt(i+1)==c)sb.append(c);
            else{
              sb.append(t.charAt(i));
              f++;
            }
          }
          cnt++;
          t = sb.toString();
          if(f==0){
          	min = Math.min(min,cnt);
            cnt = 0;
            break;
          }
        }
      }
      System.out.println(min);
    }
}


Measured memory_bytes: 22484
#include <iostream>


using namespace std;

int partition(int *A ,int p ,int r){
  int x = A[r];
  int i = p-1;
  int tmp;
  for(int j=0;j<r;j++){
    if(A[j] <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  return i+1;
}

int main(){
  int n,q;
  int A[100000];

  while(1){
    cin >> n;
    if(cin.eof())
      break;
    char c = ' ';
    for(int i=0;i<n;i++){
      cin >> A[i];
    }
    q = partition(A,0,n-1);
    for(int i=0;i<n;i++){
      if(i == n-1)
        c = '\n';
      if(i == q)
        //printf("[%d]%c",A[i],c);
        cout << '[' << A[i] << ']' << c;
      else
        //printf("%d%c",A[i],c);
        cout << A[i] << c;
    }
  }
  return 0;
}



Measured memory_bytes: 3460
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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









int main(){
    int N, K, mod(998244353); std::cin >> N >> K;
    std::vector<long long> dp(N);
    dp[0] = 1; dp[1] = -1;
    std::vector<int> L(K), R(K);
    for(int i(0); i < K; ++i) std::cin >> L[i] >> R[i];
    for(int i(0); i < N; ++i){
        if(i) (dp[i] += dp[i-1]) %= mod;
        for(int j(0); j < K; ++j){
            if(i + L[j] < N) (dp[i + L[j]] += dp[i]) %= mod;
            if(i + R[j] + 1< N) (dp[i + R[j] + 1] -= dp[i]) %= mod;
        }
    }
    if(dp[N-1] < 0) dp[N-1] += mod;
    std::cout << dp[N-1] << std::endl;
    return 0;
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int tmp = 0;
  int m = 0;
  for (int i = 0; i < S.size(); i++) {
    char c = S.at(i);
    if (c == 'A' || c == 'G' || c == 'C' || c == 'T')  tmp++; 
    
    else if (tmp > m) {
      m = tmp;
      tmp = 0;
    }
  }
  m = max(m, tmp);
  cout << m << endl;
}

Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm> 
using namespace std;
#define int long long
int flag = 0;
int a[100005];
vector <int> G[100005];
void dfs (int x, int fa) {
	if (G[x].size() == 1) return ;
	int sum = 0, _max = 0;
	for (int i = 0; i < G[x].size(); i++) {
		int y = G[x][i];
		if (y == fa) continue;
		dfs (y, x);
		sum += a[y];
		_max = max (_max, a[y]);
	}
	int left;
	if (_max > sum - _max) left = sum - _max;
	else left = sum / 2;
	if (sum < a[x]) {
		flag = 1;
		return ;
	}
	if (sum - a[x] > left) {
		flag = 1;
		return ;
	}
	a[x] = 2 * a[x] - sum;
}
int in[100005];
signed main () {
	int n;
	scanf ("%lld", &n);
	for (int i = 1; i <= n; i++) scanf ("%lld", &a[i]);
	for (int i = 1; i < n; i++) {
		int x, y;
		scanf ("%lld %lld", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
		in[x]++, in[y]++; 
	}
	if (n == 2) {
		if (a[1] == a[2]) printf ("YES");
		else printf ("NO");
		return 0;
	}
	int root = 1;
	while (in[root] == 1 && root < n) root++;
	dfs (root, 0);
	if (flag == 1 || a[root] != 0) printf ("NO");
	else printf ("YES");
	return 0;
}

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


int main(){
  int N;
  cin >> N;
  vector<int> A(N+1);
  for(auto& a : A){
    cin >> a;
  }

  vector<long long> A_rev_sum(N+1);
  long long pre = 0;
  for(int ii=N; ii>=0; ii--){
    A_rev_sum[ii] = pre + A[ii];
    pre = A_rev_sum[ii];
  }
  

  long long ans=0;
  long long num_node = 1;
  for(int ii=0; ii<N+1; ii++){
    ans += num_node;
    if(num_node < A[ii]){
      cout << -1 << endl;
      return 0;
    }
    if(num_node > A_rev_sum[ii]){
      cout << -1 << endl;
      return 0;
    }
    num_node = min(A_rev_sum[ii+1], (num_node-A[ii])*2);
  }
  cout << ans << endl;

  return 0;
}


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

const int MAX_A = 300005;

int op(int a, int b) { return max(a,b);}
int e() { return 0;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  segtree<int,op,e> dp(MAX_A);
  rep(i,n) {
    int x = a[i];
    int l = x-k, r = x+k+1;
    l = max(l,0);
    r = min(r,MAX_A);
    int now = dp.prod(l,r)+1;
    dp.set(x, now);
  }
  int ans = dp.prod(0,MAX_A);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9620
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <utility>
#include <iomanip>
#include <queue>
#include <set>
#include <numeric>
#include <unordered_set>

#define rep(i,n) for(int i=0;i< (n);++i)
typedef long long ll;

using namespace std;


int main(){
    
    ll X;
    cin>>X;
    ll K;
    cin>>K;
    ll D;
    cin>>D;

    
    
    
    ll n=X/D;
    ll an=abs(n);
    
    if(K<=an){
        cout<<abs(X)-K*D<<endl;
    }else{
        if((K-an)%2==0){
        cout<< abs(X-n*D)<<endl;
        }else{
            if(n>=0){
            cout<<abs(X-(n+1)*D)<<endl;
            }else{
                cout<<abs(X-(n-1)*D)<<endl;
                    
                }
        }
    }
     
}



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

ll gcd(ll x, ll y){
    if(x < y) return gcd(y, x);
    if(x%y == 0) return y;
    return gcd(y, x%y);
}

int main(){
    ll n,x;
    cin >> n >> x;
    vector<ll>d(n);
    for(int i=0;i<n;i++){
        ll a;
        cin >> a;
        d[i] = abs(a - x);
    }
    ll ans = d[0];
    for(int i=1;i<n;i++) ans = gcd(ans, d[i]);

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}

uint tzcnt(uint x) {
    x = ~x & (x - 1);
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

int popcount(uint x) {
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

struct Point {
    int x, y;

    Point(int p, int q) : x(p), y(q) {}
};

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

    int N;
    cin >> N;

    map<char, ll> person_count = {
        { 'M', 0 },
    { 'A', 0 },
    { 'R', 0 },
    { 'C', 0 },
    { 'H', 0 },
    };

    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;

        char first = s[0];

        if (first == 'M' || first == 'A' || first == 'R' || first == 'C' || first == 'H') {
            ++person_count[first];
        }
    }

    ll ans = 0;

    const char table[] = { 'M', 'A' ,'R', 'C', 'H' };

    for (int i = 0b111; i <= 0b11111; ++i) {
        if (popcount(i) != 3) continue;

        int j = i;

        char p1 = table[tzcnt(j)];

        j &= j - 1;

        char p2 = table[tzcnt(j)];

        j &= j - 1;

        char p3 = table[tzcnt(j)];

        ans += person_count[p1] * person_count[p2] * person_count[p3];
    }

    out(ans);

    int aaa;
    cin >> aaa;
}

Measured memory_bytes: 256
a[100];main(n,k,x,i){for(;scanf("%d%d",&n,&k),n;){for(i=0;i<k;i++)scanf("%d",a+i);for(;n--;)for(i=0;i<k;a[i++]-=x)scanf("%d",&x);for(i=0;i<k&&a[i]>=0;i++);puts(k-i?"No":"Yes");}exit(0);}

Measured memory_bytes: 584
#include <iostream>

using namespace std;

int k, s, x, y, z, h;
int main()
{   cin >> k >> s;
    for(x=0; x<=k; x++) {
        for(y=0; y<=k; y++) {
            z = s - x - y;
            if(z >= 0 && z <= k) {
                h++;
            }
        }
    }
    cout << h;
    return 0;
}


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

signed main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(),v.end());
  int ans=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<i;j++)
      for(int k=0;k<j;k++)
        ans+=(v[i]!=v[j]&&v[j]!=v[k]&&v[k]+v[j]>v[i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    struct Drink{
        public long price;
        public long num;
        public Drink(long price,long num){
            this.price = price;
            this.num = num;
        }
    }
    public static void Main(){
        var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var N = input[0];
        var M = input[1];
        var ans = 0L;
        
        var list = new List<Drink>();
        for(var i = 0;i < N;i++){
            var line = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var price = line[0];
            var num = line[1];
            list.Add(new Drink(price,num));
            
        }
        list.Sort((a,b) => a.price.CompareTo(b.price));
        // foreach(var i in list){
        //     Console.WriteLine($"{i.price}:{i.num}");
        // }
        for(var i = 0;i < N;i++){
            if(M >= list[i].num){
                ans += list[i].price * list[i].num;
                M -= list[i].num;        
            }else{
                ans += M * list[i].price;
                break;
            }
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 19280
import java.util.*;

public class Main {

    static <T extends Comparable<? super T>> boolean nextPermutation(T[] sequence) {
        int first = getFirst(sequence);
        if (first == -1) return false;
        int toSwap = sequence.length - 1;
        while (sequence[first].compareTo(sequence[toSwap]) >= 0) --toSwap;
        swap(sequence, first++, toSwap);
        toSwap = sequence.length - 1;
        while (first < toSwap) swap(sequence, first++, toSwap--);
        return true;
    }

    static <T extends Comparable<? super T>> int getFirst(T[] sequence) {
        for (int i = sequence.length - 2; i >= 0; --i)
            if (sequence[i].compareTo(sequence[i + 1]) < 0) return i;
        return -1;
    }

    static <T extends Comparable<? super T>> void swap(T[] sequence, int i, int j) {
        T tmp = sequence[i];
        sequence[i] = sequence[j];
        sequence[j] = tmp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        Integer[][] graph = new Integer[N][N];
        for (int i = 0; i < N; ++i) Arrays.fill(graph[i], 0);
        for (int i = 0; i < M; ++i) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            graph[a][b] = 1;
            graph[b][a] = 1;
        }

        Integer[] arr = new Integer[N];
        for (int i = 0; i < N; ++i) arr[i] = i;

        int res = 0;
        do {
            if (arr[0] != 0) break;
            boolean flag = true;
            for (int i = 0; i < N-1; ++i) {
                if (graph[arr[i]][arr[i+1]] == 0) flag = false;
            }
            if (flag) ++res;
        } while(nextPermutation(arr));

        System.out.println(res);
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		if(n.matches(".*7.*")) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 35732
#include <iostream>
      #include <string>
      #include <vector>
      #include <algorithm>
      using namespace std;
      typedef long long ll;
      #define rep(i,n) for (int i=0;i < (int)(n);i++)
      
      int v[100001];
      int main(){
        int n;
        cin >> n;
        rep(i,n){
          int l,r;
          cin >> l >> r;
          for (int i=l-1;i < r;i++){
            v[i] = 1;
          }
        }
        int ans = 0;
        rep(i,100000){
          ans += v[i];
        }
        cout << ans << endl;
        
        return 0;

        
      }
        
        

Measured memory_bytes: 640
a,b,c,x,y=parse.(Int,split(readline()))
x>=y ? (l=(x,a);s=(y,b)) : (l=(y,b);s=(x,a))
d=l[1]-s[1]
println(min(
  a*x+b*y,
  l[1]*2c,
  2c*s[1]+d*l[2]
))

Measured memory_bytes: 172376
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N, A, B;

/*==================================================*/
/*function*/

/*==================================================*/

int main() {

    cin>>N>>A>>B;
    if(B < N*A){
        cout<<B<<endl;
    }else{
        cout<<A*N<<endl;
    }


    return 0;
}


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

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 22
#define maxmask (1ll<<maxbits)
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int  N=100000 +10, M=(ll)1e9+1 ;
 const int mod =(ll)1e9+7,sz=5 ;

vl g[N],vis(N,0),deg(N,0),tin(N,0);
vll ans;
ll tim;

void dfs(ll u,ll par=-1){
    vis[u]=1;
    tin[u]=++tim;
    for(auto &it:g[u]){
        if(it==par)
            continue;
        if(!vis[it]){
            dfs(it,u);
        }
        else if(tin[u]>tin[it]){
            ans.pb({u,it});
            deg[u]++;
        }
    }
    if(par!=-1){
        if(deg[u]&1){
            ans.pb({u,par});
            deg[u]++;
        }
        else{
            ans.pb({par,u});
            deg[par]++;
        }
    }
}
void work(){
 ll n,m;
 cin >> n >> m;
 for(ll i=0;i<m;i++){
    ll u,v;
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
 }
    if(m&1){
        cout << -1;
        return;
    }
    dfs(1,-1);
    for(ll i=0;i<ans.size();i++)
        cout << ans[i].f << " " << ans[i].s << "\n";
}
int main(){
 ios_base::sync_with_stdio(0);
// cin.tie(0);
    ll t;
//    cin >> t;
    t=1;
    while(t--){
            work();
    }
   return 0;

}


Measured memory_bytes: 17136
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        K: i64,
    }

    let ans = if K % 2 == 0 {
        (K / 2) * (K / 2)
    } else {
        (K - 1) / 2 * (K + 1) / 2
    };
    println!("{}", ans);
}


Measured memory_bytes: 2020
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int min = 1145141919;
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			int c = 0;
			while(a%2==0) {
				a/=2;
				c++;
			}
			min = Math.min(min, c);
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#define Max zhi5968
typedef long long ll;
using namespace std;

int main ()
{
	string s;
	cin>>s;
	for(int i=1;i<s.length();i++)
		if(s[i]=='C'&&s[i-1]=='A')
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <vector>
#include <set>
#include <utility>

using namespace std;

template <typename T, T kMod>
struct ModInt {
    using M = ModInt; 
    T v;
 
    ModInt(T _v = 0) { set_norm(_v % kMod + kMod); }
    M& set_norm(T _v) {
        v = (_v < kMod) ? _v : _v - kMod;
        return *this;
    }
 
    explicit operator bool() const { return v != 0; }
    M operator+(const M& a) const { return M().set_norm(v + a.v); }
    M operator-(const M& a) const { return M().set_norm(v + kMod - a.v); }
    M operator*(const M& a) const { return M().set_norm(ull(v) * a.v % kMod); }
    M operator/(const M& a) const { return *this * a.inv(); }
    M& operator+=(const M& a) { return *this = *this + a; }
    M& operator-=(const M& a) { return *this = *this - a; }
    M& operator*=(const M& a) { return *this = *this * a; }
    M& operator/=(const M& a) { return *this = *this / a; }
    M operator-() const { return M() - *this; }
    M& operator++(int) { return *this = *this + 1; }
    M& operator--(int) { return *this = *this - 1; }
 
    M pow(T n) const {
        if (n < 0) return inv().pow(-n);
        M x = *this, res = 1;
        while (n) {
            if (n & 1) res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }
 
    M inv() const {
        T a = v, b = kMod, p = 1, q = 0, t;
        while (b != 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(p -= t * q, q);
        }
        return M(p);
    }
 
    bool operator==(const M& a) const { return v == a.v; }
    bool operator!=(const M& a) const { return v != a.v; }
    friend ostream& operator<<(ostream& os, const M& a) { return os << a.v; }
    static T get_mod() { return kMod; }
};
 
using MInt = ModInt<int64_t, 998244353>;

struct Step {
  int64_t from;
  int64_t left;
  int64_t right;
  int64_t pattern;
};

int main() {
  int64_t N, K;
  cin >> N >> K;

  vector<pair<int64_t, int64_t>> ranges;
  ranges.reserve(10);
  for (int64_t k = 0; k < K; ++k) {
    int64_t l, r;
    cin >> l >> r;
    ranges.push_back({l, r+1});
  }
  vector<MInt> dp(N+1);
  dp[1] = 1;dp[2] = -1;
  for (int64_t n = 1; n <= N; ++n) {
    dp[n] += dp[n-1];
    for (auto& range : ranges) {
      if (n + range.first <= N) {
        dp[n + range.first] += dp[n];
      }
      if (n + range.second <= N) {
        dp[n + range.second] -= dp[n];
      }
    }
  }
  cout << dp[N] << endl;

  return 0;
}


Measured memory_bytes: 4748
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>

using namespace std;

#define int long long

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    
    cin >> s;
    
    int d = 0;
    
    for(auto c : s)
    {
        d += c-'0';
    }
    
    int x = stoi(s) % d;
    
    cout << (x == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
	string w1;
	string w2;
	string w3;
	while(cin >> w1){
		cin >> w2;
		cin >> w3;

		if(w1[w1.length() - 1] == w2[0] && w2[w2.length() - 1] == w3[0]) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n,m;
  cin >> n >> m;
  string s,t;
  cin >> s >> t;
  int g;
  LL a=n,b=m;
  a=a%b;
  while(a%b){
    g=a%b;
    a=b;
    b=g;
  }
  g=b;
  LL lcm=(LL)n*m/g;
  for(int i=0,j=0;i<n;i+=(n/g),j+=(m/g)){
    if(s[i]!=t[j]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << lcm << endl;
  return 0;
}


Measured memory_bytes: 512
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N = int(readline())
    if N == 0:
        return False
    C = [list(map(int, readline().split())) for i in range(N)]
    e = 2**.5/2
    r_min = max(r*e for x, r in C)
    r_max = max(r for x, r in C)
    H = []
    for i in range(N-1):
        x0, r0 = C[i]; x1, r1 = C[i+1]
        dx = x1 - x0
        l = (r0**2 + dx**2 - r1**2) / (2*dx)
        h = (r0**2 - l**2)**.5
        H.append(h)
    def check(h):
        k = -1
        for i in range(N):
            xi, ri = C[i]
            if k == -1:
                if h <= ri:
                    k = i
            else:
                if H[i-1] < h:
                    if k != -1:
                        xp, rp = C[k]
                        xq, rq = C[i-1]
                        x0 = xp - (rp**2 - h**2)**.5
                        x1 = xq + (rq**2 - h**2)**.5
                        if x1 - x0 >= 2*h:
                            return True
                    if h <= ri:
                        k = i
                    else:
                        k = -1
        if k == -1:
            return False
        xp, rp = C[k]
        xq, rq = C[N-1]
        x0 = xp - (rp**2 - h**2)**.5
        x1 = xq + (rq**2 - h**2)**.5
        return x1 - x0 >= 2*h
    left = r_min; right = r_max+1
    EPS = 1e-5
    while right - left > EPS:
        mid = (left + right) / 2
        if check(mid):
            left = mid
        else:
            right = mid
    write("%.16f\n" % (left*2))
    return True
while solve():
    ...


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

const int mxN = 2e5 + 5;
set<int> adj[mxN];
vector<int> group(mxN, -1);
int g = 0;

void dfs(int v) {
    group[v] = g;
    for(auto u : adj[v]) {
        if(group[u] == -1) dfs(u);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].insert(b);
        adj[b].insert(a);
    }
    for(int i = 0; i < n; i++) {
        if(group[i] == -1) dfs(i), g++;
    }
    g++;
    vector<int> cnt(g, 0);
    for(int i = 0; i < n; i++) {
        cnt[group[i]]++;
    }
    int ans = *max_element(cnt.begin(), cnt.end());
    cout << ans << endl;
}

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

using namespace std;
using namespace __gnu_pbds;
#define  st first
#define  nd second
#define int long long

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef cc_hash_table<int, int, hash<int > > ht;
#define TIMES_PER_SEC (CLOCKS_PER_SEC)


double get_absolute_time()
{
	return (double)clock()/TIMES_PER_SEC;
}
double starttime_acrush;
void starttime()
{
	starttime_acrush=get_absolute_time();
}
double gettime()
{
	return get_absolute_time()-starttime_acrush;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define M   1000000007
const int N = 10001;  // limit for array size

int32_t main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int n ;
  cin >> n ;
  int a[n] ;
  for ( int i = 0 ; i< n ; i++ )
    cin >> a[i];
  int ans = 1 ;
  int mi = a[0] ;
  for ( int i = 1 ; i< n ; i++ ){
    mi = min (mi , a[i]);
    if(mi == a[i])
        ans++;
  }
  cout << ans ;


}



Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = Integer.MIN_VALUE;
        int min = sc.nextInt();
        for(int i = 1; i < n; i++){
            int t = sc.nextInt();
            ans = Math.max(t-min, ans);
            if(t < min) min = t;
        }
        System.out.println(ans);
        sc.close();

    }

}



Measured memory_bytes: 98808
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        sc.close();

        if (a + b >= c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21460
#include <stdio.h>
int ans[200000];
int main(void)
{
    int n,i,x;
    scanf("%d",&n);
    for(i=0; i<n-1; i++)
    {
        scanf("%d",&x);
        ans[x-1]++;
    }
    for(i=0; i<n; i++)
    {
        printf("%d\n",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 2480
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<sstream>
#include<stack>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;


int main() {
	int l, r;
	char a[100000];
	cin >> a;
	l = 0;
	r = strlen(a)-1;
	int num = 0;
	bool ifcan;
	while (l < r) {
		if (a[l] != a[r]) {
			if (a[l] == 'x') {
				num++;
				l++;
			}
			else if (a[r] == 'x') {
				num++;
				r--;
			}
			else {
				ifcan = false;
				break;
			}
		}
		else {
			l++;
			r--;
		}
		if (l <= r)
			ifcan = true;
	}
	if (ifcan == true)
		cout << num;
	else
		cout << -1;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k;
ll a[200005];
ll l=-1e18-5,r=1e18+5,mid,ans;
int main()
{
//	freopen("data1.in","r",stdin);
//	freopen("jindian.out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	sort(a+1,a+1+n);
//	for(int i=1;i<=n;++i)
//  {
//      printf("%lld ",a[i]);
//  }
//  printf("\n");
	while(l<=r)
	{
		mid=(l+r)>>1;
		ll cnt=0;
//		printf("%lld\n",mid);
		for(int i=1;i<n;++i)
		{
			int li=i+1,ri=n,midi,tmp=0;
			while(li<=ri)
			{
				midi=(li+ri)>>1;
				if(a[i]*a[midi]<=mid)
				{
					if(a[i]>0)
					li=midi+1;
					else
					ri=midi-1;
					tmp=midi;
				}
				else
				{
					if(a[i]>0)
					ri=midi-1;
					else
					li=midi+1;
				}
			}
//			printf("%lld %lld\n",a[i],a[tmp]);
			if(tmp==0)
			continue;
			if(a[i]>0)
			cnt+=tmp-i;
			else
			cnt+=n-tmp+1;
		}
//		printf("%d\n",cnt);
		if(cnt>=k)
		{
			r=mid-1;
			ans=mid;
		}
		else
		{
			l=mid+1;
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 5260
#include <stdio.h>
#include <stdlib.h>
#define ll long long int
int compare_longlong(const void *a, const void *b) {ll *A = (ll *)a;ll *B = (ll *)b;if (*A > *B) return 1;if (*A < *B) return -1;return 0;}

int main(void){
	int N,K,i;
	scanf("%d%d",&N,&K);
	ll x[N],y[N],xary[N],yary[N];
	for(i=0;i<N;i++){
		scanf("%lld%lld",&x[i],&y[i]);
		xary[i] = x[i];
		yary[i] = y[i];
	}
	qsort(xary, N, sizeof(ll), compare_longlong);
	qsort(yary, N, sizeof(ll), compare_longlong);
	ll ans = (xary[N-1]-xary[0])*(yary[N-1]-yary[0]);
	for(int xi=0;xi<N;xi++){
		for(int xj=xi+1;xj<N;xj++){
			for(int yi=0;yi<N;yi++){
				for(int yj=yi+1;yj<N;yj++){
					int num=0;
					ll lx=xary[xi], rx=xary[xj];
					ll by=yary[yi], uy=yary[yj];
					for(i=0;i<N;i++){
						if(lx<=x[i] && x[i]<=rx && by<=y[i] && y[i]<=uy)num++;
					}
					ll s=(rx-lx)*(uy-by);
					if(num>=K && s<ans)ans=s;
				}
			}
		}
	}
	printf("%lld",ans);
	
	return 0;
}

Measured memory_bytes: 128
H, W, K = map(int, input().split())
MOD = 10 ** 9 + 7

Hd = sum([d * (H - d) * (W ** 2) for d in range(H)])
Wd = sum([d * (W - d) * (H ** 2) for d in range(W)])


# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in range(1, H * W + 2):
    factorial.append(factorial[-1] * i % MOD)
    inverse.append(pow(factorial[-1], MOD - 2, MOD))


ans = (Hd + Wd) * factorial[H * W - 2] * inverse[K - 2] * inverse[H * W - K] % MOD
print(ans)


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

vector<int> vec;

int main()
{
    
    
    int n;
    cin>>n;
    
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        vec.push_back(a);
    }
    
    
    int l=0;
    int r=0;
    int pre=INT_MAX;
    int ans=0;
    
    while(r<n)
    {
        int k=r;
        
        while(k<n && vec[k]<=pre)
        pre=vec[k++];
        
        ans=max(ans,k-l-1);
        l=k;
        r=k;
        pre=vec[k];
    }
    
    cout<<ans<<endl;
  
  
  return 0;
 
}

Measured memory_bytes: 892
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);;
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = int.Parse(spl[0]);
        var k     = int.Parse(spl[1]);
        var ary = ToIntArray(input.ReadLine(), n);

        Array.Sort(ary);

        long min = long.MaxValue;

        for(int i=1; i<n; i++) {
            var v = ary[i] - ary[i-1];
            if(v != 0 && v < min) min = v;
        }

        foreach(var x in ary) {
            if(x >= k) {
                if((x - k) % min == 0)
                    return "POSSIBLE";
            }
        }

        return "IMPOSSIBLE";
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 19808