akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int h=sc.nextInt();
		int w=sc.nextInt();
		int k=sc.nextInt();
		char[][] fig=new char[h][w];
		for(int i=0; i<h; i++){
			fig[i]=sc.next().toCharArray();
		}
		int ansm=1010;
		label:
		for(int i=0; i<1<<(h-1); i++){
			int[][] a=new int[h][w];
			int jh=0;
			int ans=Integer.bitCount(i);
			for(int t=0; t<h; t++){
				for(int j=0; j<w; j++){
					a[jh][j]+=fig[t][j]-'0';
				}
				if((i>>t & 1)==1){
						jh++;
				}
			}
			int[] sum=new int[h];
			int front=0;
			for(int j=0; j<w; j++){
				for(int t=0; t<h; t++){
					sum[t]+=a[t][j];
					if(sum[t]>k){
						if(j==front){
							continue label;
						}
						front=j;
						Arrays.fill(sum,0);
						ans++;
						j--;
						break;
					}
				}
			}
			ansm=Math.min(ansm,ans);
		}
		System.out.println(ansm);
	}
}


Measured memory_bytes: 39244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  string s,t,u;
  cin >> s >> t >> u;
  int slide = 'A' - 'a';
  char S = s[0] + slide;
  char T = t[0] + slide;
  char U = u[0] + slide;
  cout << S << T << U << endl;
}

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

int main() {
    string S;
    cin >> S;
    if (S[0] != S[1] && S[1] != S[2] && S[2] != S[0]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll i,j;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin>>s;
    string s1=s.substr(0,s.length()-8);
    cout<<s1<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int main() {
  int test;
  scanf("%d", &test);
  while (test--) {
    int sx, sy, w, h, n;
    scanf("%d %d %d %d %d", &sx, &sy, &w, &h, &n);
    int ans = 0;
    REP(iter, n) {
      int x, y;
      scanf("%d %d", &x, &y);
      if (sx <= x && x <= sx + w && sy <= y && y <= sy + h) { ans++; }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 0
package main

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

const p = 998244353

func Solve() {
  var N, K int
  NextInt(&N, &K)
  LR := make([][]int, K)
  for i := range LR { NextIntSlice(&LR[i]) }
  P := make([]int, N + 1)
  P[1]++; P[2]--
  for i := 1; i <= N; i++ {
    P[i] = (P[i - 1] + P[i]) % p
    if P[i] == 0 { continue }
    for _, lr := range LR {
      j := i + lr[0]
      if j > N { continue }
      P[j] = (P[j] + P[i]) % p
      j = i + lr[1] + 1
      if j > N { continue }
      P[j] = (P[j] - P[i] + p) % p
    }
  }
  Write(P[N])
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]int, 0)
    return
  }
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]float64, 0)
    return
  }
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  fmt.Fprintln(writer, B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 3448
from fractions import gcd
from math import sqrt
def div(a):
    ret = set()
    for i in range(1,int(sqrt(a))+1):
        if a % i == 0: ret.add(i); ret.add(a/i);
    return sorted(ret)
n = input()
l = map(int, raw_input().split())
ans = div(reduce(gcd,l))
for i in ans: print i

Measured memory_bytes: 7972
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n, k;
	string s;
	cin >> n >> k >> s;
	for(int i = 0; i < n; i++) {
		if(k - 1 == i) cout << (char)tolower(s[i]);
		else cout << s[i];
	}	
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll n, k; cin >> n >> k;
  V a(n);
  cin >> a;

  // cout << a << "\n";

  // rep(_, k) {
  //   V b(n);
  //   rep(i, n) rep(j, n) if (a[j] >= abs(i-j)) ++b[i];
  //   swap(a, b);
  //   cout << a << "\n";
  // }

  rep(_, k) {
    V b(n);
    rep(i, n) {
      ++b[max(int(i)-a[i], 0)];
      if (i+a[i]+1 < n) --b[i+a[i]+1];
    }
    rep(i, n-1) b[i+1] += b[i];
    swap(a, b);

    if (*min_element(all(a)) == n) {
      rep(i, n) cout << n << " ";
      cout << "\n";
      return 0;
    }
  }

  cout << a << "\n";
  return 0;
}


Measured memory_bytes: 4744
using System;
using System.Linq;

class A
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		Console.ReadLine();
		var s = Read();
		Console.ReadLine();
		var t = Read();
		Console.WriteLine(s.Intersect(t).Count());
	}
}



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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int l, r;
  cin >> l >> r;

  ll result = INT_MAX;
  for (int i = l; (i < r && i <= (l + 2019)); ++i) {
    for (int j = i + 1; j <= r && j <= (i + 1 + 2019); ++j) {
      result = min(result, ((ll) i * j) % 2019);
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

long int n,m;
vector<vector<long int>> g;
vector<bool> visited;
vector<long int> parent;

void BFS(long int root){
  visited[root] = true;

  queue<long int> q;
  q.push(root);

  while(q.size()){
    auto ele = q.front();
    q.pop();

    for(auto e : g[ele]){
      if(visited[e])
        continue;
      visited[e] = true;
      q.push(e);
      parent[e] = ele;
    }
  }
}


int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   cin>>n>>m;
   g.resize(n);
   parent.resize(n);
   visited.resize(n);

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

   BFS(0);

   for(auto ele : visited)
    if(!ele)
      return cout<<"No", 0;

   cout<<"Yes\n";
   for(long int i = 1; i < n; i++)
     cout<<parent[i] + 1<<endl;

   return 0;
}

Measured memory_bytes: 12948
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  if(n<105){
    cout << 0 << endl;
  }
  else if(n<135){
    cout << 1 << endl;
  }
  else if(n<165){
    cout << 2 << endl;
  }
  else if(n<189){
    cout << 3 << endl;
  }
  else if(n<195){
    cout << 4 << endl;
  }
  else{
    cout << 5 << endl;
  }

}


Measured memory_bytes: 256
#include <stdio.h>
#define MOD 1000000007
long long int power(long long int a, long long int b)
{
	long long int ans = 1;
	long long int s = a;
	while(b)
	{
		if(b%2==1) ans*=s, ans%=MOD;
		s*=s, s%=MOD;
		b/=2;
	}
	return ans;
}
long long int inv(long long int k)
{
	return power(k,MOD-2);
}
int main()
{
	int a;
	scanf("%d",&a);
	long long int S1 = 0, S2 = 0;
	for(int i=1;i<=a;i++)
	{
		long long int b;
		scanf("%lld",&b);
		S1 += b, S1%=MOD;
		S2 += b*b, S2%=MOD;
	}
	S1 = S1*S1, S1%=MOD;
	printf("%lld\n",(S1-S2+MOD)*inv(2)%MOD);
}

Measured memory_bytes: 1728
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024
var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt()
	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	alice, bob := 0, 0
	for i := 0; i < n; i++ {
		if i % 2 == 0 {
			alice += a[i]
		} else {
			bob += a[i]
		}
	}
	fmt.Println(alice-bob)
}

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

int main(){
  char str[201];
  cin >> str;
  int n = strlen(str);
  for(int i=n-2;i;i-=2){
    if(strncmp(str,str+i/2,i/2) == 0){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
  
  
}


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

int main() {
    int N, K;
    cin >> N >> K;
    int ans = 1;
    for (int i = 0; i < N; ++i) {
        if (ans * 2 < ans + K) {
            ans *= 2;
        } else {
            ans += K;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 char s[100005],b[100005];
int main()
{
   int t,i,count=0;

   scanf("%d", &t);
   for(i=0;i<=t;i++)
   {
       scanf("%c", &s[i]);
   }
   for(i=0;i<t;i++)
   {
       if(s[i]!=s[i+1])
       {
          count++;
       }
   }
   if(t==1)
   {
       count=1;
   }

  if(t==2)
  {
      if(s[1]==s[2])
      {
          count=1;
      }
      else
      {
          count=2;
      }
  }

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


     return 0;
 }


Measured memory_bytes: 256
// Code for B - Multiple of 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,x,y) for(ll i=x;i<(ll)(y);i++)

#define MOD 1000000007
#define mod(x) ( (x) % MOD + MOD ) % MOD

#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T, typename U> void view(const std::map<T, U>& m){ for(const auto& e : m){ std::cout << e.first << "=>" << e.second << " "; } std::cout << std::endl; }

int main() {
  string S;
  cin >> S;

  ll total = 0;
  REP(i, S.length()) {
    ll n = (ll)(S[i] - '0');
    total += n;
  }

  if (total % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3720
import java.util.Scanner;

/**
 * @author yoshida3203
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
//		String str="ABCDE";
//		char[]a=str.toCharArray();
//		System.out.println(a);
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[]H=new int[N];

		for(int i=0;i<H.length;i++){

			H[i]=sc.nextInt();
	}
		sc.close();

		int ans=1;
		int max=H[0];

		for(int i=1;i<H.length;i++){
			if(max<=H[i]){
				max=H[i];
				ans++;
			}
		}System.out.println(ans);

	}
}

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

int abs(int x, int y) {
  if (x < y) {
    return y-x;
  }
  else{
    return x-y;
  }
}
int main(){
  int N;
  cin >>N;
  vector<int> V(N),C(N);
  for(int i =0;i<N; i++){
    cin >> V.at(i);
  }
  for(int i =0;i<N; i++){
    cin >> C.at(i);
  }
  vector<int> sa(N);
  int max =0;
  for(int i =0;i<N;i++){
    sa.at(i) =V.at(i)-C.at(i);
  }
  for(int i =0;i<N;i++){
    if(sa.at(i) >= 0){
      max += sa.at(i);
    }
  }
  cout << max <<endl;
  
}

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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};
using namespace std;
void solve(){
   int a,b;
   cin>>a>>b;
    cout<<(a*b)-(a+b)+1;  
}

int main(){
    std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)

t = s[0:(n-1)//2]
l = s[1+(n-1)//2::]

flag = 1
for i in range(len(t)//2):
  if t[i] != t[-i-1]:
    flag = 0

if t == l and flag == 1:
  print("Yes")
else:
  print("No")

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

using namespace std;
using ll = long long;

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

  ll a;
  string s;
  cin >> a >> s;
  auto comma = s.find('.');
  ll b = stoi(s.substr(0, comma) + s.substr(comma + 1, 2));
  cout << (a * b) / 100 << endl;

  return 0;
}


Measured memory_bytes: 3656
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;

int main()
{
	int n,k;
	cin>>n>>k;
	vi A(n);
	take(A,0,n);

	int low = 1,high = MOD;
	int ans;
	while(low<=high)
	{
		int mid = low+(high-low)/2;
		int cuts = 0;
		for(int i=0;i<n;i++)
		{
			cuts += (A[i]-1)/mid;
		}
		if(cuts<=k)
		{
			ans = mid;
			high = mid-1;
		}
		else low=mid+1;
	}
	cout<<ans<<endl;
}	

Measured memory_bytes: 4016
# include<iostream>
# include<vector>
# include<time.h>
# include<random>
using namespace std;
using vector1 = vector<int>;
using vector2 = vector<vector1>;
int last(int d, int j, vector1 t){ //d日目から数えてタイプjのコンテストが最後に開催された日を計算
  for(int i=d; i>=1; i--){
    if(t[i] == j) return i;
  }
  return 0;
}
int penalty(vector1 c, int d, vector1 t){ //ペナルティの合計を計算
  int m = 0;
  for(int i=1; i<=26; i++){
    m += c[i] * (d - last(d, i, t));
  }
  return m;
}
int calc_score(int d, int j, int c, vector1 t){ //開催されるコンテストが変更された場合のスコア差を算出
  int s = 1;
  if(d > 1) s = d - last(d-1, j, t);

  int r = s * c; //1日分のスコア差
  int sum = 0;  //スコア差の合計
  int i = d;
  do{
    sum += r;
    i++;
    if((int)t.size() < i) break;
  }while(t[i] != j);
  return sum;
}
void swap_(int d1, int d2, vector1& t){
  int tmp = t[d1]; t[d1] = t[d2]; t[d2] = tmp;
  return;
}
int main(){
  clock_t start = clock();
  int D; cin >> D; //日数d
  vector1 c(26+1, 0); for(int i=1; i<=26; i++) cin >> c[i]; //ペナルティc
  vector2 s(D+1, vector1(26+1)); //あるコンテストが開催された場合の満足度s
  for(int i=1; i<=D; i++){
    for(int j=1; j<=26; j++){
      cin >> s[i][j];
    }
  }
  vector1 t(D+1, 0); for(int i=1; i<=D; i++) t[i] = (i % 26) + 1;
/*  vector1 v(D+1, 0); //スコアv
  for(int i=1; i<=D; i++){
    v[i] = s[i][t[i]];
    v[i] -= penalty(c, i, t);
  }*/
  int score = 0;
  for(int i=1; i<=D; i++){
    score += s[i][t[i]];
    score -= penalty(c, i, t);
  }
  clock_t end = clock();
//  cout << score <<"\n";
  random_device random_a;
  auto num = random_a();
  mt19937 random_b;
  //num = 3180901575;
  random_b.seed(num);
//  cout <<"num: "<< num <<"\n";

  while((double)(end - start) / CLOCKS_PER_SEC < 1.9){
    int r = (int)random_b();
    if(r > 0){
      int p = ((int)random_b() * random_b() % 26) + 1;
      int d = ((int)random_b() * random_b() % D) + 1;
      int old = t[d];
      t[d] = p;
      int up = calc_score(d, p, c[p], t); //増えるスコア
      int down = calc_score(d, old, c[old], t); //減るスコア
      int l = up - down + s[d][p] - s[d][old];
      if(l > 0){
        score += l;
      }else{
        t[d] = old;
      }
    }else{
      int d1 = ((int)random_b() * random_b() % D) + 1;
      int d2 = ((int)random_b() * random_b() % D) + 1;
      int l_old_d1 = calc_score(d1, t[d1], c[t[d1]], t);
      int l_old_d2 = calc_score(d2, t[d2], c[t[d2]], t);
      //cout << t[d1] <<"  "<< t[d2] <<"\n";
      swap_(d1, d2, t);
      //cout << t[d1] <<"  "<<t[d2] <<"\n";
     // break;
      int l_d1 = calc_score(d1, t[d1], c[t[d1]], t);
      int l_d2 = calc_score(d2, t[d2], c[t[d2]], t);
      int l = l_d1 + l_d2 - l_old_d1 - l_old_d2 + s[d1][t[d1]] - s[d1][t[d2]] + s[d2][t[d2]] - s[d2][t[d1]];
      if(l >0){
        score += l;
      }else{
        swap_(d1, d2, t);
      }
    }
    end = clock();
  }
  for(int i=1; i<=D; i++){
    cout << t[i] <<"\n";
  }
  /*cout << score <<"\n";
  int score2=0;
  for(int i=1; i<=D; i++){
    score2 += s[i][t[i]];
    score2 -= penalty(c, i, t);
  }
  cout <<score2 <<"\n";*/
  return 0;
}


Measured memory_bytes: 3264
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> T keta(T num){ T k=0; while(num>0){ num/=10; k++; } return k; }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int n;
    string s, t;
    cin >> n >> s >> t;

    int ind = 0;
    reps(i, 0, n-1){
        bool flg = true;
        int sind = i;
        reps(j, 0, n-1-i){
            if(s[sind] != t[j]){
                flg = false;
                break;
            }
            sind++;
        }
        if(flg) break;
        ind++;
    }

    cout << n+ind << endl;

    return 0;
}


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

            #define rep(i,a,b) for(int i=a;i<b;i++)
            #define repe(i,a,b) for(ll i=a;i>=b;i--)

            #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

            #define ll long long
            #define ld long double

            #define V vector<ll>
            #define pp pair<ll,ll>
            #define pb push_back
            #define mp make_pair
            #define Pr pair<ll,ll>
            #define all(A) A.begin(),A.end()
            #define allr(A) A.rbegin().A.rend()
            #define ff first
            #define ss second
            #define len length()
            ll max3(ll a,ll b,ll c)
            {
                if(a>=b&&a>=c)
                    return a;
                else if(b>=a&&b>=c)
                    return b;
                else
                    return c;
            }
            int min3(int a,int b,int c)
            {
                if(a<=b&&a<=c)
                    return a;
                else if(b<=a&&b<=c)
                    return b;
                else
                    return c;
            }
            ll binarySearch(ll arr[], ll l, ll r, ll x)
            {      ll mid = l + (r - l) / 2;
                if (r >= l) {


                    if (arr[mid] == x)
                        return mid;

                    if (arr[mid] > x)
                        return binarySearch(arr, l, mid - 1, x);


                    return binarySearch(arr, mid + 1, r, x);
                }

                return mid;
            }
            vector<ll> divisors(ll n)
            {   vector<ll> v;
                for(ll i=1;i*i<=n;i++)
                 {
                     if(n%i==0)
                     {
                         if(n/i==i)
                            v.pb(i);
                         else
                            v.pb(i),v.pb(n/i);
                     }
                 }
                 return v;
            }
            vector<ll> factors(ll n)
            {   vector<ll> v;
              ll f=n;
                for(ll i=2;i<=sqrt(f);i++)
                {
                    if(n%i==0)
                        while(n%i==0)
                            {
                                v.pb(i);
                                n=n/i;
                            }
                }
                if(n!=1)
                v.pb(n);
                return v;
            }
            int main()
            {
                    
                        string s,t;
                        cin>>s>>t;
                        ll cnt=0;
                        rep(i,0,s.size())
                        {
                            if(s[i]!=t[i])
                                cnt++;
                        }
                    cout<<cnt<<endl;
                return 0;
            }


Measured memory_bytes: 3964
#include<bits/stdc++.h>
#define mz 998244353
#define pq priority_queue
using namespace std;

long long gg[205];

int main()
{
    for(long long i=1;i<=200;i++)
        gg[i]=i*i*i*i*i;
    long long x;
    bool f=1;
    scanf("%lld",&x);
    for(int i=0;i<=200 && f;i++)
        for(int j=0;j<=200 && f;j++)
        {
            if(gg[i]-gg[j]==x)
            {
                printf("%d %d\n",i,j);
                f=0;
            }
            else if(gg[i]+gg[j]==x)
            {
                printf("%d %d\n",i,-j);
                f=0;
            }
        }
    return 0;
}


Measured memory_bytes: 3824
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;



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

	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	sort(rall(a));

	int ans1, ans2;
	ans1 = ans2 = 0;
	rep(i, n) {
		if (i % 2 == 0) {
			ans1 += a[i];
		}
		else {
			ans2 += a[i];
		}
	}

	int ans = ans1 - ans2;
	cout << ans << endl;

	return 0;
}
 

Measured memory_bytes: 256
A,B = map(int,input().split())
grid = 100
tizu = []
for i in range(grid):
  tori = ["."] * 100
  tizu.append(tori)
a = 0
b = 0
if A == 1:
  tizu[1][0] = "#"
while A > 1:
  tizu[0+b][1+a] = "#"
  tizu[1+b][0+a] = "#"
  tizu[1+b][1+a] = "#"
  a += 2
  A -= 1
  if a >= 98:
    b += 2
    a = 0
a = 0
b = 0
while B > 1:
  tizu[99-b][0+a] = "#"
  a += 2
  B -= 1
  if a >= 98:
    b += 2
    a = 0
print(grid,grid)
for i in range(grid):
  print(''.join(tizu[i]))

Measured memory_bytes: 3192
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(b<10) a=a*10+b;
	else if(b<100) a=a*100+b;
	else a=a*1000+b;
	int t=sqrt(a);
	if(t*t==a) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

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

    if(N % 2 == 0){
        cout << (float)1/2 << endl;
    }

    else{
        cout << (float)((N/2)+1)/N << endl;
     }
    return 0;

}
    
    

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();

		String[] array = s.split("");
		long ans = 0L;
		long tmp = 0L;

		for(int i = 0;i<s.length();i++) {
			if(array[i].equals("W")) {
				ans = ans + tmp;
			}else {
				tmp = tmp + 1L;

			}
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 53484
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

int n, dp[200001];
vector<pair<i64, i64>> ps;
int main() {
    cin >> n;
    ps.resize(n);

    map<i64, int> mp;
    for (int i = 0; i < n; ++i) {
        i64 x, l;
        cin >> x >> l;
        mp[x - l] = mp[x + l] = 0;
        ps[i] = {x - l, x + l};
    }
    int c = 1;
    for (auto& p : mp) {
        mp[p.first] = c++;
    }
    for (int i = 0; i < n; ++i) {
        ps[i].first = mp[ps[i].first];
        ps[i].second = mp[ps[i].second];
    }
    sort(begin(ps), end(ps), [](auto p, auto q) { 
        return p.second < q.second; 
    });

    for (int i = 1, j = 0; i <= 2 * n; ++i) {
        dp[i] = dp[i - 1];
        while (j < n && ps[j].second == i) {
            // cerr << j << ' ' << i << endl;
            int a, b;
            tie(a, b) = ps[j];
            dp[b] = max(dp[b], dp[a] + 1);
            ++j;
        }
    }

    cout << dp[2 * n] << endl;
    return 0;
}

Measured memory_bytes: 15736
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int h,w,n;
  cin>>h>>w>>n;
  pair<int, int> p[n];
  int ans = h;
  rep(i,n) cin>>p[i].first>>p[i].second;
  sort(p, p + n);
  int k = 1;
  rep(i,n) {
    if(p[i].first == p[i].second + k - 1) {
      k++;
    } else if(p[i].first >= p[i].second + k) {
      ans = min(ans, p[i].first - 1);
    }
  }
  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 1792
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {
	lli N, L,eat;

	cin >> N >> L;

	lli R = N + L - 1;

	if (R <= 0) {
		eat = R;
	}
	else if (L >= 0) {
		eat = L;
	}
	else {
		eat = 0;
	}

	lli ans = L * N + N * (N - 1) / 2 - eat;

	COUT(ans);

	return 0;
}

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

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

int main() {
    int X,Y;
    cin >> X >> Y;
    if(X == 1 && Y == 1){
        cout << 1000000 << endl;
    }else{
        int res = 0;
        if(X==1) res+= 300000;
        if(X==2) res+= 200000;
        if(X==3) res+= 100000;
        if(Y==1) res+= 300000;
        if(Y==2) res+= 200000;
        if(Y==3) res+= 100000;
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    # print(a)
    if(n % 2 == 0):
        for i in range(n-1):
            if i % 2 == 0 and a[i] != a[i+1] or i % 2 == 1 and a[i]+2 != a[i+1]:
                print(0)
                exit(0)
        print(2**(n//2) % (10**9+7))
        exit(0)
    if a[0] != 0:
        print(0)
        exit(0)
    for i in range(1, n-1):
        if i % 2 == 0 and a[i]+2 != a[i+1] or i % 2 == 1 and a[i] != a[i+1]:
            print(0)
            exit(0)
    print(2**((n-1)//2) % (10**9+7))
    exit(0)


if __name__ == '__main__':
    main()

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

#include <cmath>
#include <cstdlib>

using namespace std;

int main(void){
    //
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i=0;i<n;i++){
        cin >> arr[i];
    }
    //input finish

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

    cout << arr[n-1] - arr[0] << endl;

    return 0;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**7)

n = int(input())
G = [[] for _ in range(n)]
for i in range(n-1):
  uvw = list(map(int, input().split()))
  u = uvw[0]-1
  v = uvw[1]-1
  w = uvw[2]
  G[u].append([v, w])
  G[v].append([u, w])
  
color = [-1]*n
def dfs(G, v, cur = 0):
  if color[v] == -1:
    
    color[v] = cur
    for next_v, w in G[v]:
     
      if color[next_v]==-1:
        if (w % 2 != 0):
          dfs(G, next_v, 1-cur)
        if (w% 2 == 0):
          dfs(G, next_v, cur)
        continue
      


        

for v in range(n):
  if color[v] != -1:
    continue
  else:
    dfs(G, v)


print(*color, sep='\n')
          
  

Measured memory_bytes: 95280
n, p = map(int, input().split())
s = input()

if 10%p==0:
    ans = 0
    for r in range(n):
        if int(s[r])%p == 0:
            ans += r+1
    print(ans)
    exit()

d = [0]*(n+1)
ten = 1

for i in range(n-1, -1, -1):
    a = int(s[i])*ten%p
    d[i] = (d[i+1]+a)%p
    ten *= 10
    ten %= p

cnt = [0]*p
ans = 0
for i in range(n, -1, -1):
    ans += cnt[d[i]]
    cnt[d[i]] += 1
print(ans)

Measured memory_bytes: 11076
N = int(input())
A = list(map(int, input().split()))

print(' '.join(map(str, A)))

for i in range(1, N):
    v = A[i]
    j = i - 1
    while j >=0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(' '.join(map(str, A)))



Measured memory_bytes: 5596
n=input()
lenn=len(n)
#print(lenn)

n1=n[0]
n2=n[1:]

if n2.count('9')==lenn-1:
    ans=int(n[0])+9*(lenn-1)
else:
    ans=int(n[0])-1+9*(lenn-1)
  
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, a, b;
    long long maxt = 0, maxa = 0;
    cin >> n;
    vector<int> sum(n);
    for(int i = 0; i < n; i++)
	{
        cin >> a >> b;
        sum.at(i) = a + b;
        maxt += b;
    }
    sort(sum.begin(), sum.end(), greater<int>());
    for(int i = 0; i < n; i++)
	{
        if(i % 2 == 0)
        maxa += sum.at(i);
    }
    cout << maxa - maxt << endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <math.h>
using namespace std;

int main(void){
 int N;
 cin >> N;
 char S[N];
 for(int i = 0;i<N;i++){
     cin >> S[i];
 }
 int t = 0;
 for(int i = 0;i < N/2;i++){
     if(S[i] == S[i+N/2]){
         t++;
     }
 }
 if(N%2 == 1){
    cout << "No" << endl;
 }else if(t == N/2){
    cout << "Yes" << endl;
 }else{
    cout << "No" << endl;
 }
 return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>

using namespace std;


int tate,yoko,taka,n;

double naname(int x, int y){
    return sqrt(x*x+y*y);
}

int main(){
    while(cin>>tate>>yoko>>taka){
        if(tate==0&&yoko==0&&taka==0)break;
        double min_naname=min(min(naname(tate, yoko),naname(tate, taka)),naname(yoko,taka));
        
        cin>>n;
        for(int i=0; i<n; i++){
            double iriguchi;
            cin>>iriguchi;
            if(iriguchi*2>min_naname)cout<<"OK"<<endl;
            else cout<<"NA"<<endl;
        }
        
        
    }
}

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

const int MAXNUM = 100000;

int main() {
	int n;
	cin >> n;
	int cnt[2][MAXNUM+1];
	rep(i,2) rep(j,MAXNUM+1) cnt[i][j] = 0;
	rep(i,n) {
		int v;
		cin >> v;
		cnt[i%2][v]++;	
	}
	int max_idx[2] = {0,0};
	int next_max_idx[2] = {0,0};
	int ans = 0;
	rep(i,2) rep(j,MAXNUM+1) if (cnt[i][j] >= cnt[i][max_idx[i]]) max_idx[i] = j;
	rep(i,2) rep(j,MAXNUM+1) if ((cnt[i][j] >= cnt[i][next_max_idx[i]]) && (j != max_idx[i])) next_max_idx[i] = j;
	//sort(cnt[0].begin(), cnt[0].end(), greater<int>());
	//sort(cnt[1].begin(), cnt[1].end(), greater<int>());
	if (max_idx[0] != max_idx[1]) {
		ans = n - cnt[0][max_idx[0]] - cnt[1][max_idx[1]];
		//ans = n - cnt[0][0] - cnt[1][0];
	}
	else {
		ans = min(n - cnt[0][next_max_idx[0]] - cnt[1][max_idx[1]], n - cnt[0][max_idx[0]] - cnt[1][next_max_idx[1]]);
		//ans = min(n - cnt[0][1] - cnt[1][0], n - cnt[0][0] - cnt[1][1]);
	}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


void eratosthenesbool(vector<bool> &prime,ll n){
    for (int i = 0; i < n; i++) prime[i] = 1;
    prime[0] = prime[1] = 0;
    for (int i = 0; i < n; i++){
        if(prime[i]){
            for(int j = i + i; j < n; j+=i){
                prime[j] = 0;
            }
        }
    }
}



int main() {
  ll q;
  cin >> q ;


  ll num =100001;

  vector<ll> l(q);
  vector<ll> r(q);

  for (int i = 0; i < q; ++i)
  {
    cin >> l[i] >> r[i];
  }

  vector<bool> primbool(num, false);
  eratosthenesbool(primbool,num-1);

  vector<ll> lis(num,0);

  for(ll i = 2;i<num;i++){
    lis[i] = lis[i-1];
    if ( primbool[i] == true && primbool[ (i+1)/2 ] ==true  && i%2==1 ){
      lis[i]++;
    }
  }


  for(int i=0;i<q;i++){
    cout << lis[r[i]] - lis[l[i]-1] <<endl;
  }

}




















Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  for(int i =0; i < N; i++){
    cin >> p[i];
  }
  vector<int> copy(N);
  for(int i =0; i < N; i++){
    copy[i] = p[i];
  }
  sort(copy.begin(),copy.end());
  int count = 0;
  for(int i =0; i < N; i++){
    if(p[i] != copy[i]){
      count ++;
    }
  }
  if(count == 2 || count == 0){
    cout << "YES";
  }
  else{
    cout << "NO";
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

inline unsigned nextSubset(unsigned S, unsigned U)
{
  return (S - U) & U;
}

int n, m, p;
int g[100][100];
double memo[1 << 14];
int cnt[1 << 14];
double P[200];

double calc(int use) {
  assert(use != 0);
  if (!isnan(memo[use])) { return memo[use]; }
  double ret = 1;
  for (int divide = use & -use; divide != use; divide = nextSubset(divide, use)) {
    if ((divide & 1) != 1) { continue; }
    int c = cnt[divide] + cnt[use ^ divide] - cnt[((1 << n) - 1) ^ use];
    c /= 2;
    ret -= calc(divide) * P[c];
  }
  //cout << use << " " << ret << endl;
  return memo[use] = ret;
}

int main() {
  while (scanf("%d %d %d", &n, &m, &p) > 0) {
    P[0] = 1.0;
    REP(i, 110) { P[i + 1] = P[i] * p / 100.0; }
    MEMSET(memo, -1);
    MEMSET(g, 0);
    MEMSET(cnt, 0);
    REP(i, m) {
      int f, t;
      scanf("%d %d", &f, &t);
      f--; t--;
      g[f][t]++; g[t][f]++;
    }
    REP(use, 1 << n) {
      REP(f, n) {
        if (!((use >> f) & 1)) { continue; }
        REP(t, n) {
          if ((use >> t) & 1) { continue; }
          cnt[use] += g[f][t];
        }
      }
    }
    double ans = calc((1 << n) - 1);
    printf("%.10f\n", ans);
  }
}

Measured memory_bytes: 1072
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	int a;
	cin >> a;
	string s;
	cin >> s;

	if (a >= 3200) {
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}

	return 0;
}

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

int main(){
  int N;
  int t[100001], x[100001], y[100001];
  cin >> N;
  t[0] = x[0] = y[0] = 0;
  for (int i = 0; i < N; i++) cin >> t[i+1] >> x[i+1] >> y[i+1];

  bool can = true;
  for (int i = 0; i < N; i++) {
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if (dt < dist) can = false;
    if (dist % 2 != dt % 2) can = false;
  }

  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
using namespace std;
#define LL long long
LL A, B, N;

int main() {
	scanf ( "%lld %lld %lld", &A, &B, &N );
	LL temp = A * N / B - A * ( N / B );
	if ( B - 1 > N ) return ! printf ( "%lld", temp );
	LL tmp = A * ( B - 1 ) / B;
	printf ( "%lld", max ( temp, tmp ) );	
	return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

int main(){
	ll a,b,c,d; cin>>a>>b>>c>>d;
	ll cc=b/c - (a+c-1)/c,dd=b/d - (a+d-1)/d;
	if (b/c==0 && (a+c-1)/c==1) cc = 0;
	if (b/d==0 && (a+d-1)/d==1) dd = 0;
	if (b/c!=0) cc++;
	if (b/d!=0) dd++;
	ll e = lcm(c,d);
	ll ee = b/e - (a+e-1)/e;
	if (b/e==0 && (a+e-1)/e==1) ee = 0;
	if (b/e!=0) ee++;
	cout << b-a+1 - cc - dd + ee << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int min = 1000;
    int max = 0;
    for (int i=0; i < n; i++) {
        int a = 0;
        cin >> a;
        if (max < a) {
            max = a;
        }
        if (min > a) {
            min = a;
        }
    }

    int ans = max - min;

    cout <<  ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans;
const int N=2e5+2999;
long long a[N],az;
int main(){
	//freopen("p.in","r",stdin);
	ios::sync_with_stdio;
	cin>>n;
	for(int i=1;i<=n;i++){
	cin>>a[i];
	a[i]-=i;
	}
	sort(a+1,a+1+n);
	if(n%2)az=a[n/2+1];else az=a[n/2];
	for(int i=1;i<=n;i++)
	ans+=abs(a[i]-az);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1920