akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = 998244353;
	static long inf = (long) 1e16;
	static int[] l, r;
	static int n, m, id;
	static long all, ans;
	static ArrayList<Integer>[] ad;
	static long[][][] memo;
	static long[] a;
	static ArrayList<Integer> h;
	static boolean vis[];

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		n = sc.nextInt();
		n = 1 << n;
		int[] a = sc.nextArrInt(n);
		pair[] dp = new pair[n];
		int[] ans = new int[n];
		for (int i = 0; i < n; i++)
			dp[i] = new pair(i, -1);
//		System.out.println(Arrays.toString(dp));
		for (int i = 1; i < n; i++) {
			for (int b = 0; b < 19; b++) {
				if ((i & (1 << b)) != 0) {
					int id = (i ^ (1 << b));
					PriorityQueue<Integer> ts = new PriorityQueue<>((x, y) -> a[y] - a[x]);
					ts.add(dp[id].x);
					ts.add(dp[i].x);
					if (dp[i].y != -1)
						ts.add(dp[i].y);
					if (dp[id].y != -1)
						ts.add(dp[id].y);
					dp[i].x = ts.poll();
					if(ts.peek()==dp[i].x)
						ts.poll();
					dp[i].y = ts.poll();
				}
			}
	//		System.err.println(i + " " + Arrays.toString(dp));
		}
		int max = 0;
		for (int i = 1; i < n; i++) {
			max = Math.max(max, a[dp[i].x] + a[dp[i].y]);
			ans[i] = max;
		}
		for (int i = 1; i < n; i++)
			out.println(ans[i]);
		out.flush();
	}

	static class pair implements Comparable<pair> {
		int x;
		int y;

		pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return x + " " + y;
		}

		@Override
		public int compareTo(pair o) {
			return x - o.x;
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, -1)
#define RREP(i, n, k) for(auto i = n; i != k; i--)

#define debug(x) cerr << #x << " " << x << endl
#define print(x) cout << x;
#define println(x) cout << x << endl;
#define spc << " " <<

#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define eb emplace_back
#define np next_permutation

using ll = long long;
using Pii = pair<int, int>;
using Tiii = tuple<int, int, int>;
template<typename T>using V = vector<T>;
template<typename T>using VV = vector<vector<T>>;
using Vi = vector<int>;
using VVi = vector<vector<int>>;

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

    map<char, char> m({{'A', 'T'}, {'T', 'A'}, {'G', 'C'}, {'C', 'G'}});

    char c; cin >> c;
    cout << m[c] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define INF 1000
using namespace std;

int number[100];
int mod[10];

int main() {
    int N, count = 0;
    cin >> N;
    for (int i = 0; i < 100; i++) mod[i] = INF;
    for (int i = 0; i < N; i++) {
        cin >> number[i];
        count += number[i];
        mod[number[i] % 10] = min(mod[number[i] % 10], number[i]);
    }
    sort(mod + 1, mod + 10);
    if (count % 10 != 0) {
        cout << count << endl;
    }
    else {
        for (int i = 1; i < 10; i++) {
            if (mod[i] != INF) {
                cout << count - mod[i] << endl;
                return 0;
            }
        }
        cout << 0 << endl;
    }
    
    return 0;
}

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

#define ll long long
#define forr(i,n) for(ll i=0;i<n;i++)
#define f(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())

ll power(ll a,ll b){ll r=1;while(b--)r*=a;return r;}
const ll INF=1e17L+5;

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

    int n;cin>>n;
    vector<vector<long double>> dp(n,vector<long double>(n+1,0.0));

    vector<long double> p(n);f(i,0,n)cin>>p[i];

    dp[0][0]=(1-p[0])*1.0;dp[0][1]=p[0];
    
    f(i,0,n-1){
        f(j,0,i+2){
            dp[i+1][j]+=dp[i][j]*(1-p[i+1])*1.0;
            dp[i+1][j+1]+=dp[i][j]*p[i+1]*1.0;
        }
    }
    long double ans=0;
    for(int h=n/2+1;h<=n;h++){
        ans+=dp[n-1][h];
    }cout<<fixed<<setprecision(9)<<ans<<endl;
    

  }


Measured memory_bytes: 144564
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <decimal/decimal>
using namespace std;
using namespace __gnu_pbds;

#define rep(i, s, t) for (int i = s; i < int(t); ++i)

#define sc	scanf
#define pr	printf
#define ff	first
#define ss	second
#define mp	make_pair
#define pb	push_back
#define eb	emplace_back
#define range(c)	c.begin(), c.end()
#define lowbit(x)	((x) & -(x))
#define pop_count	__builtin_popcount
#define pop_count_64	__builtin_popcountll
#define tail_count	__builtin_ctz
#define tail_count_64	__builtin_ctzll
#define lead_count	__builtin_clz
#define lead_count_64	__builtin_clzll

#define TEMP template<typename
#define CONST(type) constexpr type const

TEMP... Ts> struct is_con { static CONST(bool) value = false; };
TEMP... Ts> struct is_con<vector<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<list<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<deque<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<set<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<unordered_set<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<map<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<unordered_map<Ts...>> { static CONST(bool) value = true; };

TEMP T1, typename T2> ostream& operator<<(ostream& os, pair<T1, T2> const& p) { return os << "<" << p.ff << "," << p.ss << ">"; }
TEMP T> typename enable_if<is_con<T>::value, ostream>::type& operator<<(ostream& os, T const& c) {
	os << "{";
	bool first = true;
	for (auto const& x : c) {
		if (first) first = false;
		else os << ",";
		os << " " << x;
	}
	return os << " }";
}

TEMP T, typename... Ts> void dbg(T h, Ts... t) { cerr << " " << h; dbg<Ts...>(t...); }
template<> void dbg<int>(int x) { cerr << endl; }

#ifdef LOCAL
#define debug(...) cerr << "[ "#__VA_ARGS__" ] :", dbg(__VA_ARGS__, 0)
#else
#define debug(...) 0
#endif

TEMP T, typename U> using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
TEMP T> using ordered_set = ordered_map<T, null_type>;

typedef long long i64;
typedef decimal::decimal128 i99;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef float f32;
typedef double f64;
typedef long double f80;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<i64> vl;

TEMP T> T& minn(T& lhs, T const& rhs) { return lhs = min(lhs, rhs); }
TEMP T> T& maxx(T& lhs, T const& rhs) { return lhs = max(lhs, rhs); }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	vector<string> s(n);
	rep(i, 0, n) cin >> s[i];
	vvi dp(n, vi(m, INT_MAX));
	dp[0][0] = s[0][0] == '#';
	rep(i, 1, m) dp[0][i] = dp[0][i - 1] + (s[0][i] == '#' && s[0][i - 1] == '.');
	rep(i, 1, n) dp[i][0] = dp[i - 1][0] + (s[i][0] == '#' && s[i - 1][0] == '.');
	rep(i, 1, n) rep(j, 1, m) {
		minn(dp[i][j], dp[i][j - 1] + (s[i][j] == '#' && s[i][j - 1] == '.'));
		minn(dp[i][j], dp[i - 1][j] + (s[i][j] == '#' && s[i - 1][j] == '.'));
	}
	rep(i, 0, n) debug(dp[i]);
	cout << dp[n - 1][m - 1] << endl;
}


Measured memory_bytes: 384
N = int(input())
A = sorted(((i, int(input())) for i in range(N)), key=lambda x: x[1])

maxidx, maxi = A[-1]
secidx, second = A[-2]

A.sort()
for a in A:
    if a[0] == maxidx:
        print(second)
    else:
        print(maxi)




Measured memory_bytes: 33200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){

  int n;
  cin >> n;

  vector<int> cards(n);
  for (int i=0; i<n; ++i){
    cin >> cards[i];
  }
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());

  int compari = 0;
  int turn = 1;
  for (int i=0; i<n; ++i){
    compari += turn * cards[i];
    turn *= -1;
  }
  cout << compari << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    int n, a, b;
    cin >> n;
    cin >> a >> b;
    vector <int> x(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    ll ans = 0;
    for (int i = 1; i < n; i++)
    {
        ans += min((x[i] - x[i - 1]) * (ll) a, (ll) b);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int a,b,c,d=0,e,f;
    scanf("%d %d",&a,&b);
    c=b;
    while(c!=0)
    {
        c=c/10;
        d++;
    }
    while(d!=0){
      a=a*10;
      d--;
    }
    e=a+b;
    f=(int)sqrt(e);
    if(f*f==e)
        printf("Yes");
    else
        printf("No");
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>


int notA[ 100 + 1 ] ;
int yesB[ 100 + 1 ] ;

int ans ;


int main()
{
	int N ;

	int i ;
	int p ;

	scanf( "%d" ,&N ) ;


	scanf( "%d" ,&N ) ;


	for( i = 0 ; i < N ; ++i )
	{
		scanf( "%d" ,&p ) ;


		notA[ p ] = 1 ;
	}


	scanf( "%d" ,&N ) ;

	for( i = 0 ; i < N ; ++i )
	{
		scanf( "%d" ,&p ) ;


		yesB[ p ] = 1 ;
	}


	scanf( "%d" ,&N ) ;

	for( i = 0 ; i < N ; ++i )
	{
		scanf( "%d" ,&p ) ;


		if( notA[ p ] != 1 || yesB[ p ] == 1 )
		{
			++ans ;
		}
	}


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



	return 0 ;
}

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

int main() {
    ios::sync_with_stdio(false);
    int n, c4, c2;
    cin >> n; c4 = c2 = 0;
    vector<int>a(n);
    for( int i = 0; i < n; ++i) {
        cin >> a[i];

        if(a[i] % 4 == 0)
            c4++;
        else if(a[i] % 2 == 0)
            c2++;
    }
    c2 = c2/2;

    if(c4 + c2 >= n/2)
        cout << "Yes\n";
    else
        cout << "No\n";


    return 0;
}


Measured memory_bytes: 640
N = int(input())
aList = list(map(int, input().split()))

ac = 0
ad = 999
mean = sum(aList) / len(aList)
for i in range(N):
    iad = abs(aList[i] - mean)
    if iad == 0:
        ac = i
        break
    elif iad < ad:
        ad = iad
        ac = i
    else:
        continue
print(ac)

Measured memory_bytes: 3064
s = input()
flg = 0
n = len(s)
s1 = s[0:(n-1)//2]
s2 = s[(n+3)//2-1:]
t1 = s1[::-1]
t2 = s2[::-1]
#print(s1,s2,t1,t2)

for i in range(len(s1)):
  if s1[i] != t1[i] or s2[i] != t2[i]:
    flg = 1
    break
for i in range(n//2):
  if s[i] != s[-(i+1)]:
    flg = 1
    break
 
print("Yes" if flg == 0 else "No")


Measured memory_bytes: 3064
#-*- coding:utf-8 -*- 

def main():
	N, T = map(int,input().split())
	c_list = []
	t_list = []
	for i in range(N):
		c, t = map(int,input().split())
		c_list.append(c)
		t_list.append(t)
	
	#print(t_list)
	#print(type(t_list[0]))
	index_list = []
	for i in range(len(t_list)):
		if t_list[i] <= T:
			index_list.append(i)
	
	#print(index_list)
	
	if len(index_list) == 0:
		return print("TLE")

	cost_min = float("inf")
	for i in index_list:
		if c_list[i] < cost_min:
			cost_min = c_list[i]
	
	print(int(cost_min))
	

if __name__ == "__main__":
	main()


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

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

int n;
int t[105];
int v[105];
int tt[105];

int main()
{
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> t[i];
		tt[i+1] = tt[i] + t[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}

	double ans = 0;
	double p = 0;
	for (double d = 0.0; d <= tt[n]; d += 0.5) {
		double imin = min(d,tt[n]-d);
		for (int i = 0; i < n; i++) {
			double k;
			if (tt[i] >= d) k = v[i] + (tt[i] - d);
			else if (tt[i + 1] <= d)k = v[i] + (d - tt[i + 1]);
			else k = v[i];
			imin = min(k,imin);
		}
		ans += (p + imin) / 4;
		//cout << imin << endl;
		p = imin;
	}

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

	return 0;
}

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

int main(){
    //int flag=1;
    int n,x,m;
    int MIN=1001;
    int ans=0;

    cin >>n>>x;

    for (int i = 0; i < n; i++){
        cin >>m;

        ans++;
        x-=m;
        
        MIN=min(MIN,m);
    }

    while(1){
        x -= MIN;
        if(x<0)break;
        ans++;
    }
    
    cout << ans <<endl;
    //cout <<fixed<<setprecision(16)<< ans <<endl;
    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

from collections import defaultdict
from heapq import heappush, heappop
import sys


def main(K, N):
    P = 10 ** 9 + 7

    P25 = [1] * (K + 1)
    P26 = [1] * (K + 1)
    F = [1] * (N + K)
    INV = [1] * (N + K)
    INVF = [1] * (N + K)

    p25 = 1
    p26 = 1
    for i in range(1, K + 1):
        p25 *= 25
        p25 %= P
        P25[i] = p25

        p26 *= 26
        p26 %= P
        P26[i] = p26

    f = 1
    invf = 1
    for i in range(2, N + K):
        f *= i
        f %= P
        F[i] = f
        q, r = divmod(P, i)
        INV[i] = -INV[r] * q % P
        invf *= INV[i]
        invf %= P
        INVF[i] = invf

    def comb_rep(n, r):
        return (F[n + r - 1] * INVF[r] % P) * INVF[n - 1] % P

    ret = 0
    for i in range(K + 1):
        ret += (
            P25[i] *
            P26[K - i] % P *
            comb_rep(N, i) % P
        )
    return (ret % P)


if sys.argv[-1] == 'ONLINE_JUDGE':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', 'i8(i8,i8)')(main)
    # b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
    cc.compile()
    exit()
else:
    # read parameter
    from my_module import main
    K = int(input())
    S = input()
    print(main(K, len(S)))


Measured memory_bytes: 90668
package main

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

func solve(N int64, S string) {
	m := make(map[byte]int64, 3)
	for i := 0; i < len(S); i++ {
		m[S[i]]++
	}

	ans := m['R'] * m['G'] * m['B']

	for i := 0; i < len(S); i++ {
		for d := 0; d <= len(S); d++ {
			j, k := i+d, i+2*d
			if k >= len(S) {
				continue
			}
			if S[i] != S[j] && S[j] != S[k] && S[k] != S[i] {
				ans--
			}
		}
	}

	fmt.Println(ans)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int64
	scanner.Scan()
	N, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	var S string
	scanner.Scan()
	S = scanner.Text()
	solve(N, S)
}


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

typedef long long int ll;
bool check(ll x,ll y){
	while( y % x == 0){
		y /= x;
	}
	return y % x == 1;
}
void solved(){
	ll n;cin>>n;
	ll ans = 0;
	for(ll i = 1; i * i<= n - 1; i++){
		if((n - 1)%i==0){
			if(i * i == n - 1)ans++;
			else ans += 2;
		}
	}
	ans--;
	for(ll i = 2; i * i <= n; i++){
		if(n % i == 0 && check(i,n)){
			ans++;
		}
	}
	ans++;
	cout<<ans<<endl;
}
int main(){
	solved();
	return 0;
} 

Measured memory_bytes: 256
n = int(input())
b = 2
p = 2
max_n = 1
while True:
    power = b**p
    if power <= n:
        max_n = max(power, max_n)
        p += 1
    else:
        p = 2
        b += 1
    if b == 33:
        break
print(max_n)
        

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

int main(){
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    int ans = (k * x) + ( (n-k) * y);
    if( n <= k){
        ans = n * x;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int gcd(int a, int b) {
	return b != 0 ? gcd(b, a % b) : a;
}


int main(){
	int a1,m1,a2,m2,a3,m3;

	while(1){
		int lc1,x=1,cn1=0,cn2=0,cn3=0;
		long long lc2;
		scanf("%d%d%d%d%d%d",&a1,&m1,&a2,&m2,&a3,&m3);
		if(!(a1|m1|a2|m2|a3|m3)) break;
		do{
			x = (x*a1) % m1;
			cn1++;
		}while(x != 1);
		do{
			x = (x*a2) % m2;
			cn2++;
		}while(x != 1);
		do{
			x = (x*a3) % m3;
			cn3++;
		}while(x != 1);		
		lc1 = cn1*cn2 / gcd(cn1,cn2);
		lc2 = (long long)lc1 * (long long)cn3 / (long long)gcd(lc1,cn3);
		printf("%lld\n",lc2);
	}

	return 0;
} 

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long K = long.Parse(str[1]);
		long[] x = new long[N];
		long amin = 9999999999999999;
		string[] str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			x[i] = long.Parse(str2[i]);
		}
		long ia = 0;
		long aa = 0;
		while(true){
			long a = x[ia + K - 1];
			long b = x[ia];
			if((a>= 0 && b >= 0) || a<=0 && b<=0){
				aa = Math.Max(Math.Abs(b) , Math.Abs(a));
			} else {
				aa = Math.Max(Math.Abs(a) , Math.Abs(b)) + Math.Min(Math.Abs(a) , Math.Abs(b))*2;
			}
			amin = Math.Min(aa,amin);
			ia += 1;
			if(ia + K - 1 >= N){
				break;
			}
		}
		Console.WriteLine(amin);
	}
}

Measured memory_bytes: 20704
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

Q = INT()
L = [LIST() for _ in range(Q)]

def prime_for(n):
   is_prime = [True] * (n + 1)
   is_prime[0] = False
   is_prime[1] = False
   for i in range(2, n + 1):
       for j in range(i * 2, n + 1, i):
           is_prime[j] = False
   return is_prime

prime = prime_for(10**5)

acc = [0]*10**5
for i in range(1, 10**5):
	if i%2 == 0:
		acc[i] = acc[i-1]
	if prime[i] and prime[int((i+1)/2)]:
		acc[i] = acc[i-1]+1
	else:
		acc[i] = acc[i-1]

for i in range(len(L)):
	print(acc[L[i][1]] - acc[L[i][0]-1])

Measured memory_bytes: 86156
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
  string s, t;
  int ch = 0;
  cin >> s >> t;
  rep(i, 3){
    if(s.at(i) == t.at(i)) ch++;
  }
  cout << ch << endl;
}

Measured memory_bytes: 256
void main() {
	auto S = rs.to!(dchar[]);
	if(S.length < 26) {
		foreach(i; 'a'..'z'+1) {
			if(!S.canFind(i)) {
				writeln(S ~ i);
				return;
			}
		}
		
	}
	else {
		foreach(i; iota(25, 0, -1)) {
			if(S[i] > S[i-1]) {
				writeln(S[0..i-1] ~ S[i..$].filter!(k => k > S[i-1]).reduce!min);
				return;
			}
		}
		writeln(-1);
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
package main

import (
  "fmt"
  "strings"
)

func main() {
    var N, K int
    var S string

    fmt.Scan(&N, &K)
    fmt.Scan(&S)

  ret := ""
  for i, s := range S{
    xs := string(s)
    if i == K-1 {
      xs = strings.ToLower(xs)
    }
    ret += xs
  }

   fmt.Println(ret)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll X, Y; cin >> X >> Y;
    int res = 0;
    while(X <= Y){
        res++;
        X *= 2;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
mod = 10**9+7
n , k = map(int,input().split())
arr =[ int(i) for i in input().split() ]
cnt_tot = [ 0 for i in range(2005) ]
bit = [ 0 for i in range(2005) ]
def sum(r):
    global bit
    ret = 0
    while r >= 0:
        ret += bit[r]
        r = ( r & (r+1) ) - 1
    return ret

def add(idx, delta):
    global bit
    while idx < 2005:
        bit[idx] += delta
        idx = idx | (idx+1)

def sum2(l,r):
    return sum(r) - sum(l-1)

for i in range(n):
    cnt_tot[arr[i]] += 1
for i in range(1,2005):
    cnt_tot[i] += cnt_tot[i-1]

ans = 0
full = (k-1) * (k) * pow(2,mod-2,mod)
for i in range(n):
    ans += (n-cnt_tot[arr[i]])
ans = ans * full
# print(ans)
other = 0
for i in range(n):
    other += sum2(arr[i]+1,2004)
    add(arr[i],1)
other = other * k
# print(other)
ans += other

ans = ans % mod

print(ans)


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

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

  // ここにプログラムを追記
  for (int i = 0; i < N; i++) {
    string x;
    cin >> x;
    if (x == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if (i == N-1)
      cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
char str[55];
int N,K; 
int main(){
  scanf("%d %d",&N,&K);
  scanf("%s",str);
  if(str[K-1]=='A'){
    str[K-1]='a';
  }
  else if(str[K-1]=='B'){
    str[K-1]='b';
  }
  else {
    (str[K-1]='c');   
  }
  printf("%s",str);

















  return 0;
}

Measured memory_bytes: 2108
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;

int main(){
  ll r,d,x;
  cin>>r>>d>>x;

  rep(i,10){
    x=r*x-d;
    cout<<x<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,x,i,j,k,s=0;
  scanf("%d%d%d%d",&a,&b,&c,&x);
  for(i=0;i<=a;i++){
    for(j=0;j<=b;j++){
      for(k=0;k<=c;k++){
        if(500*i+100*j+50*k==x) s++;
      }
    }
  }
  printf("%d",s);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,p=0,k=0,d=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int m = sizeof(a)/sizeof(a[0]); 
	sort(a,a+m);
	p=n/2;
	k=p-1;
	if(a[p]-a[k]>=1)
	d=a[p]-a[k];
	else
	d=0;
	cout<<d;
}

Measured memory_bytes: 640
x = input()


if x == 'SAT':
    print(1)
elif x == 'SUN':
    print(7)
elif x == 'MON':
    print(6)
elif x == 'TUE':
    print(5)
elif x == 'WED':
    print(4)
elif x == 'THU':
    print(3)
elif x == 'FRI':
    print(2)



Measured memory_bytes: 2940
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n;
ll a[100000], b[100000];

int main(int argc, char **argv) {
	cin >> n;
	REP(i, n) cin >> a[i] >> b[i];
	ll res = 0;
	for (int i = n - 1; i >= 0; --i) {
		a[i] += res;
		ll t = (b[i] - a[i] % b[i]) % b[i];
		res += t;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100000001
#define dmp make_pair
#define dpb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int dx[4] = {-1,0,0,1}, dy[4] = {0,-1,1,0};
char a[1002][1002];
int b[1002][1002];
queue<pair<int,int> > q;
int main(){
	int h, w, n, t = 0;
	char str[1000][1000];
	rep(i,1002)rep(j,1002)a[i][j] = 'X';
	scanf("%d%d%d", &h, &w, &n);
	rep(i,h)scanf("%s", str[i]);
	rep(i,h)rep(j,w){
		a[i+1][j+1] = str[i][j];
		if(a[i+1][j+1] == 'S'){
			q.push(dmp(i+1, j+1));
		}
	}
	
	pair<int,int> p;
	int x, y, xx, yy, tx, ty, res, ans = 0;
	for(int i = 1;i <= n;i++){
		fill((int*)b, (int*)(b+1002), INF);
		y = q.front().fi, x = q.front().se;
		b[y][x] = 0;
		while(!q.empty()){
			p = q.front();q.pop();
			y = p.fi;x = p.se;t = b[y][x];
			for(int j = 0;j < 4;j++){
				xx = x+dx[j], yy = y+dy[j];
				if(a[yy][xx] != 'X'){
					if(b[yy][xx] == INF)q.push(dmp(yy, xx));
					b[yy][xx] = min(b[yy][xx], t+1);
				}
			}
			if(a[y][x] == i+'0'){
				tx = x;ty = y;
				res = t;
			}
		}
		q.push(dmp(ty, tx));
		ans += res;
	}
	printf("%d\n", ans);
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> rate(8, 0);
	int in;
	int over = 0;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		cin >> in;
		if(in >= 3200)over++;
		else rate[in / 400]++;
	}

	for(int i = 0; i < 8; i++)if(rate[i] > 0)cnt++;

	cout << max(1, cnt) << ' ' << cnt + over << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,st,num)for(int i=(st);i<(num);++i)
#define ll long long
using namespace std;

int N,A[200001];
ll S[2000002],ans=LLONG_MAX;

int can(ll high) {
    vector<ll> nums;
    int idx=0,before=0;
    REP(i,1,N+2){
        if(S[i] - S[before] > high) {
            if(i-1==before){
                nums.push_back(S[i]-S[before]);
                before=i;
            }else{
                nums.push_back(S[i-1]-S[before]);
                before=i-1;
            }

        }
    }
    if(before!=N){
        nums.push_back(S[N+1]-S[before]);
    }
    // cout<<high<<endl;
    // REP(i,0,nums.size()){
    //     cout<<nums[i]<<" ";
    // }
    // cout<<endl;
    // cout<<"idx = " << idx << endl;
    if (nums.size() < 4)return -1;
    else if (nums.size() > 4) return 1;
    ll mi=LLONG_MAX,ma=-1;

    REP(i,0,4){
        mi=min(mi,nums[i]);
        ma=max(ma,nums[i]);
    }
    // cout<<endl;
    // cout<<"ans = " << (ma-mi)<<endl;
    ans = min(ans, (ma-mi));
    return 0;
}

ll maxValue(ll a, ll b, ll c, ll d){
    ll ans=-1;
    ans=max(ans,a);
    ans=max(ans,b);
    ans=max(ans,c);
    ans=max(ans,d);
    return ans;
}
ll minValue(ll a, ll b, ll c, ll d){
    ll ans=LLONG_MAX;
    ans=min(ans,a);
    ans=min(ans,b);
    ans=min(ans,c);
    ans=min(ans,d);
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin>>N;
    S[0]=0;
    REP(i,0,N){
        cin>>A[i];
        S[i+1] = S[i]+A[i];
    }
    int left=1,right=3;
    ll ans=LLONG_MAX,b,c,d,e;
    REP(i,3,N){
        ll lSum=S[i-1]-S[0];
        ll rSum=S[N]-S[i-1];
        // cout<<lSum<<" "<<rSum<<endl;
        while (lSum/2>S[left+1]&&left<i-1)left++;
        while (rSum/2>S[right+1]-S[i-1]&&right<N)right++;
        b=S[left];
        c=lSum-S[left];
        d=S[right]-S[i-1];
        e=S[N]-S[right];
        if(abs(c-b)>abs((lSum-S[left+1])-S[left+1])){
            left++;
            b=S[left];
            c=lSum-S[left];
        }
        if(abs(e-d)>abs((S[N]-S[right+1])-(S[right+1]-S[i-1]))){
            right++;
            d=S[right]-S[i-1];
            e=S[N]-S[right];
        }
        // cout<<b<<" "<<c<<" "<<d<<" "<<e<<endl;
        ans=min(ans,maxValue(b,c,d,e)-minValue(b,c,d,e));
        // cout<<"ans = " <<ans<<endl;
    }
    cout<<ans;
    return 0;
}
//10
//10 71 84 33 6 47 23 25 52 64
//

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
using vc = vector<char>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()



int main(){
  long x;
  cin >> x;
  for(int i=1;i<20000;i++){
    long top = 360*i;
    if(top % x == 0){
      cout << top/x << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3612
#include <iostream>

using namespace std;

typedef long long int ll;
#define REP(i, I, N) for (int i = I; i < N; ++i)
#define rep(i, N) REP(i, 0, N)

int main() {
    int N, M, C;
    cin >> N >> M >> C;
    int B[M], l;
    rep(i, M) {
        cin >> l;
        B[i] = l;
    }

    int ans = 0;
    int amount = 0;
    rep(i, N) {
        int A;
        rep(j, M) {
            cin >> A;
            amount += A * B[j];
        }
        if (amount + C > 0) ans++;
        amount = 0;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
ll i,j,k;
ll n,m;
ll x,y;
ll num[100005];
bool kano[100005];

int main(){
	cin>>n>>m;
	for(i=1;i<=n;i++){
		num[i]=1;
		if(i==1)kano[i]=true;
		else kano[i]=false;
	}
	for(i=0;i<m;i++){
		cin>>x>>y;
		if(kano[x] && num[x]!=1){
			kano[y]=true;
		}else if(kano[x] && num[x]==1){
			kano[x]=false;
			kano[y]=true;
		}
		num[x]--;
		num[y]++;
	}
	ll ans=0;
	for(i=1;i<=n;i++){
		if(kano[i])ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5760
N,X,Y = map(int,input().split())

ans = [0 for i in range(N+1)]

def calc_goal(start,goal):
    if goal <= X:
        return goal-start
    if goal <= Y:
        if X >= start:
            return min(goal-start,X-start+Y-goal+1)
        else:
            return min(start-X+Y-goal+1,goal-start)
    else:
        if X >= start:
            return X-start+goal-Y+1
        else:
            return min(start-X+goal-Y+1,goal-start)

for i in range(1,N):
    for j in range(i+1,N+1):
        ans[calc_goal(i,j)] += 1

for i in range(1,N):
    print(ans[i])

Measured memory_bytes: 3444
#include <stdio.h>

int main(){

    int n[110],x[110],ans,i,j,k,l,num=1;
    
    n[1]=1;
    x[1]=1;
     
    while(1){
	 scanf("%d",&n[num]);  	 
  	 scanf("%d",&x[num]);
   
     //printf ("num %d n= %d x %d\n",num,n[num],x[num]);
   	 	 
  	 if ((n[num]==0)&&(x[num]==0)) break;
  	 ++num;  	 
    }
  
  l=1;
  while(l<num){	 
    ans=0;
    for(i=1;i<=n[l]-2;++i){
	  for(j=i+1;j<=n[l]-1;++j){
		for(k=j+1;k<=n[l];++k){
	    if (i+j+k==x[l]) ans+=1;	
	    }   	     
	  }
    }	 	  
      printf ("%d\n",ans);
      ++l;
  }  	

	return 0;
}

Measured memory_bytes: 600
N = int( input() )
A = list(map(int, input().split() ))
S = sum(A)
odds = range(0,N,2)
Ans=[]
Ans.append(-S + 2*sum([s for s,num in zip(A, range(N)) if num in odds] ) )
for i in range(1,N):
    Ans.append(2*A[i-1]-Ans[i-1])
print(" ".join(map(str,Ans) ))

Measured memory_bytes: 19096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    string s; cin >> s;
    string t = s.substr(0,4);
    if(t == "YAKI") {cout << "Yes" << endl; return 0;}
    else {cout << "No" << endl; return 0;}
}


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

using lint = long long int;

lint target = (lint)1e18;
void solve() { 
    int n;
    cin >> n;
 
     lint ret = 1;
     bool ok = 0;
     bool f = 0;
     while(n --> 0) { 
         lint curr; cin >> curr;
         if(curr <= (target)/ret && !f) {  ;//comparing with the floor value is important here;;;
             ret*=curr;
         } else { 
            //  cout << -1 << '\n';
            //  return;
            f = 1;
         }

         if(curr == 0) { 
             ok = 1;
         }
     }

     if(ok) {
         cout << 0 << '\n';
         return ;
     }

     cout << (f?-1:ret) << '\n';
}

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

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K;
	cin >> N >> K;


	vector<Int> a(N);
	vector<Int> f(N);

	for (Int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	for (Int i = 0; i < N; i++) {
		cin >> f[i];
	}
	sort(f.begin(), f.end(), greater<Int>());

	Int ok = 1e12;
	Int ng = -1;
	while (abs(ok - ng) > 1) {
		Int mid = (ok + ng) / 2;

		Int cnt = 0;
		for (Int i = 0; i < N; i++) {
			if (a[i] * f[i] < mid)continue;
			else cnt += a[i] - mid / f[i];
		}
		(cnt <= K ? ok : ng) = mid;
    
	}
	cout << ok << "\n";
}


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

int main(){
    string s;
    cin >> s;
    ll l = s.size();
    map<char,ll> m;
    rep(i,l) m[s[i]]++;
    ll ans = l*(l+1)/2 + 1;
    for(auto x : m) ans -= x.second*(x.second+1)/2;
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 640
A = []
for _ in range(3):
    a1 = list(map(int, input().split()))
    A.append(a1)
N = int(input())
for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                A[j][k] = 0
s = 0
for i in range(3):
    if sum(A[i]) == 0:
        s = 1
for i in range(3):
    if A[0][i] + A[1][i] + A[2][i] == 0:
        s = 1
if A[0][0] + A[1][1] + A[2][2] == 0:
    s = 1
if A[0][2] + A[1][1] + A[2][0] == 0:
    s = 1
    
if s == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define INF 2140000000
#define MOD 1000000007

int main() {
	int n, count[26] = {0};
	long long ans = 1;
	string s;

	cin >> n >> s;

	for (int i = 0; i < s.size(); ++i) {
		count[s[i]-'a']++;
	}

	for (int i = 0; i < 26; ++i) {
		ans = (ans * (count[i] + 1)) % MOD;
	}

	ans--;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        a: u64, b: u64, k: u64
    }

    if b+1-a > 2*k {
        for i in a..a+k {
            println!("{}", i);
        }
        for i in b-k+1..b+1 {
            println!("{}", i);
        }
    } else {
        for i in a..b+1 {
            println!("{}", i);
        }
    }
}

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

int l;
long long a[200005];
long long dp[200005][5];
constexpr long long big = 1000000000000000;
int main()
{
	std::cin >> l;
	for (int i = 0; i < l; ++i)
		std::cin >> a[i];

	for (int i = 0; i <= l + 1; ++i)
		for (int j = 0; j <= 4; ++j)
			dp[i][j] = big;

	dp[0][0] = 0;
	for (int i = 0; i < l; ++i) {
		dp[i + 1][0] = dp[i][0] + a[i];
		dp[i + 1][1] = std::min(dp[i][0], dp[i][1]) + (a[i] ? a[i] % 2 : 2);
		dp[i + 1][2] = std::min({ dp[i][0],dp[i][1],dp[i][2] }) + (a[i] ? !(a[i] % 2) : 1);
		dp[i + 1][3] = std::min({ dp[i][0],dp[i][1],dp[i][2],dp[i][3] }) + (a[i] ? a[i] % 2 : 2);
		dp[i + 1][4] = std::min({ dp[i][0],dp[i][1],dp[i][2],dp[i][3],dp[i][4] }) + a[i];
	}

	long long ans = big;
	for (int i = 0; i <= 4; ++i)
		ans = std::min(ans, dp[l][i]);

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


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int n, a[100010], kane[1000010][2];

int main(void){
    cin >> n;
    a[0] = 0;
    a[n+1] = 0;
    int sum = 0;
    for(int i=1;i<=n;++i){
        cin >> a[i];
        sum += abs(a[i]-a[i-1]);
    }
    sum += abs(a[n]-0);
    for(int i=1;i<=n;++i){
        cout << (sum-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i-1]-a[i+1])) << endl;
    }
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
using namespace std;
using namespace boost::range;
using boost::irange;

using ll = int64_t;
constexpr char LN = '\n';
template<class T> bool chmax(T& a, const T& b) {if(a<b){a=b;return true;}else{return false;}}
template<class T> bool chmin(T& a, const T& b) {if(b<a){a=b;return true;}else{return false;}}

#ifdef LOCAL
template<class H> void dump_(const char* s, H h) {cout<<s<<"="<<h<<LN; }
template<class H, class... T> void dump_(const char* s, H h, T... t) {for(;*s!=',';++s){cout<<*s;}cout<<"="<<h<<",";dump_(++s,t...);}
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#endif

struct init_ {init_(){ 
    cin.tie(nullptr); ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}} init_;

template<class C> C scan(size_t n) {C c(n);for(auto& v:c){cin>>v;}return c;}
template<class C> C scan(size_t n, size_t m) {C vss(n);for(auto& vs:vss){vs.resize(m);for(auto& v:vs){cin>>v;}}return vss;}

template<class R> struct Joined { const R& r; const char* s; };
template<class R> Joined<R> joined(const R& r, const char* s = " ") {return{r,s};}
template<class R> ostream& operator<<(ostream& out, Joined<R> j) {bool f=true;for(const auto& v:j.r){if(f){f=false;}else{out<<j.s;}out<<v;}return out;}

template<class T> using matrix = vector<vector<T>>;
template<class T> matrix<T> make_matrix(size_t n, size_t m, const T& init = T()) {matrix<T> vss(n);for(auto& vs:vss){vs.resize(m,init);}return vss;}
template<class T> ostream& operator<<(ostream& out, Joined<matrix<T>> j) {bool a=true;for(const auto& vs:j.r){if(a){a=false;}else{out<<LN;}bool f=true;for(const auto& v:vs){if(f){f=false;}else{out<<j.s;}out << v;}}return out;}

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<int>> choco(H);
    for (int i : irange(0, H)) {
        choco[i].resize(W);
        for (int j : irange(0, W)) {
            char c;
            cin >> c;
            choco[i][j] = (c - '0');
        }
    }
    int min_cut_num = numeric_limits<int>::max();
    const unsigned max_h_cut = (1 << H - 1);
    vector<int> h_part(H);
    for (unsigned h_cut = 0; h_cut < max_h_cut; h_cut++) {
        fill(h_part, 0);
        int cut_num = __builtin_popcount(h_cut);
        int last_cut_w = -1;
        for (int w = 0; w < W; w++) {
            bool over = false;
            for (int h = 0, h_part_i = 0; h < H; h++) {
                h_part[h_part_i] += choco[h][w];
                if (h_part[h_part_i] > K) {
                    over = true;
                    break;
                }
                if (h_cut & (1 << h)) {
                    h_part_i++;
                }
            }
            if (over) {
                if (last_cut_w == w) {
                    cut_num = numeric_limits<int>::max();
                    break;
                } else {
                    fill(h_part, 0);
                    cut_num++;
                    last_cut_w = w;
                    w--;
                }
            }
        }
        chmin(min_cut_num, cut_num);
    }
    cout << min_cut_num << LN;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    ll n,m;
    cin>>n>>m;
    if(2*n<m){
        cout<<(n+(m/2))/2<<endl;
    }else{
        cout<<m/2<<endl;
    }    
    return 0;
}

Measured memory_bytes: 256