akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

input = sys.stdin.readline
s = input()
odd = "R"
even = "L"
ans = 0

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == even:
            ans += 1
    else:
        if s[i] == odd:
            ans += 1

if ans == 0:
    print("Yes")
else:
    print("No")


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

int main()
{
    int A, B, C, K, ans = 0;
    cin >> A >> B >> C >> K;
    if(K <= A) ans += K;
    else{
        K -= A;
        ans += A;
        if(K > B){
            K -= B;
            if(K >= C) ans -= C;
            else ans -= K;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
s = input()

buf = [1]*len(s) # 各マスに一人いる状態

for i in range(len(buf)-2): 
  # RとLが隣り合っている場合は最終的に移動することは無いので、連続している場合のみを対象として移動を行う。
  if s[i] == "R" and s[i+1] == "R": 
    buf[i+2] += buf[i]
    buf[i] = 0
    
for i in range(len(buf)-1, 1, -1):
  if s[i] == "L" and s[i-1] == "L":
    buf[i-2] += buf[i]
    buf[i] = 0
    
print(" ".join(map(str, buf)))

Measured memory_bytes: 17176
#include <iostream>

using namespace std;

int route = 0;
int a, b, n;
bool road[17][17];

void dfs(int x, int y) {
	if (x == a && y == b) {
		route++;
		return;
	}
	if (x > a || y > b) return;
	if (road[y][x]) return;
	dfs(x + 1, y);
	dfs(x, y + 1);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (cin >> a >> b, a, b) {
		cin >> n;
		for (int y = 0; y < 17; y++)
			for (int x = 0; x < 17; x++)
				road[y][x] = false;
		while (n-- > 0) {
			int x, y;
			cin >> x >> y;
			road[y][x] = true;
		}
		route = 0;
		dfs(1, 1);
		cout << route << endl;
	}
}

Measured memory_bytes: 1188
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  long x;
  cin >> x;

  if (x < 1200)
    cout << "ABC" << endl;
  else
    cout << "ARC" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int A, B, C, D;//入力される値
  int S1, S2;//面積
  int max;
  scanf("%d %d %d %d", &A, &B, &C, &D);
  S1 = A*B;
  S2 = C*D;
  if(S1 > S2){
    max = S1;
  }else{
    max = S2;
  }
  printf("%d\n", max);
  return 0;
}

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

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;

ll a[10], x, ans;
int main()
{
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> a[6];                    
	
	x = 0;
	if(x >= 0 && x >= 0 && x <= a[0] && x <= a[3] && x <= a[4])
		ans = max(ans, (a[0] - x) / 2 * 2 + a[1] + (a[3] - x) / 2 * 2 + (a[4] - x) / 2 * 2 + x * 3);
	
	x = 1;
	if(x >= 0 && x <= a[0] && x <= a[3] && x <= a[4])
		ans = max(ans, (a[0] - x) / 2 * 2 + a[1] + (a[3] - x) / 2 * 2 + (a[4] - x) / 2 * 2 + x * 3);
	
	x = a[0];
	if(x >= 0 && x <= a[0] && x <= a[3] && x <= a[4])
		ans = max(ans, (a[0] - x) / 2 * 2 + a[1] + (a[3] - x) / 2 * 2 + (a[4] - x) / 2 * 2 + x * 3);
	
	x = a[0] - 1;
	if(x >= 0 && x <= a[0] && x <= a[3] && x <= a[4])
		ans = max(ans, (a[0] - x) / 2 * 2 + a[1] + (a[3] - x) / 2 * 2 + (a[4] - x) / 2 * 2 + x * 3); 	
	
	x = a[3];
	if(x >= 0 && x <= a[0] && x <= a[3] && x <= a[4])
		ans = max(ans, (a[0] - x) / 2 * 2 + a[1] + (a[3] - x) / 2 * 2 + (a[4] - x) / 2 * 2 + x * 3); 	
	
	x = a[4];
	if(x >= 0 && x <= a[0] && x <= a[3] && x <= a[4])
		ans = max(ans, (a[0] - x) / 2 * 2 + a[1] + (a[3] - x) / 2 * 2 + (a[4] - x) / 2 * 2 + x * 3); 	
	
	x = a[3] - 1;
	if(x >= 0 && x <= a[0] && x <= a[3] && x <= a[4])
		ans = max(ans, (a[0] - x) / 2 * 2 + a[1] + (a[3] - x) / 2 * 2 + (a[4] - x) / 2 * 2 + x * 3); 	
	
	x = a[4] - 1;
	if(x >= 0 && x <= a[0] && x <= a[3] && x <= a[4])
		ans = max(ans, (a[0] - x) / 2 * 2 + a[1] + (a[3] - x) / 2 * 2 + (a[4] - x) / 2 * 2 + x * 3); 	
	
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
package main

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

func abs(n int) int {
	if n < 0 {
		return -n
	} else {
		return n
	}
}

func main() {
	var sc = bufio.NewScanner(os.Stdin)	
	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	A := strings.Split(sc.Text(), " ")

	max := 0
	min := 1000000000
	for i := 0; i < N; i++ {
		tmp, _ := strconv.Atoi(A[i])
		if max < tmp {
			max = tmp
		}
		if min > tmp {
			min = tmp
		}
	}

	//fmt.Println(max, min)
	fmt.Println(abs(max - min))
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main ()
{
	int n,i,j;
	char s[1000];
	char v[1000];
	scanf("%d",&n);
	scanf("%s%s",s,v);
	for(i=0;i<n;i++)
	{
		printf("%c%c",s[i],v[i]);
		
	}
}

Measured memory_bytes: 128
def myAnswer(W:int,H:int,x:int,y:int) -> None:
   if(x+x==W and y + y == H):
      print(float(W)*float(H)/2,1)
   else:
      print(float(W)*float(H)/2,0)

def modelAnswer():
   return
def main():
   W,H,x,y = map(int,input().split())
   myAnswer(W,H,x,y)
if __name__ == '__main__':
   main()

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

vector< int> q[20];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        for (int j = 0; j < 20; ++j) if ((x >> j) & 1) q[j].emplace_back(i);
    }

    for(int i = 0; i < 20; ++i) q[i].emplace_back(n), q[i].emplace_back(n);

    long long int res = 0;
    for(int i = 0; i < n; ++i) {
        int k = n;
        for(int j = 0; j < 20; ++j) {
           auto it = lower_bound(q[j].begin(), q[j].end(), i);
           it++;
           //cerr << *it << endl;
           k = min(k, *it);
        }
        //cerr << i << ' ' << k << endl;
        res += k - i;
    }
    printf("%lld\n", res);
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

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 (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int r,g;
	cin >> r >> g;

	cout << 2 * g - r << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
using namespace std;

int main(){
  int N;
  cin >> N;
  int sum=0;
  int esc = N;
  while(esc){
    sum += esc%10;
    esc /= 10;
  }
  
  if(N%sum==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

#define lson l, m, rt*2
#define rson m + 1, r, rt*2+1
#define xx first
#define yy second

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;

const int N = 1e5 + 10;
LL a[N];

LL get_result(int sign, int n) {
    LL sum = 0, res = 0;
    for (int i = 1; i <= n; i++) {
        sum += a[i];
        if (sign) {
            if (sum >= 0) {
                res += sum + 1;
                sum = -1;
            }
        }
        else {
            if (sum <= 0) {
                res += -sum + 1;
                sum = 1;
            }
        }
        sign ^= 1;
    }
    return res;
}

int main() {
#ifdef JUDGE
    freopen("case.in", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        scanf("%lld", a + i);
    }
    cout << min(get_result(0, n), get_result(1, n)) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    ll l,r;
    cin >> l >> r;
    ll Min = LINF;
    if (r-l > 2019) {
        cout << 0 << endl;
        return 0;
    }
    else {
        for (ll i = l; i <= r; ++i) {
            for (ll j = i+1; j <= r; ++j) {
                ll sum = i%2019*j%2019;
                Min = min(sum, Min);
            }
        }
    }
    cout << Min << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var A, B int
var op string

func main() {
	fmt.Scan(&A, &op, &B)

	if op == "+" {
		fmt.Println(A + B)
	} else {
		fmt.Println(A - B)
	}
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}


Measured memory_bytes: 512
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    var pins = mutableSetOf<String>()

    for (i in 0..999) {
        val num = i.toString().padStart(3, '0')
        var idx = 0

        for (j in s.indices) {
            if (s[j] == num[idx]) {
                idx++

                if (idx == 3) {
                    pins.add(num)
                    break
                }
            }
        }
    }

    println(pins.size)
}

Measured memory_bytes: 39424
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        final int m = fs.nextInt();
        final int[] arr = fs.nextIntArray(n);
        final Map<Integer, Integer> remainders = new HashMap<>(Collections.singletonMap(0, 1));
        long sum = 0;
        long res = 0;
        for (int i = 0; i < n; i++) {
            sum = (sum + arr[i]) % m;
            final int r = (int) (sum % m);
            res += remainders.getOrDefault(r, 0);
            remainders.merge(r, 1, Integer::sum);
        }
        System.out.println(res);
    }

    static final class Util {
        public static void shuffleSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffleSort(long[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void shuffle(long[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            final int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        public static void swap(long[] x, int i, int j) {
            final long t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


Measured memory_bytes: 50828
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    String S = sc.next();
    StringBuilder sb = new StringBuilder();

    for(int i = 0 ; i < S.length() ; i ++ ){
      if( i % 2 == 0){
        sb.append( S.charAt(i) );
      }
    }

    System.out.println(sb);

  }
}


Measured memory_bytes: 24808
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

map<string, int> dic;

int d[] = {-1, 1, 4, -4};

void init(){
        string str = "01234567";
        dic[str] = 0;
        queue<string> que;
        que.push(str);
        while(!que.empty()){
                string n = que.front();
                que.pop();
                int p = 0;
                for (int i = 0; i < n.size(); i++){
                        if (n[i] == '0') p = i;
                }
                for (int i = 0; i < 4; i++){
                        int x = p + d[i];
                        if (x >= 0 && x <= 7 &&
                        !(p == 4 && x == 3) &&
                        !(p == 3 && x == 4)){
                                string temp = n;
                                swap(temp[p], temp[x]);
                                if (dic.find(temp) == dic.end()){
                                        dic[temp] = dic[n] + 1;
                                        que.push(temp);
                                }
                        }
                }
        }
}

int main(){
        init();
        string line;

        while (getline(cin, line)){
                remove(line.begin(), line.end(), ' ');
                line.erase(8, line.size());
                cout << dic[line] << endl;
        }
        return 0;
}

Measured memory_bytes: 5392
#include <iostream>

 using namespace std;

int main()
{
   int i, h, m, s;
   cin >> i;
   h = i / 3600;
   m = i / 60 - (h * 60);
   s = i % 60;
   cout << h << ":" << m << ":" << s << endl;

   return 0;
}


Measured memory_bytes: 3092
import numpy as np

n, k = map(int, input().split())

people = [0] * n

for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in a:
        people[j-1] += 1

people = np.array(people)
a = np.count_nonzero(people)
print(n - a)

Measured memory_bytes: 27136
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    ll n, m;
    cin >> n >> m;
    vl a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    ll cnt = 0, ans = 0;
    vector<ll> sum(n+1);
    rep(i, n) sum[i+1] = sum[i] + a[i];
    auto calc = [&](ll med) {
        cnt = 0, ans = 0;
        rep(i, n) {
            auto it = lower_bound(all(a), med-a[i]);
            ll cur = it - a.begin();
            ll cur_cnt = a.end() - it;
            ll cur_sum = sum[n] - sum[cur];
            cur_sum += cur_cnt*a[i];

            cnt += cur_cnt;
            ans += cur_sum;
        }
    };
    ll l = 0, r = 2e5+10;
    while(r - l > 1) {
        ll med = (l + r) / 2;
        calc(med);
        if(cnt >= m) l = med;
        else r = med;
    }
    
    calc(l);
    // cout << l <<  " " << r << " " << cnt << " "  << ans << endl;
    if(cnt > m) ans -= l * (cnt - m);
    cout << ans << endl;
    return 0;
}

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

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

    int p[N];
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }

    double exps[N];
    for (int i = 0; i < N; i++) {
        int sum = p[i]*(p[i]+1) / 2;
        exps[i] = double(sum) / double(p[i]);
    }

    double exp = 0.0;
    for (int i = 0; i < K; i++) {
        exp += exps[i];
    }

    double ans = exp;
    for (int i = 1; i < N - (K-1); i++) {
        exp = exp - exps[i-1] + exps[i+(K-1)];
        if (ans < exp) {
            ans = exp;
        }
    }

    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define all(x) begin(x), end(x)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int main(){
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    int X; cin >> X;
    if(X >= 30) cout << "Yes";
    else cout << "No";
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int s;
  cin>>s;
  vector<in> a(s+1,0);

  for(int i=3;i<=s;i++){
    a.at(i)=1;
    for(int j=3;j<i;j++){
      if(i-j<3) break;
      a.at(i)+=a.at(i-j);
      a.at(i)=a.at(i)%MOD;
    }
  }
  cout<<a.at(s)<<endl;
}

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

using namespace std;

int main()
{
    string s;
    int i;

    cin >> s;

    if (s == "AAA")
    {
        cout << "No" << endl;
    }
    else if (s == "BBB")
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

int main(){
    LL N,M;
    cin >> N >> M;
    if(N==1&&M==1) cout << 1;
    else if(N==1) cout << M-2;
    else if(M==1) cout << N-2;
    else if(N==2||M==2) cout << 0; 
    else cout << (N-2)*(M-2);
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
std::vector<std::vector<long long>> comb(int n, int r) {
  std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}
void solve(long long N, long long M){
  cout << comb(N,2)[N][2] + comb(M,2)[M][2] << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
}


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

ll inf=1ll<<60;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i,j,n,s=0,a[101]={0},t;
	bool q=false;
	cin>>n;
	for (i=0;i<n;i++){
		cin>>t;
		s+=t;
		a[t]++;
	}
	if (s%10!=0){
		cout<<s;
		q=true;
	}
	else {
		for (i=1;i<100;i++){
			if (a[i]>0&&i%10!=0){
				cout<<s-i;
				q=true;
				break;
			}
		}
	}
	if (q==false){
		cout<<"0";
	}
	return 0;
}

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

int main(void) {
    string A,B;
    cin>>A>>B;
    if (A.size() > B.size()) cout << "GREATER" << endl;
    else if (A.size() < B.size()) cout << "LESS" << endl;
    else {
        bool hit = false;
        for (int i = 0; i < A.size(); i++) {
            int a = stoi(to_string(A[i]));
            int b = stoi(to_string(B[i]));
            if (a > b) {
                cout << "GREATER" << endl;
                hit = true;
                break;
            } else if (a < b) {
                cout << "LESS" << endl;
                hit = true;
                break;
            }
        }
        if (!hit) cout << "EQUAL" << endl;
    }
    return 0;
}

Measured memory_bytes: 504
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

#a = list(map(int, input().split()))

robos = []
n = int(input())

for i in range(n):
    robos.append(list(map(int, input().split())))

robos.sort(key=lambda x:x[0]+x[1])

ans=0
prev=-999999999999
for i in range(n):
    if(prev<=robos[i][0]-robos[i][1]):
        ans+=1
        prev = robos[i][0]+robos[i][1]
        
print(ans)


Measured memory_bytes: 90964
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#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 <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long
#define mo 1000000007

char a[2][100];

int main()
{
  int i,j,n,pre;
  _int64 ans;
  scanf("%d",&n);
  scanf("%s%s",a[0],a[1]);
  ans=1;
  pre=-1;
  for (i=0;i<n;i++)
  {
    if (a[0][i]==a[1][i])
    {
      if (pre==-1)
      {
        ans*=3;
        ans%=mo;
      }
      else if (pre==0)
      {
        ans*=2;
        ans%=mo;
      }
      else
      {
      }
      pre=0;
    }
    else
    {
      if (pre==-1)
      {
        ans*=6;
        ans%=mo;
      }
      else if (pre==0)
      {
        ans*=2;
        ans%=mo;
      }
      else
      {
        ans*=3;
        ans%=mo;
      }
      pre=1;
      i++;
    }
  }
  printf("%lld\n",ans);
  return 0;
}

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

int main(){
  string S,T,U;
  int A,B;
  cin >> S >> T >> A >> B >> U;
  if(U == S){
    cout << A-1 << " " << B << endl;
  }
  else{
    cout << A << " " << B-1 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<char>> vec(h, vector<char>(w, 'a'));
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
        cin >> vec.at(i).at(j);
    }
  }
  for (int i = 0; i < h; i++) {
    for (int k = 0; k < 2; k++) {
        for(int j = 0; j < w; j++) {
            cout << vec.at(i).at(j);
        }
        cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int n, m;


int GCD(int a, int b){
    if(a < b) swap(a, b);
    if(b==0) return a;
    return GCD(b, a%b);
}
int main() {
    int n, K; cin >> n >> K;
    string s; cin >> s;

    s[K-1] = tolower(s[K-1]);
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String S = in.next();
            long K = in.nextLong();

            int c1 = count(S);
            int c2 = count(S + S);
            int c3 = count(S + S + S);

            out.println(c1 + (c2 - c1) * (K / 2) + (c3 - c2) * (Math.max(K - 1, 0) / 2));
        }

        int count(String S) {
            char[] cs = S.toCharArray();
            int cnt = 0;
            for (int i = 0; i < cs.length - 1; i++) {
                if (cs[i] == cs[i + 1]) {
                    cs[i + 1] = '@';
                    cnt++;
                }
            }
            return cnt;
        }

    }
}



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

int main() {
    string s, t; cin >> s >> t;
    int n = s.size(), m = t.size();

    for (int i = 0; i < n; i++) {
        bool flag = true;
        for (int j = 0; j < m; j++) {
            if (s[(i+j)%n] != t[j]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

const int MAX = 50;
int main() {
	int N, M;
	cin >> N >> M;
	string A[MAX], B[MAX];
	for (int i = 0;i < N;i ++) cin >> A[i];
	for (int i = 0;i < M;i ++) cin >> B[i];
	
	for (int i = 0;i < N - M + 1;i ++) {
		for (int j = 0;j < N - M + 1;j ++) { // (i,j)から(i+M-1, j+M-1)までの範囲がBと一致するか調べる
			bool include = true;
			for (int k = i;k < i + M;k ++) {
				for (int l = j;l < j + M;l ++) {
					if (A[k][l] != B[k - i][l - j]) { // もしBと一致しない部分があったら
						include = false;
						k = i + M;
						break;
					}
				}
			}
			if (include) { // もしBがAに含まれていたら
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

実際にBが入る全ての座標において、Bと一致するかどうか判定してみる
その時のオーダーはO((N-M)^2・M^2)なのでまぁ間に合うか
*/

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			
			final long K = sc.nextLong();
			
			long[] as = new long[N];
			long[] prefix_as = new long[N + 1];
			for(int i = 0; i < N; i++) { as[i] = sc.nextLong(); }
			
			long[] bs = new long[M];
			long[] prefix_bs = new long[M + 1];
			for(int i = 0; i < M; i++) { bs[i] = sc.nextLong(); }
			
			for(int i = 0; i < N; i++) {
				prefix_as[i + 1] += as[i];
				prefix_as[i + 1] += prefix_as[i];
			}
			for(int i = 0; i < M; i++) {
				prefix_bs[i + 1] += bs[i];
				prefix_bs[i + 1] += prefix_bs[i];
			}
			
			int answer = 0;
			for(int i = 0; i <= N; i++) {
				final long rest = K - prefix_as[i];
				if(rest < 0) { continue; }
				
				int pos = Arrays.binarySearch(prefix_bs, rest);
				if(pos < 0) { pos = -(pos + 2); }
				
				answer = Math.max(answer, i + pos);
			}
			
			System.out.println(answer);
			
			
			
			
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 68876
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, x, sum = 0;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> x;
    sum += (x < K-x ? x : K-x)*2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tii;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)


int main(){
  int N; cin >> N;
  ll sum = 0;
  ll cnt = 0;
  ll mn = 1000000000;
  for(int i=0;i<N;i++){
    ll x; cin >> x;
    if(x<0){
      x *= -1;
      cnt++;
    }
    sum += x;
    mn = min(mn,x);
  }
  if(cnt%2==1) sum -= 2*mn;
  cout << sum << endl;
}

Measured memory_bytes: 3596
program A331C
    implicit none
    integer(8)::N,c_all,ans,i
    integer(8),allocatable,dimension(:)::A
    read*,N
    allocate(A(N))
    read*,A
    c_all=abs(A(1))+abs(A(N))
    do i=1,N-1
        c_all=c_all+abs(A(i+1)-A(i))
    end do

    do i=1,N
        if(i==1)then
            ans=c_all-abs(A(1))-abs(A(2)-A(1))+abs(A(2))
        else if(i==N)then
            ans=c_all-abs(A(N)-A(N-1))-abs(A(N))+abs(A(N-1))
        else
            ans=c_all-abs(A(i+1)-A(i))-abs(A(i)-A(i-1))+abs(A(i+1)-A(i-1))
        end if
        print'(i0)',ans
    end do
end program A331C

Measured memory_bytes: 2816
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////



///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int n, m;
	cin >> n >> m;
	vector< vector<int> > s(m);
	for(int i = 0; i < m; i++){
		int k;
		cin >> k;
		s[i].resize(k);
		for(int j = 0; j < k; j++){
			cin >> s[i][j];
			--s[i][j];
		}
	}
	
	vector<int> p(m);
	for(int i = 0; i < m; i++){
		cin >> p[i];
	}
	
	int ans = 0;
	for(int i = 0; i < (1 << n); i++){
		bitset<32> bs(i);
		vector<int> counter(m, 0);
		for(int j = 0; j < m; j++){
			for(int k : s[j]){
				if(bs[k]){
					counter[j]++;
				}
			}
		}
		
		bool ok = true;
		for(int j = 0; j < m; j++){
			if(counter[j] % 2 != p[j]){
				ok = false;
			}
		}
		
		if(ok) ans++;
	}
	
	cout << ans << endl;
	
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n, k;
int hs[105];
int cp[105];
int dp[105][105];

const int mod = 1e9 + 7;

void add(int &x, llong y) {
    x += y % mod;
    x %= mod;
}

int mul(int x, int y) {
    return (llong)x * y % mod;
}

int pw(int x, int p) {
    if (p == 0) return 1;
    int ret = pw(x, p >> 1);
    ret = mul(ret, ret);
    if (p & 1) ret = mul(ret, x);
    return ret;
}

int solve(int s, int e) {
    dp[s - 1][0] = 1;
    for (int i = s; i <= e; ++i) {
        if (hs[i - 1] < hs[i]) {
            dp[i][0] = dp[i - 1][0];
            add(dp[i][0], dp[i][0]);
            
            for (int j = 1; j <= hs[i - 1]; ++j) {
                dp[i][j] = mul(dp[i - 1][j], pw(2, cp[hs[i]] - cp[hs[i - 1]]));
            }
            for (int j = hs[i - 1] + 1; j <= hs[i]; ++j) {
                dp[i][j] = mul(dp[i - 1][0], mul((pw(2, cp[j] - cp[j - 1]) + mod - 1 - (j == 1 ? pw(2, cp[j] - 1) : 0)) % mod, pw(2, cp[hs[i]] - cp[j] + 1)));
            }
        }
        else {
            dp[i][0] = dp[i - 1][0];
            for (int j = hs[i] + 1; j < k; ++j) {
                add(dp[i][0], dp[i - 1][j]);
            }
            add(dp[i][0], dp[i][0]);
            for (int j = 1; j <= hs[i]; ++j) {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    int ret = 0;
    for (int i = 0; i < k; ++i) {
        add(ret, dp[e][i]);
    }
    return ret;
}

int main() {
    scanf("%d", &n);
    vector<int> one;
    one.push_back(0);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", hs + i);
        if (hs[i] == 1) hs[i] = 0, one.push_back(i);
        cp[i] = hs[i];
    }
    one.push_back(n + 1);
    sort(cp, cp + (n + 1));
    k = unique(cp, cp + (n + 1)) - cp;
    for (int i = 1; i <= n; ++i) {
        hs[i] = lower_bound(cp, cp + k, hs[i]) - cp;
    }
    int ret = pw(2, one.size() - 2);
    for (int i = 1; i < one.size(); ++i) {
        ret = mul(ret, solve(one[i - 1] + 1, one[i] - 1));
    }
    printf("%d\n", ret);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = 1e5+7;
int a[maxn];

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

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


Measured memory_bytes: 512
class BinaryIndexedTree():
    def __init__(self, n):
        self.n = n
        self.tree = [0 for _ in range(n + 1)]

    def sum(self, idx):
        res = 0
        while idx:
            res += self.tree[idx]
            idx -= idx & -idx
        return res

    def add(self, idx, x):
        while idx <= self.n:
            self.tree[idx] += x
            idx += idx & -idx

from sys import stdin
input = stdin.buffer.readline

N, Q = map(int, input().split())
A = tuple(map(int, input().split()))

bit = BinaryIndexedTree(N)
res = list()

for i, a in enumerate(A):
    bit.add(i + 1, a)

for _ in range(Q):
    q, x, y = map(int, input().split())
    if q == 0:
        bit.add(x + 1, y)
    else:
        res.append(bit.sum(y) - bit.sum(x))

print('\n'.join(map(str, res)))

Measured memory_bytes: 189240
import sys
from collections import defaultdict

N = 10**6 + 1
p = list(range(N))
p[1] = 0
for i in range(2, int(N**.5) + 1):
    p[i * 2::i] = [0] * len(p[i * 2::i])

cart2num = {}


def cart2spi(x, y):
    size = max(abs(x), abs(y))
    if x + y > 0:
        num = (2 * size - 1) ** 2
        sx, sy = size, 1 - size
        num += y - sy + sx - x
    else:
        num = (2 * size) ** 2
        sx, sy = -size, size
        num += sy - y + x - sx
    return num


def spi2cart(n):
    root = int(n ** .5)
    diff = n - root ** 2
    if root % 2:
        x, y = root // 2 + 1, -root // 2 + 1
        dx, dy = -1, 1
    else:
        x, y = -root // 2, root // 2
        dx, dy = 1, -1
    x += dx * max(diff - root, 0)
    y += dy * min(diff, root)
    return x, y


def solve(max_p, s):
    prv = {spi2cart(s - 1): [1, s] if p[s] else [0, 0]}
    res = []
    while 1:
        nxt = defaultdict(lambda: [0, 0])
        for x, y in prv:
            ny = y - 1
            for dx in [-1, 0, 1]:
                nx = x + dx
                if (nx, ny) in cart2num:
                    num = cart2num[nx, ny]
                else:
                    num = cart2num[nx, ny] = cart2spi(nx, ny) + 1
                if num > max_p:
                    if dx == 0:
                        res.append(prv[x, y])
                    continue
                nxt_cnt, prv_cnt = nxt[nx, ny][0], prv[x, y][0]
                if p[num]:
                    if nxt_cnt < prv_cnt + 1:
                        nxt[nx, ny] = [prv_cnt + 1, num]
                    elif nxt_cnt == prv_cnt + 1:
                        nxt[nx, ny][1] = max(nxt[nx, ny][1], num)
                else:
                    if nxt_cnt < prv_cnt:
                        nxt[nx, ny] = prv[x, y]
                    elif nxt_cnt == prv_cnt:
                        nxt[nx, ny][1] = max(nxt[nx, ny][1], prv[x, y][1])
        if not nxt:
            break
        prv = nxt
    return max(res)


for e in sys.stdin.readlines()[:-1]:
    m, n = map(int, e.split())
    print(*solve(m, n))


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

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> a(n);

  for (auto &i : a) {
    std::cin >> i;
  }

  int64_t s = 0, e = 1, sum = a[0], count = 0;

  while (e != n) {
    while (e != n && (sum & a[e]) == 0) {
      sum += a[e];
      e++;
    }
    if (e != n) {
      sum -= a[s];
      count += e - s;
      s++;
    }
  }
  while (s != e) {
    count += e - s;
    s++;
  }

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

Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut ans = 0;
    for i in 1..=n {
        let x:usize = read();
        if i % 2 != 0 && x % 2 != 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2084
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",c);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int primes[200];
int prime[1000000];
int pr[100000];
int el[314514],wl[314514];
int er[314514],wr[314514];
int a[114514];
string s[214514];
int b[214514],c[214514];
char ans[110];
signed main(){
	ic(a) ic(b) ic(c)
	int A=a,B=b,C=c;
	rep(0,i,10000){
		if(A%2==1||B%2==1||C%2==1){
			c(i)
			return 0;
		}	
		A=(b+c)/2;
		B=(a+c)/2;
		C=(a+b)/2;
		a=A,b=B,c=C;
	}
	c(-1)
}	
		


Measured memory_bytes: 4352
#define  _CRT_SECURE_NO_WARNiINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	long long n;
	cin >> n;
	int final_ans = 1000000;
	for (int i = 1; i < n; ++i) {
		int hoge = i;
		string a = to_string(hoge);
		string b = to_string(n - hoge);
		int ans = 0;
		for (int i = 0; i < a.length(); ++i) {
			ans += a[i] - '0';
		}
		REP(i, b.length()) {
			ans += b[i] - '0';
		}
		final_ans = min(final_ans, ans);
	}
	cout << final_ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())

A = []
for _ in range(N):
    a = int(input())
    A.append(a)
    
nums = A[:]
colors = [float('inf')] * N

from bisect import bisect_left, bisect_right, insort_right
ans = 0
for n in nums:
    idx = bisect_right(colors, -n)
    colors[idx] = -n
    #print(ans)
    if idx > ans:
        ans = idx
    #print(idx, colors)
            
print(ans+1)

        

Measured memory_bytes: 58072