akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>   
#include <stdio.h>    
 
using namespace std;
     
#define F first
#define S second
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)1e4 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, c, dp[401][401], a[401], b[401], pref[401][401];

inline int mult (int a, int b) {
   return 1ll * a * b % mod;
}

inline int add (int a, int b) {
   a += b;
   if (a >= mod) a -= mod;
   if (a < 0) a += mod;
   return a;
}

inline int binpow (int a, int b) {
   int res = 1;
   while (b) {
      if (b & 1) res = mult (res, a);
      a = mult (a, a);
      b >>= 1;
   }
   return res;
}

inline int sum (int l, int r, int u) {
   return add (pref[u][r], -pref[u][l - 1]);   
}

int calc (int i = 1, int k = c) {
   if (i == n + 1) return (k == 0);
   if (~dp[i][k]) return dp[i][k];
   int &res = dp[i][k];
   res = 0;
   for (int u = 0; u <= k; u ++) {
      res = add (res, mult (sum (a[i], b[i], u), calc (i + 1, k - u)));
   }
   return res;
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {  
   cin >> n >> c;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i <= n; i ++) cin >> b[i];
   for (int u = 0; u <= c; u ++)
      for (int x = 1; x <= 400; x ++) {
         pref[u][x] = add (pref[u][x - 1], binpow (x, u));         
      }
   memset (dp, -1, sizeof dp);
   cout << calc ();
}                                     

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
// cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}


Measured memory_bytes: 1536
import math

a, b, h, m = map(int, input().split())

degree_minute = 360 * m/60
degree_hour = 360 * h / 12 + 30 * m/60

angle = abs(degree_minute - degree_hour)
if angle > 180:
    angle = 360 - angle

distance = math.sqrt(a ** 2 + b ** 2 - 2 * a * b *
                     math.cos(math.radians(angle)))

print(distance)


Measured memory_bytes: 9500
#include<bits/stdc++.h>
using namespace std;
inline char res(char l,char name,char w){
	if(name=='S'&&w=='o')return l;
	if(name=='W'&&w=='x')return l;
	if(l=='S')return 'W';
	else return 'S';
} 
int n;
int main(){
cin>>n;
char w[n],name[n],l;
for(int i=0;i<n;i++){
	cin>>w[i];
}
name[0]='S';
name[1]='S';
for(int i=1;i<n-1;i++){
	name[i+1]=res(name[i-1],name[i],w[i]);
}
if(name[0]==res(name[n-2],name[n-1],w[n-1])&&name[1]==res(name[n-1],name[0],w[0])){
	for(int i=0;i<n;i++){
		cout<<name[i];
	}
	return 0;
}
name[0]='S';
name[1]='W';
for(int i=1;i<n-1;i++){
	name[i+1]=res(name[i-1],name[i],w[i]);
}
if(name[0]==res(name[n-2],name[n-1],w[n-1])&&name[1]==res(name[n-1],name[0],w[0])){
	for(int i=0;i<n;i++){
		cout<<name[i];
	}
	return 0;
}
name[0]='W';
name[1]='S';
for(int i=1;i<n-1;i++){
	name[i+1]=res(name[i-1],name[i],w[i]);
}
if(name[0]==res(name[n-2],name[n-1],w[n-1])&&name[1]==res(name[n-1],name[0],w[0])){
	for(int i=0;i<n;i++){
		cout<<name[i];
	}
	return 0;
}
name[0]='W';
name[1]='W';
for(int i=1;i<n-1;i++){
	name[i+1]=res(name[i-1],name[i],w[i]);
}
if(name[0]==res(name[n-2],name[n-1],w[n-1])&&name[1]==res(name[n-1],name[0],w[0])){
	for(int i=0;i<n;i++){
		cout<<name[i];
	}
	return 0;
}
cout<<-1;
return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;

class MainClass
{
    static void Main()
    {
        int D = int.Parse(Console.ReadLine());
        if (D == 25) Console.WriteLine("Christmas");
        if (D == 24) Console.WriteLine("Christmas Eve");
        if (D == 23) Console.WriteLine("Christmas Eve Eve");
        if (D == 22) Console.WriteLine("Christmas Eve Eve Eve");
    }
}

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

using namespace std;
#define int long long int
#define lli long long int
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define loop(i,k,n) for(int i=k;i<n;i++)
#define MOD 1000000007
#define r0 return 0
/*
//gcd in O(log(a))
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
*/
/*
int gcd, x, y;

void extendedEuclid (int a, int b)
{
    if (b==0)
    {
        x=1;
        y=0;
        gcd=a;
        return;
    }
    extendedEuclid(b, a%b);
    int x1=y;
    int y1=x-(a/b)*y;
    x=x1;
    y=y1;
}

int nCr (int n, int r)
{
    int p=1, k=1, modInv;
    if (n-r<r)
        r=n-r;
    if (r!=0)
    {
        while (r)
        {
            p=(p*n)%MOD;
            k*=r;
            n--;
            r--;
        }
        extendedEuclid(k, MOD);
        modInv=(x+MOD)%MOD;
        p=(p*modInv)%MOD;
    }
    else
        p=1;
    return p;
}
*/
int memo[100001];
int32_t main(void)
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int arr[n+1];
        for(int i=1;i<=n;i++)
            cin>>arr[i];
        memo[1]=0;
        memo[2]=abs(arr[2]-arr[1]);
        for(int i=3;i<=n;i++)
            memo[i]=min(memo[i-1]+abs(arr[i]-arr[i-1]),memo[i-2]+abs(arr[i]-arr[i-2]));
        cout<<memo[n]<<endl;






    }
}


Measured memory_bytes: 1792
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> a(n), b(m);
  for (auto &i : a) cin >> i;
  for (auto &i : b) cin >> i;
  sort(all(a));
  sort(all(b));
  if (a.back() < b.front() && a.back() < y && b.front() > x) cout << "No War" << '\n';
  else cout << "War" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3604
#include <stdio.h>
int main()
{
	long long m;
	int i, a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	m = a;
	int vis = 0;
	for(i = 1 ; i <= 1000000 ; i++)
	{
		if((m * i ) % b == c)
		{
			vis = 1;
			printf("YES\n");
			break;
		}
	}
	if(vis == 0)
	{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String args[]) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<Integer> set = new HashSet<>();
		for(int i = 0; i < n; i++){
			set.add(sc.nextInt());
		}
		if(set.size() != n) {
			System.out.println("NO");
		}
		else {
			System.out.println("YES");
		}
	}
}


Measured memory_bytes: 100340
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {

	int X, A, B;
	scanf("%d%d%d", &X, &A, &B);

	printf("%d", (X - A) % B );








}

Measured memory_bytes: 128
n , a , b = map(int,input().split())
ans = 0
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)
for i in range(1,n+1):
    if a <= digitSum(i) <= b:
        ans += i
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
  int S,h,m,s,a;

  scanf("%d",&S);
 if( S >= 3600 )
 {
   h = S / 3600;
   a = S - ( h * 3600 );
   m = a / 60;
   s = a - ( m * 60 );
 }
 else
 {
   m = S / 60;
   s = S - ( m * 60 );
 }

 printf("%d:%d:%d\n",h,m,s);
 return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    for(int n, cnt; cnt = -1, cin >> n, n; cout << endl){
        vi p(n); rep(i, n) cin >> p[i];
        vi pre;

        do{
            pre = p;
            rep(i, n) p[i] = count(ALL(pre), pre[i]);
            cnt ++;
        }
        while(p != pre);

        cout << cnt << endl;
        rep(i, n) cout << (i ? " ":"") << p[i];
    }
 
    return 0;
}

Measured memory_bytes: 1220
#include<stdio.h>
#define suit 4
#define rank 13
int main(){
  int card[suit][rank],n;
  for(int i=0;i<suit;i++){
    for(int j=0;j<rank;j++){
      card[i][j]=0;
    }
  }
  char st,space;
  int num;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%c",&space);
    scanf("%c %d",&st,&num);
    if(st == 'S'){
      card[0][num] = 1;
    }else if(st == 'H'){
      card[1][num] = 1;
    }else if(st == 'C'){
      card[2][num] = 1;
    }else if(st == 'D'){
      card[3][num] = 1;
    }
  }
  for(int i=1;i<=rank; i++){
    if(card[0][i]!=1){
      printf("S %d\n",i);
    }
  }
  for(int i=1;i<=rank; i++){
    if(card[1][i]!=1){
      printf("H %d\n",i);
    }
  }for(int i=1;i<=rank; i++){
    if(card[2][i]!=1){
      printf("C %d\n",i);
    }
  }for(int i=1;i<=rank; i++){
    if(card[3][i]!=1){
      printf("D %d\n",i);
    }
  }
}



Measured memory_bytes: 2132
# coding: utf-8
# Your code here!
import sys

SIZE=1000000; MOD = 10**9+7 #ここを変更する

inv = [0]*(SIZE+1)# inv[j] = j^{-1} mod MOD
fac = [0]*(SIZE+1)# fac[j] = j! mod MOD
finv = [0]*(SIZE+1)# finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE+1):
    inv[i] = MOD -(MOD//i)*inv[MOD%i]%MOD
    fac[i] = fac[i-1]*i%MOD
    finv[i]= finv[i-1]*inv[i]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0

n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

a.sort()
b.sort()

if a[n-1] != n*m or b[m-1] != n*m:
    print(0)
    sys.exit()
for i in range(n-1):
    if a[i] == a[i+1]:
        print(0)
        sys.exit()
for i in range(m-1):
    if b[i] == b[i+1]:
        print(0)
        sys.exit()

#print(a)
#print(b)
cn = 0; cm=0
ans = 1
num=0
while cn<n-1 or cm<m-1:
    if a[cn] < b[cm]:
        ans = ans * choose(a[cn]-num-1,m-cm-1) % MOD
        ans = ans * fac[m-cm] % MOD
        num += m-cm
#        print(ans, '<', cn,cm,num)
        if ans == 0:
            break
        cn += 1

    elif a[cn] > b[cm]:
        ans = ans * choose(b[cm]-num-1,n-cn-1) % MOD
        ans = ans * fac[n-cn] % MOD
        num += n-cn
#        print(ans, '>',cn,cm,num)
        if ans == 0:
            break
        cm += 1

    elif a[cn] == b[cm]:
#        print(ans, '=',cn,cm,num,'before')
        ans = ans * choose(a[cn]-num-1,m-cm + n-cn -2) % MOD
        ans = ans * fac[m-cm + n-cn -2] % MOD
        num += m-cm + n-cn - 1
#        print(ans, '=',cn,cm,num)
        if ans == 0:
            break
        cn += 1
        cm += 1
print(ans)            
        
        

Measured memory_bytes: 123732
#include <cstdio>
#include <bitset>

using namespace std;

bitset<2005 * 2005> dp[2];
int n;

int main(int argc, char* argv[]) {
    scanf("%d", &n);
    
    dp[0].set(0);
    int sum = 0;
    int p = 1;

    for (int i = 0; i < n; ++i) {
        int a;
        scanf("%d", &a);

        sum += a;
        dp[p] = dp[p ^ 1] | (dp[p ^ 1] << a);

        p ^= 1;
    }

    p ^= 1;
    for (int i = (sum + 1) / 2; i <= sum; ++i) {
        if (dp[p].test(i)) {
            printf("%d\n", i);
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 2688
#include <cassert>
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>
#include <fstream>
#include <ostream>
#include <random>
#include <chrono>
using namespace std;
//#define int long long

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, x;
	cin >> n >> x;
	int curr = 0;
	vector<int> rr;
	for (int i = 0; i < n; i++)
	{
		int r;
		cin >> r;
		rr.push_back(r);
	}
	int ans = 1;
	for (int i = 1; i <= n; i++)
	{
		curr = curr + rr[i - 1];
		if (curr <= x)
			ans++;
	}
	cout << ans << "\n";

	
}

Measured memory_bytes: 256
import math
from itertools import permutations
n = int(input())
x, y = [0] * n, [0]*n
for i in range(n):
    x[i], y[i] = map(int, input().split())
    
dist = [[0]*n for _ in range(n)]
for i in range(n):
    for t in range(n):
        dist[i][t] = math.sqrt((x[i]-x[t])**2 + (y[i]-y[t])**2)
        
ans = 0
for p in permutations(range(n)):
    for i in range(len(p)-1):
        ans += dist[p[i]][p[i+1]]

print(ans / math.factorial(n))

Measured memory_bytes: 41964
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto d0 = divisor(N - 1);
    auto d1 = divisor(N);
    // writeln(d0);
    // writeln(d1);s
    bool[long] dict;
    foreach (d; d0)
        dict[d] = true;
    long ans = d0.length - 1;
    foreach (d; d1)
    {
        if (d == 1 || (d in dict) || N < d)
            continue;
        long n = N;
        while (0 < n && n % d == 0)
            n /= d;
        if (n % d == 1)
        {
            // writeln(d);
            ans++;
        }
    }
    writeln(ans);
}

long[] divisor(long N)
{
    long[] ret;
    foreach (i; 1 .. N + 1)
    {
        if (N < i * i)
            break;
        if (N % i == 0)
        {
            ret ~= i;
            if (i * i != N)
                ret ~= N / i;
        }
    }
    return ret;
}


Measured memory_bytes: 380
#include<stdio.h>

int main()
{
  int n,a[100001],b[100001];
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    {
      scanf("%d",&a[i]);
    }
  for(int i=0;i<n;i++)
    b[a[i]-1]=i+1;//配列は０からはじまるので、a[i]-1であり、i+1である
  for(int i=0;i<n;i++){
    printf("%d ",b[i]);
  }
  printf("\n");
  return 0; 
}


Measured memory_bytes: 1536
#include<stdio.h>
int n;
int pa[100001],si[100001],de[100001];
int cald(int i);
int calh(int i);
int main() {
  int i,j;
  scanf("%d", &n);
  for(i=0;i<n;i++) {
    pa[i] = -1;
    si[i] = -1;
    de[i] = 0;
  }
  for(i=0;i<n;i++) {
    int id, left, right;
    scanf("%d %d %d", &id, &left, &right);
    if(left != -1) {
      pa[left] = id;
      si[left] = right;
      ++de[id];
    }
    if(right != -1) {
      pa[right] = id;
      si[right] = left;
      ++de[id];
    }
  }
  for(i=0;i<n;i++) {
    int dep;
    dep=cald(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height\
\
 = %d, ",i, pa[i], si[i], de[i], dep, calh(i));
    if(dep== 0) printf("root\n");
    else if(de[i] == 0) printf("leaf\n");
    else printf("internal node\n");

  }
  return 0;
}
int cald(int s){
  if(pa[s]==-1)return 0;
  return cald(pa[s])+1;
}
int calh(int s){
  int i,h=0;
  for(i=0;i<n;i++){
    if(pa[i]==s){
      int tmp;
      tmp=calh(i)+1;
      if(tmp>h)h=tmp;
    }
  }
  return h;
}


Measured memory_bytes: 2148
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

int main(){
  int n, k, m;
  while(scanf("%d%d%d", &n, &k, &m) && n+k+m){
    vector<int>p(n);
    rep(i, n) p[i] = i+1;
    m--; k--;
    p.erase(p.begin()+m);
    //    rep(i, p.size()) printf("%d ", p[i]); puts("");
    while(p.size() > 1){
      m += k; m %= p.size();
      p.erase(p.begin() + m);
      //      rep(i, p.size()) printf("%d ", p[i]); puts("");
    }

    printf("%d\n", p[0]);
  }
  return 0;
}

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

int main() {
  int n,k;cin>>n>>k;
  int x[109];
  for(int i=0;i<n;++i) cin>>x[i];
  
  int ans=0;
  for(int i=0;i<n;++i){
    ans+=2*min(x[i],k-x[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int prime[1000001],i,j,n,sum,count;
  
  for(i=0;i<1000000;i++)
    prime[i]=0;  

  prime[0]=1;
  prime[1]=1;

  for(i=2;i*i<1000000;i++){
    if(prime[i]==0){
      for(j=2*i;j<1000000;j+=i){
	prime[j]=1;
      }
    }
  }
  while(1){
    sum=0;
    count=0;
    scanf("%d",&n);
    if(n==0)break;
    
    for(i=2;count<n;i++){
      if(prime[i]==0){
	sum+=i;
	count++;
      }
    }
    printf("%d\n",sum);
  }
  
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 N;
  cin >> N;
  vector<i64> X(N), L(N);
  vector<i64> idx(N);
  rep(i,0,N) {
    cin >> X[i] >> L[i];
    idx[i] = i;
  }
  sort(all(idx), [&](i64 a, i64 b) { return X[a] < X[b]; });
  i64 R = X[idx[0]] + L[idx[0]];
  i64 ans = 1;
  rep(ii,1,N) {
    i64 i = idx[ii];
    if(R <= X[i] - L[i]) {
      ans++;
      R = X[i] + L[i];
    }
    else {
      if(R > X[i] + L[i]) {
        R = X[i] + L[i];
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const llong MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
template<class T>
int range_check(int val, int min, int max) {
	if (val < min) {
		return -1;
	}
	if (val > max) {
		return -1;
	}
	return val;
}
class item{
public:
	int a;
	int b;
	int c;
};
int main() {
	int a, b, m;
	cin >> a >> b >> m;
	VE avec(a), bvec(b);
	vector<item> ivec(m);
	REP(i, a) {
		cin >> avec[i];
	}
	REP(i, b) {
		cin >> bvec[i];
	}
	REP(i, m) {
		int aa, bb;
		item itm;
		cin >> aa >> bb >> itm.c;
		itm.a = aa - 1;
		itm.b = bb - 1;
		ivec[i] = itm;
	}
	int min_val = *min_element(avec.begin(), avec.end()) + *min_element(bvec.begin(), bvec.end());
	REP(i, m) {
		int now_val = avec[ivec[i].a] + bvec[ivec[i].b] - ivec[i].c;
		min_val = min(now_val, min_val);
	}
	cout << min_val << endl;
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef list<ll> listl;
typedef string str;

#define min(A, B) min(static_cast<ll>(A), static_cast<ll>(B))
#define max(A, B) max(static_cast<ll>(A), static_cast<ll>(B))
#define all(x) (x).begin(), (x).end()
#define mp make_pair

#define _rep(i, m)		for(ll i = 0, i_max = m; i < i_max; i++)
#define _erep(i, m)		for(ll i = 0, i_max = m; i <= i_max; i++)
#define _brep(i, b, m)	for(ll i = b, i_max = m; i < i_max; i++)
#define _ebrep(i, b, m)	for(ll i = b, i_max = m; i <= i_max; i++)
#define _rrep(i, m)		for(ll i = m; i >= 0; i--)
#define _rerep(i, b, e)	for(ll i = b; i >= e; i--)

#define rep(m)			_rep(i, m)
#define erep(m)			_erep(i, m)
#define brep(b, m)		_brep(i, b, m)
#define ebrep(b, m)		_ebrep(i, b, m)
#define rrep(m)			_rrep(i, m)
#define rerep(b, e)		_rerep(i, b, e)

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void in(ll& I)
{
	cin >> I;
}

void in(vl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(listl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(str& s)
{
	cin >> s;
}

void out(ll O)
{
	cout << O;
}

void out(vl& O)
{
	for (auto& o : O)
	{
		cout << o;
	}
}

void rout(bool b, str True, str False)
{
	if (b) cout << True.c_str();
	else cout << False.c_str();
}

int main()
{
	ll n;
	in(n);
	vl v(n);
	in(v);

	sort(all(v));

	cout << v[n / 2] - v[n / 2 - 1];

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define forx(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define caseout(i, x) cout << "Case #" << i << ": " << x << endl;



int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    string s;
    cin>>n>>s;
    int dif=0;
    
    rep(i,n)
      if(s[i]=='B')dif--;
      else dif++;
      
    if(dif>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    
    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++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
#define ALL(V) V.begin(), V.end()
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}


int Main(int N, string S)
{
    int ans = 0;
    REP(i, N-2) {
        if(S[i] == 'A' && S[i+1] == 'B' && 
        S[i+2] == 'C') {
            ans++;
        }
    }
    return ans;
}


int main(void){
    int N;
    cin >> N;
    string S;
    cin >> S;
    cout << Main(N, S) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        
       int N=sc.nextInt();
       int K=sc.nextInt();
       
       int[] A=new int[N];
       for(int i=0;i<N;i++){
           A[i]=sc.nextInt();
       }
       Arrays.sort(A);
       
       int num=1;
       for(int i=1;i<N;i++){
           if(A[i-1]<A[i]){
               num++;
           }
       }
       
       int[] s=new int[num];
       s[0]=1;
       int count=0;
       for(int i=1;i<N;i++){
           if(A[i-1]<A[i]){
               count++;
           }
           s[count]++;
       }
       Arrays.sort(s);
       
       if(num<=K){
           System.out.println(0);
       }else{
           int ans=0;
           for(int i=0;i<num-K;i++){
               ans+=s[i];
           }
           System.out.println(ans);
       }
    }
}

Measured memory_bytes: 63956
/* monitored by peyha
* X19
*/

#include <iostream>
#include <queue>
#include <vector>
#include <fstream>
#include <algorithm>
#include <set>
#include <string>

//on aurait pu faire #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int NMAX=5*1e5+1;
int n,compteur[NMAX],valeur[NMAX],aim[NMAX];
string s;
queue<int> ids;
ll ans=0;

int main(){
	ios::sync_with_stdio(false);
	
	cin >> s;
	
	n=s.size()+1;
	

	for(int i=1;i<n-1;i++){
		aim[i]= (s[i]=='>') + (s[i-1]=='<');
	}
	aim[0]=(s[0]=='>');
	aim[n-1]=(s[n-2]=='<');
	
	for(int i=0;i<n;i++){
		if(aim[i]==0) ids.push(i);
	}

	while(!ids.empty()){
		int id=ids.front();
		ids.pop();
		//cout << id << '\n';
		if( id>0 && s[id-1]=='>' ){
			compteur[id-1]++;
			
			if( compteur[id-1]==aim[id-1]  ){
				valeur[id-1]= valeur[id]+1;
				ids.push( id-1 );
			}
		}

		if( id<n-1 && s[id]=='<' ){
			compteur[id+1]++;
			if( compteur[id+1]==aim[id+1]  ){
				valeur[id+1]=valeur[id]+1;
				ids.push( id+1 );
			}
		}
	}

	for(int i=0;i<n;i++){
		ans+=valeur[i];
	//	cout << valeur[i] << ' ';
	}	

	//cout << '\n';
	
	cout << ans << '\n';

	for(int i=0;i<n-1;i++){
		if( !( (s[i]=='>' && valeur[i]>valeur[i+1]) || (s[i]=='<' && valeur[i]<valeur[i+1])))
			cout << "FATAL " << i << ' ' << valeur[i]  << ' ' << valeur[i+1] << '\n';
	}
	return 0;
}



Measured memory_bytes: 7324
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int n;
    cin >> n;
    if(n<105) cout << "0" << endl;
    else if(105<=n&&n<135) cout << "1" << endl;
    else if(135<=n&&n<165) cout << "2" << endl;
    else if(165<=n&&n<189) cout << "3" << endl;
    else if(189<=n&&n<195) cout << "4" << endl;
    else cout << "5" << endl;
    return 0;
}


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

typedef long long ll;
ll N, M;

set<ll> factors(ll n) {
  set<ll> factors;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i ==0) {
      factors.insert(i);
      factors.insert(n/i);
    }
  }
  return factors;
}

int main() {
  cin >> N >> M;
  ll ans = 1;
  for(const auto f: factors(M)) {
    if(M/f >= N) {
      ans = f;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
  
#define W 0
#define G 1
#define B 2
#define M 105
 
int Color[M];
int d[M],f[M],Adj[M][M],mu[M];
int time = 0;
 
void DFS(int q)
{
   
  int i;
 
  Color[q] = G;
  d[q] = ++time;
   
  for(i = 0 ; i < mu[q] ; i++){
 
    if(Color[Adj[q][i]] == W){
      DFS(Adj[q][i]);
    }
 
  }
   
  Color[q] = B;
  f[q] = ++time;
   
}
 
int main(){
 
  int n,i,j,Tmp;
  
  for(i = 0 ; i < M ; i++){
      Color[i] = W;
    }
   
  scanf("%d",&n);
   
  for(i = 1 ; i <= n ; i++){
     
      scanf("%d",&Tmp);
      scanf("%d",&mu[i]);
 
      for(j = 0 ; j < mu[i] ; j++){
      scanf("%d",&Adj[i][j]);
      }
  }
   
  for(i = 1 ; i <= n ; i++){
    if(Color[i] == W){
    DFS(i);
      }
  }
   
  for(i = 1 ; i <= n ; i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
   
  return 0;
}

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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 1e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "4";

vector <vector <int> > graph;
bool vis[siz];

void dfs(int u) {
    vis[u] = true;
    for (auto &v : graph[u]) {
        if (vis[v]) {
            continue;
        }
        dfs(v);
    }
}

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

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    int n, m;
    cin >> n >> m;

    graph.resize(n + 1);
    while (m--) {
        int u, v;
        cin >> u >> v;

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    int ans = 0;
    for (int u = 1; u <= n; u++) {
        if (!vis[u]) {
            ans++;
            dfs(u);
        }
    }

    cout << ans - 1 << "\n";

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


Measured memory_bytes: 9972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;

ll inv(ll a, ll b){
    return (a > 1 ? b - inv(b%a, a)*b/a : 1);
}

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))

const ld e = 2.71828182845904523536028747;
const ld PI = 3.14159265359;
const ll inf = (1LL<<62);
const int iinf = (1<<30);
//CLOCKS_PER_SEC



int main(){
    //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    //ios_base::sync_with_stdio(0); cin.tie(0);
    //ifstream cin ("test.in");
    int a, b, c;
    cin >> a >> b >> c;
    cout << c - smin(c, a - b);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second

const int mod = 1e9+7;
int dp[2005][2005];

inline void add(int &x, int y)
{
	if (y >= mod)
		y -= mod;
	x += y;
	if (x >= mod)
		x -= mod;
}

int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("b.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m);
	for (auto &i : a) cin >> i;
	for (auto &i : b) cin >> i;

	//a.push_back(0);
	//b.push_back(0);
	a.insert(a.begin(), 0);
	b.insert(b.begin(), 0);

	for (int i = 2003; i >= 0; --i) dp[0][i] = dp[i][0] = 1;

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
		{
			add(dp[i][j], dp[i-1][j]);
			add(dp[i][j], dp[i][j-1]);
			add(dp[i][j], mod-dp[i-1][j-1]);
			if (a[i] == b[j]) add(dp[i][j], dp[i-1][j-1]);
		}

	cout << dp[n][m] << "\n";

	return 0;
}


Measured memory_bytes: 16000
#include <iostream>
#include <math.h>
#include <string>
#include <stdio.h>

using namespace std;

int main()
{
	int N,count;
	string S;
	cin >> N;
	cin >> S;
	count = 0;

	for (int i = 0; i < N-2; i++)
	{
		char c1 = S[i];
		char c2 = S[i+1];
		char c3 = S[i+2];

		if ( (c1 == 'A') && (c2 == 'B') && (c3 == 'C') )
			count++;
	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;

int main(){
string s;
cin >> s;
if(s == "ABC") cout << "ARC" << endl;
else cout << "ABC" << endl;
}



Measured memory_bytes: 3548
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


int main() {
    int N;
    cin >> N;
    priority_queue<pair<int,int> > pq;
    rep(i,0,N){
        int inp;
        cin >> inp;
        pq.push(make_pair(inp, 0));
    }
    rep(i,0,N){
        int inp;
        cin >> inp;
        pq.push(make_pair(inp, 1));
    }


    ll ans = 1;
    int cnt = 0;

    while(!pq.empty()){
        if(cnt == 0){
            if(pq.top().second == 0){
                cnt++;
            }else{
                cnt--;
            }
        }else if(cnt > 0){
            if(pq.top().second == 0){
                cnt++;
            }else{
                ans = ans * abs(cnt) % MOD;
                cnt--;
            }
        }else if(cnt < 0){
            if(pq.top().second == 0){
                ans = ans * abs(cnt) % MOD;
                cnt++;
            }else{
                cnt--;
            }
        }
        pq.pop();
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2420
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>
 
#define REP(I, S, E) for (decltype(S + E) I = (S), _E = (E); I < _E; ++I)
#define REP_REV(I, S, E) for (decltype(S + E) I = (E)-1, _S = (S); I >= _S; --I)
 
using namespace std;
using ll = long long;
 
int A, B, Q;
 
ll S[100000];
ll T[100000];
ll X[100000];
pair<ll, int> Y[100000];
ll D[100000];
 
auto main() -> int {
    scanf("%d %d %d", &A, &B, &Q);
 
    REP(si, 0, A) { scanf("%lld", &S[si]); }
    REP(ti, 0, B) { scanf("%lld", &T[ti]); }
    REP(xi, 0, Q) { scanf("%lld", &X[xi]); }
 
    REP(q, 0, Q) { Y[q] = {X[q], q}; }
    sort(Y, Y + Q); // 開始位置のリストをソート
 
    // 位置 x からみてすぐ右にある神社の番号 (なければ A)
    auto si = 0;
    auto ti = 0;

    // 線形探索
    REP(yi, 0, Q) {
        auto x = Y[yi].first;
        auto q = Y[yi].second;
 
        while (si < A && S[si] < x) {
            si += 1;
        }
        while (ti < B && T[ti] < x) {
            ti += 1;
        }
 
        auto min_dist = 1LL << 60;
        REP(s, max(0, si - 1), min(A, si + 1)) {
            REP(t, max(0, ti - 1), min(B, ti + 1)) {
                auto ds = abs(S[s] - x);
                auto dt = abs(T[t] - x);
                auto dist = abs(S[s] - T[t]) + ds + dt - max(ds, dt);
                min_dist = min(min_dist, dist);
            }
        }
 
        D[q] = min_dist;
    }
 
    REP(q, 0, Q) { printf("%lld\n", D[q]); }
    return 0;
}

Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846



int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a<=c && c<=b){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

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

    ll num (0);
    for (auto i: s)
    {
        if (i == '-') num--;
        if (i == '+') num++;
    }

    cout << num << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)

	s := ""
	if n == 0 {
		s = "0"
	} else {
		for n != 0 {
			if n%2 == 0 {
				s = "0" + s
			} else {
				s = "1" + s
				n -= 1
			}
			n /= -2
		}
	}

	fmt.Println(s)
}


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

int main()
{
  int ans = 0;
  string s;
  int n;
  cin >> n;
  map<string, int> mp;
  string a[n];
  rep(i, n){
    cin >> a[i];
    mp[a[i]]++;
  }
  int x;
  cin >> x;
  rep(i, x){
    cin >> s;
    mp[s]--;
  }
  rep(i, n){
    ans = max(ans, mp[a[i]]);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

bool solve(vector<int> balls, vector<int> &b,vector<int> &c, int index) {
    
    if (index >= 10) return true;
    if (b.back() < balls[index]) {
        b.push_back(balls[index]);
        index++;
        return solve(balls, b, c, index);
    }
    if (c.back() < balls[index]) {
        c.push_back(balls[index]);
        index++;
        return solve(balls, b, c, index);
    }
    return false;
}

int main(){
    int N;
    cin >> N;
    bool flag;
    vector<vector<int> > balls(N, vector<int>(10));
    
    for (int j = 0; j < N; j++) {
        for (int i = 0; i < 10; i++) {
            cin >> balls[j][i];
        }
    }
    for (int j = 0; j < N; j++) {
        vector<int> b, c;
        b.push_back(0);
        c.push_back(0);
        flag = solve(balls[j], b, c, 0);
        if (flag) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    
  return 0;
}



Measured memory_bytes: 3168
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

const ll MOD = 1e9 + 7;
const int MAXN = 120000;

ll fv0[MAXN];
ll fv1[MAXN];
int n;
ll dp[MAXN][2];

ll get0(int x) {
	ll ans = 0;
	for (; x >= 0; x = (x & (x + 1)) - 1)
		ans = (ans + fv0[x]) % MOD;
	return ans;
}

ll get1(int x) {
	ll ans = 0;
	for (; x >= 0; x = (x & (x + 1)) - 1)
		ans = (ans + fv1[x]) % MOD;
	return ans;
}

ll get0(int l, int r) {
	if (r <= l)
		return 0;
	ll ans = 0;
	if (r > 0)
		ans = get0(r - 1);
	if (l > 0)
		ans += MOD - get0(l - 1);
	if (ans >= MOD)
		return ans - MOD;
	return ans;
}

ll get1(int l, int r) {
	if (r <= l)
		return 0;
	ll ans = 0;
	if (r > 0)
		ans = get1(r - 1);
	if (l > 0)
		ans += MOD - get1(l - 1);
	if (ans >= MOD)
		return ans - MOD;
	return ans;
}

void upd0(int x, ll d) {
	for (; x < n; x |= (x + 1))
		fv0[x] = (fv0[x] + d) % MOD;
}

void upd1(int x, ll d) {
	for (; x < n; x |= (x + 1))
		fv1[x] = (fv1[x] + d) % MOD;
}

ll a, b;
ll s[MAXN];

int main() {
	scanf("%d%lld%lld", &n, &a, &b);
	for (int i = 1; i <= n; ++i)
		scanf("%lld", s + i);
	++n;
	s[n] = s[n - 1] + max(a, b);
	s[0] = s[1] - max(a, b);
	dp[0][0] = 1;
	dp[0][1] = 1;
	upd0(0, dp[0][0]);
	upd1(0, dp[0][1]);
	int n00 = 0;
	int n01 = 0;
	int n10 = 0;
	int n11 = 0;
	for (int i = 1; i < n; ++i) {
		if (s[i] - s[i - 1] < a)
			n00 = i;
		if (s[i] - s[i - 1] < b)
			n10 = i;
		while (n01 + 1 < i && s[n01 + 1] + b <= s[i + 1])
			++n01;
		while (n11 + 1 < i && s[n11 + 1] + a <= s[i + 1])
			++n11;
		dp[i][0] = get1(n00 - 1, n01 + 1);
		dp[i][1] = get0(n10 - 1, n11 + 1);
		upd0(i, dp[i][0]);
		upd1(i, dp[i][1]);
	}
	ll ans = dp[n - 1][0] + dp[n - 1][1];
	ans %= MOD;
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 4224
import sys
sys.setrecursionlimit(2147483647)
from functools import lru_cache

@lru_cache(maxsize=None)
def solve(n, a, b, c, d):
    if n == 0:
        return 0
    if n == 1:
        return d
    res = 10**18
    res = min(res, d * n)
    res = min(res, d * (n - n // 2 * 2) + a + solve(n // 2, a, b, c, d))
    res = min(res, d * (n - n // 3 * 3) + b + solve(n // 3, a, b, c, d))
    res = min(res, d * (n - n // 5 * 5) + c + solve(n // 5, a, b, c, d))
    res = min(res, d * ((n + 2 - 1) // 2 * 2 - n) + a + solve((n + 2 - 1) // 2, a, b, c, d))
    res = min(res, d * ((n + 3 - 1) // 3 * 3 - n) + b + solve((n + 3 - 1) // 3, a, b, c, d))
    res = min(res, d * ((n + 5 - 1) // 5 * 5 - n) + c + solve((n + 5 - 1) // 5, a, b, c, d))
    return res

T = int(input())
for _ in range(T):
    N, A, B, C, D = map(int, input().split())
    print(solve(N, A, B, C, D))

Measured memory_bytes: 29620
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	int answer = 0;
  for(int i=1; i<=N; i+=2){
    int kosuu=0;
    for(int j=1;j<=i; j++){
      if(i%j==0)kosuu++;
    }
 if(kosuu==8)answer++;
    
  }
 cout<<answer<< endl;
return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<list>
#include<string>
using namespace std;
int o;
bool b[1000][1000];
void solve(int m, int n, char hw[100][100], char p,int h,int w) {
	if (m + 1 < h&&hw[m + 1][n] == p&&b[m + 1][n] == false) {
		b[m + 1][n] = true;
		o--;
		solve(m + 1, n, hw, p, h, w);
	}
	if (m - 1 >= 0 && hw[m - 1][n] == p&&b[m - 1][n] == false) {
		b[m - 1][n] = true;
		o--;
		solve(m - 1, n, hw, p, h, w);
	}
	if (n + 1 < w&&hw[m][n + 1] == p&&b[m][n + 1] ==false) {
		o--;
		b[m][n + 1] = true;
		solve(m , n+1, hw, p, h, w);
	}
	if (n - 1 >=0&&hw[m][n - 1] == p&&b[m][n - 1] == false) {
		b[m][n - 1] = true;
		o--;
		solve(m, n - 1, hw, p, h, w);
	}
}
int main() {
	int h, w;
	char hw[100][100];
	while (cin >> h >> w&&h != 0 && w != 0) {
		for (int i = 0; i < h; i++) {
			string a;
			cin >> a;
			for (int j = 0; j < w; j++) {
				hw[i][j] = a[j];
				b[i][j] = false;
			}
		}
		o = h*w;
		int m, n;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (b[i][j] == false) {
					m = i;
					n = j;
					b[m][n] = true;
					solve(m, n, hw, hw[m][n], h, w);
				}
			}
		}
		cout << o << endl;
	}
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    vector<ll> a(n),b(n),c(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n) cin>>c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll res=0;
    rep(i,n){
        ll B=b[i];
        auto itr=lower_bound(a.begin(),a.end(),B);
        ll k=itr-a.begin();
        itr=upper_bound(c.begin(),c.end(),B);
        ll l=itr-c.begin();
        l=n-l;
        //cout<<k<<" "<<l<<endl;
        res+=k*l;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 2560
//q099.cpp
//Fri Sep 18 22:19:51 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	ll D=0;
	ll S=0;
	rep(i,m){
		ll d,c;
		cin >> d >> c;
		D+=c;
		S+=d*c;
	}

	cout << D-1+(S-1)/9 << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5;
char s[N], t[N];

int dp[4000][4000], cnt[4000][4000];

int main(){
    cin >>(s + 1) >> (t + 1);
    int ls = strlen((s + 1));
    int lt = strlen((t + 1));
    for(int i = 1; i <= ls; i++){
        for(int j = 1; j <= lt; j++){
            if(s[i] == t[j]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
                cnt[i][j] = 1;
            }else{
                if(dp[i - 1][j] > dp[i][j - 1]){
                    dp[i][j] = dp[i - 1][j];
                    cnt[i][j] = 2;
                }else{
                    dp[i][j] = dp[i][j - 1];
                    cnt[i][j] = 3;
                }
            }
        }
    }
    vector<char>g;
    int x = ls, y = lt;
   // cout << cnt[x][y]<< endl;
    while(cnt[x][y]){
        if(cnt[x][y] == 1){
            g.push_back(s[x]);
            x--;
            y--;
        }else if(cnt[x][y] == 2){
            x--;
        }else if(cnt[x][y] == 3){
            y--;
        }
    }
    reverse(g.begin(), g.end());
    for(auto it: g){
        cout << it;
    }
    cout << endl;
}

Measured memory_bytes: 97392
N, K = map(int, input().split())
S = list(input())

l = []
tmp = 0
for i in range(1, N):
  if S[i - 1] != S[i]:
    l.append([tmp, i - 1, i - tmp])
    tmp = i
  if i == N - 1:
    l.append([tmp, i, i - tmp + 1])

for k in range(K):
  i = 2 * k + 1
  if i >= len(l):
    break
  if S[l[i][0]] == "L":
    S[l[i][0] : l[i][1] + 1] = "R" * l[i][2]
  else:
    S[l[i][0] : l[i][1] + 1] = "L" * l[i][2]

ans = 0
for i in range(N - 1):
  if S[i] == S[i + 1]:
    ans += 1

print(ans)

Measured memory_bytes: 20364