akhauriyash/Code-Regression huggingface dataset:
N = gets.to_i
points = []

N.times do
  x, y, h = gets.split.map(&:to_i)
  points << [x, y, h]
end

ans = nil
found = false
0.upto(101) do |cx|
  break if found
  0.upto(101) do |cy|
    break if found
    heights = []
    negatives = []
    points.each do |p|
      x = p[0]
      y = p[1]
      h = p[2]
      if h == 0
        negatives << [x, y, h]
      else
        heights << (x - cx).abs + (y - cy).abs + h
      end
    end

    if heights.uniq.size == 1
      if negatives.empty?
        ans = [cx, cy, heights.first]
        found = true
        break
      else
        found = true
        negatives.each do |p|
          x = p[0]
          y = p[1]
          h = p[2]
          if heights.first > (x - cx).abs + (y - cy).abs
            found = false
            break
          end
        end

        if found
          ans = [cx, cy, heights.first]
          break
        end
      end
    end
  end
end

puts ans.join(' ')


Measured memory_bytes: 3580
import java.util.*;

public class Main {

	static int[] getSwapList (int p) {
		switch (p) {
			case 0 : return new int[]{1,4};
			case 1 : return new int[]{0,2,5};
			case 2 : return new int[]{1,3,6};
			case 3 : return new int[]{2,7};
			case 4 : return new int[]{0,5};
			case 5 : return new int[]{1,4,6};
			case 6 : return new int[]{2,5,7};
			case 7 : return new int[]{3,6};
			default : return null;
		}
	}

	public static char[] copyOf (char[] c) {
		char[] ret = new char[c.length];
		for (int i = 0; i < c.length; i++)
			ret[i] = c[i];
		return ret;
	}

	public static void main (String[] args) {

		Scanner sc = new Scanner(System.in);

		int step = 1;
		char[] g = new char[]{'0','1','2','3','4','5','6','7'};
		ArrayList<char[]> list = new ArrayList<char[]>();
		HashMap<String,Integer> memo = new HashMap<String,Integer>();
		list.add(g);
		memo.put(new String(g), 0);

		while (!list.isEmpty()) {
			ArrayList<char[]> next = new ArrayList<char[]>();
			for (char[] c : list) {
				int p = new String(c).indexOf("0");
				int[] swaps = getSwapList(p);
				for (int i = 0; i < swaps.length; i++) {
					char[] temp = copyOf(c);
					temp[p] = temp[swaps[i]];
					temp[swaps[i]] = '0';
					if (!memo.containsKey(new String(temp))) {
						memo.put(new String(temp), step);
						next.add(temp);
					}
				}
			}

			list = next;
			step++;
		}

		while (sc.hasNext()) {
			String[] str = sc.nextLine().split(" ");
			String s = "";
			for (String st : str)
				s += st;
			System.out.println(memo.get(s));
		}

	}

}

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

int main()
{
  int n;
  bool cards[4][14] = {};
  cin >> n;
  for (int i=0; i<n; i++) {
    char pict;
    int rank;
    cin >> pict >> rank;
    if (pict=='S') cards[0][rank] = true;
    else if (pict=='H') cards[1][rank] = true;
    else if (pict=='C') cards[2][rank] = true;
    else if (pict=='D') cards[3][rank] = true;
  }
  for (int i=0; i<4; i++) {
    for (int j=1; j<=13; j++) {
      if (cards[i][j]) continue;
      char pict;
      if (i==0) pict = 'S';
      else if (i==1) pict = 'H';
      else if (i==2) pict = 'C';
      else if (i==3) pict = 'D';
      cout << pict << ' ' << j << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3048
import collections

S = input()

dic = collections.Counter(S)

ans = len(S)

for k in dic.keys():
    tmp = S
    tmp_ans = 0
    while True:
        ch = ''
        lens = len(tmp)

        for i,s in enumerate(tmp):
            if ch == '' or ch == s:
                ch = s
            else:
                break

        else:
            break

        for i in range(len(tmp)-1):
            if tmp[i+1] == k:
                tmp = tmp[:i] + k + tmp[i+1:]

        tmp = tmp[:-1]
        tmp_ans += 1


    ans = min(ans,tmp_ans)

print(ans)


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

int main()
{

int N,d;
int count=0;
cin>>N>>d;
int x,y;
for(int i=0;i<N;i++)
{
    cin>>x>>y;
    if(sqrt(pow(x,2)+pow(y,2))<=d)
    {
        count++;
    }
}

cout<<count<<endl;




    return 0;
}


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

// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o 

int main(){
 int n;
 cin>>n;
 string s;
 cin>>s;
 vector<int>v;
 for(int i=0;i<n;i++){
  if(s[i]=='R')
   v.pb(i);
 }
 int ans=0;
 int i=0;
 while(i<n-1){
  if(s[i]=='W'){
   if(!v.empty() && v.back()>i){
    swap(s[i],s[v.back()]);
    v.pop_back();
    ans++;
   }
   else if(s[i+1]=='R'){
    s[i]='R';
    ans++;
   }
  }
  i++;
 }
 cout<<ans<<"\n";
 return 0;
}


Measured memory_bytes: 4412
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a==1){
		a=14;
	}
	if(b==1){
		b=14;
	}
	if(a>b){
		printf("Alice\n");
	}else if(a<b){
		printf("Bob\n");
	}else{
		printf("Draw\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    string ans;
    for(int i=0;i<n;++i)
    {
        ans+=s[i];
        ans+=t[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = gets.to_i
ps = gets.split.map(&:to_i)
qs = gets.split.map(&:to_i)

len = Array.new
n.times{ |i|
    len.push(i+1)
}
#-----------------------------------
c=1;pn=0;qn=0;
len.permutation{ |x|
    if x == ps then pn = c end
    if x == qs then qn = c end
    c+=1
    if pn > 0 && qn > 0 then break end
}
p (pn - qn).abs

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main()
{
  const double PI = acos(-1);
  double a, b, h, m, ans;
  pair<double, double> aa, bb;
  cin >> a >> b >> h >> m;
  h = h * PI / 6 + m * PI / 360;
  m = m * PI / 30;
  aa = {a * cos(h), a * sin(h)};
  bb = {b * cos(m), b * sin(m)};
  ans = sqrt(pow(aa.first - bb.first, 2) + pow(aa.second - bb.second, 2));
  cout << fixed << setprecision(9);
  cout << ans;
}


Measured memory_bytes: 4144
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    vector<string> sub;
    rep(i, s.size())
    {
        sub.push_back(s.substr(i));
    }

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

    vector<int> lcp(sub.size());
    rep(i, sub.size())
    {
        if (i == 0) {
            lcp[i] = 0;
        } else {
            int j = 0;
            while (j < sub[i - 1].size() && sub[i - 1][j] == sub[i][j])
                j++;
            lcp[i] = j;
        }
    }

    rep(i, sub.size())
    {
        int m = (sub[i].size() + 1) - (lcp[i] + 1);
        if (K <= m) {
            cout << sub[i].substr(0, lcp[i] + K) << endl;
            return 0;
        }
        K -= m;
    }

    return 0;
}

Measured memory_bytes: 16128
// 基本テンプレート
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

signed main() {
    int N; string s;
    cin >> N >> s;
    int Q; cin >> Q;
    while(Q--) {
        int K; cin >> K;

        int cntD = 0, cntM = 0, ans = 0, sum = 0;
        for(int i=0; i<N; i++) {
            if(i-K>=0) {
                if(s[i-K] == 'D') cntD--, sum -= cntM;
                if(s[i-K] == 'M') cntM--;
            }
            if(s[i] == 'D') cntD++;
            if(s[i] == 'M') cntM++, sum += cntD;
            if(s[i] == 'C') ans += sum;
        }
        cout << ans << endl;
    }
    return 0;
}


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

int mn = 1000000;
signed main(){
  
  int n;
  cin >> n;

  int sum = 0;
  int psum[n+1];
  psum[0] = 0;
  for(int i = 1 ;i<=n;i++){
    int x;
    cin >> x;
    sum+=x;
    psum[i]= psum[i-1]+x;
  }
  
  for(int i = 1;i<=n;i++){
    mn = min(mn, abs(sum-2*psum[i]));
  }

  cout << mn <<  endl;
  return 0;
}
    
  


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

int main(void){
    int n, m, a[55], b[55], c[55], d[55], man[55][55];
    cin >> n >> m;
    for(int i=0;i<n;++i){
        cin >> a[i] >> b[i];
    }
    for(int i=0;i<m;++i){
        cin >> c[i] >> d[i];
    }
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            man[i][j] = abs(a[i]-c[j])+abs(b[i]-d[j]);
        }
    }
    for(int i=0;i<n;++i){
        int min=1000000000, check=0;
        for(int j=0;j<m;++j){
            if(min > man[i][j]){
                min = man[i][j];
                check = j;
            }
        }
        cout << check+1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast                         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int                          long long int
#define double                       long double
#define ff                           first
#define ss                           second
#define pb                           push_back
#define eb                           emplace_back
#define all(x)                       (x).begin(), (x).end()
#define sz(x)                        ((int)(x).size())
#define len(x)                       ((int)(x).length())
#define pii                          pair<int,int>
#define vi                            vector<int>
#define vd                           vector<double>
#define vs                            vector<string>
#define mp                          map<int,int>

#define ump                         unordered_map<int,int>

#define lb                            lower_bound
#define ub                            upper_bound
#define nx                            cout<<"\n";
#define inf                           9223372036854775807
#define PI                            3.14159265

const int MOD = 1e9 + 7;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
inline int add(int a, int b) {    return ((a % MOD) + (b % MOD)) % MOD;}

inline int multi(int a, int b) {   return ((a % MOD) * (b % MOD)) % MOD;}

inline int sub(int a, int b) {       a %= MOD; b %= MOD; a -= b; if (a < 0) a += MOD; return a;}

inline int power(int a, int b) {       a %= MOD; int res = 1; while (b > 0) {if (b & 1) {res = multi(res, a);} a = multi(a, a); b >>= 1;}  return res;}

bool isPrime(int  x) {      if (x <= 4 || x % 2 == 0 || x % 3 == 0) {return x == 2 || x == 3;} for (int i = 5; i * i <= x; i += 6) {if (x % i == 0 || x % (i + 2) == 0) { return 0;}} return 1;}

int32_t main()
{
  fast ;


  int n, w; cin >> n >> w;
  int wt[n], val[n];
  for (int i = 0; i < n; i++)cin >> wt[i] >> val[i];
  int dp[105][100005];
  dp[0][0] = 0;
  for (int i = 1; i <= 100000; i++)dp[0][i] = INT_MAX;
  for (int i = 1; i <= n; i++)
  {
    for (int j = 1; j <= 100005; j++)
    {
      dp[i][j] = dp[i - 1][j];
      if (val[i - 1] <= j)
      {
        dp[i][j] = min(dp[i][j], wt[i - 1] + dp[i - 1][j - val[i - 1]]);
      }
    }
  }
  int ans = 0;
  for (int j = 1; j <= 100000; j++)
  {
    if (dp[n][j] <= w)ans = max(ans, j);
  }
  cout << ans;

}



Measured memory_bytes: 81024
#include <iostream>
using namespace std;
int main(){
	int n,a,b;
	bool primes[1000001];
        primes[2] = true;
        for (int i = 3; i < 1000001; i += 2) {
                primes[i] = true;
        }
        for (int i = 3; i * i < 1000001; i += 2) {
                if (primes[i]) {
                for (int j = i * 2; j < 1000001; j += i) {
                 primes[j] = false;
                 }
            }
        }
	while(true){
		int cnt=0;
		cin >> n;
		b=n/2;
		if(n==0) break;
		for(int i=0;i<b+1;i++){
			if(primes[i]==true){
				a=n-i;
				if(primes[a]==true){
					cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  VV<> g(n);
  while (m--) {
    int u, v; cin >> u >> v, --u, --v;
    g[u].push_back(v);
  }

  int mn = 1e9;
  V<> res;
  for (int r = 0; r < n; ++r) {
    queue<int> q;
    V<> d(n, -1), prv(n, -1);
    d[r] = 0;
    q.push(r);
    [&] {
      while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int u : g[v]) if (d[u] == -1) {
          d[u] = d[v] + 1;
          prv[u] = v;
          q.push(u);
        } else if (u == r and d[v] + 1 < mn) {
          mn = d[v] + 1;
          V<>().swap(res);
          int x = v;
          while (true) {
            res.push_back(x);
            if (x == r) return;
            x = prv[x];
          }
        }
      }
    }();
  }

  if (res.empty()) {
    cout << -1 << '\n';
  } else {
    cout << res.size() << '\n';
    for (int v : res) {
      cout << v + 1 << '\n';
    }
  }
}

Measured memory_bytes: 512
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TooManyListenersException;

public class Main {

	static int[][] map;
	static int[][] directions8 = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 },
			{ 1, 1 } };
	static int[][] directions4 = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
	static int ans;
	static int m;
	static int n;
	static Shougen[] shougen;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		m = sc.nextInt();
		n = sc.nextInt();

		shougen = new Shougen[n];

		for (int i = 0; i < n; i++) {
			shougen[i] = new Shougen(sc.nextInt(), sc.nextInt());
		}

		List<Integer> ansArray = solve(new ArrayList<Integer>(), 0);

		for (int i = 0; i < ansArray.size(); i++) {
			System.out.println(ansArray.get(i));
		}
	}

	static ArrayList<Integer> solve(ArrayList<Integer> tmpList, int idx) {
		if (m == idx) {
			return tmpList;
		}

		Set<Integer> nextCandidates = new HashSet<Integer>();
		for (int i = 1; i <= m; i++) {
			nextCandidates.add(i);
		}
		for (int i = 0; i < n; i++) {
			if (!tmpList.contains(shougen[i].num) && !tmpList.contains(shougen[i].after)
					&& nextCandidates.contains(shougen[i].after)) {
				nextCandidates.remove(shougen[i].after);
			}
		}
		for (int i = 1; i <= m; i++) {
			if (!nextCandidates.contains(i) || tmpList.contains(i)) {
				continue;
			}
			tmpList.add(i);
			ArrayList<Integer> tmp = solve(tmpList, idx + 1);
			if (tmp != null) {
				return tmp;
			}
		}
		return null;
	}

	// BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for (int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	// //二分探索
	// k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray) {
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedArray[mid] <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// 二分探索
	// k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList) {
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedList.get(mid) <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}

class Shougen {
	int num;
	int after;

	Shougen(int num, int after) {
		this.num = num;
		this.after = after;
	}
}



Measured memory_bytes: 26372
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;

#define MAXN 524288
#define MAXC 1048576
#define NO_VALUE -1

#define LEFT(x) ( 2*(x) )
#define RIGHT(x) ( 2*(x)+1 )

int A, B, C, M;

int r() {
    A = 36969 * (A & M) + (A >> 16);
    B = 18000 * (B & M) + (B >> 16);
    return (C & ((A << 16) + B)) % 1000000;
}

int x[MAXN], y[MAXN], z[MAXN], ox[MAXN], val[MAXN], used[MAXC], stack[MAXN], ymap[MAXC], Y;

bool cmp_x(const int &a, const int &b) { return x[a] < x[b]; }

map<int, int> bit[MAXC];

int answer(int idx, int th) {
    map<int, int>::iterator it = bit[idx].lower_bound(th);
    if (it != bit[idx].begin()) return (--it)->second;
    else return NO_VALUE;
}

int query(int idx, int th) {
    int res = NO_VALUE;
    while (idx > 0) {
        res = max(res, answer(idx, th));
        idx &= idx-1;
    }
    return res;
}

void update(int idx, int th, int v) {
    map<int,int>::iterator it1, it2;
    while (idx < Y) {
        it1 = it2 = bit[idx].upper_bound(th);
        while (it2 != bit[idx].end() && it2->second <= v) it2++;
        bit[idx].erase(it1, it2);
    
        it1 = bit[idx].upper_bound(th);
        if (it1 == bit[idx].begin() || (--it1)->second < v) bit[idx][th] = v;
        idx += idx&(-idx);
    }
}

int main() {
    int m, n, i, j, N, t = 1, STACK;

    while (scanf("%d %d %d %d", &m, &n, &A, &B) && (m || n || A || B)) {
        C = ~(1<<31); M = (1<<16)-1;
        for (i=0; i<m; i++) scanf("%d %d %d", &x[i], &y[i], &z[i]);
        for (i=m; i<m+n; i++) { x[i] = r(); y[i] = r(); z[i] = r(); }
        N = m+n;

        Y = 0;
        for (i=0; i<N; i++) {
            ox[i] = i;
            if (used[y[i]] < t) { used[y[i]] = t; stack[Y++] = y[i]; }
        }
        sort(ox, ox+N, cmp_x);
        sort(stack, stack+Y);
        for (i=0; i<Y; i++) ymap[stack[i]] = i+1;
        for (i=0; i<N; i++) y[i] = ymap[y[i]];
        t++; Y++;

        for (i=0; i<Y; i++) bit[i].clear();

        i = 0;
        do {
            for (j=i; j<N && x[ox[j]]==x[ox[i]]; j++) val[ox[j]] = max(1, query(y[ox[j]]-1, z[ox[j]])+1);
            for (; i<j; i++) update(y[ox[i]], z[ox[i]], val[ox[i]]);
        } while (i < N);
        printf("%d\n", query(Y-1, MAXC));
    }

    return 0;
}

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

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    while(k-- > 0){
        if(b <= a){
            b *= 2;
            continue;
        }
        if(c <= b){
            c *= 2;
            continue;
        }
    }
    if(a < b && b < c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
	int s = 0, t = 0;
	int a;
	int i;
	
	for (i = 0; i < 4; i++){
		scanf("%d", &a);
		s += a;
	}
	for (i = 0; i < 4; i++){
		scanf("%d", &a);
		t += a;
	}
	
	(s >= t) ? printf("%d\n", s) : printf("%d\n", t);
	
	return (0);
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    int ma = 0;
    rep(i,n){
        int x;
        cin >> x;
        ma = max(ma,x);
        if(ma==x)ans++;
    }
    
    cout << ans << endl;
    return 0;
}
 
 


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

int main(){
  long a,b;
  while(1){
    cin>>a>>b;
    if(!a && !b)break;
    long rest=b-a;
    int sand,five,hand;
    sand=rest/1000;
    five=(rest-sand*1000)/500;
    hand=(rest-sand*1000-five*500)/100;
    cout<<hand<<" "<<five<<" "<<sand<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
using namespace std;

int main(){
	int n,x;
	cin>>n>>x;
	vector<int> a(n);
	REP(i,n) cin>>a[i];
	
	sort(ALL(a));
	
	int cnt=0;
	REP(i,n){
		x-=a[i];
		cnt++;
		if(x<=0) break;
	}
	
	if(x==0) cout<<cnt<<endl;
	else cout<<cnt-1<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())

a = [0] * (n + 1)

for i in range(2, n + 1):
    x = i
    for j in range(2, i + 1):
        if x < j:
            break
        c = 0
        while x % j == 0:
            x //= j
            c += 1
        if c > 0:
            a[j] += c
    if x > 1:
        a[x] += 1
    
ans = 1
rem = 10 ** 9 + 7
for k in range(2, n + 1):
    if a[k] > 0:
        ans = (ans * (a[k] + 1)) % rem

print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define RMAX 4294967295
#define equals(a,b)(fabs((a)-(b))<EPS)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef complex<double> comp;
typedef vector<complex<double>> vcomp;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef string::const_iterator State;
class ParseError {};
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


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

	string s;
	cin >> s;

	vi num(3, 0);


	for (auto c : s){
		num[c - 'a']++;
	}
	sort(all(num));
	if(num.back() - num.front() > 1) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n,cot=0,t=0,a[55],b[55];
bool vis[105][105];
int main()
{
    memset(vis,true,sizeof(vis));
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        vis[i][i]=false;
    int p=n;
    if(n%2==1)
        n--;
    int l=1,r=n;
    while(l<=r)
    {
        vis[l][r]=vis[r][l]=false;
        l++,r--;
    }
    int ans=0;
    for(int i=1;i<=p;i++)
        for(int j=i+1;j<=p;j++)
        if(vis[i][j]) ans++;
    printf("%d\n",ans);
    for(int i=1;i<=p;i++)
        for(int j=i+1;j<=p;j++)
            if(vis[i][j])
            printf("%d %d\n",i,j);
}


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>;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}

int main() {
  ll k, ans = 0; cin >> k;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int l = 1; l <= k; l++) {
        ans += gcd(gcd(i, j), l);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
N = int(input())                            
ans = 0                                     
                                            
def num(x,y):                               
    base = x                                
    while x <= y:                           
        x = x * base                        
    return x // base                        
a = N                                       
#while a >= 6:                              
#    ans += 1                               
#    n6 = num(6,a)                          
#    n9 = num(9,a)                          
#    if a >= 12 and a <= 14:                
#        a = a - n6                         
#    elif n6 < n9:                          
#        a = a -n9                          
#    else:                                  
#        a = a - n6                         
def ttt(a):                                 
    if a <= 5:                              
        return a                            
    else:                                   
        n6 = num(6,a)                       
        n9 = num(9,a)                       
        return min(ttt(a-n9),ttt(a-n6)) + 1 
print(ttt(a))                               


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

ll gcd(ll a, ll b)
{
    while (b != 0)
    {
        ll temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

int main(void)
{
    int k;
    cin >> k;

    int sum = 0;
    for (int a = 1; a <= k; a++)
    {
        for (int b = 1; b <= k; b++)
        {
            for (int c = 1; c <= k; c++)
            {
                sum += gcd(a, gcd(b, c));
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main(){
  string s;
  int n,i,ans=0;
  cin >> n >> s;
  for(i=0;i<n-2;i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3508
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    int a    = INF;
    double b = INF;
    vector<pair<int, pair<double, double>>> v(n);
    rep(i, n) cin >> v[i].fi >> v[i].se.fi >> v[i].se.se;
    sort(all(v));
    rep(i, v.size()) {
      double h = v[i].se.fi, w = v[i].se.se;
      double diff = abs(w * 10000.0 / h / h - 22.0);
      if (cmin(b, diff)) a = v[i].fi;
    }
    cout << a << endl;
  }
}

Measured memory_bytes: 3228
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Card{
    string suit;
    int value;
};

int Func(){
    int x = 0;
    return x;
}

int main(){
    int A, B, K;
    float f;
    string S;
    
    cin >> S;
    //for (int i=0;i<N;i++) cin >> A[i];
    
    
    int count0 = 0;
    int count1 = 0;
    
    for (int i=0;i<S.length();i++) {
        if (S[i]=='0') count0 += 1;
        else count1 += 1;
    }
    if (count0 < count1) cout << 2*count0 << endl;
    else cout << 2*count1 << endl;
    


    
    return 0;
}


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

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

	cout << s[0] << s[1] << s[2] << endl;
	return (0);
}


Measured memory_bytes: 3624
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>

using namespace std;

int main() {
	int n;
	cin >> n;
	
	vector<int> p(n);

	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		p[i] = tmp;
	}

	*std::max_element(p.begin(), p.end()) /= 2;

	int sum = 0;;

	for (int i = 0; i < n; i++) {
		sum += p[i];
	}

	cout << sum << endl;
	
	return 0;
}

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

int N;
int L[2000];

signed main() {
  cin >> N;
  for(int i=0; i<N; i++) cin >> L[i];
  sort(L, L+N);

  long long ans = 0;
  for(int i=0; i<N; i++) for(int j=i+1; j<N; j++) {
    int a = L[i], b=L[j];
    auto l = upper_bound(L, L+N, abs(a-b));
    auto r = lower_bound(L, L+N, a+b);
    ans += distance(l,r);
    if( *l <= a && a <= *(r-1)) ans--;
    if( *l <= b && b <= *(r-1)) ans--;
  }
  assert(ans%3==0);
  cout << ans / 3<< endl;
}


Measured memory_bytes: 256
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順

using namespace std;
using ll = long long int;

int main(){
    int K,A,B;cin>>K>>A>>B;
    for(int i=A;i<=B;i++){
        if(i%K==0){
            cout << "OK" << endl;
            exit(0);
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  string s;
  cin >> s;
  bool ans = true;
  if(s.find('a')==string::npos) ans = false;
  if(s.find('b')==string::npos) ans = false;
  if(s.find('c')==string::npos) ans = false;
  cout << (ans?"Yes":"No") << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int max = sc.nextInt();
      	int sum = 0;
        
      for(int a=1;a<=max;a++){
        for(int b=1;b<=max;b++){
          for(int c=1;c<=max;c++){
            int tmp = gcd(b,c);
            sum += gcd(a,tmp);
          }
         
        }
      }
      System.out.println(sum);
	}
  
  	 private static int gcd(int x,int y) {
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
       return y;
    }
}

Measured memory_bytes: 35760
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

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

    deque<char> dq;
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        dq.push_back(s[i]);
    }
    int q;
    cin>>q;
    int toggle=1;
    for(int i=0;i<q;i++){
        int f;
        cin>>f;
        if(f==1){
            toggle=1-toggle;
        }
        else{
            int v;
            char ch;
            cin>>v>>ch;
            if(v==1){
                if(toggle){
                    dq.push_front(ch);
                }
                else{
                    dq.push_back(ch);
                }
            }
            else{
                if(toggle){
                    dq.push_back(ch);
                }
                else{
                    dq.push_front(ch);
                }
            }
        }
    }
    string ans="";
    if(toggle){
        for(auto it=dq.begin();it!=dq.end();it++){
            ans+=*(it);
        }
    }
    else{
        for(auto it=dq.rbegin();it!=dq.rend();it++){
            ans+=*(it);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1368
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool sosu(int n)
{
	if(n == 1)
	{
		return false;
	}
	if(n == 2)
	{
		return true;
	}
	
		
	for(int i = 2; i < (n/2) + 1; i++)
	{
		if((n % i) == 0)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	int n;
	cin >> n;
	
	vector<int> s;
	int cnt = 0;
	for(int k = 1; k <= 100000; k++)
	{
		if(k == 1 || k == 2)
		{
			s.push_back(cnt);
			continue;
		}
		
		bool flag = true;
		for(int i = 2; i < (k/2) + 1; i++)
		{
			if((k % i) == 0)
			{
				flag = false;
				s.push_back(cnt);
				break;
			}
		}
		if(flag == true)
		{
			if(sosu((k+1)/2) == true)
			{
				s.push_back(++cnt);
			}
			else
			{
				s.push_back(cnt);
			}
		}
	}
	
	int ans[n] = {0};
	for(int i = 0; i < n; i++)
	{
		int l, r;
		cin >> l >> r;
		
		ans[i] = s[r - 1] - s[l - 2];
	}
	
	for(int i = 0; i < n; i++)
	{
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define L_T_S_K ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);  
const int mod = 1e9 + 7;
const int N = 2e5;

bool isPrime(int n){
  int k = 0;
  for(int i = 2 ; i <= sqrt(n) ;i++){
    if(n%i == 0) return 0;
  }
  return 1;
}
int32_t main(){
 L_T_S_K;
  int n;
  cin >> n;
  for(int i = n ; ;i++){
    if(isPrime(i)){
      cout << i << " ";
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

ll dp[2001][2001];
ll s[2001],t[2001];

int main()
{
	#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	#endif

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,m;
	cin >> n >> m;
	rep(i,1,n+1) cin >> s[i];
	rep(i,1,m+1) cin >> t[i];

	for(ll i=1; i<=n; i++){
		for(ll j=1; j<=m; j++){
			dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+mod)%mod;
			if(s[i]==t[j]) dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1+mod)%mod;
		}
	}
	cout << (dp[n][m]+1)%mod;
	return 0;
}
/* The judge is never wrong! Your code is buggy 
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 31616
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    char string[200001];

    //printf("Input the string:");
    scanf("%s",string);

    int length=0;
    int count=0;
    int i=0,j=0;
    while(string[j]!='\0'){
        length++;
        j++;
    }
    while(string[i]!='A'){
        i++;
        count++;
    }
    int k=length;
    int count2=0;
    while(string[k]!='Z'){
        k--;
        count2++;
    }
    
    //printf("%d\n%d\n%d\n",count,count2,length);

    printf("%d",length-count-count2+1);
    return 0;
}

Measured memory_bytes: 384
#

import sys
input=sys.stdin.readline

def main():
    N=int(input())
    A=list(map(int,input().split()))
    Ac=[0]*(N+1)
    for i in range(N):
        Ac[A[i]]+=1
    sumc=0
    iset=set()
    for i in range(1,N+1):
        if Ac[i]>=2:
            sumc+=Ac[i]*(Ac[i]-1)//2
            iset.add(i)
    for i in range(N):
        v=A[i]
        if v in iset:
            print(sumc-Ac[v]+1)
        else:
            print(sumc)
    
if __name__=="__main__":
    main()


Measured memory_bytes: 91084
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
 
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
 
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")


#define lli long long int 
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define loopb(i,a,b) for (lli i=a;i>=b;i--)
#define pb push_back
#define mod 1000000007
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) (__gcd((a),(b)))
#define lcm(a,b)(((a)*(b))/gcd((a),(b)))
#define bc __builtin_popcountll
#define vi vector<lli>
#define pr pair<lli,lli>
#define vp vector<pr>
#define F  first
#define S   second
#define lld long double 
lli wt[100001];
lli val[100001];
lli dp[101][100001];
lli n,tw;
lli solve(lli w,lli item)
{if(dp[item][w]!=-1)
{return dp[item][w];
}
else{
if(item==n-1)
{if(w+wt[item]<=tw)
{return val[item];
}
else
{ return 0;
}
}
else
{if(w+wt[item]>tw)
{dp[item][w]=(solve(w,item+1));
return dp[item][w];
}
else
{dp[item][w]=(max(solve(w+wt[item],item+1)+val[item],solve(w,item+1)));
return dp[item][w];
}
}
}}
int main()
{fast();
cin>>n>>tw;
loop(i,0,n)
{cin>>wt[i]>>val[i];
}
loop(i,0,n)
{loop(j,0,tw+1)
{dp[i][j]=-1;
}
}
cout<<solve(0,0)<<"\n";
}



Measured memory_bytes: 80128
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif

static void B_task();

int main()
{
	B_task();
	
	fflush(stdout);
	return 0;
}

static void B_task()
{
	int r, D, x2k;
	scanf(" %d %d %d", &r, &D, &x2k);

	int x = x2k;
	for (int i = 1; i <= 10; i++) {
		x = (r * x) - D;
		printf("%d\n", x);
	}
}


Measured memory_bytes: 256
n = int(input())
bomb = []
kotae = []
hako = list(map(int, input().split()))
for h in hako:
  if h % 2 == 0:
    bomb.append(h)
for h in bomb:
  if h % 3 == 0 or h % 5 == 0:
    kotae.append(h)
if len(kotae) == len(bomb):
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
using namespace std;

int n, i;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	ll a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
      
	deque<ll> ans;
	if (n % 2) {
		ans.pb(a[i]);
		i++;
	}
	while (i < n) {
		ans.pb(a[i]);
		ans.pf(a[i + 1]);
		i += 2;
	}
	for (auto x : ans) cout << x << " ";
}

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

public class A
{
  public static void Main(string[] args)
  {
     var nums = Console.ReadLine().Split(" ").Select(n => int.Parse(n)).ToArray();
     var result = (nums[0] * nums[1]) % 2 == 0;
     Console.WriteLine(result ? "Even" : "Odd");
  }
}

Measured memory_bytes: 28184
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


int main(){
    ll n;cin >> n;
    vl a(n);rep(i,n)cin >> a[i];
    ll sum=0;rep(i,n)sum+=a[i];
    vl ps(n);ll hh=sum;
    rep(i,n){
        hh=(hh-a[i]+MOD)%MOD;
        ps[i]=hh;
    }
    vl pp(n);
    rep(i,n){
        pp[i]=(a[i]*ps[i])%MOD;
        //ここa[i]が10^9,ps[i]が10^9*10^5なのでかけた瞬間にオーバーフローしてそう
    }
    ll fin=0;
    rep(i,n){
        fin+=pp[i];
        fin%=MOD;
    }
    cout << fin <<endl;
}

Measured memory_bytes: 7992
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        int c = int.Parse(Console.ReadLine());
        int d = int.Parse(Console.ReadLine());
        int e = int.Parse(Console.ReadLine());
        int k = int.Parse(Console.ReadLine());
        Console.WriteLine(e - a <= k ? "Yay!" : ":(");
    }
}

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

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

int n, m, t;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; ++i) {
      cin >> t;
      sum += t;
    }
    if (sum > n)
      cout << -1 << endl;
    else
      cout << n - sum << endl;
    
    return 0;
}


Measured memory_bytes: 3612
n = int(input())
H = list(map(int,input().split()))
ans = "Yes"
 
for i in range(n-1):
    if H[i] < H[i+1]:
        H[i+1] -= 1
    
    if H[i] > H[i+1]:
        ans = "No"
        break
        
print(ans)

Measured memory_bytes: 14252