akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	int a, b, n;
	cin >> a >> b >> n;
	int moda = a % b;
	if(b > n) {
		cout << (a * n) / b << endl;
	} else {
		cout << (a * (b - 1)) / b << endl;
	}
	return 0;
}

Measured memory_bytes: 3648
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int h[210000], DP[210000] = {};

int main(){
	
	long long int N, C;
	cin >> N >> C;
	
	for(int i = 0; i < N; i++){
		cin >> h[i];
	}
	
	priority_queue<P, vector<P>, greater<P> > pque;
	
	pque.push(P(INF, INF));
	
	int pos = 0;
	
	for(int i = 1; i < N; i++){
		//cout << i << endl;
		while(true){
			P p = pque.top();
			//cout << p.first << " " << p.second << endl;
			long long int id = p.second;
			if(id == INF){
				break;
			}
			long long int hmin = (DP[id] + h[id] * h[id]- DP[pos] - h[pos] * h[pos]) / 2 / (h[id] - h[pos]);
			if((DP[id] + h[id] * h[id]- DP[pos] - h[pos] * h[pos]) % (2 * (h[id] - h[pos]))){
				hmin += 1;
			}
			if(p.first != hmin){
				pque.pop();
				p.first = hmin;
				pque.push(p);
				continue;
			}
			if(p.first > h[i]){
				break;
			}
			if(p.second < pos){
				pque.pop();
			}else{
				pos = p.second;
				pque.pop();
			}
		}
		DP[i] = DP[pos] + C + (h[i] - h[pos]) * (h[i] - h[pos]);
		long long int nex = (DP[i] + h[i] * h[i]- DP[pos] - h[pos] * h[pos]) / 2 / (h[i] - h[pos]);
		if((DP[i] + h[i] * h[i]- DP[pos] - h[pos] * h[pos]) % (2 * (h[i] - h[pos]))){
			nex += 1;
		}
		pque.push(P(nex, i));
		//cout << DP[i] << endl << endl;
	}
	
	cout << DP[N - 1] << endl;
	
	return 0;
}


Measured memory_bytes: 8432
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

signed main(){
	ll n;
	cin >> n;
	cout << n*n << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair 
#define INF 1000000000
#define MOD 1000000007 
#define MAXN 2010
using namespace std;

bitset<MAXN*MAXN> B;
int n,s;



int main()
{
	B[0]=1;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x;
		scanf("%d",&x);
		B|=(B<<x);
		s+=x;	
	}	
	
	for(int i=(s+1)/2;i<=s;i++)if(B[i])
	{
		cout<<i<<endl;
		return 0;
	}
	

	return 0;	
} 

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int k, q;
  cin >> k >> q;
  vector<int64> ds(k);
  for (int i = 0; i < k; i++) {
    cin >> ds[i];
  }
  for (int q_index = 0; q_index < q; q_index++) {
    int64 n, x, mod;
    cin >> n >> x >> mod;
    
    x %= mod;
    vector<int> es(k);
    for (int i = 0; i < k; i++) {
      es[i] = ds[i] % mod;
    }

    int64 l = (n - 1) / k;
    int64 r = (n - 1) % k;
    int64 zero_count = 0;
    int64 sum = 0;
    for (int i = 0; i < k; i++) {
      if (i < r) {
        // l + 1
        sum += es[i] * (l + 1);
        if (es[i] == 0) zero_count += l + 1;
      } else {
        // l
        sum += es[i] * l;
        if (es[i] == 0) zero_count += l;
      }
    }

    int64 decrease_count = ((x + sum) - (x + sum) % mod) / mod;
    if (DEBUG) cout << "zero_count: " << zero_count << endl;
    if (DEBUG) cout << "decrease_count: " << decrease_count << endl;
    int64 ans = (n - 1) - zero_count - decrease_count;
    cout << ans << endl;
  }
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int n, m;
    bool s1 = false;
    int ans = -1;
    cin >> n >> m;
    vector<int> s(m);
    vector<int> c(m);
    for (int i = 0; i < m; i++) {
        cin >> s.at(i) >> c.at(i);
    }
    for (int i = 0; i < m; i++) {
        for (int j = i + 1; j < m; j++) {
            if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
                ans = -1;
                cout << ans << endl;
                return 0;
            }
        }
        if (n != 1 && s.at(i) == 1 && c.at(i) == 0) {
            cout << ans << endl;
            return 0;
        }
    }
    ans = 0;
    for (int i = 0; i < m; i++) {
        if (s.at(i) == 1) {
            if (n == 1) {
                ans += c.at(i);
            }
            else if (n == 2) {
                ans += 10 * c.at(i);
            }
            else {
                ans += 100 * c.at(i);
            }
            s1 = true;
            goto second;
        }
    }
    second:
    for (int i = 0; i < m; i++) {
        if (s.at(i) == 2) {
            if (n == 2) {
                ans += 1 * c.at(i);
            }
            else if (n == 3) {
                ans += 10 * c.at(i);
            }
            goto third;
        }
    }
    third:
    for (int i = 0; i < m; i++) {
        if (s.at(i) == 3) {
            if (n == 3) {
                ans += 1 * c.at(i);
                goto last;
            }
        }
    }
    last:
    if (!s1) {
        if (n == 3) {
            ans += 100;
        }
        if (n == 2) {
            ans += 10;
        }
        if (n == 1) {
            ans += 0;
        }
    }
    cout << ans << endl;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  int d, t, s; scanf("%d%d%d", &d, &t, &s);
  if (s*t < d) puts("No");
  else puts("Yes");
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3720
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer


object Main {

  // u: from
  // v: to
  case class Edge(u: Int, v: Int, w: Long)

  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    // ここ、0オリジン化した方がいい
    val edges = IndexedSeq.fill(n-1)(Edge(sc.nextInt(), sc.nextInt(), sc.nextInt()))
    (n, edges)
  }

  def solve(n:Int, edges:IndexedSeq[Edge]): IndexedSeq[Int] = {
    val nextList = IndexedSeq.fill(n+1)(ArrayBuffer.empty[Edge])
    for(edge <- edges){
      val from = edge.u
      val to = edge.v
      nextList(from).append(edge)
      nextList(to).append(Edge(to, from, edge.w))
    }
    val visited = Array.fill(n+1)(false)
    // 1から
    visited(1) = true
    val open: java.util.Queue[Int] = new java.util.ArrayDeque[Int]()
    //add, remove
    open.add(1)
    //白:false ,黒:true
    val colors = Array.fill(n+1)(true)
    colors(1) = false


    while(!open.isEmpty){
      val current = open.remove()
      for(edge <- nextList(current)){
        val next = edge.v
        if(!visited(next)) {
          val w = edge.w
          if (w % 2 == 0) {
            colors(next) = colors(current)
          } else {
            colors(next) = !colors(current)
          }
          visited(next) = true
          open.add(next)
        }
      }
    }
    colors.takeRight(n).map(p => if(p) 1 else 0)
  }

  def output1(result: IndexedSeq[Int]) = {
    result.foreach(println)
  }

  def output2(result: IndexedSeq[Int]) = {
    result.foreach(System.out.println)
  }

  def output3(result: IndexedSeq[Int]) = {
    val out = new java.io.PrintWriter(System.out)
    result.foreach(out.println)
    out.flush()
  }

  def main(args: Array[String]): Unit = {
    val (n, edges) = read()
    output3(solve(n,edges))
  }
}

Measured memory_bytes: 119612
A, B = list(map(int, input().split()))

def xorsum(m):
  if m==3:
    return 0
  if m==2:
    return 3
  if m==1:
    return 1
  if m==0:
    return 0
  if m==-1:
    return 0
  h=1
  while h<=m:
    h=h*2
  h=h//2
  return xorsum(m-h)^(((m-h+1)%2)*h)

print(xorsum(B)^xorsum(A-1))

  
  

  
  

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <cmath>
#include <assert.h>
#define rep(i,a,b) for(int (i)=(a);i<(b);i++)
#define INF 100000000
#define MAX_N 150005
#define EPS 0.000000001
using namespace std;

int main(){
    int n;
    int a[10005];
    pair<int ,int>pai[10005];
    cin>>n;
    cout<<"? 1 2"<<endl;
    a[1]=0;
    cin>>a[2];
    for(int i=3;i<=n;i++){
        cout<<"? 1 "<<i<<endl;
        int b,c;
        cin>>b;
        cout<<"? 2 "<<i<<endl;
        cin>>c;
        if(b+c==a[2])a[i]=b;
        else if(b<c)a[i]=-b;
        else a[i]=c+a[2];
    }
    for(int i=1;i<=n;i++){
        pai[i].first=a[i];
        pai[i].second=i;
    }
    sort(pai+1,pai+n+1);
    
    cout<<"!";
    
    for(int i=1;i<=n;i++){
        cout<<" "<<pai[i].second;
    }
    cout<<endl;
    
    return 0;
}

Measured memory_bytes: 3628
s = gets.strip
q = gets.to_i

pre = []
suf = []

reversed = false

q.times do |i|
  t, f, char = gets.split
  if t == '1'
    reversed = !reversed
  elsif t == '2'
    if f == '1'
      if reversed
        suf.push char
      else
        pre.unshift char
      end
    elsif f == '2'
      if reversed
        pre.unshift char
      else
        suf.push char
      end
    end
  end
end

s = pre.join + s + suf.join

if reversed
  puts s.reverse!
else
  puts s
end



Measured memory_bytes: 17276
#include <stdio.h>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>


using namespace std;

#define MAX_L (20010)
int main()
{
    stack<int> S1;
    stack< pair<int, int> > S2;
    char s[MAX_L];
    int size = 0;
    vector<int> ans;
    int total = 0;
    scanf("%s", s);
    
    while( s[size] != '0' ) {
	size++;
    }

    for ( int i = 0; i < size; i++ ) {
	if ( s[i] == '\\' ) {
	    S1.push( i );
	}
	else if ( s[i] == '/' && !S1.empty() ) {
	    int j = S1.top(); S1.pop();
	    int add_area = ( i - j );
	    total += ( i - j );
	    while( !S2.empty() && S2.top().first > j ) {
		add_area += S2.top().second;
		S2.pop();
	    }
	    S2.push( make_pair( j, add_area ) );
	}
    }
    
    while ( !S2.empty() ) {
	ans.push_back( S2.top().second );
	S2.pop();
    }

    reverse( ans.begin(), ans.end() );

    printf("%d\n", total);
    printf("%d", (int)ans.size());

    for ( int i = 0; i < ans.size(); i++ ) {
	printf(" %d", ans[i]);
    }

    printf("\n");

    return 0;
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

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

int main() {
    int N;
    cin >> N;
    int x[109], y[109], h[109];
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }

    int Cx, Cy, H;
    for (int Cx = 0; Cx <= 100; Cx++) {
        for (int Cy = 0; Cy <= 100; Cy++) {
            for (int i = 0; i < N; i++) {
                if (h[i] > 0) {
                    H = abs(Cx - x[i]) + abs(Cy - y[i]) + h[i];
                    break;
                }
            }

            int flag = 1;
            for (int i = 0; i < N; i++) {
                if (max(H - abs(Cx - x[i]) - abs(Cy - y[i]), 0) != h[i]) {
                    flag = 0;
                    break;
                }
            }
            if (flag == 1) {
                cout << Cx << " " << Cy << " " << H << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int max = 0;
		for (int i = 0; i < n; i++) {
			int h = sc.nextInt();
			if (max <= h) {
				max = h;
				count++;
			}
		}
		System.out.println(count);
	}
}


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

const ll N = 3001;
ll dp[N][N][4];
int arr[N][N];
int n , m ,k;
const ll negInf = -1e15;
ll rec(int row,int col,int rowprev){
		if(row==n&&col==m){
			if(rowprev<3) return arr[row][col];
			else return 0;
		}
		if(row>n||col>m){
			return negInf;
		}
		if(dp[row][col][rowprev]!=-1)
			return dp[row][col][rowprev];
		ll ans =  0;
		if(rowprev<3){
			ans = max(ans , arr[row][col] + rec(row,col+1,rowprev+1));
			ans = max(ans , arr[row][col] + rec(row+1,col,0));
		}
		ans = max(ans , rec(row,col+1,rowprev));
		ans = max(ans , rec(row+1,col,0));
		return dp[row][col][rowprev] = ans;
}


int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> k;
	while(k--){
		int i , j , v;
		cin >> i >> j >> v;
		arr[i][j] = v;
	}
	for(int i = 0 ;i <= n ; i ++){
		for(int j = 0 ; j <= m ; j ++)
			for(int k = 0 ;k <=3; k ++)
				dp[i][j][k] = -1;
	}
	cout << rec(1,1,0) << "\n";
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int m=1;
  int i =0;
  while(n/m>0) {
    m *= k;
    i++;
  }
  cout << i << endl;
}

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

int main(){
	char S[5];

	cin >> S;
	char first = S[0];
	char second = '\0';
	int f = 1, s = 0;
	
	for(int i = 1; i < 4; i++){
		if(S[i] == first) {
			f++;
		} else if (S[i] == second || second == '\0'){
			if(second == '\0'){
				second = S[i];
			}
			s++;
		}
	}
	if(f == 2 && s == 2){
		cout << "Yes";
	} else {
		cout << "No";
	}
	
	return 0;
}

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

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

    char S[N];
    scanf("%s", S);

    int ans = 0;
    int counter = 0;
    char X[N], Y[N];
    memset(X, 0, sizeof(X));
    memset(Y, 0, sizeof(Y));

    for (int i = 0; i < N; i++)
    {
        counter = 0;
        for (int j = 0; j <= i; j++)
        {
            X[j] = S[j];
        }
        for (int k = i; k < N; k++)
        {
            Y[k - i] = S[k + 1];
        }
        
        for (int L = 0; L < N; L++)
        {
            for (int M = L + 1; M < N; M++)
            {
                if (X[L] == X[M])
                {
                    X[M] = '\0';
                }
                if (Y[L] == Y[M])
                {
                    Y[M] = '\0';
                }
            }
        }

        for (int L = 0; L < N; L++)
        {
            for (int M = 0; M < N; M++)
            {
                if (X[L] == '\0' || Y[M] == '\0')
                {
                }
                else if (X[L] == Y[M])
                {
                    counter += 1;
                }
            }
        }

        if (counter > ans)
        {
            ans = counter;
        }
    }
    printf("%d", ans);
    return 0;
}

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

int N;
int main(){
  while( cin >> N && N ) {
    vector<int> A(N);
    vector<int> B(N);
    for(int i=0;i<N;i++)
      cin >> A[i];
    for(int i=0;i<N;i++) 
      cin >> B[i];
    sort( A.rbegin(), A.rend() );
    sort( B.rbegin(), B.rend() );
    
    int win = 0;
    int res = -1;
    priority_queue<int> q;    
    for(int k=0;k<N-1;k++){
      q.push( B[k] );
      if( A[k] <= q.top() ) 
	q.pop();
      else
	win++;
      if( (k+1)/2 < win ) {
	res = k+1; break;
      }
    }
    if( res == -1 ) cout << "NA" << endl;
    else cout << res << endl;
  }

}

Measured memory_bytes: 3348
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Pipes;

namespace cswork
{
    class Program
    {
        public Program() { }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        void Omame()
        {
            cin = new Scanner();
            int n = cin.nextInt();
            long y = cin.nextLong();

            int ans = 0;
            for (int i = 0; i <= n; i++)
            {
                for (int j = 0; j <= n - i; j++)
                {
                    int l = n - i - j;
                    if (10000 * i + 5000 * j + 1000 * l == y)
                    {
                        Console.WriteLine(i + " " + j + " " + l);
                        return;
                    }
                }
            }

            Console.WriteLine("-1 -1 -1");
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

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

using namespace std;

vector<int> vc;

int main()
{
	int a;
	vc.resize(3);
	for (int i = 0; i < 3; i++)scanf("%d", &vc[i]);
	sort(vc.begin(), vc.end());
	printf("%d", vc[2] * 10 + vc[1] + vc[0]);
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・a,b,a+b,a,b,a+b,...
・0,a,a,0,a,a,...
・0,0,0,0,0,0,...
"""

N,*A = map(int,read().split())

def solve(N,A):
    if all(x == 0 for x in A):
        return True
    q,r = divmod(N,3)
    if r:
        return False
    from collections import Counter
    counter = Counter(A)
    n = len(counter)
    if n == 1:
        return False
    if n == 2:
        a,b = counter.keys()
        if a > b:
            a,b = b,a
        if a != 0:
            return False
        # 0,b
        if counter[0] != N//3:
            return False
        return True
    if n == 3:
        a,b,c = counter.keys()
        for x in [a,b,c]:
            if counter[x] != q:
                return False
        return a^b^c == 0

answer = 'Yes' if solve(N,A) else 'No'
print(answer)

Measured memory_bytes: 12980
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int n,m,q;
vi a,b,c,d;

int f(int i,vi &x,int s){
    int res=0;
    if(i==n){
        rep(j,q){
            res+=x[b[j]]-x[a[j]]==c[j]?d[j]:0;
        }
        return res;
    }
    REP(j,s,m){
        x[i]=j;
        res=max(res,f(i+1,x,j));
    }
    return res;
}

void run(){
    cin>>n>>m>>q;
    a=b=c=d=vi(q);
    rep(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--,b[i]--;
    }
    vi x(n);
    cout<<f(0,x,1)<<endl;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        //ABC125 D
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        long[] a = new long[n];
        
        int count = 0;
        
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
            
            if(a[i] < 0){
                count++;
            }
        }
        
        long res = Arrays.stream(a).map(Math::abs).sum();
        
        if(count % 2 != 0){
            long min = Arrays.stream(a).map(Math::abs).min().getAsLong();
            
            res-=min*2;
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 51912
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a;
	cin >> b;
	//cin >> c;
	//cin >> d;
	(a + b) %2 == 0 ? cout << (a + b) / 2 << endl : cout << (a + b) / 2 + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int gcd(int a, int b){
    int tmp;
    if (a < b){
        tmp = b % a;
        if (tmp == 0) return a;
        else return gcd(a, tmp);
    }else{
        tmp = a % b;
        if (tmp == 0) return b;
        else return gcd(b, tmp);
    }
}
 
int main(void){
    int a, b;
    cin >> a >> b;
    cout << gcd(a,b) << endl;
    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
typedef long long ll;
inline ll read() {ll x = 0;char ch = getchar(), w = 1;while(ch < '0' || ch > '9') {
if(ch == '-') w = -1;ch = getchar();}while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0';
ch = getchar();}return x * w;}
void write(ll x) {if(x < 0) putchar('-'), x = -x;if(x > 9) write(x / 10);putchar(x % 10 + '0');}
inline void writeln(ll x) {write(x);puts("");}
void setIO() {
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
using namespace std;
const int N = 9999;
int a[N], n;
priority_queue<double,vector<double>,greater<double> >q;
int main() {
	n = read();
	for(int i = 1; i <= n; ++i) a[i] = read(), q.push(a[i]);
	while(q.size() > 1) {
		double x = q.top(); q.pop();
		double y = q.top(); q.pop();
		q.push((x + y) / 2);
	}
	printf("%.10lf\n", q.top());
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
ABs = [list(map(int, input().split())) for i in range(n)]
ABs.sort()

at_n_hon = m
money = 0
for AB in ABs:
    kau_hon = AB[1] if AB[1] <= at_n_hon else at_n_hon
    at_n_hon -= kau_hon
    money += kau_hon *AB[0]
    if at_n_hon == 0:
        break

print(money)

Measured memory_bytes: 27880
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    ll x1 = accumulate(all(a), 0LL);
    for(int i = 1; i < n; i+=2){
        x1 -= 2 * a[i];
    }
    cout << x1 << " ";
    ll bf = x1;
    for(int i = 0; i < n-1; i++){
        cout << 2 * a[i] - bf << " ";
        bf = 2 * a[i] - bf;
    }
    cout << endl;
}


Measured memory_bytes: 2048
#include<stdio.h>

int main()
{
    char s[100];
    int N;
    scanf("%d",&N);
    scanf("%s",s);

    int alpha[1000];
    int i,j,k,count=0,count_max=0;;

    for(i=1;i<N;i++){
        count=0;
        for(j=0;j<1000;j++){
        alpha[j]=0;
        }
        for(j=i;j<N;j++){
            for(k=0;k<i;k++){
                if(s[j]==s[k] && alpha[s[j]]==0){
                    count++;
                    alpha[s[j]] = 1;
                }
            }
        }
        if(count>=count_max){
            count_max=count;
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        int n=sc.nextInt();
  		int ans=0;
  		int min=0;
  		int max=101;
  		int g=0;
  if(n==0){
  ans=x;
  }else{
  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		 a[c]=sc.nextInt();
    	}
    
    Arrays.sort(a);
    for(int b=x;b<100;b++){
      g=0;
    for(int d=0;d<n;d++){
    	if(a[d]==b){ 
          g=1;
          break;
        }
    }
     if(g==0){
       max=b;
       break;
      }
    }
    for(int b=x-1;b>0;b--){
      g=0;
    for(int d=0;d<n;d++){
    	if(a[d]==b){ 
          g=1;
          break;
        }
    }
     if(g==0){
       min=b;
       break;
      }
    }
    if((max-x)>=(x-min)){
    ans=min;
      
    }else{
    ans=max;
    }
  
  }
    

    	System.out.println(ans);
    }
}

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

int main(){
    string a,b;
    cin>>a>>b;
    if(a.size()>b.size()){
        cout<<"GREATER"<<endl;
    }
    else if(a.size()<b.size()){
        cout<<"LESS"<<endl;
    }
    else if(a>b){
        cout<<"GREATER"<<endl;
    }
    else if(a<b){
        cout<<"LESS"<<endl;
    }
    else{
        cout<<"EQUAL"<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,ans;
int s;
int main()
{
    cin>>n; 
    for(int i=sqrt(n);i>0;--i) 
        if(n%i==0)
		{
            ans=n/i;
            break;
        }
    while(ans>0)
        s++,ans/=10;
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mm(a,x) memset(a,x,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
int a[105];
int main(void)
{
    sync;
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
        cin>>a[i];
    int res=0;
    for(int i=0;i<n;++i)
        for(int j=i+1;j<n;++j)
            for(int k=j+1;k<n;++k)
            {
                if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
                {
                    if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i])
                        ++res;
                }
            }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3184
a,b,m=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
minimum=100000000000000
for i in range(m):
  x,y,z=map(int,input().split())
  minimum=min(minimum,alist[x-1]+blist[y-1]-z)
alist.sort()
blist.sort()
minimum=min(minimum,alist[0]+blist[0])
print(minimum)

Measured memory_bytes: 68460
n = int(input())
p = list(map(int, input().split()))
cnt = 0

for i in range(n-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        cnt += 1
if p[n-1] == n:
    p[n-2], p[n-1] = p[n-1], p[n-2]
    cnt += 1

print(cnt)


Measured memory_bytes: 14004
l = int(input())

r = 1
power = 2
while power * 2 <= l:
    power *= 2
    r += 1

n = r + 1
m = 0
adj = [[] for _ in range(n + 1)]

power = 1
for i in range(1, n):
    adj[i].append([i+1, power])
    adj[i].append([i+1, 0])
    power *= 2
    m += 2

power = 2 ** (n - 1)
base = pow(2, r)
for t in range(n - 1, 0, -1):
    power //= 2
    if l - power >= base:
        adj[t].append([n, l - power])
        l -= power
        m += 1

print(n, m)
for i, edges in enumerate(adj[1:], 1):
    for j, w in edges:
        print(i, j, w)


Measured memory_bytes: 3064
#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
struct st{
    int n;
    int index;
}a[100010];
bool cmp(st a,st b)
{
    return a.n < b.n;
}
int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i].n;
        a[i].index = i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++)
    {
        cout << a[i].index << " ";
    }
    return 0;
}

Measured memory_bytes: 4300
def Main(N, K, H):
    H.sort()
    if N <= K:
        return 0
    else:
        return sum(H[:N-K])

def main():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    print(Main(N, K, H))

if __name__ == '__main__':
    main()

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

int N;
vector<int> A(25);
vector<int> B(25);
vector<int> C(25);

int main(){

    cin >> N;
    for (int i=1; i<=N; i++){
        cin >> A.at(i);
    }
    for (int i=1; i<=N; i++){
        cin >> B.at(i);
    }
    for (int i=1; i<=N-1; i++){
        cin >> C.at(i);
    }

    int satis = 0;
    int mem = 0;
    for (int i=1; i<=N; i++){
        satis += B.at(A.at(i));
        if (mem + 1 == A.at(i)){
            satis += C.at(mem); 
        }
        mem = A.at(i);
    }

    cout << satis << endl;
    return 0;
}

Measured memory_bytes: 256
def Z_algo(S):
    n = len(S)
    LCP = [0]*n
    i = 1
    j = 0
    c = 0#最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        #i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i+LCP[i-c] < c+LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and S[j] == S[i+j]: j+=1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP

def resolve():
    N = int(input())
    S = input()

    ans = 0
    for i in range(N):
        LCP = Z_algo(S[i:])
        for j, l in enumerate(LCP):
            tmp = min(l, j)
            ans = max(ans, tmp)
    print(ans)


if __name__ == "__main__":
    resolve()


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

using namespace std;

int main() {
    int N;
    cin >> N;
    if (N == 1) {
        cout << "Hello World\n";
        return 0;
    }
    int A, B;
    cin >> A >> B;
    cout << A + B << "\n";
    return 0;
}

Measured memory_bytes: 256
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 2e5+5 ;

int n ,k ,x ,cnt[N] ;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i){
        scanf("%d",&x);
        ++cnt[x] ;
    }
    vector<int> v ;
    for(int i=1;i<=n;++i)if(cnt[i]) v.push_back(cnt[i]);
    sort(v.begin(),v.end());
    int ans = 0 ;
    for(int i=0;i<v.size();++i){
        if(v.size()-i<=k) break;
        ans += v[i] ;
    }
    cout << ans ;
    return 0;
}


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

namespace solver{
  void solve(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);

    std::string N; std::cin >> N;

    int s = 0;
    for(auto c : N){
      (s += (int)(c - '0')) %= 9;
    }

    std::cout << (s == 0 ? "Yes" : "No") << "\n";
  }
}

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


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

using namespace std;

const char ord[][10] = {
    "pre-meiji",
    "meiji",
    "taisho",
    "showa",
    "heisei"
};

int main() {
    int y, m, d;
    while (scanf("%d %d %d", &y, &m, &d) != EOF) {
        int ans, ny;
        if (y >= 1989) {
            ans = 4;
            if (y == 1989 && m == 1 && d < 8) ans = 3;
        } else if (y >= 1926) {
            ans = 3;
            if (y == 1926 && ((m < 12) || (m == 12 && d < 25))) ans = 2;
        } else if (y >= 1912) {
            ans = 2;
            if (y == 1912 && ((m < 7) || (m == 7 && d < 30))) ans = 1;
        } else if (y >= 1868) {
            ans = 1;
            if (y == 1868 && ((m < 9) || (m == 9 && d < 8))) ans = 0;
        }

        switch (ans) {
            case 1: y -= 1868; break;
            case 2: y -= 1912; break;
            case 3: y -= 1926; break;
            case 4: y -= 1989; break;
        }

        if (ans) printf("%s %d %d %d\n", ord[ans], ++y, m, d);
        else printf("%s\n", ord[ans]);
    }

    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
 
int n, i, sum;  
int main() {

  cin >> n ;

  for ( i = n ; i > 0;) {
    sum = sum + i%10;
    i = i/10;
  }
  
  if (n%sum == 0) {
    cout << "Yes" << endl;  
  }else {
    cout << "No" << endl;
  }  
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  map<ll,ll>mp;
  rep(i,0,n){
    res+=mp[a[i]-i];
    mp[-a[i]-i]++;
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 27436
import bisect
def factorization(n):
  m = {}
  _n = n
  for i in range(2, int(n ** (1/2)) + 1):
    if _n % i == 0:
      cnt = 0
      while _n % i == 0:
        _n //= i
        cnt += 1
      m[i] = cnt
  if _n != 1:
    m[_n] = 1
  return m

n = int(input())
m = factorization(n)

ans = 0
for _m in m:
  p = m[_m]
  _tri = 0
  _cnt = 0
  while p >= _tri:
    _cnt += 1
    _tri += _cnt
  ans += _cnt - 1

print(ans)

Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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


  ll h,w,n;
  cin >> h >> w >> n;

  ll a[n],b[n];
  set<pair<int,int>> se;
  rep(i,n){
    cin >> a[i] >> b[i];
    --a[i];--b[i];
    se.insert(mp(a[i],b[i]));
  }

  
  vector<int> ans(10,0);
  
  rep(i,n){
    for(int dx=-2;dx<=0;dx++){
      for(int dy=-2;dy<=0;dy++){
	int na=a[i]+dx;
	int nb=b[i]+dy;
	if(na>=0 && nb>=0 && na+2<h && nb+2<w){
	  int c=0;
	  rep(mx,3) rep(my,3){
	    if(se.count(mp(na+mx,nb+my))) c++;
	  }
	  ans[c]++;
	}	
      }
    }
  }
  ll z=(h-2)*(w-2);
  rep1(i,9) z-=ans[i]/i;
  rep(i,10){
    if(i!=0) cout << ans[i]/i << endl;
    else cout << z << endl;
  }
  
  
  //  cout << endl << endl;
  //  cout << static_cast<double>(clock()) / CLOCKS_PER_SEC << "s"<<endl;
  return 0;


}


Measured memory_bytes: 6528
# coding: utf-8
# Your code here!
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N,M = LI()
    loadArray = [LI() for _ in range(M)]

    ans = 0

    class UnionFind():
        #クラスコンストラクタ
        #selfはインスタンス自身
        def __init__(self, n):
            #親ノードを-1に初期化する
            self.parents = [-1] * n

        #根を探す（再帰関数）
        def find(self, x):
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        #xとyの木を併合する
        def union(self, x, y):
            #x,yの根をX,Yとする
            X = self.find(x)
            Y = self.find(y) 

            #根が同じなら結合済み
            if X == Y:
                return
            #ノード数が多い方をXとする
            if self.parents[X] > self.parents[Y]:
                X, Y = Y, X

            #XにYのノード数を足す
            self.parents[X] += self.parents[Y]
            #Yの根を X>0 とする
            self.parents[Y] = X

    uf = UnionFind(N)
    for a, b in loadArray:
        #インデックスを調整し、a,bの木を結合
        a -= 1; b -= 1
        uf.union(a, b)

    for u in uf.parents:
        if u<0:
            ans += 1

    

    print(ans-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 29940
#include <iostream>
using namespace std;
int main(void){
    int val[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int i;
    
    std::cin >> i;
    std::cout << val[i-1] << endl;
    
    return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val count =
      Iterator.continually(io.StdIn.readInt())
        .take(n)
        .count(isPrime)
    println(count)
  }

  def isPrime(n: Int): Boolean = {
    val rt = Math.sqrt(n).toInt

    @annotation.tailrec
    def isPrime(i: Int): Boolean = {
      if (i <= rt)
        if (n % i ==0) false
        else isPrime(i + 2)
      else
        true
    }

    if (n == 2)
      true
    else if (n < 1 || n % 2 == 0)
      false
    else
      isPrime(3)
  }
}

Measured memory_bytes: 49892
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int Q;
  cin >> Q;
  vector<int> l(Q), r(Q);
  REP(i, Q)
  cin >> l[i] >> r[i];
  vector<bool> is_prime(100001);
  REP(i, 100001)
  is_prime[i] = true;
  is_prime[0] = false, is_prime[1] = false;
  for (int i = 2; i * i <= 100000; i++)
  {
    if (is_prime[i])
    {
      for (int j = 2; i * j <= 100000; j++)
        is_prime[i * j] = false;
    }
  }
  vector<bool> is_like_prime(100001);
  REP(i, 100001)
  is_like_prime[i] = false;
  for (int i = 3; i <= 100000; i += 2)
  {
    if (is_prime[i] && is_prime[(i + 1) / 2])
      is_like_prime[i] = true;
  }
  vector<int> num(100001);
  num[0] = 0;
  REP(i, 100000)
  {
    num[i + 1] = num[i];
    if (is_like_prime[i + 1])
      num[i + 1]++;
  }
  REP(i, Q)
  cout << num[r[i]] - num[l[i] - 1] << endl;
  return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    

    class ClassMain {

        public static char[,] soroban = new char[8, 10]{
        //0   1   2   3   4   5   6   7   8   9  
        {'*','*','*','*','*',' ',' ',' ',' ',' '},
        {' ',' ',' ',' ',' ','*','*','*','*','*'},
        {'=','=','=','=','=','=','=','=','=','='},
        {' ','*','*','*','*',' ','*','*','*','*'},
        {'*',' ','*','*','*','*',' ','*','*','*'},
        {'*','*',' ','*','*','*','*',' ','*','*'},
        {'*','*','*',' ','*','*','*','*',' ','*'},
        {'*','*','*','*',' ','*','*','*','*',' '}
        };


        public static void printSoroban(int n) {
            int n0 = n / 10000;
            int n1 = n / 1000; n1 %= 10;
            int n2 = n / 100; n2 %= 10;
            int n3 = n / 10; n3 %= 10;
            int n4 = n % 10;
            for (int i = 0; i < 8; i++) {
                Console.WriteLine(soroban[i, n0]+"" + soroban[i, n1]+
                    soroban[i, n2] + soroban[i, n3]+
                    soroban[i, n4]);
            }


        }

        public static void Main(String[] args) {
            string line; bool first = true;
            while ((line = Console.ReadLine()) != null) {
                if (first == false) { Console.WriteLine(); }
                first = false;
                int n = int.Parse(line);
                printSoroban(n);

                
            }
        }


       

    }

    
}

Measured memory_bytes: 5508
h,w = gets.chomp.split(" ").map(&:to_i)
s = Array.new(h){Array.new}
h.times do |i|
  s[i] = gets.chomp
end
dp = Array.new(h){Array.new(w,0)}
dp[0][0] = 1 if s[0][0] == "#"
(w-1).times do |i|
  dp[0][i+1] = dp[0][i]
  dp[0][i+1] += 1 if s[0][i] == "." && s[0][i+1] == "#"
end
(h-1).times do |i|
  dp[i+1][0] = dp[i][0]
  dp[i+1][0] += 1 if s[i][0] == "." && s[i+1][0] == "#"
  (w-1).times do |j|
    a = dp[i+1][j]
    a += 1 if s[i+1][j] == "." && s[i+1][j+1] == "#"
    b = dp[i][j+1]
    b += 1 if s[i][j+1] == "." && s[i+1][j+1] == "#"
    dp[i+1][j+1] = [a,b].min
  end
end
puts dp[h-1][w-1]

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

#define CO const
#define IN inline
typedef long long int64;

template<class T> IN T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> IN T read(T&x){
	return x=read<T>();
}

CO int mod=1e9+7;
IN int add(int a,int b){
	return (a+=b)>=mod?a-mod:a;
}
IN int mul(int a,int b){
	return (int64)a*b%mod;
}
IN int fpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=mul(a,a))
		if(b&1) ans=mul(ans,a);
	return ans;
}

CO int N=51,O=50;
int fac[N],ifac[N];
int F[N][2*N];

int main(){
	int n=read<int>();
	fac[0]=1;
	for(int i=1;i<=n;++i) fac[i]=mul(fac[i-1],i);
	ifac[n]=fpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i) ifac[i]=mul(ifac[i+1],i+1);
	F[0][O+1]=1;
	for(int i=0;i<=n-1;++i){
		if(i==0){
			int x=1,y=0;
			for(int d=-y;d<=x;++d)
				F[i+x+y][O+d]=add(F[i+x+y][O+d],mul(F[i][O+x-y],mul(ifac[x-d],ifac[y+d])));
			continue;
		}
		for(int x=0;x<=n-i;++x)for(int y=0;y<=n-i-x;++y)if(x+y>0)
			for(int d=-y;d<=x;++d)
				F[i+x+y][O+d]=add(F[i+x+y][O+d],mul(F[i][O+x-y],mul(ifac[x-d],ifac[y+d])));
	}
	int ans=mul(fac[n],F[n][O]);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=(1<<30)-1;
const LL OO=1e18;

const int N=2e5+100;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

int mi[N*4];
#define lc i<<1
#define rc lc|1
inline void push(int i,int l,int r,int L,int R,int t) {
	if (L<=l&&r<=R) mi[i]=min(mi[i],t);
	else {
		int mid=(l+r)/2;
		if (L<=mid) push(lc,l,mid,L,R,t);
		if (mid<R) push(rc,mid+1,r,L,R,t);
	}
}
inline int query(int i,int l,int r,int k) {
	if (l==r) return mi[i];
	int mid=(l+r)/2;
	return min(mi[i],k<=mid?query(lc,l,mid,k):query(rc,mid+1,r,k));
}

int pre[N],sum[N],f[N];
#define l first
#define r second
PR p[N];
int main()
{
	int n,m,i,cur=0,w,l,r;
	for (i=1,n=gi();i<=n;i++) sum[i]=sum[i-1]+gi();
	int ans=sum[n];
	for (i=1,m=gi();i<=m;i++) p[i].r=gi(),p[i].l=gi();
	sort(p+1,p+1+m);
	for (i=n*4;i;i--) mi[i]=oo;
	for (i=1;i<=m;i++) {
		l=p[i].r,r=p[i].l;
		while (cur<r)
			pre[cur+1]=pre[cur],cur++;
		w=(r-l+1)-(sum[r]-sum[l-1])+sum[l-1]+pre[l-1];
		w=min(w,r-sum[r]+query(1,1,n,l));
		pre[r]=min(pre[r],w-sum[r]);
		push(1,1,n,l,r,w+sum[r]-r);
		ans=min(ans,w+sum[n]-sum[r]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6912
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#include <cstdint>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18
const long MAX = 1000000;

int main(){
    long n;
    scanf("%ld", &n);
    std::vector<long> a(n);
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
    }
    std::vector<bool> cieve(MAX+1);
    std::sort(a.begin(), a.end());
    long ans = 0;
    for(long i = 0; i < n; i++){
        if(i == n-1 || a[i+1] != a[i]){
            if(!cieve[a[i]]){
                ans++;
            }
        }
        if(!cieve[a[i]]){
            for(long j = 1; a[i]*j <= MAX; j++){
                cieve[a[i]*j] = true;
            }
        }
    }
    printf("%ld\n", ans);
}


Measured memory_bytes: 4836
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;
const int Maxn = 1e5 + 5;
typedef int arr[Maxn];
//ll Add(ll x, ll y) { return (x += y) >= Mod ? x - Mod : (x < 0 ? x + Mod : x); }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
int n;
int main()
{
	rg int cnt = 0,a;
	cin >> n;
	for (int i = 1; i <= n; i++)
		{
    scanf("%d",&a);
		    if (a== cnt + 1)
			cnt++;
		}
	if (!cnt)
		puts("-1");
	else
		cout << n - cnt << '\n';
	return 0;
}

Measured memory_bytes: 256