akhauriyash/Code-Regression huggingface dataset:
/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline LL ri() {LL x; scanf("%lld", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/

const int maxn = 5005;
const LL inf = 1e18;

LL p[maxn][maxn], a[maxn], n, A, B, d[maxn], b[maxn];

int main() {
  rep(i, maxn) rep(j, maxn) p[i][j] = inf;
  cin >> n >> A >> B;
  rep(i, n) cin >> a[i];

  p[0][0] = 0;

  d[0] = 0; b[0] = a[0];
  rep(i, 1, n) {
    int t = lower_bound(b, b + i, a[i]) - b;
    d[i] = t;
    drep(j, i, t) {
      b[j + 1] = b[j]; 
    }
    b[t] = a[i];
  }
  //cout << d[0] << d[1] << d[2];

  rep(i, n) {
    rep(j, i + 1) {
      if (d[i] >= j) {
        //smin(p[i + 1][j], p[i][j]);
        //smin(p[i + 1][i + 1], p[i][j]);
        smin(p[i + 1][d[i] + 1], p[i][j]);
        smin(p[i + 1][j], p[i][j] + A);
      }
      else {
        smin(p[i + 1][j + 1], p[i][j] + B);
      }
      //smin(p[i + 1][i + 1], p[i][j]);
      if (j + 1 <= i) {
        smin(p[i][j + 1], p[i][j]);
      }
    }
  }

  LL res = inf;
  rep(i, n + 1) {
    smin(res, p[n][i]);
  }

  //cout << p[1][0] << endl;

  //cout << p[2][1] << endl;

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 196096
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<deque>
#include<string>
using namespace std;

int h, w;
int n = 0;
vector<int> field;
vector<vector<bool>> taken;
deque<string> ans;


int main(void) {
	cin >> h >> w;

	for (int i = 0; i < h; i++) {
		vector<int> tmp(w);
		for (int j = 0; j < w; j++) {
			cin >> tmp[j];
		}
		if (i % 2 == 1) {
			reverse(tmp.begin(), tmp.end());
		}
		field.insert(field.end(), tmp.begin(), tmp.end());
	}

	for (int i = 0; i < h * w - 1; i++) {
		if (field[i] % 2 == 1) {
			string tmp = to_string(i / w + 1) + " ";
			field[i]--;
			field[i + 1]++;
			if ((i / w) % 2 == 0) {
				tmp += to_string(i % w + 1) + " " + to_string((i + 1) / w + 1) + " ";
				if (i % w != w - 1)
					tmp += to_string((i + 1) % w + 1);
				else
					tmp += to_string(w);
			}
			else {
				tmp += to_string(w - i % w) + " " + to_string((i + 1) / w + 1) + " ";
				if (i % w != w - 1)
					tmp += to_string(w - (i + 1) % w);
				else
					tmp += "1";
			}
			ans.push_back(tmp);
			n++;
		}
	}

	cout << n << endl;
	for (int i = 0; i < n; i++) {
		cout << ans.front() << endl;
		ans.pop_front();
	}
	return 0;
}

Measured memory_bytes: 11920
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int mod = (int) 1e9 + 7;
const int N = 2005;

int n, m;
int dp[N][N];
int a[N], b[N];

inline void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += mod;
}

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      add(dp[i][j], dp[i - 1][j]);
      add(dp[i][j], dp[i][j - 1]);
      sub(dp[i][j], dp[i - 1][j - 1]);
      if (a[i] == b[j]) {
        add(dp[i][j], dp[i - 1][j - 1] + 1);
      }
    }
  }
  cout << (dp[n][m] + 1) % mod << endl;
  return 0;
}


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

public class Main{
	
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		while(true){
			String[] line = br.readLine().split(" ");
			
			int h = Integer.parseInt(line[0]);
			int w = Integer.parseInt(line[1]);
			
			if(h == 0 && w == 0){
				break;
			}
			
			for(int i=0; i<h; i++){
				for(int j=0; j<w; j++){
					sb.append("#");
				}
				sb.append("\n");
			}
			sb.append("\n");
			System.out.print(sb);
			sb.delete(0,sb.length());
		}
	}
}

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

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

  int H[N];

  for(int i=0; i<N; i++){
    cin >> H[i];
  }
  int cnt = 0, mx = 0;
  for(int i=N-1; i>0; --i){
    if(H[i] <= H[i-1]) cnt++;
    else cnt = 0;
    mx = max(mx, cnt);
  }
  cout << mx;
  return 0;
}
          

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

int dp[31];

int main()
{
	while (true)
	{
		for(int i = 0; i < 31; i++)
			dp[i] = 0;

		int n;
		cin >> n;
		if(n == 0)break;

		dp[1] = 1;
		dp[2] = 2;
		dp[3] = 4;

		for(int i = 4; i <= n; i++)
			dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];

		int ans = 0;
		if(dp[n] / 3650 == 0)ans = 1;
		else
			ans = (dp[n] / 3650) ? dp[n] / 3650 + 1 : dp[n] / 3650;

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;

public class Hello{
    public static void Main(){

        string[] line = Console.ReadLine().Split(' ');
        int ab = int.Parse(line[0]);
        int bc = int.Parse(line[1]);
        int ac = int.Parse(line[2]);

        // 三角形の面積を求める
        int S = (ab * bc) / 2; 
        Console.WriteLine(S);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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

vector<int> IntegerToVector(int bit, int N)
{
  vector<int> S;
  for (int i = 0; i < N; ++i)
  {
    if (bit & (1 << i))
    {
      S.push_back(i);
    }
  }
  return S;
}

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

  rep(i, m)
  {
    int k;
    cin >> k;

    rep(j, k)
    {
      int st;
      cin >> st;
      s[i].push_back(st);
    }
  }

  rep(i, m)
  {
    int x;
    cin >> x;
    p.push_back(x);
  }

  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++)
  {
    bool is_ok = true;
    rep(i, m)
    {
      int on_count = 0;
      for (auto ss : s[i])
      {
        if ((bit >> (ss-1)) & 1)
          on_count++;
      }

      if (on_count % 2 != p[i])
        is_ok = false;
    }

    if (is_ok)
    {
      ans++;
    }
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef pair<int,int> P;

int main(){
    int N,x;
    cin >> N >> x;
    string ans;
    int narabi[200100];
    if(N==1){
        if(x==1){
            ans="Yes";
            narabi[0]=1;
        }else{
            ans="No";
        }
    }else if(N==2){
        if(x==2){
            ans="Yes";
            narabi[0]=1;
            narabi[1]=2;
            narabi[2]=3;
        }else{
            ans="No";
        }
    }else if(N==3){
        if(x==1||x==5){
            ans="No";
        }else if(x==2){
            ans="Yes";
            narabi[0]=5;
            narabi[1]=2;
            narabi[2]=1;
            narabi[3]=4;
            narabi[4]=3;
        }else if(x==3){
            ans="Yes";
            narabi[0]=1;
            narabi[1]=2;
            narabi[2]=3;
            narabi[3]=4;
            narabi[4]=5;
        }else{
            ans="Yes";
            narabi[0]=1;
            narabi[1]=4;
            narabi[2]=5;
            narabi[3]=2;
            narabi[4]=3;
        }
    }else{
        if(3<=x && x<= 2*N-3){
            ans="Yes";
            narabi[N-3]=x+2;
            narabi[N-2]=x-1;
            narabi[N-1]=x;
            narabi[N]=x+1;
            narabi[N+1]=x-2;
            int a=1;
            for(int i=0;i<2*N-1;i++){
                if(i<N-3 || i>N+1){
                    if(x==3&&a==1){
                        a=6;
                    }
                    narabi[i]=a;
                    if(a+1==x-2){
                        a=x+3;
                    }else{
                        a++;
                    }
                }
            }
        }else if(x==2 || x==2*N-2){
            ans="Yes";
            if(x==2){
                narabi[N-2]=x-1;
                narabi[N-1]=x;
                narabi[N]=x+1;
            }else{
                narabi[N-2]=x+1;
                narabi[N-1]=x;
                narabi[N]=x-1;
            }
            int a=1;
            for(int i=0;i<2*N-1;i++){
                if(i<N-2 || i>N){
                    if(x==2&&a==1){
                        a=4;
                    }
                    narabi[i]=a;
                    if(x==2){
                        if(a==1){
                            a=5;
                        }else{
                            a++;
                        }
                    }else{
                        if(a+1 == x-1){
                            a=x+2;
                        }else{
                            a++;
                        }
                    }
                }
            }
        }else{
            ans="No";
        }
    }
    if(ans=="Yes"){
        cout << ans << endl;
        for(int i=0;i<2*N-1;i++){
            cout << narabi[i] << endl;
        }
    }else{
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 2304
import java.util.ArrayList;
import java.util.Scanner;

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

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		long min = Long.MAX_VALUE;
		long max = Long.MIN_VALUE;
		int min_arg = -1, max_arg = -1;
		ArrayList<Integer> add_sub = new ArrayList<>();
		ArrayList<Integer> add = new ArrayList<>();

		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextLong();
			max = Math.max(max, a[i]);
			min = Math.min(min, a[i]);
			if (max == a[i])
				max_arg = i;
			if (min == a[i]) {
				min_arg = i;
			}
		}
		if (max + min >= 0) {
			for (int i = 0; i < n; ++i) {
				if (a[i] < 0) {
					a[i] += max;
					add.add(max_arg);
					add_sub.add(i);
				}
			}
			for (int i = 1; i < n; ++i) {
				if (a[i - 1] > a[i]) {
					a[i] += max;
					add.add(max_arg);
					add_sub.add(i);
					if (a[i] > max) {
						max = a[i];
						max_arg = i;
					}
				}
			}
		} else if (min + max < 0) {
			for (int i = 0; i < n; ++i) {
				if (a[i] > 0) {
					a[i] += min;
					add.add(min_arg);
					add_sub.add(i);
				}
			}
			for (int i = n - 2; i >= 0; --i) {
				if (a[i] > a[i + 1]) {
					a[i] += min;
					add.add(min_arg);
					add_sub.add(i);
					if (a[i] < min) {
						min = a[i];
						min_arg = i;
					}
				}
			}
		}
		System.out.println(add.size());
		for (int i = 0; i < add.size(); ++i) {
			System.out.println((add.get(i) + 1) + " " + (add_sub.get(i) + 1));
		}

	}
}


Measured memory_bytes: 23252
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long B = long.Parse(str[0]);
		long W = long.Parse(str[1]);
		long mod = 1000000007;
		long[]C = new long[200001];
		long[]NC = new long[200001];
        C[0] = 1;
		C[1] = 1;
		NC[0] = 1;
		NC[1] = 1;
		for(var i=2;i<=200000;i++){
			C[i] = C[i-1] * i % mod;
			NC[i] = NC[i-1] * Mpow(i,mod-2,mod) % mod;
		}
		long[]A1 = new long[B+W];
		long[]A2 = new long[B+W];
		long c1 = 1;
		long p1 = 0;
		long q1 = 0;
		for(var i=0;i<B+W;i++){
			A1[i] = c1;
			A2[i] = c1*2%mod;
			if(i>=W){
				q1 = (q1 * 2 + C[i-1] * NC[i-W] % mod * NC[W-1] % mod) % mod;
				A1[i] = (c1 + q1) % mod;
			}
			if(i>=B){
				p1 = (p1 * 2 + C[i-1] * NC[i-B] % mod * NC[B-1] % mod) % mod;
				A1[i] = (A1[i] + mod - p1) % mod;
			}
			c1 = c1 * 2 % mod;
		}
		for(var i=0;i<B+W;i++){
			Console.WriteLine(A1[i] * Mpow(A2[i],mod-2,mod) % mod);
		}
	}
	public static long Mpow(long x,long n,long m)
	{
		long ans = 1;
		while(n > 0){
			if(n % 2 == 1){
				ans = ans * x % m;
				n -= 1;
			}
			x = x * x % m;
			n /= 2;
		}
		return ans;
	}
	public static long Ncr(long n,long r,long m)
	{
		long ans = 1;
		for(var i=n-r+1;i<=n;i++){
			ans = ans * i % m;
		}
		for(var i=2;i<=r;i++){
			ans = ans * Mpow(i,m-2,m) % m;
		}
		return ans;
	}
}

Measured memory_bytes: 23132
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var pi = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var count = 0;
            for (var i = 0; i < pi.Length; i++)
            {
                if (i + 1 != pi[i]) count++;
            }
            Console.WriteLine(count <= 2 ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 13396
import sys
sys.setrecursionlimit(100000)  ##再帰呼び出しの上限設定
 


n=int(input())
A=[int(x) for x in input().split()]
minA=min(A)  ##Aの最小値
sumA=sum(A)  ##Ａの総和


 
q=int(input())
M=[int(x) for x in input().split()]
 
 
def solve(i,m):
    global n
    global A
    global minA
    global sumA
     
    if m<0 or m>sumA:
        return False
    if m==0:
        return True
    if i>=n:
        return False
     
    return solve(i+1,m) or solve(i+1,m-A[i])
     
     
for m in M:
    if m<minA or m>sumA: ##そもそもAで実現不可
        print('no')
    else:
        if solve(0,m):
            print('yes')
        else:
            print('no')


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

const int N = 100010;
const int INF = 1e9;
int distB[N], distW[N];

vector<vector<int>> G;

void bfs(int s, int flag){ // 1:Black 0:White
    queue<int> que;
    que.push(s);
    if(flag == 1) distB[s] = 0;
    if(flag == 0) distW[s] = 0;

    while(!que.empty()){
        int from = que.front();
        que.pop();

        for(auto to : G[from]){
            if(flag == 1){
                if(distB[to] == INF){
                    distB[to] = distB[from] + 1;
                    que.push(to);
                }
            }
            if(flag == 0){
                if(distW[to] == INF){
                    distW[to] = distW[from] + 1;
                    que.push(to);
                }
            }
        }
    }
}

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

    G.resize(n);
    fill(distB, distB + N, INF);
    fill(distW, distW + N, INF);

    for (int i = 0; i < n - 1; i++) {
        int a,b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    bfs(0,1);
    bfs(n-1, 0);

    int B = 0, W = 0;
    for(int i = 0; i < n; i++){
        if(distB[i] <= distW[i]) B++;
        else if(distB[i] > distW[i]) W++;
    }

    if(B > W) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;

}

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

int main(){
    string n;
    cin>>n;
    for(int i=0;i<n.size();i++){
    	if(n[i]=='7'){
    		cout<<"Yes"<<endl;
    		return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3628
maxColorNum = 8
rates = [False] * maxColorNum
overRed = 0
N = int(input())
people = list(map(int, input().split()))
for i in people:
    idx = i // 400
    if idx >= maxColorNum:
        overRed += 1
    else:
        rates[idx] = True
minNum = 1 if rates.count(True) == 0 and overRed != 0 else rates.count(True)
maxNum = rates.count(True) + overRed

print(str(minNum) + " " + str(maxNum))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;

int main(){
    ll n, k; cin >> n >> k;
    cout << k * (ll)pow((k-1), n-1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int n, t, a, h, mi;
double y, mn = 1e9;
int main() {
	cin>>n>>t>>a;
	for(int i=1; i<=n; i++) {
		cin>>h;
		y = abs(t - h * 0.006 - a);
		if(y < mn) {
			mn = y;
			mi = i;
		}
	}
	cout<<mi;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int m = in.nextInt();
        int d = in.nextInt();

        int ans = 0;
        for (int i=1; i <= m; i++) {
            for (int j=1; j <= d; j++) {
                if (String.valueOf(j).length() > 1) {
                    int j1 = Integer.valueOf(String.valueOf(j).substring(0, 1));
                    int j2 = Integer.valueOf(String.valueOf(j).substring(1));

                    if (j1 >= 2 && j2 >= 2 && j1 * j2 == i) {
                        ans++;
                    }
                }
            }
        }
        out.println(ans);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }

}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  for(int i=1;i<=9;++i)if(n%i==0&&n/i<=9&&n/i>=1){cout<<"Yes"<<endl;return 0;}
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int less(const void* a, const void* b){
  return *(int*)a - *(int*)b;
}

int is_no_need(int i, const int* a, int K, int N){
  int dp[K]; dp[0] = 1;
  for(int k = 1; k < K; k++) dp[k] = 0;

  for(int j = 1; j <= N; j++){
    if(j == i) continue;

    for(int k = K - 1; k >= a[j]; k--){
      dp[k] |= dp[k - a[j]];
    }
  }

  for(int k = K - 1; k >= 0; k--){
    if(dp[k]) return k + a[i] < K;
  }
}

int count_no_need(const int* a, int K, int N){
  //不必要でないカードのうち, 書かれた数が最小であるもの
  int need = N + 1;
  //不必要であるカードのうち, 書かれた数が最大であるもの
  int no_need = 0;

  while(need - no_need > 1){
    int i = (need + no_need) >> 1;

    if(is_no_need(i, a, K, N)) no_need = i;
    else need = i;
  }

  return no_need;
}

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

  int a[N + 1]; a[0] = 0;
  for(int i = 1; i <= N; i++) scanf("%d", a + i);
  qsort(a, N + 1, sizeof(int), less);

  printf("%d\n", count_no_need(a, K, N));

  return 0;
}

Measured memory_bytes: 252
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define FILE_NAME "a"

const int MAXN = 2e5 + 10;
const int A = 26;

int n;
char s[MAXN];

bool read() {
	scanf("%s\n", s);
	n = int(strlen(s));
	return 1;
}


ll solve() {
	ll ans = 0;
	vi cnt(A, 0);
	int sum = 0;
	ford(i, n) {
		int other = sum - cnt[s[i] - 'a'];
		ans += other;
		++cnt[s[i] - 'a'];
		++sum;
	}
	++ans;
	return ans;
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		printf("%lld\n", solve());

		break;
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 384
H,W=map(int,input().split())
L=[]
Z=["#" for i in range(W+2)]
L.append(Z)
for i in range(H):
    S=["#"]+list(input())+["#"]
    L.append(S)
L.append(Z)

#print(L)
X=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if L[i][j]==".":
            X.append([i,j])
#print(X)
x=[1,-1,0,0]
y=[0,0,1,-1]
import copy
ans=0
for i in range(len(X)):
    l=copy.deepcopy(L)
    l[X[i][0]][X[i][1]]=0
    Q=[[X[i][0],X[i][1]]]
    for j in range(10**9):
        if j==len(Q):
            break
        for k in range(4):
            if l[Q[j][0]+x[k]][Q[j][1]+y[k]]==".":
                l[Q[j][0]+x[k]][Q[j][1]+y[k]]=l[Q[j][0]][Q[j][1]]+1
                Q.append([Q[j][0]+x[k],Q[j][1]+y[k]])
    for a in range(1,H+1):
        for b in range(1,W+1):
            if l[a][b]!="#":
                if l[a][b]>ans:
                    ans=l[a][b]
print(ans)
    

Measured memory_bytes: 54492
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

int main() {
    ll n;
    cin >> n;
    n++;
    string N = to_string(n);
    int len = N.length();
    //cout << (N[0] -'0' + N[1]-'0') << endl;
    //cout << (N[0] -'0' + N[1]-'0' - 1) << endl;
    ll sum = N[0] - '0' - 1;
    sum += 9 * (N.length() - 1);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N;
	String[] S;

	public void solve() {
		N = nextInt();
		S = new String[N];

		for (int i = 0; i < N; i++) {
			S[i] = next();
		}

		int[][] a = new int[N][26];

		for(int i = 0;i < N;i++){
			for(char c : S[i].toCharArray()){
				a[i][c-'a']++;
			}
		}

		StringBuilder sb = new StringBuilder();

		for(int j = 0;j< 26;j++){
			int min = Integer.MAX_VALUE;
			for(int i = 0;i < N;i++){
				min = Math.min(min,a[i][j]);
			}

			for(int i = 0;i < min;i++){
				sb.append((char)('a'+j));
			}
		}
		out.println(sb);

	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

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

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

  int ans = 0;
  int tmp = 0;
  int a[n];
  reg(i,n){
    cin >> a[i];
  }

  while(1){
    reg(i,n){
      if(a[i] % 2){
	cout << ans << endl;
	return 0;
      }else{
	++tmp;
	a[i] = a[i] / 2;
      }
      ans = tmp / n;
    }
  }
}


Measured memory_bytes: 256
N, M = map(int, input().split())
s = []
for i in range(M):
    s.append(list(map(int, input().split())))
p = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    Flg = True
    for j in range(M):
        cnt = 0
        for m in range(1, len(s[j])):
            for k in range(N):
                if((i>>k)&1 and s[j][m]-1 == k):
                    cnt += 1
        if(cnt%2 != p[j]):
            Flg = False
    if(Flg):
        ans += 1        
print(ans)   

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
 
#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tolower(c) char(c+0x20)
#define toupper(c) char(c-0x20)

const ll MAX_N = 100000;
 
int main(void){
    ll a,b,c,d;
    string s,t,u;
 
    //cin >> a >> b>> c >> d;
    cin >> s >> t >> u;
    
    cout << toupper(s[0])<< toupper(t[0])<< toupper(u[0])<< endl;



    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main()
{
	double x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	double d = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));

	printf("%lf\n", d);

	return 0;

	
}

Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,ans=0,l=0,r=100000;
  cin >> N>>M;
  vector<int> L(M);
  vector<int> R(M);
  for (int i = 0; i < M; i++) {
    cin>>L[i]>>R[i];
    l=max(l,L[i]);
    r=min(r,R[i]);
  }
  if(l<=r){
   cout<<r-l+1;
  }
  else{
    cout<<0;
  }
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h=sc.nextInt();
        int w=sc.nextInt();
        String[] nums=new String[h];
        for(int i=0;i<h;i++){
            nums[i]=sc.next();
        }
        int[][] output=new int[h][w];
        int[] x={1,1,0,-1,-1,-1,0,1};
        int[] y={0,1,1,1,0,-1,-1,-1};
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(nums[i].charAt(j)=='#'){
                    output[i][j]=-1;
                    continue;
                }
                for(int k=0;k<8;k++){
                    try{
                        if(nums[i+x[k]].charAt(j+y[k])=='#')output[i][j]++;
                    }catch(Exception e){}
                }
            }
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                System.out.print(output[i][j]>=0?output[i][j]:"#");
            }
            System.out.println();
        }
    }
}

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

using namespace std;
const int N = 200200;
int a[N];
int n;
int k;

bool check(int x) {
        long long res = 0;
        for (int i = 1; i <= n; i++) {
                res += (a[i] + x - 1) / x - 1;
        }
        return (res <= k);
}

void solve() {

        cin >> n;
        cin >> k;

        for (int i = 1; i <= n; i++) {
                cin >> a[i];
        }
        int l = 1;
        int r = 1e9;
        int ans = r;
        while (l <= r) {
                int m = (l + r) >> 1;
                if (check(m)) {
                        r = m - 1;
                        ans = m;
                } else l = m +1;
        }
        cout << ans << endl;
}


int main() {
#ifdef QWERTY
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
        ios_base::sync_with_stdio(false);


        int t = 1;
//        cin >> t;

        for (int i = 1; i <= t; i++) {
//                cout << "Case #" << i << ':' << endl;
                solve();
        }


        return 0;
}

Measured memory_bytes: 4392
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    c -= min(a - b, c);
    cout << c;
    return 0;
}

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

Measured memory_bytes: 2680
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,i,j,k,x=0,y,z;
    cin>>x>>y;
    
    if((x==1 && y==2)|| (x==2 && y==1)){
        cout<<3<<endl;
    }
    else if((x==1 && y==3)||(x==3 && y==1)){
        cout<<2<<endl;
    }
    else if((x==2 && y==3)|| (x==3 && y==2)){
        cout<<1<<endl;
    }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;
 
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  string ans(N, '?');
  bool isok = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ans[s] != '?' && ans[s] != '0' + c) {
      isok = false;
    }
    ans[s] = '0' + c;
  }
  if (!isok || (N > 1 && ans[0] == '0')) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < N; i++)
      if (ans[i] == '?') {
        ans[i] = '0' + (i || N == 1 ? 0 : 1);
      }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3568
import bisect
def mark(s, x):
    for i in xrange(x + x, len(s), x):
        s[i] = False

def sieve(n):
    s = [True] * n
    for x in xrange(2, int(n**0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in xrange(0,n) if s[i] and i > 1]


primes = sieve(10**5)
likes = []
for i in primes:
	if primes[bisect.bisect_left(primes,(i+1)/2)] == (i+1)/2:
		likes.append(i)

cs = [0 for i in range(10**5+1)]

i = 1
j = 0

while i < 10**5+1 and j < len(likes):
	if likes[j] > i:
		cs[i] = cs[i-1]

	else:
		cs[i] = cs[i-1]+1
		j +=1
	i += 1
t = cs[i-1]
while i < 10**5+1:
	cs[i] = t
	i += 1

q = int(input())

for i in range(q):
	l,r = map(int,raw_input().split())
	print cs[r+1]- cs[l-1]

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

#define ll long long

int main(){
    int n,k,sum=0;
    vector<int> a;
    cin >> n >> k;
    for(int i=0; i<n; ++i){
        int data;
        cin >> data;
        a.push_back(data);
    }
    sort(a.rbegin(),a.rend());
    for(int i=0; i<k; ++i){
        sum+=a[i];
    }
    cout << sum;
}

Measured memory_bytes: 3604
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    void solve(Scanner in, PrintWriter out) {
        long a = in.nextInt();
        long b = in.nextInt();
        long c = in.nextInt();
        long d = in.nextInt();
        out.println(Math.max(a * c, Math.max(a * d, Math.max(b * c, b * d))));
    }

    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }
}


Measured memory_bytes: 35968
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
#define PI 3.141592653589793
#define MOD 1000000007
//#define MOD 998244353
#define ALL(obj) (obj).begin(),(obj).end()
const ll INF = 1LL << 60;
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first+firstElof.second < secondElof.first+secondElof.second;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first-firstElof.second < secondElof.first-secondElof.second;
}

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;

ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
int main(){
    ll n,ans=0;
    cin >> n;
    pair<ll,ll> x[n],y[n];
    for (ll i=0;i<n;i++){
        cin >> x[i].first >> x[i].second;
        y[i]=x[i];
    }
    sort(x,x+n,pairCompare);
    sort(y,y+n,pairCompareSecond);
    ans=max(ans,abs(x[0].first-x[n-1].first)+abs(x[0].second-x[n-1].second));
    ans=max(ans,abs(y[0].first-y[n-1].first)+abs(y[0].second-y[n-1].second));
    cout << ans << endl;
    return 0;
}


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

const int INF = 1<<30;

typedef struct{
    int to, cap, cost, rev;
}Edge;

class MinCostFlow{
private:
    int V;
    vector<vector<Edge>> G;
public:
    MinCostFlow(int V): V(V){
        G.resize(V);
    }
    void add_edge(int u, int v, int c, int d){
        G[u].push_back({v, c, d, (int)G[v].size()});
        G[v].push_back({u, 0, -d, (int)G[u].size()-1});
    }
    int solve(int s, int t, int f){
        int res = 0;
        while(f > 0){
            vector<int> d(V, INF);
            vector<int> pars(V, -1);
            vector<int> eids(V, -1);
            d[s] = 0;
            
            bool updated = true;
            while(updated){
                updated = false;
                for(int v=0; v<V; v++) if(d[v]!=INF){
                    for(int i=0; i<G[v].size(); i++){
                        auto edge = G[v][i];
                        if(edge.cap == 0)
                            continue;
                        if(d[edge.to] > d[v] + edge.cost){
                            d[edge.to] = d[v] + edge.cost;
                            pars[edge.to] = v;
                            eids[edge.to] = i;
                            updated = true;
                        }
                    }
                }
            }
            if(d[t] == INF)
                return -1;
            
            int mc = f;
            for(int v=t; v!=s; v=pars[v]){
                mc = min(mc, G[pars[v]][eids[v]].cap);
            }
            res += mc * d[t];
            f -= mc;
            for(int v=t; v!=s; v=pars[v]){
                auto &edge = G[pars[v]][eids[v]];
                edge.cap -= mc;
                G[v][edge.rev].cap += mc;
            }
        }
        return res;
    }
};

int V, E, F;

int main(){
    cin >> V >> E >> F;
    
    MinCostFlow mcf(V);
    for(int i=0; i<E; i++){
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        mcf.add_edge(u, v, c, d);
    }
    
    cout << mcf.solve(0, V-1, F) << endl;
    
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    string s[n];
    int t[n];
    for(int i = 0; i < n; i++)  cin >> s[i] >> t[i];
    string x;
    cin >> x;
    for(int i = 0; i < n; i++){
        if(s[i] == x){
            int ret = 0;
            for(int j = i+1; j < n; j++)    ret += t[j];
            cout << ret << endl;
            return 0;
        }
    }
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<bool> S(13, true), H(13, true), C(13, true), D(13, true);
  for(int i = 0;i < n;i++)
  {
    char s;
    int number;
    cin >> s >> number;
    if(s == 'S')
    S[number - 1] = false;
    if(s == 'H')
    H[number - 1] = false;
    if(s == 'C')
    C[number - 1] = false;
    if(s == 'D')
    D[number - 1] = false;
  }
  for(int i = 0;i < 13;i++)
  {
    if(S[i]) cout << "S " << i + 1 << endl;
  }
  for(int i = 0;i < 13;i++)
  {
    if(H[i]) cout << "H " << i + 1 << endl;
  }
  for(int i = 0;i < 13;i++)
  {
    if(C[i]) cout << "C " << i + 1 << endl;
  }
  for(int i = 0;i < 13;i++)
  {
    if(D[i]) cout << "D " << i + 1 << endl;
  }
}


Measured memory_bytes: 3096
program main
integer(16), allocatable :: x(:)
integer(16) :: N,S,A,F
A = 10**18_16
read *,N
allocate(x(N))
read *,x
F=0
do i = 1, N, 1
if( x(i) == 0) then
	F = 1
    S = 0
    exit
end if
end do


if( F == 0 ) then
S = x(1)
do i = 2, N, 1
S = S * x(i)
if ( S > A ) then
	S = -1
    exit
end if
end do
end if

print '(i0)',S
end program main

Measured memory_bytes: 4580
#include <stdio.h>
int main() {
	int N, M, i, city1, city2;
	scanf("%d %d", &N, &M);
	int city[N];
	for (i = 1; i <= N; i++) {
		city[i] = 0;
	}
	for (i = 0; i < M; i++) {
		scanf("%d %d", &city1, &city2);
		city[city1] += 1;
		city[city2] += 1;
	}
	for (i = 1; i <= N; i++) {
		printf("%d\n", city[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

// ???????????¢?????????
class DiceSurface
{
private:
	unsigned short	number_;	// ????????¢??????????????????

public:
	DiceSurface() {}
	DiceSurface(const unsigned short& number)
		: number_(number)
	{}

	~DiceSurface() {}

	// ?????????
	void setNumber(const unsigned short& number) { number_ = number; }
	// ?????????
	unsigned short getNumber() const { return number_; }

};


class Dice
{
private:
	const DiceSurface* top_;	// ?????¢
	const DiceSurface* north_;	// ?????¢
	const DiceSurface* south_;	// ?????¢
	const DiceSurface* east_; 	// ??±??¢
	const DiceSurface* west_; 	// ?\???¢
	const DiceSurface* bottom_;	// ?????¢

private:
	Dice() {}

public:
	Dice( const unsigned short& topNumber
		, const unsigned short& northNumber
		, const unsigned short& southNumber
		, const unsigned short& eastNumber
		, const unsigned short& westNumber
		, const unsigned short& bottomNumber )
	{
		top_	= new DiceSurface(topNumber);
		north_	= new DiceSurface(northNumber);
		south_	= new DiceSurface(southNumber);
		east_	= new DiceSurface(eastNumber);
		west_	= new DiceSurface(westNumber);
		bottom_	= new DiceSurface(bottomNumber);
	}

	~Dice() {
		delete top_;		
		delete north_;
		delete south_;
		delete east_; 
		delete west_; 
		delete bottom_;
	}

	unsigned short getTopNumber() {
		return top_->getNumber();
	}

	void rotateNorth() {
		const DiceSurface* tmp = top_;
		top_	= south_;
		south_	= bottom_;
		bottom_	= north_;
		north_	= tmp;
	}

	void rotateSouth() {
		const DiceSurface* tmp = top_;
		top_	= north_;
		north_	= bottom_;
		bottom_	= south_;
		south_	= tmp;
	}

	void rotateEast() {
		const DiceSurface* tmp = top_;
		top_	= west_;
		west_	= bottom_;
		bottom_	= east_;
		east_	= tmp;
	}

	void rotateWest() {
		const DiceSurface* tmp = top_;
		top_	= east_;
		east_	= bottom_;
		bottom_ = west_;
		west_	= tmp;
	}

	void rotateClockwise() {
		const DiceSurface* tmp = north_;
		north_	= west_;
		west_	= south_;
		south_	= east_;
		east_	= tmp;
	}

	void rotateAnticlockwise() {
		const DiceSurface* tmp = north_;
		north_	= east_;
		east_	= south_;
		south_	= west_;
		west_	= tmp;
	}
};

int main(int, char**)
{
	const unsigned short surfaceSize = 6;
	int numbers[surfaceSize];
	for ( int i = 0; i < surfaceSize; ++i) {
		cin >> numbers[i];
	}

	Dice dice(numbers[0]	// ?????¢
			, numbers[4]	// ?????¢
			, numbers[1]	// ?????¢
			, numbers[2]	// ??±??¢
			, numbers[3]	// ?\???¢
			, numbers[5]);	// ?????¢

	string commands;
	cin >> commands;
	for ( unsigned int i = 0; i < commands.size(); ++i ) {
		char& command  = commands[i];
		if ( command == 'N' ) {
			dice.rotateNorth();
		} else if ( command == 'S' ) {
			dice.rotateSouth();
		} else if ( command == 'E' ) {
			dice.rotateEast();
		} else if ( command == 'W' ) {
			dice.rotateWest();
		}
	}
	
	cout << dice.getTopNumber() << endl;

	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long
#define lli long long int

using namespace std;
using P = pair<int,int>;

int main(){

  int N;
  string S;
  cin >> N >> S;
  int ans = 0;

  for (int i = 0; i < N-2; i++) {

    char a = S[i];
    char b = S[i+1];
    char c = S[i+2];
    string A(1, a);
    string B(1, b);
    string C(1, c);
    string ABC = A+B+C;

    if(ABC == "ABC") ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3580
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
m = min(n, k)
for i in range(m + 1):
    for j in range(m - i + 1):
        t = v[:i] + v[n - j:]
        t.sort()
        d = tuple(filter(lambda x: x < 0, t))[:k - i - j]
        ans = max(ans, sum(t) - sum(d))
print(ans)


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

int main()
{
  int n,ans;
  ans=0;
  cin>>n;
  vector<int64_t> l(n);
  for(int i=0;i<n;i++)
  {
    cin>>l.at(i);
  }
  if(n>=3)
  {
    for(int i=0;i<n-2;i++)
    {
      for(int j=i+1;j<n-1;j++)
      {
        for(int k=j+1;k<n;k++)
        {
          if(((l.at(i)==l.at(j))||(l.at(j)==l.at(k)))||(l.at(i)==l.at(k)))
            continue;
          else
          {
            if(l.at(i)+l.at(j)>l.at(k))
            {
              if(l.at(j)+l.at(k)>l.at(i))
              {
                if(l.at(i)+l.at(k)>l.at(j))
                  ans++;
              }
            }
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  lint n,k;
  cin>>n>>k;
  if(n>=k){
    cout<<min({n,n%k,abs((n%k)-k)})<<endl;
  }else{
    cout<<min(n,k-n)<<endl;
  }

  return 0;
}




Measured memory_bytes: 256
//                                    ∴In the name of God∴
//                     ✫✗⚡😳😳😄😄😝😝😁😁😎😎😛😛😄😄😮😮⚡✗✫
//                                       H.Pouya  ◠?◠
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<bitset>
#include<iostream>
#include<algorithm>
using namespace std;
typedef short int ss;
typedef long double dd;
typedef long long int ll;
#define give_up return 0;
#define mix(x,y) x*pow(10,y)+5
const ll hp1=999998727899999;
const ll hp2=1012345678901;
const int hp3=2147483647;
const int maxn=mix(1,4);
vector<int>adj[maxn];
bool mark[maxn];
int scr[maxn];
int ans[maxn];
int ptr;
void dfs(int v)
{
    mark[v]=true;
    ans[v]=scr[ptr];
    ptr--;
    int sz=adj[v].size();
    for(int i=0;i<sz;i++)
    {
        if(!mark[adj[v][i]])
            dfs(adj[v][i]);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    vector<pair<int,int>>edg;
    for(int u,v,i=1;i<n;i++)
    {
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
        edg.push_back({u,v});
    }
    for(int i=0;i<n;i++)
        scanf("%d",&scr[i]);
    sort(scr,scr+n);
    ptr=n-1;
    dfs(1);
    int anser=0;
    for(int i=0;i<n-1;i++)
        anser+=min(ans[edg[i].first],ans[edg[i].second]);
    printf("%d\n",anser);
    for(int i=1;i<=n;i++)
        printf("%d ",ans[i]);
    give_up
}
//  🙄


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

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

  int cnt = 0;
  for(int i = 0; i < n; ++i){
  	if(a[i] == cnt + 1)++cnt;
  }

  if(cnt == 0)cout << -1 << endl;
  else cout << n - cnt << endl;
  return 0;
}


Measured memory_bytes: 1024