akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

const double pi = acos(-1);

int main() {
  int n;
  scanf("%d", &n);
  while(n--) {
    int h, m;
    scanf("%d:%d", &h, &m);
    double rh = (h+m/60.0)/6.0;
    double rm = m/30.0;
    double rad = min(abs(rh-rm), abs(fmod(rh+1,2)-fmod(rm+1,2)));
    if(rad < 1.0/6.0) {
      cout << "alert" << endl;
    } else if(1.0/2.0 <= rad && rad <= 1.0) {
      cout << "safe" << endl;
    } else {
      cout << "warning" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1200
#include <cstdio>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;

typedef unsigned long long ull;

const int thr = 2;

map<ull,int> memo;

vector<ull> tbl;

void maketbl(ull s, int t, int u){
	if(t == 0){
		tbl.push_back(s);
	}
	for(u = min(t, u); u >= 1; --u){
		maketbl(s + (1ull << ((u - 1) * 8)), t - u, u);
	}
}

int dfs2(ull, int, int);

int dfs1(ull s){
	if(s < 10){ return 0; }
	if(memo.count(s)){
		return memo[s];
	}
	int k;
	for(k = 8; !(s >> ((k - 1) * 8)); --k);

	int res = 0;
	if(k <= thr){
		ull r = s;
		for(size_t i = 0; i < tbl.size(); ){
			ull p = r;
			bool ok = true;
			for(int j = thr; j >= 1; --j){
				if((p >> ((j - 1) * 8) & 0xff) >= (tbl[i] >> ((j - 1) * 8) & 0xff)){
					p -= tbl[i] & (0xffull << ((j - 1) * 8));
				}
				else{
					ok = false;
				}
			}
			if(ok){
				r = p;
				++res;
			}
			else{
				++i;
			}
		}
	}
	else{
		int a = dfs2(s - (1ull << ((k - 1) * 8)), 10 - k, k);
		int b = dfs1(s & ((1ull << ((k - 1) * 8)) - 1));
		res = max(a, b);
	}
	
	memo[s] = res;
	return res;
}

int dfs2(ull s, int t, int u){
	if(s >> ((t - 1) * 8) & 0xff){
		return dfs1(s - (1ull << ((t - 1) * 8))) + 1;
	}
	if(t == 1){
		return 0;
	}
	if(t == 2){
		if((s & 0xff) >= 2){
			return dfs1(s - 2) + 1;
		}
		return 0;
	}
	if(t == 3){
		if(s & 0xff && s & 0xff00){
			return dfs1(s - 0x101) + 1;
		}
		if((s & 0xff) >= 3){
			return dfs1(s - 3) + 1;
		}
		return 0;
	}
	
	int res = 0;
	for(u = min(t, u); u >= 1; --u){
		if(s >> ((u - 1) * 8) & 0xff){
			int a = dfs2(s - (1ull << ((u - 1) * 8)), t - u, u);
			res = max(res, a);
		}
	}
	return res;
}

int main(){
	maketbl(0, 10, thr);
	sort(tbl.begin(), tbl.end(), greater<ull>());

	int n, x;
	while(scanf("%d", &n), n){
		int cnt[10] = {};
		for(int i = 0; i < n; ++i){
			scanf("%d", &x);
			++cnt[x];
		}
		
		int ans = 0;
		for(int i = 1; i <= 4; ++i){
			x = min(cnt[i], cnt[10 - i]);
			ans += x;
			cnt[i] -= x;
			cnt[10 - i] -= x;
		}
		
		ans += cnt[5] / 2;
		cnt[5] &= 1;
		
		ull s = 0;
		for(int i = 1; i <= 8; ++i){
			s |= (ull)cnt[i] << ((i - 1) * 8);
		}
		
		memo.clear();
		ans += dfs1(s);
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1692
#include<bits/stdc++.h>
#define ll long long
#define mod (ll)1000000007
#define MAX 100005
using namespace std;
int n,k;
int h[MAX];
int dp[MAX];
int rec(int pos)
{
	if(pos >= n)
		return mod;

	if(pos == n-1)
		return 0;

	if(dp[pos] != -1)
		return dp[pos];

	dp[pos] = INT_MAX;
	for(int i = 1; i<= k; i++){
		if(pos+i < n)
			dp[pos] = min(rec(pos+i)+abs(h[pos]-h[pos+i]),dp[pos]);
	}


	return dp[pos];
}

int main()
{
	cin>>n>>k;
	for(int i = 0; i < n; i++)
		cin>>h[i];
	memset(dp,-1,sizeof(dp));
	
	cout<<rec(0)<<"\n";
	return 0;
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FasterScanner in = new FasterScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FasterScanner in, PrintWriter out) {
            double n = in.nextDouble();
            double m = in.nextDouble();
            double d = in.nextDouble();

            double ans;
            if (d == 0) ans = (m - 1) / n;
            else ans = (m - 1) * 2 * (n - d) / Math.pow(n, 2);

            out.println(ans);
        }

    }

    static class FasterScanner {
        private InputStream in;
        private byte[] buffer;
        private int bufPointer;
        private int bufLength;

        public FasterScanner(InputStream in) {
            this.in = in;
            buffer = new byte[1024];
        }

        private boolean hasNextByte() {
            if (bufPointer < bufLength) return true;
            bufPointer = 0;
            try {
                bufLength = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (bufLength > 0);
        }

        private int readByte() {
            if (hasNextByte()) return buffer[bufPointer++];
            return -1;
        }

        private static boolean isPrintableChar(int c) {
            return (c >= 33 && c <= 126);
        }

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

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

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

    }
}



Measured memory_bytes: 21460
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <list>
#include <bitset>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <climits>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <initializer_list>
#include <iomanip>
#include <functional>
#include <unordered_map>
#include <regex>

using namespace std;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  int odd = 0, even = 0;
  for (int i = 0; i < N; ++i)
    {
      int a;
      cin >> a;
      odd += a & 1;
      even += !(a & 1);
    }
  while (true)
    {
      if (odd > even) odd -= 2, ++even;
      else if (even >= 2 && even >= odd) --even;
      else even = -1;
      if (odd < 0 || even < 0) return cout << "NO" << endl, 0;
      if (odd + even == 1) return cout << "YES" << endl, 0;
    }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n, q;
  std::string s;
  cin >> n >> q;
  cin >> s;
  int cum[100001] = {};
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == 'A' && s[i] == 'C') {
      cum[i]++;
    }
    cum[i] += cum[i - 1];
  }
  for (int i = 0; i < n; i++) {
    cerr << cum[i] << endl;
  }

  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    cout << cum[r] - cum[l] << endl;
  }

  return 0;
}


Measured memory_bytes: 1488
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){

			final String inputLine = br.readLine();
			final String[] inputNumber = inputLine.split(" ");

			final Integer a = Integer.valueOf(inputNumber[0]);
			final Integer b = Integer.valueOf(inputNumber[1]);

			if(a < b) {
				System.out.println("a < b");
			}
			if(a > b) {
				System.out.println("a > b");
			}
			if(a.equals(b)) {
				System.out.println("a == b");
			}

		}

	}

}


Measured memory_bytes: 24252
#include <iostream>
#include <vector>

void solve(int n, int x) {
    int ans = 1;
    int d = 0;
    std::vector< int > vec(n);
    for (auto &v : vec) std::cin >> v;

    for (auto v : vec) {
        d += v;
        if (d > x) break;
        ++ans;
    }
    std::cout << ans << std::endl;
}

int main() {
    int n, x;
    std::cin >> n >> x;
    solve(n, x);
    return 0;
}


Measured memory_bytes: 256
M=10**9+7

class Combination
  def initialize(n, m=10**9+7)
    @m = m
    @fact, @inv, @finv = Array.new(3){[1, 1]}
    2.upto(n) do |i|
      @fact[i] = (@fact[i-1] * i) % @m
      @inv[i]  = (@inv[@m % i] * (@m - @m / i) ) % @m
      @finv[i] = (@finv[i-1] * @inv[i] ) % @m
    end
  end
  def query(n, r)
    return 0 if (n < r) || (n < 0) || (r < 0)
    (@fact[n] * @finv[n-r] % @m) * @finv[r] % @m
  end
end

def sum(n, r)
  C.query(n+r+2, r+1) - 1
end

r1,c1,r2,c2=gets.split.map(&:to_i)
r1-=1
c1-=1
C=Combination.new(r2+c2+2, M)
ans = 0
ans += sum(r2, c2)
ans -= sum(r1, c2)
ans -= sum(r2, c1)
ans += sum(r1, c1)
ans %= M
p (ans + M) % M


Measured memory_bytes: 50528
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <climits>

using namespace std;
#define ll long long
#define ve vector
#define umap unordered_map

int main() {
    ve<string> s(3);
    cin>>s[0]>>s[1]>>s[2];
    int t=0;
    while(true){
        if(s[t].size() == 0){
            cout<<(char) (t+'A')<<endl;
            return 0;
        }
        char c = s[t][0];
        s[t].erase(s[t].begin());
        t = c-'a';
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int d;cin>>d;
    d = 25-d;
    cout<<"Christmas";
    rep(i,d){
        cout<<" "<<"Eve";
    }
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int N;
    static int K;
    static String S;

    private static void read() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        K = sc.nextInt();
        S = sc.next();
    }

    public static void main(String[] args) {
        read();
        solve();
    }

    private static void solve() {
        List<Integer> ary = new ArrayList<>();
        int cur = '1';
        int curCnt = 0;
        for (char s : S.toCharArray()) {
            if (s == cur) {
                curCnt += 1;
            } else {
                ary.add(curCnt);
                cur = cur == '1' ? '0' : '1';
                curCnt = 1;
            }
        }
        if (curCnt != 0) {
            ary.add(curCnt);
        }
        if (ary.size() % 2 == 0) {
            ary.add(0);
        }

        List<Integer> cumSum = new ArrayList<>();
        cumSum.add(0);
        for (int i = 0; i < ary.size(); i += 1) {
            cumSum.add(cumSum.get(i) + ary.get(i));
        }

        int stride = 2 * K + 1;
        int best = 0;
        for (int left = 0; left < ary.size(); left += 2) {
            int right = Integer.min(left + stride, cumSum.size() - 1);
            best = Integer.max(best, cumSum.get(right) - cumSum.get(left));
        }

        System.out.println(best);
    }

}


Measured memory_bytes: 30808
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int M = sc.nextInt();
   int C = sc.nextInt();
   int[] Bi = new int[M];
   for(int i = 0; i<M;i++)
   {
		Bi[i] = sc.nextInt();       
   }
   int count =0;
   int sum = 0;
   for(int i = 0;i <N;i++)
   {
     sum = 0;
    for(int k = 0;k <M;k++)
    {
      sum += Bi[k]*sc.nextInt();      
    }
     sum += C;
     if(sum >0) count++;
   }
   System.out.println(count);
 }
}

Measured memory_bytes: 23252
def resolve():
    N, max_W = map(int, input().split())
    W, V = zip(*[list(map(int, input().split())) for _ in range(N)])
    max_V = sum(V)
    dp = [[1 << 60] * (max_V + 1) for _ in range(N + 1)]
    dp[0][0] = 0

    for i in range(N):
        for v in range(max_V + 1):
            dp[i + 1][v] = min(dp[i + 1][v], dp[i][v])
            if V[i] <= v:
                dp[i + 1][v] = min(dp[i + 1][v], dp[i][v - V[i]] + W[i])

    # ミス： range関数の時[0, 8)で +1をして調整している。if文でもmax_W+1で調整しWA
    ans = 0
    for v in range(max_V + 1):
        if dp[N][v] <= max_W:
            ans = max(ans, v)
    print(ans)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 151304
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int K; cin >> K;
    vector<LLONG> As(K); for (auto &Ai : As) cin >> Ai;
    // 試合を逆順に辿る：O(K)
    LLONG min = 2, max = 2;
    for (int i = K - 1; i >= 0; --i)
    {
        LLONG Ai = As[i];
        // [min, max]に含まれるAiの倍数のうち，最小値Xiおよび最大値Yiを計算
        LLONG Xi = min % Ai == 0 ? min : (min / Ai + 1) * Ai;
        LLONG Yi = max / Ai * Ai;
        if (Xi > max || Yi < min)
        {
            cout << -1 << endl;
            return 0;
        }
        // 組を作る前の最小人数はXi
        min = Xi;
        // 組を作る前の最大人数はYi＋Ai-1
        max = Yi + Ai - 1;
    }
    cout << min << ' ' << max << endl;
}


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

int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for( int i = 0; flag; i++ ) {
    flag = 0;
    for ( int j = N - 1; j >= i + 1; j-- ) {
      if ( A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        flag =1;
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for( int i = 0; i < N; i++ ) cin >> A[i];

  sw = bubbleSort(A, N);

  for ( int i = 0; i < N; i++ ) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}




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

int main(void)
{
    int h,w,a[500][500],i,j,ifhave=0,n=0;

    scanf("%d %d",&h,&w);
    for ( i = 0; i < h; i++)
    {
        for ( j = 0; j < w; j++)
        {
            scanf("%d",a[i]+j);
        }
    }

    for ( i = 0; i < h; i++)
    {
        for ( j = 0; j < w; j++)
        {
            int k;
            if(i%2==0) k=j;
            else k=w-1-j;
            if(ifhave==1)
            {
                int prei,prej;
                n++;
                if(i%2==0)
                {
                    prei=i;
                    prej=k-1;
                    if(prej==-1)
                    {
                        prei=i-1;
                        prej=k;
                    }
                }
                else
                {
                    prei=i;
                    prej=k+1;
                    if(prej==w)
                    {
                        prei=i-1;
                        prej=k;
                    }
                }
                //printf("%d %d %d %d\n",prei+1,prej+1,i+1,k+1);

                if(a[i][k]%2==1) ifhave=0;
            }
            else
            {
                if(a[i][k]%2==1) ifhave=1;
            }
        }
    }

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

    ifhave=0;
    for ( i = 0; i < h; i++)
    {
        for ( j = 0; j < w; j++)
        {
            int k;
            if(i%2==0) k=j;
            else k=w-1-j;
            if(ifhave==1)
            {
                int prei,prej;
                n++;
                if(i%2==0)
                {
                    prei=i;
                    prej=k-1;
                    if(prej==-1)
                    {
                        prei=i-1;
                        prej=k;
                    }
                }
                else
                {
                    prei=i;
                    prej=k+1;
                    if(prej==w)
                    {
                        prei=i-1;
                        prej=k;
                    }
                }
                printf("%d %d %d %d\n",prei+1,prej+1,i+1,k+1);

                if(a[i][k]%2==1) ifhave=0;
            }
            else
            {
                if(a[i][k]%2==1) ifhave=1;
            }
        }
    }

    return 0;
}

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int a, b;
	string s, t, p;
	map<string, int> m;
	cin >> s >> t;
	cin >> a >> b;
	m[s] = a;
	m[t] = b;
	cin >> p;
	--m[p];
	cout << m[s] << " " << m[t];

	return 0;
}



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

X.sort()

l = []
for i in range(1, len(X)):
  l.append(X[i] - X[i-1])

l.sort(reverse=True)

if len(l) <= N - 1:
    print(0)
else:
    print(sum(l[N-1:]))

Measured memory_bytes: 13968
#!/usr/bin/env python3


X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P = sorted(P)
Q = sorted(Q)
R = sorted(R)

x_p = []
y_q = []
xy_r = []
c = 0
for p in P[::-1]:
    if c == X: break
    x_p.append(p)
    c += 1
c = 0
for q in Q[::-1]:
    if c == Y: break
    y_q.append(q)
    c += 1
c = 0
for r in R[::-1]:
    if c == X+Y: break
    xy_r.append(r)
    c += 1



p_i = len(x_p)-1
q_i = len(y_q)-1
xy_i = 0


f = True

while f:
    if xy_i == len(xy_r): break
    p = x_p[p_i]
    q = y_q[q_i]
    s = ''
    if p > q:
        s = 'q'
        mi = q_i
    else:
        s = 'p'
        mi = p_i
    if s == 'p' and p < xy_r[xy_i]:
        x_p[p_i] = xy_r[xy_i]
        p_i -= 1
        xy_i += 1
    elif s == 'q' and q < xy_r[xy_i]:
        y_q[q_i] = xy_r[xy_i]
        q_i -= 1
        xy_i += 1
    else:
        f = False

ans = sum(x_p) + sum(y_q)
print(ans)





Measured memory_bytes: 23328
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    stack<char> s;
    rep(i,n){
        char a;
        cin>>a;
        if(s.empty()){
            s.push(a);
        }else{
            char b = s.top();
            if(a==b){
                
            }else{
                s.push(a);
            }
        }
        
    }
    cout<<s.size()<<endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
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 mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

int main(){
  int n,d,q;
  cin>>n>>d;
  vector<int> vec(n);
  rep(i,n) cin>>vec[i];
  cin>>q;
  vector<int> query(q);
  rep(i,q) cin>>query[i];
  rep(i,q) query[i]--;

  vector<int> pos(n); // i番目の移動の前の位置
  pos[0] = d;
  rep(i,n-1){
    if(pos[i] > abs(pos[i]-vec[i])){
      pos[i+1] = abs(pos[i]-vec[i]);
    } else {
      pos[i+1] = pos[i];
    }
  }
//dbg(pos);
  vector<long> cannot(n+1); // i番目以降でゴールできない最小値
  cannot[n]=1;
  for(int i=n-1; i>=0; i--){
    if(vec[i]<=cannot[i+1]) cannot[i] = min<long>(cannot[i+1] + vec[i], INF);
    else if(vec[i]<=cannot[i+1]*2-1) cannot[i] = min<long>(vec[i]+cannot[i+1], INF);
    else cannot[i] = cannot[i+1];
  }
//dbg(cannot);
  for(auto i : query){
    if(pos[i] > cannot[i+1]-1) cout << "YES" << endl;
    else cout << "NO" << endl;
  }


  return 0;
}


Measured memory_bytes: 12160
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << '\n'

typedef int64_t Int;
const double pi = M_PI;

using namespace std;

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


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100005
#define NIL -1

typedef struct {int p, l, r;} Node;

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if( T[u].p == NIL ) printf("root, ");
  else if( T[u].l == NIL ) printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for(i=0, c=T[u].l; c != NIL; i++, c=T[c].r) {
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

void rec(int u, int p) {
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r,p);
  if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(void) {
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;
  for(i=0;i<n;i++) {
    scanf("%d %d",&v,&d);
    for(j=0;j<d;j++) {
      scanf("%d",&c);
      if(j==0) T[v].l=c;
      else T[l].r =c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0;i<n;i++) {
    if(T[i].p == NIL) r = i;
  }
  
  rec(r,0);
  
  for(i=0;i<n;i++) print(i);
  
  return 0;
}


Measured memory_bytes: 6384
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>
#include <complex>

using namespace std;

#define mod 1000000007


int main()
{
	int n;
	cin >> n;
	vector<pair<int, int> > ans;
	if(n % 2 == 0){
		for(int i = 1; i <= n; i++){
			for(int j = i + 1; j <= n; j++){
				if(i + j != n + 1) ans.push_back(make_pair(i, j));
			}
		}
	} else {
		for(int i = 1; i <= n - 1; i++){
			for(int j = i + 1; j <= n - 1; j++){
				if(i + j != n) ans.push_back(make_pair(i, j));
			}
			ans.push_back(make_pair(i, n));
		}
	}
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++){
		cout << ans[i].first << " " << ans[i].second << endl;
	}
}

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

char buf[1000000];
signed main() {
  int n, k;
  char s[11];
  scanf("%d %d %s", &n, &k, s);
  char *p = buf;
  size_t len = strlen(s);
  s[len++] = ' ';
  int i = 0;
  while (i++ < k) {
    strcpy(p, s);
    p += len;
    if (p - buf > 100000) {
      int j = 0;
      while (j++ < k / i) {
        write(STDOUT_FILENO, buf, p - buf);
      }
      i *= j - 1;
      p = buf;
    }
  }
  i--;
  while (i++ < n) {
    *p++ = '7';
    *p++ = ' ';
  }
  write(STDOUT_FILENO, buf, p - buf);
}


Measured memory_bytes: 1408
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0

for i in range(N):
    if i%2==0:
        if A[i//2]>=B[i//2]:
            A[i//2]-=B[i//2]
            ans+=B[i//2]
            B[i//2]=0
        else:
            B[i//2]-=A[i//2]
            ans+=A[i//2]
            A[i//2]=0
        if A[i//2+1]>=B[i//2]:
            A[i//2+1]-=B[i//2]
            ans+=B[i//2]
            B[i//2]=0
        else:
            B[i//2]-=A[i//2+1]
            ans+=A[i//2+1]
            A[i//2+1]=0
    else:
        if A[N-i//2]>=B[N-i//2-1]:
            A[N-i//2]-=B[N-i//2-1]
            ans+=B[N-i//2-1]
            B[N-i//2-1]=0
        else:
            B[N-i//2-1]-=A[N-i//2]
            ans+=A[N-i//2]
            A[N-i//2]=0
        if A[N-i//2-1]>=B[N-i//2-1]:
            A[N-i//2-1]-=B[N-i//2-1]
            ans+=B[N-i//2-1]
            B[N-i//2-1]=0
        else:
            B[N-i//2-1]-=A[N-i//2-1]
            ans+=A[N-i//2-1]
            A[N-i//2-1]=0

print(ans)


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  stack<char> s;
  for (int i = 0; i < N; i++) {
    if (i == 0 || s.empty()) s.push(S[i]);
    else if (s.top() == '(' && S[i] == ')') s.pop();
    else s.push(S[i]);
  }
  string left, right;
  while (!s.empty()) {
    if (s.top() == '(') right += ')'; else left += '(';
    s.pop();
  }
  cout << left << S << right << endl;
}

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

typedef long long LL;

LL cari(LL x, LL a, LL b){
	LL ret = x/a;
	ret+=x/b;
	ret-=x/((a*b)/__gcd(a,b));
	return ret;
}

LL a,b,c,d;

int main(){
	cin >> a >> b >> c >> d;
	a--;
	LL tmp1 = cari(b,c,d);
	LL tmp2 = cari(a,c,d);
	cout << b-a-(tmp1 - tmp2) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
	int a;
	int b;
	int d;
	int r;
	
	double f;
	double c;
	double k;
	
	scanf("%d %d",&a,&b);
	
	d=a/b;
	r=a%b;
	
	c=a;
	k=b;
	
	f=c/k;
	
	printf("%d %d %f",d,r,f);
	
	return (0);
}

Measured memory_bytes: 636
#include <iostream>
#include <stdio.h>
#include <vector>
 
using namespace std;
 
int w, h;
int mindepth = 0;
int d[4][2] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } }; 

bool isValid( int x, int y ) {
	return !( x < 0 || y < 0 || x >= w || y >= h ); 
}

void dfs_search( vector< vector< int > > map, int x, int y, int depth ) {
	if( depth >= 10 || depth >= mindepth ) return;
	for( int i = 0; i < 4; i++ ) {
		vector< vector< int > > currentmap = map;
		int cx = x, cy = y;
		if( !isValid( cx + d[i][1], cy + d[i][0] ) || currentmap[cy + d[i][0]][cx + d[i][1]] == 1 ) continue;
		for( ;isValid( cx, cy ); cx += d[i][1], cy += d[i][0] ) {
			if( currentmap[cy][cx] == 1 ) {
				currentmap[cy][cx] = 0;
				dfs_search( currentmap, cx - d[i][1], cy -  d[i][0], depth + 1 );
				break;
			}
			if( currentmap[cy][cx] == 3 ) {
				mindepth = depth + 1;
				break;
			}
		}
	}
	
}

int main(void){
 
	while( true ) {
		cin >> w >> h;
		if( !( w | h ) ) break;
		mindepth = 1 << 30;
		vector< vector< int > > startmap( h, vector< int >( w, 0 ) );
		int sx, sy;
		for( int i = 0; i < h; i++ ) {
			for( int j = 0; j < w; j++ ) {
				cin >> startmap[i][j];
				if( startmap[i][j] == 2 ) {
					startmap[i][j] = 0;
					sx = j; sy = i;
				}
			}
		}
		dfs_search( startmap, sx, sy, 0 );
		if( mindepth == ( 1 << 30 ) ) mindepth = -1;
		cout << mindepth << endl;
	}

	return 0;
}

Measured memory_bytes: 1340
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define xmod int(1e9+7)
#define hmod 1223334444555553LL
using namespace std;

ll n,ans,sum1,sum2,a[100005],b[100005],c[100005],mx[100005],mn[100005]; 
priority_queue <int> q1,q2;
int main(){
	cin >> n;
	for (int i=1;i<=n;i++){
		cin >> a[i];
		q1.push(-a[i]);
		sum1+=a[i];
	}
	for (int i=1;i<=n;i++){
		cin >> b[i];
	}
	for (int i=1;i<=n;i++){
		cin >> c[i];
		sum2+=c[i];
		q2.push(c[i]);
	}
	ans=-1e18;
	for (int i=0;i<=n;i++){
		mx[i]=sum1;
		if (i != n){
			sum1+=b[i+1];
			q1.push(-b[i+1]);
			sum1+=q1.top();
			q1.pop(); 
		}
	}
	for (int i=0;i<=n;i++){
		mn[i]=sum2;
		if (i != n){
			sum2+=b[n-i];
			q2.push(b[n-i]);
			sum2-=q2.top();
			q2.pop(); 
		}
	}
	for (int i=0;i<=n;i++){
	//	cout << mx[i] << " " << mn[n-i] << endl;
		ans=max(ans,mx[i]-mn[n-i]);
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 5112
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
  int x, a;
  cin >> x >> a;
  int ans = x < a ? 0 : 10;
  cout << ans << endl;
}

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

using namespace std;
using ll = long long int;

int main(){

    int k, cnt = 1;
    cin >> k;

    ll num = 7 % k;

    while(cnt < 1e7){
        if (num == 0) {
            cout << cnt << endl;
            return 0;
        }
        num = (num * 10 + 7) % k;
        cnt++;
     }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3596
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        m: usize,
        k: usize,
        a: [usize; n],
    }
    let mut dp = a.clone();
    let mut deq = std::collections::VecDeque::new();
    for k in 2..(k + 1) {
        deq.clear();
        deq.push_back((dp[k - 2], k - 2));
        for (i, dp) in dp[(k - 1)..].iter_mut().enumerate() {
            let i = i + k - 1;
            if deq.front().unwrap().1 + m < i {
                deq.pop_front();
            }
            let p = *deq.front().unwrap();
            let b = (*dp, i);
            *dp = p.0 + k * a[i];
            while let Some(p) = deq.pop_back() {
                if p.0 > b.0 {
                    deq.push_back(p);
                    break;
                }
            }
            deq.push_back(b);
        }
    }
    let ans = dp.into_iter().max().unwrap();
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 6396
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <tuple>

int main() {
	int N, M;
	std::cin >> N >> M;
	//市の番号、県の番号、誕生年
	std::vector<std::tuple<int, int, int>> cities;
	for (int i = 0; i < M; ++i) {
		int P, Y;
		std::cin >> P >> Y;
		cities.emplace_back(i, P, Y);
	}

	std::sort(cities.begin(), cities.end(), [](auto a, auto b) { return std::get<1>(a) == std::get<1>(b) ? std::get<2>(a) < std::get<2>(b) : std::get<1>(a) < std::get<1>(b); });
	{
		int i = 1;
		int prev = -1;
		for (auto &v : cities) {
			std::get<2>(v) = (prev != std::get<1>(v) ? i = 1 : ++i);
			prev = std::get<1>(v);
		}
	}
	std::sort(cities.begin(), cities.end(), [](auto a, auto b) { return std::get<0>(a) < std::get<0>(b); });
	for (auto&v : cities) {
		printf("%06d%06d\n", std::get<1>(v), std::get<2>(v));
	}
}

Measured memory_bytes: 2804
n, k = map(int, input().split())
s = input()

h=0
for i in range(n-1):
  if s[i]==s[i+1]:
    h+=1
  else:
    if s[i]==s[0] and k>0:
      if s[0] in s[i+1:]:
        h+=2
        k-=1
      else:
        h+=1
        k-=1
print(h)

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

int main(void) {
	double *A;
	double a = 0;
	int N;
	int i;
  scanf("%d",&N);
	A = (double*)malloc(sizeof(double)*N);
	for (i = 0; i < N; i++) {
		scanf("%lf", &A[i]);
	}
	for (i = 0; i < N; i++) {
      a+=1/A[i];
	}

	printf("%lf\n", 1/a);
    
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int findtotaldigits(int sum);

int main()
{
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF)
	{
		
		int sum = a + b;
		int totalDigits = 0;
		totalDigits = findtotaldigits(sum);
		
		printf("%d\n",totalDigits);
	}
}

int findtotaldigits(int sum)
{
	if(sum == 0)
	{
		return 0;
	}
	return 1 + findtotaldigits(sum/10);
}


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

using namespace std;

const long long INF = (1LL << 60);
const int MAX_N = 1<<17;
long long segVal[2*MAX_N-1];
int segUpdate[2*MAX_N-1];

void change(int l, int r, long long val, int idx = 0, int rangeL = 0, int rangeR = MAX_N){
	if(rangeR <= l || r <= rangeL) return;
	if(l <= rangeL && rangeR <= r){
        segVal[idx] = val;
        segUpdate[idx] = 1;
        // cout << "c" << segVal[idx] << " " << segUpdate[idx] << " " << idx << endl;
	} else {
		int rangeM = (rangeL+rangeR)/2;
		change(l, r, val, 2*idx+1, rangeL, rangeM);
		change(l, r, val, 2*idx+2, rangeM, rangeR);
	}
}

long long getVal(int l, int r, int idx = 0, int rangeL = 0, int rangeR = MAX_N){
	if(rangeR <= l || r <= rangeL) return INF;
	if(l <= rangeL && rangeR <= r){
        // cout << "r" << segVal[idx] << " " << idx << " " << rangeL << " " << rangeR << endl;
        return segVal[idx];
	} else {
        // cout << "u" << idx << " " << rangeL << " " << rangeR << endl;
        // cout << segVal[idx] << " " << segUpdate[idx] << endl;
        int rangeM = (rangeL+rangeR)/2;
        if(segUpdate[idx]){
            // cout << "Update" << endl;
            change(rangeL, rangeM, segVal[idx], 2*idx+1, rangeL, rangeM);
            change(rangeM, rangeR, segVal[idx], 2*idx+2, rangeM, rangeR);
            segUpdate[idx] = 0;
        }
        return min(getVal(l, r, 2*idx+1, rangeL, rangeM), getVal(l, r, 2*idx+2, rangeM, rangeR));
	}
}

long long getVal(int idx){
    return getVal(idx, idx+1);
}

int main(){
    int N, M;
    while(cin >> N >> M){
        for(int i=0;i<2*MAX_N-1;i++) segUpdate[i] = 0;
        change(0, N, INF);
        vector<pair<pair<int,int>, long long>> Q(M);
        for(auto& t : Q){
            cin >> t.first.first >> t.first.second >> t.second;
            --t.first.first;
            --t.first.second;
        }
        sort(Q.begin(), Q.end());
        // cout << "test " << segUpdate[32767] << endl; 
        // cout << getVal(0) << endl; return 0;
        for(int i=0;i<N;i++) getVal(i);
        change(0, 1, 0);
        // for(int i=0;i<N;i++) cout << getVal(i) << " "; cout << endl;
        for(auto& q : Q){
            // cout << q.first.first << " " << q.first.second << " " << q.second << endl;
            long long next = getVal(q.first.first) + q.second;
            if(getVal(q.first.second) <= next) continue;
            int L = q.first.first, R = q.first.second;
            while(R-L > 1){
                int mid = (L+R)/2;
                if(getVal(mid) > next) R = mid;
                else L = mid; 
            }
            // cout << R << endl;
            change(R, q.first.second+1, next);
            // for(int i=0;i<N;i++) cout << getVal(i) << " "; cout << endl;
        }
        long long res = getVal(N-1);
        cout << (res == INF ? -1 : res) << endl;
    }
}

Measured memory_bytes: 4352
#include <stdio.h>
int n,m,q,a,b,c,d,rui[1005][1005][3],ret[3];char f[1005][1005],e[3]={'J','O','I'};
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=0;i<n;i++) scanf("%s",&f[i]);
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) for(int k=0;k<3;k++)
	rui[i][j][k]=rui[i-1][j][k]+rui[i][j-1][k]-rui[i-1][j-1][k]+(f[i-1][j-1]==e[k]);
	for(int i=0;i<q;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		for(int j=0;j<3;j++) ret[j]=rui[c][d][j]-rui[c][b-1][j]-rui[a-1][d][j]+rui[a-1][b-1][j];
		printf("%d %d %d\n",ret[0],ret[1],ret[2]);
	}
}

Measured memory_bytes: 13672
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
#define pi 3.1415926535
typedef long long ll;


int main(){
   int N,A,B;
   string S;
   cin>>N>>A>>B>>S;
   int count_d=0,count_o=0,count_t=0;;
   rep(i,N){
       if(S[i]=='a'){
           if(count_t<A+B){
               count_d++;
               count_t++;
               cout<<"Yes"<<endl;
           }else{
               cout<<"No"<<endl;
           }
       }else if(S[i]=='b'){
           if(count_t<A+B&&count_o+1<=B){
               count_o++;
               count_t++;
               cout<<"Yes"<<endl;
           }else{
               cout<<"No"<<endl;
           }
       }else{
           cout<<"No"<<endl;
       }
   }

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int h, w, ans;
int main (void) {
    scanf ("%d %d", &h, &w);
    for (int i = 1; i <= h; ++i) {
        getchar ();
        for (int j = 1; j <= w; ++j) {
            char ch = getchar ();
            if (ch == '#') ++ans;
        }
    }
    puts ((ans == h + w - 1) ? "Possible\r\n" : "Impossible\r\n");
}

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

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

    vector<int>sticks;
    for (int i =0; i<n; i++){
        int stick;
        cin >> stick;
        sticks.push_back(stick);

    }

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

    int total =0;
    for (int largest=sticks.size() -1; largest >= 0; largest--){
        int largestlength = sticks[largest];

        int left =0;
        int right = largest -1;
        while(left <right){
            int cur = sticks[left] + sticks[right];
            if(cur <= largestlength) { //if too small
                left++; //increase smallest stick
            } else {
                total += right - left;
                right --; //decrease middle stick
            }
        }
    }

    cout << total;

    return 0;
}

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

int main(void) {
	string s[3];
	for (int i = 0; i < 3; i++) {
		cin >> s[i];
	}
	if (s[0][s[0].length() - 1] == s[1][0] && s[1][s[1].length() - 1] == s[2][0]) printf("YES\n");
	else printf("NO\n");


	return 0;
}


Measured memory_bytes: 3576
import sys
s=input()
rs=s[::-1]
h=len(s)//2
s2=s[:h]
rs2=s2[::-1]
t=(len(s)+3)//2
s3=s[t-1:]
rs3=s3[::-1]
if s==rs and s2==rs2 and s3==rs3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 1000005;

int f[MAX_N];
int sm[MAX_N];

ll add(ll x,ll y)
{
    return (x + y)%MOD;
}

ll sub(ll x,ll y)
{
    return (x+MOD-y)%MOD;
}

ll mul(ll x,ll y)
{
    return x*y%MOD;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n;
	cin >> n;
	f[0] = 0, f[1] = n;
	sm[0] = 0, sm[1] = f[1];
	srep(i,2,n+1){
		f[i] = sub(add(sub(sm[i-1],sm[max(i-n-2,0)]),add(max(n-i+2,0),mul(n-1,n-1))),f[i-2]);
		if(i == 2) f[i] = sub(f[i],1);
		sm[i] = add(sm[i-1],f[i]);
	}
	cout << f[n] << "\n";
    return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
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; }
/**************************************/
/******** User-defined Function *******/

/**************************************/
/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vector<ll> a(n), b(n), c(n);

    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];

    sort(all(a));
    sort(all(c));

    ll ans = 0;

    rep(i,n){
        ll val_b = b[i];

        ll num_a = lower_bound(a.begin(), a.end(), val_b) - a.begin();
        ll num_c = c.end() - upper_bound(c.begin(), c.end(), val_b);

        ans += ll(num_a * num_c);
    }

    cout << ans << endl;

}
/********  Main() Ends Here *************/


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

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

    int N, K;
    cin >> N >> K;

    int i = 0;
    while (N != 0){ 
        N /= K;
        i++;
    }
    
    cout << i << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, end) for (long long int i=0; i<end; i++)
#define repp(i, begin, end) for (long long int i=begin; i<end; i+)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
using vs = vector<string>;
ll sm(vll x) {ll sum=0; rep(i, x.size()) sum+=x[i]; return sum;}
void vdeb(string s, vector<int> x) {cout<<s<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<endl;}
//=======================================================================================================

int main()
{
    ll N;
    cin >> N;
    vll a(N);
    vll x(N);
    rep(i, N) {
    cin >> a[i];
    }
    ll a0 = a[0];



    rep(i, N-1) {
        a[i+1] ^= a[i];
        //cout << a[i+1] << endl;
    }

    if(a[N-1] == 0)
        cout << "Yes";
    else
        cout << "No";
    cout << endl;

    return 0;
}

Measured memory_bytes: 1792
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

class UnionFind:
    def __init__(self, N): self.N, self.group_count, self.root, self.rank = N, N, [-1] * N, [0] * N
    def __repr__(self): return str(self.all_groups())

    def find(self, x):
        while self.root[x] >= 0: x = self.root[x]
        return x

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return
        if self.rank[x] > self.rank[y]: x, y = y, x
        self.root[y] += self.root[x]
        self.root[x] = y
        if self.rank[x] == self.rank[y]: self.rank[y] += 1
        self.group_count -= 1

    def same(self, x, y): return self.find(x) == self.find(y)
    def count(self, x): return -self.root[self.find(x)]
    def members(self, x): return [i for i in range(self.N) if self.same(x, i)]
    def roots(self): return [i for i, x in enumerate(self.root) if x < 0]
    def all_groups(self):
        d = defaultdict(lambda: [])
        for i in range(self.N): d[self.find(i)].append(i)
        return dict(d)


def main():
    N, Q = LI()
    TUV = LIR(Q)

    uf = UnionFind(N)

    for t, u, v in TUV:
        if t == 0:
            uf.union(u, v)
        else:
            print(int(uf.same(u, v)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 111620
#include <bits/stdc++.h>
using namespace std;
#define Maxn 200007
int n,m;
int last[Maxn],pre[Maxn],other[Maxn],cnt=1;
bool vis[Maxn];
int d[Maxn];
int num,s,t;
void insert(int u,int v)
{
    other[++cnt]=v,pre[cnt]=last[u],last[u]=cnt;
}
void dfs(int u)
{
    if (u==t)
    {
        ++num;
        return;
    }
    for (int q=last[u];q;q=pre[q])
    {
        int v=other[q];
        if (!vis[q])
        {
            vis[q]=true;
            vis[q^1]=true;
            dfs(v);
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        ++d[u],++d[v];
        insert(u,v),insert(v,u);
    }
    for (int i=1;i<=n;i++)
        if (d[i]%2!=0)
        {
            printf("No\n");
            return 0;
        }
    int mx=0;
    for (int i=1;i<=n;i++)
        mx=max(mx,d[i]);
    if (mx>=6) printf("Yes\n");
    else if (mx==2) printf("No\n");
    else
    {
        int cnt=0;
        for (int i=1;i<=n;i++)
            if (d[i]==4) ++cnt;
        if (cnt>=3) printf("Yes\n");
        else if (cnt==1) printf("No\n");
        else
        {
            num=0;
            s=0;
            t=0;
            for (int i=1;i<=n;i++)
                if (d[i]==4)
                {
                    if (s==0) s=i; else t=i;
                }
            dfs(s);
            if (num==2) printf("Yes\n"); else printf("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 8468