akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <map>

using namespace std;


int main() {
	
	int N,T;
	int c,t;

	c = 0;
	t = 0;
	int m = 9999;

	cin >> N >> T;
	for (int i = 0; i < N; i++)
	{
		cin >> c >> t;

		if (T >= t)
		{
			m = std::min(m, c);
		}
	}

	if( m == 9999)
	{ 
		cout << "TLE" << endl;
		
	}
	else
	{
		cout << m << endl;
	}


	return 0;
}


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



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        Dictionary<int, int> dic = new Dictionary<int, int>();
        for (int i = 0; i < N; i++)
        {
            int a = cin.nextInt();
            if (!dic.ContainsKey(a)) dic[a] = 0;
            dic[a]++;
        }

        int ans = 0;
        foreach (var item in dic)
        {
            if (item.Key > item.Value) ans += item.Value;
            else ans += item.Value - item.Key;
        }
        Console.WriteLine(ans);
    }

    int[] uni;
    void init(int N)
    {
        uni = new int[N];
        for (int i = 0; i < N; i++)
        {
            uni[i] = -1;
        }
    }

    int root(int a)
    {
        if (uni[a] < 0) return a;
        else return uni[a] = root(uni[a]);
    }

    bool connect(int a, int b)
    {
        a = root(a);
        b = root(b);
        if (a == b) return false;
        if (uni[a] > uni[b]) swap(ref a, ref b);
        uni[a] += uni[b];
        uni[b] = a;
        return true;
    }

    void swap<T>(ref T a, ref T b)
    {
        T c = a;
        a = b;
        b = c;
    }  


}



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);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

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

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

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


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 26208
package main

import (
	"fmt"
	"os"
	"bufio"

)

func Abs(x int) int {
	if x < 0 {
		return -1 * x
	}
	return x
}
func min(x,y int) int{
	if x < y{
		return x
	}
	return y
}

func max(x,y int) int{
	if x > y{
		return x
	}
	return y
}

var output []int
func incircle(L int) {
	temp := (L * (L - 1) ) / 2
	for i := 1 ; i <= L / 2 ; i ++ {
		output[i] += min(L, temp)
		temp -= min(L, temp)
	}
}

func procir(A, L int){
	tota := []int{1}
	L -= 1
	for L >= 2 {
		tota = append(tota, 2)
		L -= 2
	}
	if L > 0 {
		tota = append(tota, L)
	}
	for i := 1 ; i <= A ; i ++ {
		for j := 0 ; j < len(tota) ; j ++ {
			output[ i + j ] += tota[j]
		}
	}
}

func bhr(A, B int){
	for i := 0 ; i < A ; i ++ {
		for j := 0 ; j < B ; j ++ {
			dis :=  i + j + 3
			output[dis] ++
		}
	}
}

func andr(A int){
	for i := 0 ; i < A ; i ++ {
		for j := i + 1 ; j < A ; j ++ {
			dis := j - i
			output[dis] ++
		}
	}
}

func main(){
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n, x, y int
	fmt.Fscanf(in, "%d %d %d\n", &n, &x, &y)
	var L int = int(y - x + 1)
	for i :=0 ; i < n ; i ++ {
		output = append(output, 0)
	}
	incircle(L)
	var A, B int
	A = x - 1
	B = n - y

	if A == 0 && B == 0 {

	}else if A != 0 && B != 0 {
		andr(A)
		andr(B)
		bhr(A, B)
		procir(A, L)
		procir(B, L)
	} else {
		A = max(A, B)
		andr(A)
		procir(A, L)
	}
	for i:= 1 ; i < n ; i ++ {
		fmt.Println(output[i])
	}
}


Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int main()
{
	long long		a,b,c,i,j,k,n,m,x,y,ans = 0;
	
	scanf("%d", &n);

	ans = n*(n-1)/2;

	printf("%lld\n",ans);


	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll a(n);
    REP(i,n){
        cin >> a[i];
    }
    sort(ALL(a));
    ll m = 0;
    REP(i,n){
        if(i==0){
            m -= a[i];
        }
        else if(i==n-1){
            m += a[i];
        }
        else{
            m += abs(a[i]);
        }
    }
    cout << m <<endl;
    ll plu = a[n-1];
    ll minu = a[0];
    REP(i,n){
        if(i==0 || i==n-1){
            continue;
        }
        else{
            if(a[i]>=0){
                cout << minu <<" " << a[i] <<endl;
                minu -= a[i];
            }
            else{
                cout << plu <<" " << a[i] <<endl;
                plu -= a[i];
            }
        }
    }
    cout << plu << " " << minu <<endl;

    
    return 0;
}



Measured memory_bytes: 3948
#include<stdio.h>
void insertionsort(int num[], int array_size){
  int i,j,k;
  for(i=1;i<array_size;i++){
    int v = num[i];
    j=i-1;
    while((j>=0)&&(num[j]>v)){
      num[j+1] = num[j];
      j--;
    }
    num[j+1]=v;
    for(k=0;k<array_size;k++){
      if(k>=1)printf(" ");
      printf("%d",num[k]);
    }
    printf("\n");
  }
}

int main(){
  int N,i;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for (i = 0; i < N;i++){
    if(i>=1) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  insertionsort(A,N);
  return 0;
}

Measured memory_bytes: 1808
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;

void ABC085C()
{
	int N;
	long long int Y;
	cin >> N >> Y;

	Y /= 1000;
	int YY = static_cast<int>(Y);
	int nA = YY / 10;
	int res1 = YY - nA * 10;
	int nB = res1 / 5;
	int nC = res1 - 5 * nB;
	int n = nA + nB + nC;
	if (n > N)
	{
		cout << "-1 -1 -1" << endl;
		return;
	}

	int nRes = N - n;
	if (nRes > 0)
	{
		int x = min(nA, nRes);
		nA -= x;
		nB += 2 * x;
		n += x;
	}
	nRes = N - n;
	if (nRes > 0)
	{
		int m = (nRes  + 3)/ 4;
		if (m > nB)
		{
			cout << "-1 -1 -1" << endl;
			return;
		}
		nB -= m;
		nC += 5 * m;
		n += 4 * m;
	}
	if (n > N)
	{
		int res = n - N;
		if (nB < res * 2)
		{
			cout << "-1 -1 -1" << endl;
			return;
		}
		nB -= res * 2;
		nA += res;
	}
	cout << nA << ' ' << nB << ' ' << nC << endl;

	// Check
//	cout << nA + nB + nC << ' ' << nA * 10 + nB * 5 + nC << endl;
}
int main()
{
	ABC085C();
	return 0;
}

Measured memory_bytes: 256
require 'prime'

def factorial(n)
	result = 1
	for i in 2..n
		result *= i
	end
	return result
end

# def factor(n)
# 	sum = 1
# 	for i in 2..n
# 		if n % i == 0
# 			sum += 1
# 		end
# 	end
# 	return sum
# end

def factor(n)
	return 1 if n == 1 
	primes = Prime.prime_division(n)
	primes.map! {|p| p[1] + 1}
	result = 1
	primes.each do |p|
		result *= p
		result %= 1.0e9 + 7
	end
	return result.to_i
end

n = gets.chomp.to_i
puts factor(factorial(n))

Measured memory_bytes: 4476
def solve():
  N, x = map(int, input().split())
  A = list(map(int, input().split()))
  A.sort()
  ans = 0
  for i in range(N):
    if i==N-1:
      if A[i]==x:
        ans += 1
      continue
    if x>=A[i]:
      ans += 1
      x -= A[i]
  return ans
print(solve())

Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n;
    cin >> n;
    vector<ll> factors;
    for(ll i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            factors.push_back(i);
            factors.push_back(n/i);
        }
    }
    sort(factors.begin(),factors.end());
    ll siz=factors.size();
    ll val=factors[siz/2];
    
    ll count=0;
    while(val)
    {
        count++;
        val/=10;
    }
    cout << count<<"\n";
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  int n;
  string s;
  cin >> n >> s;
  vector<string> v;
  s += "0";
  int old = 0;
  int lll = 0,rrr = 0;
  vector<int> l,r;
  REP(i,n){
    if(s[i] != s[i+1]){
      v.push_back(s.substr(old,i-old+1));
      if(s[i] == ')')lll += i-old+1,l.push_back(lll);
      else rrr += i-old+1,r.push_back(rrr);
      old = i+1;
    }
  }
  if((int)l.size() > 1)l[(int)l.size()-1] -= l[(int)l.size()-2];
  for(int i = l.size()-2;i > 0;i--){
    l[i] = l[i]-l[i-1]+l[i+1];
  }
  if((int)l.size() > 1)l[0] = l[0]+l[1];
  reverse(ALL(r));
  s.erase(s.end()-1);
  int front = 0,back = 0;
  if(v[0][0] == '('){
    int count = 1;
    for(int i = 1;i < v.size();i+=2){
      int is = lll-v[i-1].size();
      if(is <= 0){
        back += -is;
        lll = 0;
      }else{
        lll = min(l[count],lll-(int)v[i-1].size());
      }
      count++;
    }
    if(v[(int)v.size()-1][0] == '(')back += v[(int)v.size()-1].size();
  }else{
    lll -= v[0].size();
    int count = 2;
    for(int i = 2;i < v.size();i+=2){
      int is = lll-v[i-1].size();
      if(is <= 0){
        back += -is;
        lll = 0;
      }else{
        lll = min(l[count],lll-(int)v[i-1].size());
      }
      count++;
    }
    if(v[(int)v.size()-1][0] == '(')back += v[(int)v.size()-1].size();
  }
  if(v[(int)v.size()-1][0] == ')'){
    int count = 1;
    for(int i = (int)v.size()-2;i >= 0;i-=2){
      int is = rrr-(int)v[i+1].size();
      if(is <= 0){
        front += -is;
        rrr = 0;
      }else{
        rrr = min(r[count],rrr-(int)v[i+1].size());
      }
      count++;
    }
    if(v[0][0] == ')')front += v[0].size();
  }else{
    rrr -= v[(int)v.size()-1].size();
    int count = 2;
    for(int i = (int)v.size()-3;i >= 0;i-=2){
      int is = rrr-v[i+1].size();
      if(is <= 0){
        front += -is;
        rrr = 0;
      }else{
        rrr = min(r[count],rrr-(int)v[i+1].size());
      }
      count++;
    }
    if(v[0][0] == ')')front += v[0].size();
  }
  string res = "";
  REP(i,front)res += '(';
  res += s;
  REP(i,back)res += ')';
  cout << res << endl;





  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int MaxN = 100;
int a[MaxN + 5];
int n, sum = 0, cnt = 0, ans;

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
	}
	sort(a + 1, a + 1 + n);
	if(n%2 == 0)
	{
		for(int i = 1; i <= n; i++)
		{
			if(i%2 == 1) sum += a[i];
			if(i%2 == 0) cnt += a[i];
		}
		ans = cnt - sum;
		printf("%d\n", ans);
	}
	if(n%2 == 1)
	{
		for(int i = 1; i <= n; i++)
		{
			if(i%2 == 1) sum += a[i];
			if(i%2 == 0) cnt += a[i];
		}
		ans = sum - cnt;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (c % GCD(a, b) == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

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

using namespace std;

template <typename T=int>
struct Fenwick {
    int n;
    vector<T> v;
    
    Fenwick(int size = 100005) : n(size), v(n+1, 0) {}
    inline void add(int p, T val) {
        for (; p <= n; p += (p&-p)) { v[p] += val; }
    }
    inline T query(int p) {
        T tmp = 0;
        for (; p > 0; p -= (p&-p)) { tmp += v[p]; }
        return tmp;
    }
    inline T query(int l, int r) {
        return query(r) - query(l-1);
    }
};

void solve() {
    int n,m;
    cin >> n >> m;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        int x,y;
        cin >> x >> y;
        a[i] = {y-x+1, x};
    }
    sort(a.begin(), a.end());

    Fenwick<> f(m);
    int i = 0;
    for (int j = 1; j <= m; j++) {
        while (i < n && a[i].first < j) {
            int len,x;
            tie(len,x) = a[i];
            f.add(x, 1);
            f.add(x+len, -1);
            i++;
        }
        int res = n-i;
        for (int k = j; k <= m; k+=j) {
            res += f.query(k);
        }
        cout << res << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 3712
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String N =sc.next();
        String T =sc.next();
        
        for(int i=0;i<N.length();i++){
            if(N.equals(T)){
                System.out.println("Yes");
                
                return;
            }
            N=N.substring(N.length()-1, N.length())+N.substring(0,N.length()-1);
        }
        
        System.out.println("No");
        
        
        
        
        
    }
}


Measured memory_bytes: 39360
n = int(input())
days = [list(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n)]

for i in range(n):
    if 0 == i:
        dp[i][0] = days[0][0]
        dp[i][1] = days[0][1]
        dp[i][2] = days[0][2]
    else:
        dp[i][0] = max(days[i][0] + dp[i-1][1], days[i][0] + dp[i-1][2])
        dp[i][1] = max(days[i][1] + dp[i-1][2], days[i][1] + dp[i-1][0],)
        dp[i][2] = max(days[i][2] + dp[i-1][0], days[i][2] + dp[i-1][1],)

print(max(dp[-1]))


Measured memory_bytes: 47368
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    int n,k;
    cin>>n>>k;
    ll pref[200005];
    pref[0]=0;
    for(int i=1;i<=200001;i++)
    {
        pref[i]=pref[i-1]+i;
    }
    ll ans=0;
    for(int i=k;i<=n+1;i++)
    {
        ll minsum=pref[i-1];
        ll maxsum;
        if(i!=n+1)maxsum=pref[n]-pref[n-i];
        else maxsum=pref[n];
        ans+=(maxsum-minsum+1);
        ans%=MOD;
    }
    printf("%I64d",ans);
  }  
  return 0;
}

Measured memory_bytes: 5316
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int sum = 0;
    int A[110];
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }
    int ans = 0;
    double ave = (double)sum/N;
    double diff = abs(ave - A[0]);
    rep(i, N - 1) {
        if (diff - 0.0001 > abs(ave - A[i + 1])) {
            ans = i + 1;
            diff = abs(ave - A[i + 1]);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _164B
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] ABCD = Console.ReadLine().Split(' ').Select(tmp => long.Parse(tmp)).ToArray();
            long num_T = 0;
            long num_A = 0;

            if (ABCD[0] % ABCD[3] > 0)
            {
                num_A = ABCD[0] / ABCD[3] + 1;
            }
            else {
                num_A = ABCD[0] / ABCD[3];
            }

            if (ABCD[2] % ABCD[1] > 0)
            {
                num_T = ABCD[2] / ABCD[1] + 1;
            }
            else
            {
                num_T = ABCD[2] / ABCD[1];
            }

            if (num_T <= num_A)
            {
                Console.WriteLine("Yes");
            }
            else {
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 28164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  scanf("%d", &n);

  switch (n % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
    puts("hon");
    break;
    case 0:
    case 1:
    case 6:
    case 8:
    puts("pon");
    break;
    case 3:
    puts("bon");
    break;
  }
  return 0;
}

Measured memory_bytes: 3736
#include<stdio.h>
#define MAX 100000
typedef long long ll;
int n,k;
ll T[MAX];
int check(ll P){
  int i,j=0;
  ll s;
  for(i=0;i<k;i++){
    s=0;
    while(s+T[j]<=P){
      s+=T[j];
      j++;
      if(j==n)return n;
    }
  }
  return j;
}
int solve(){
  ll left=0;
  ll right=100000*10000;
  ll mid;
  while(right-left>1){
    mid=(right+left)/2;
    int v=check(mid);
    if(v>=n)right=mid;
    else left=mid;
  }
  return right;
}
int main(){
  int i;
  ll ans;
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++)scanf("%d",&T[i]);
  ans=solve();
  printf("%lld\n",ans);
}

Measured memory_bytes: 3532
#include <iostream>
using namespace std;
 
const char Col[2][2] = { { 'R','Y' },{ 'G','B' } };
int H, W, d;
 
char get_col(int x, int y) {
	int i = (x / d) % 2;
	int j = (y / d) % 2;
	return Col[j][i];
}
 
int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	cin >> H >> W >> d;
	for (int j = 0; j < H; ++j) {
		for (int i = 0; i < W; ++i) {
			int x = i + j;
			int y = i - j + H;
			char c = get_col(x, y);
			cout << c;
			if (i == W - 1)
				cout << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 512
import java.util.*;
import java.text.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static int[] num;
    public static int[] cur;
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        int m = sc.nextInt();
        num = new int[n+1];
        cur = new int[n+1];
        cur[1] = 1;
        
        for (int i = 1; i <= n; i++) {
            num[i] = 1;
        }
        
        for (int i = 1; i <= m; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            if (cur[x] > 0) {
                if (num[x] == 1) {
                    cur[x] = 0;
                }
                cur[y] = 1;
            }
            num[x]--;
            num[y]++;
        }
        
        int res = 0;
        for (int i = 1; i <= n; i++) {
            if (cur[i] > 0) {
                res++;
            }
        }
        
        System.out.println(res);
    }
}


Measured memory_bytes: 23972
// finish date: 2018/07/22
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    string A;
    cin >> A;
    int N = A.size();
    map<char, int> mp;
    rep(i, N) mp[A[i]]++;
    ll ans = 1;
    rep(i, N) {
        ans += (N - i) - mp[A[i]];
        mp[A[i]]--;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <climits>

using namespace std;


class Card
{
  public:
    Card() { }
    Card(char picture, int n)
    { Picture = picture; Num = n; }

    char Picture;
    int Num; 
    int InputNum;

};

Card *Cards1, *Cards2;
int N;
bool Stable;

void BubbleSort()
{
  bool flag = true;
  int i = 0;
  Stable = true;

  do
  {

    flag = false;
    for(int j = N - 1; j >= i + 1; --j)
    {
      if(Cards1[j].Num < Cards1[j-1].Num)
      {
	Card tmp = Cards1[j];
	Cards1[j] = Cards1[j-1];
	Cards1[j-1] = tmp;

	flag = true;
      }

    }

    ++i;


  }while(flag);

  return;
}

void SelectionSort()
{

  Stable = true;

  for(int i = 0; i < N; ++i)
  {
    int mini = i;
    bool flag = false;

    for(int j = i; j < N; ++j)
    {
      if(Cards2[j].Num < Cards2[mini].Num)
      {
	mini = j; 
	flag = true;	
      }
    }

    //if(flag)
    {
      Card tmp = Cards2[i];
      Cards2[i] = Cards2[mini];
      Cards2[mini] = tmp;
    }
  }

  return;

}

int Partition(int left, int right)
{
  /*
  int r = right - 1;
  int x = Cards1[r].Num;
  int i = left ;

  for(int j = 0; j < r; ++j)
  {
    if(Cards1[j].Num <= x)
    {
      swap(Cards1[i], Cards1[j]);
      ++i;
    }

  }

  swap(Cards1[i], Cards1[r]);
  return i;
  */
  int i = left-1,pivot = Cards1[right].Num;
  for(int start = left; start < right; start++){
    if(Cards1[start].Num <= pivot){
      i++;
      std::swap(Cards1[i],Cards1[start]);
    }
  }

  std::swap(Cards1[i+1],Cards1[right]);

    return i+1;
}

void QuickSort(int l, int r)
{
  if(l < r)
  {
    int q = Partition(l, r);
    QuickSort(l, q-1);
    QuickSort(q+1, r);
  }
}

int main()
{
  cin >> N;

  Cards1 = new Card[N];
  Cards2 = new Card[N];

  for(int i = 0; i < N; ++i)
  {
    //string s; cin >> s;
    char c; cin >> c;
    int n; cin >> n;
    //Cards1[i] = Card(s[0], s[1] - '0');
    Cards1[i] = Card(c, n);
    Cards1[i].InputNum = i;
    Cards2[i] = Cards1[i]; 
  }

  QuickSort(0, N-1);

  bool Stable = true;

  for(int i = 1; i < N; ++i)
  {
    if(Cards1[i].Num == Cards1[i-1].Num && Cards1[i].InputNum < Cards1[i-1].InputNum)
      Stable = false;
  }

  if(Stable)
    cout << "Stable" << endl;
  else 
    cout << "Not stable" << endl;

  for(int i = 0; i < N; ++i)
    cout << Cards1[i].Picture << " " << Cards1[i].Num << endl;

  /*
  BubbleSort();

  cout << Cards1[0].Picture << Cards1[0].Num;
  for(int i = 1; i < N; ++i)
    cout << " " << Cards1[i].Picture << Cards1[i].Num;
  cout << endl;
  cout << "Stable" << endl;

  SelectionSort();

  cout << Cards2[0].Picture << Cards2[0].Num;
  for(int i = 1; i < N; ++i)
    cout << " " << Cards2[i].Picture << Cards2[i].Num;
  cout << endl;

  Stable = true;
  for(int i = 0; i < N; ++i)
    if(Cards1[i].Picture != Cards2[i].Picture || Cards1[i].Num != Cards2[i].Num)
      Stable = false;

  cout << (Stable ? "Stable" : "Not stable") << endl;
*/
  delete [] Cards1;
  delete [] Cards2;

  return 0;
}


Measured memory_bytes: 5136
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	a := iSScan(n * 3)
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	ans := 0
	for i := 0; i < n; i++ {
		ans += a[i*2+1]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6696
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int k;
char r[100];

void dfs(int n, int d, int c) {
    if (d == n) {
        if (--k == 0) {
            cout << r << endl;
            exit(0);
        }
        return;
    }
    for (int i = 0; i < 10; i++) {
        if ((d == 0 && i > 0) || (d != 0 && abs(c - i) <= 1)) {
            r[d] = '0' + i;
            dfs(n, d + 1, i);
        }
    }
}

int main() {
    cin >> k;

    for (int n = 1;; n++) {
        dfs(n, 0, -1);
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    int f = 0;
    int ans = 0;
    REP(i, n) {
        if (f == 0 && s[i] == 'A') {
            f = 1;
        } else if (f == 1) {
            if (s[i] == 'A') {
                f = 1;
            } else if (s[i] == 'B') {
                f = 2;
            } else {
                f = 0;
            }
        } else if (f == 2) {
            if (s[i] == 'A') {
                f = 1;
            } else if (s[i] == 'C') {
                ans++;
                f = 0;
            } else {
                f = 0;
            }
        } else {
            f = 0;
        }
    }
    cout << ans << EOL;
}


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

using i64 = int64_t;

constexpr i64 INF = 1e18;

template <typename T, typename E> class SegmentTree {
  private:
    int n;
    vector<T> node;
    const function<T(T, T)> query_func;
    const function<T(T, E)> update_func;
    const T identity;

  public:
    SegmentTree() = default;

    SegmentTree(int size, function<T(T, T)> query_func,
                function<T(T, E)> update_func, T identity,
                vector<T> v = vector<T>())
        : query_func(query_func), update_func(update_func), identity(identity) {
        n = 1;
        while (n < size)
            n *= 2;
        node.resize(2 * n - 1, identity);
        if (size == v.size())
            build(size, v);
    }

    void build(int size, vector<T> v) {
        for (int i = 0; i < size; ++i)
            node[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; --i)
            node[i] = query_func(node[2 * i + 1], node[2 * i + 2]);
    }

    void update(int x, E val) {
        x += n - 1;

        node[x] = update_func(node[x], val);
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = query_func(node[2 * x + 1], node[2 * x + 2]);
        }
    }

    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0)
            r = n;

        if (r <= a || b <= l)
            return identity;

        if (a <= l && r <= b)
            return node[k];

        T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return query_func(vl, vr);
    }
};

struct Node{
    i64 l, r, c;
    bool operator<(const Node &obj)const{
        if(l == obj.l)return r < obj.r;
        return l < obj.l;
    }
};

int main(){
    i64 n, m;
    cin >> n >> m;
    vector<Node> v;
    for(int i=0;i<m;++i){
        i64 l, r, c;
        cin >> l >> r >> c;
        v.push_back({l, r, c});
    }
    vector<i64> dp(n+1, INF);
    dp[1] = 0;
    SegmentTree<i64, i64> sgt(
        n+1,
        [](i64 x, i64 y){return min(x, y);},
        [](i64 x, i64 y){return y;},
        INF,
        dp
    );
    sort(v.begin(), v.end());
    for(auto e: v){
        i64 tmp = sgt.query(e.l, e.r+1);
        //cout << e.l << " " << e.r << " " << tmp << endl;
        if(tmp >= INF)continue;
        if(sgt.query(e.r, e.r+1) <= tmp + e.c)continue;
        sgt.update(e.r, tmp + e.c);
    }
    i64 ans = sgt.query(n, n+1);

    cout << (ans >= INF ? -1 : ans) << endl;

    return 0;
}


Measured memory_bytes: 6896
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main()
{
    int a[6];
    cin>>a[1]>>a[2]>>a[3]>>a[4]>>a[5];

    for(int i=1;i<=5;i++){
        if(a[i]==0) {cout<<i<<endl;return 0;}
    }
}


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

using namespace std;

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

int mp[12][12];

void dfs_fill(int y, int x)
{
	if (y < 0 || y >= 12 || x < 0 || x >= 12) return;

	if (!mp[y][x]) return;

	mp[y][x] = 0;

	for (int i = 0; i < 4; ++i) dfs_fill(y + dy[i], x + dx[i]);
}

int main()
{
	string s;
	while (getline(cin, s)) {
		if (s.empty()) continue;

		for (int y = 0; y < 12; ++y) {
			for (int x = 0; x < 12; ++x) {
				mp[y][x] = s[x] - '0';
			}
			getline(cin, s);
		}

		int ans = 0;

		for (int i = 0; i < 12; ++i) for (int j = 0; j < 12; ++j) {
			if (mp[i][j]) {
				dfs_fill(i, j);
				ans++;
			}
		}

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

Measured memory_bytes: 1184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String buffer[] = new String[3];
        int array[] = new int[3];
        String ans;
 
        while(true){
 
 
            try {
                buffer = br.readLine().split("\\s+");
                for(int i = 0; i < buffer.length; i++){
                    array[i] = Integer.parseInt(buffer[i]);
                }
                if(array[0] == -1 && array[1] == -1 && array[2] == -1)break;
 
                if(array[0] == -1 || array[1] == -1){
                    ans = "F";
                }else if(array[0]+array[1] >= 80){
                    ans = "A";
                }else if(array[0]+array[1] >= 65){
                    ans = "B";
                }else if(array[0]+array[1] >= 50){
                    ans = "C";
                }else if(array[0]+array[1] >= 30){
                    if(array[2] >= 50){
                        ans = "C";
                    }else{
                        ans = "D";
                    }
                }else{
                    ans = "F";
                }
 
                System.out.printf("%s\n", ans);
 
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


Measured memory_bytes: 24800
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;

int main(){
  int n;
  cin >> n;
  VI a(n);
  rep(i,n) cin >> a[i];
  
  int max=0,max2=0;
  rep(i,n){
    if(a[i] > max){
      max2 = max;
      max = a[i];
    }else if(a[i] > max2){
      max2 = a[i];
    }
  }
  
  rep(i,n){
    if(a[i] == max) cout << max2 << endl;
    else cout << max << endl;
  }
  
  return 0;
}

Measured memory_bytes: 2432
#include <stdio.h>
int used[10];
int check(int n){
	while(n>0){
		if(used[n%10]) return 0;
		n/=10;
	}
	return 1;
}
int main(void)
{
	int n,k,a,i;
	scanf("%d%d",&n,&k);
	for(i=0;i<k;i++){
		scanf("%d",&a);
		used[a]=1;
	}
	while(!check(n)) n++;
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;

int n;

struct node{
	int l,r;
	int key;
	void init(int a){
		l=r=-1;
		key=a;
	}
};
struct bst{
	int size;
	node t[600001];
	void init(){
		size=0;
	}
	void insert(int v){
		int i=0;
		while(i<size){
			int& child=(v<t[i].key?t[i].l:t[i].r);
			if(child==-1)child=size;
			i=child;
		}
		t[size++].init(v);
	}
	bool find(int v){
		int i=0;
		while(i<size){
			if(t[i].key==v)return true;
			int child=(v<t[i].key?t[i].l:t[i].r);
			if(child==-1)child=size;
			i=child;
		}
		return false;
	}

	void preorder(int pos){
		if(pos==-1|| pos==size)return;
		printf(" %d",t[pos].key);
		preorder(t[pos].l);
		preorder(t[pos].r);
	}

	void inorder(int pos){
		if(pos==-1|| pos==size)return;
		inorder(t[pos].l);
		printf(" %d",t[pos].key);
		inorder(t[pos].r);
	}

	void postorder(int pos){
		if(pos==-1|| pos==size)return;
		postorder(t[pos].l);
		postorder(t[pos].r);
		printf(" %d",t[pos].key);
	}
};

bst T;

int main(void){
	scanf("%d",&n);
	char str[100];
	for(int i=0;i<n;i++){
		scanf("%s",str);
		if(str[0]=='i'){
			int a;
			scanf("%d",&a);
			T.insert(a);
		}else if(str[0]=='f'){
			int a;
			scanf("%d",&a);
			printf("%s\n",T.find(a)?"yes":"no");
		}else{
			T.inorder(0);
			printf("\n");
			T.preorder(0);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 7312
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod = 10e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prtd(n, var)  cout << fixed << setprecision(n) << var << endl
#define prt2(var1, var2) cout << var1 << " " << var2 << endl

//----------------------------------------------------------------

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

  vec d(n);
  rep(i,n){
    cin >> d[i];
  }

  sort(all(d));

  int ans=d[n/2]-d[n/2-1];
  prt(ans);

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define ia(n, a) rp(ia_i, 0, n) cin >> a[ia_i]
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
ll vis[222222];
ll a[222222], b[222222];
vl edge[222222];
vl que;
void dfs(ll s)
{
    rp(i, 0, edge[s].size())
    {
        if (vis[edge[s][i]] == 0)
        {
            vis[edge[s][i]] = s + 1;
            que.push_back(edge[s][i]);
        }
    }
}

int main()
{
    ll n, m;
    cin >> n >> m;
    rp(i, 0, m) cin >> a[i] >> b[i];
    rp(i, 0, m)
    {
        edge[a[i] - 1].push_back(b[i] - 1);
        edge[b[i] - 1].push_back(a[i] - 1);
    }
    vis[0] = 1;
    vl init, que2;
    que.push_back(0);
    while (que.size() > 0)
    {
        que2 = que;
        que = init;
        rp(i, 0, que2.size())
        {
            dfs(que2[i]);
        }
    }
    ce("Yes");
    rp(i, 1, n)
    {
        ce(vis[i]);
    }
}

Measured memory_bytes: 19672
INF=10**5+1
p=[1]*INF
for i in range(2,INF):
  if p[i]:
    for j in range(2*i,INF,i):p[j]=0
p[0],p[1]=0,0
q=[0]*INF
for i in range(INF):
  if i%2==0:continue
  if p[i]*p[(i+1)//2]:q[i]=1
for i in range(1,INF):
  q[i]+=q[i-1]
n=int(input())
for _ in range(n):
  l,r=map(int,input().split())
  print(q[r]-q[l-1])

Measured memory_bytes: 77532
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n){
        cin>>a[i];
    }

    bool flg = false;
    REP(i,n){
        if(a[i] % 2 == 0){
            if(a[i] % 3 == 0 || a[i] % 5 == 0){

            } else {
                flg = true;
            }
        }
    }
    if(flg){
        cout<<"DENIED"<<endl;
    } else {
        cout<<"APPROVED"<<endl;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <tuple>

using namespace std;

#define D(x) x
#define REP(i,a,b) for (int i = (a); i < (b); ++i)

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;

    int N; cin >> N;
    int x[N];
    REP(i,0,N) {
        cin >> x[i];
        x[i]--;
    }

    int res = 0;
    REP(i,0,N) {
        if (x[i] > i && x[x[i]] == i)
            res++;
    }

    cout << res << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){

    string s;
    cin >> s ;
    int cnt = 0;
    
    for(int i = 0; i < s.size() / 4 + 1; i++){
        //printf("%d %lu %c %c\n", i, ( s.size() - 3 ) / 2 - i, s.at(i), s.at(( s.size() - 3 ) / 2 - i));
        if(s.at(i) != s.at(( s.size() - 3 ) / 2 - i)){
            cnt++;
        }
        //printf("%d %lu %c %c\n", s.size() - 1 - i, ( s.size() + 1 ) / 2 + i, s.at(s.size() - 1 - i), s.at(( s.size() + 1 ) / 2 + i));
        if(s.at(s.size() - 1 - i) != s.at(( s.size() + 1 ) / 2 + i)){
            cnt++;
        }
        //printf("%d %lu %c %c\n", i, s.size() - 1 - i, s.at(i), s.at(s.size() - 1 - i));
        if(s.at(i) != s.at(s.size() - 1 - i)){
            cnt++;
        }
    }

    if(cnt == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;
int main(){
    string S;
    cin >> S;
    
    int o = 0;
    int x = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'o')o++;
        if(S[i] == 'x')x++;
    }
    if((15 - S.size() + o >= 8))cout << "YES";
    else cout << "NO";


    return 0;
}

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n;
	cin >> n;
	print(n * (n + 1) / 2);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256