akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {

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

    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    vector<int> v1(n / 2), v2(n / 2);

    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            v1[i / 2] = v[i];
        } else {
            v2[(i - 1) / 2] = v[i];
        }
    }

    vector<pair<int, int>> p1, p2;
    p1.push_back(make_pair(0, v1[0]));
    p2.push_back(make_pair(0, v2[0]));
    p1.push_back(make_pair(0, -1));
    p2.push_back(make_pair(0, -1));

    for (int i = 0; i < n / 2; i++) {
        int b = false;
        for (auto itr = p1.begin(); itr != p1.end(); itr++) {
            if (v1[i] == itr->second) {
                itr->first++;
                b = true;
                break;
            }
        }
        if (!b) {
            p1.push_back(make_pair(1, v1[i]));
        }

        b = false;
        for (auto itr = p2.begin(); itr != p2.end(); itr++) {
            if (v2[i] == itr->second) {
                itr->first++;
                b = true;
                break;
            }
        }
        if (!b) {
            p2.push_back(make_pair(1, v2[i]));
        }
    }

    sort(p1.begin(), p1.end(), greater<pair<int, int>>());
    sort(p2.begin(), p2.end(), greater<pair<int, int>>());

    if (n == 2) {
        if (p1[0].second == p2[0].second) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
    } else {
        int t[2][2];
        t[0][0] = p1[0].first;
        t[0][1] = p1[1].first;
        t[1][0] = p2[0].first;
        t[1][1] = p2[1].first;

        int ans = INT32_MAX;
        if (p1[0].second != p2[0].second) {
            int cnt;
            cnt = fabs(t[0][0] - n / 2) + fabs(t[1][0] - n / 2);
            ans = min(cnt, ans);
        } else {
            int cnt;
            cnt = fabs(t[0][0] - n / 2) + fabs(t[1][1] - n / 2);
            ans = min(cnt, ans);
            cnt = fabs(t[0][1] - n / 2) + fabs(t[1][0] - n / 2);
            ans = min(cnt, ans);
        }

        cout << ans << endl;
    }
}

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

int main(){
  long d;
  cin >> d;
  long n = 26, csum = 0, ccost = 0;
  vector<long> c(n),last(n);
  rep(i,n){
    cin >> c[i];
    csum += c[i];
    last[i] = 0;
  }
  vector<vector<long>> s(d,vector<long>(n));
  rep(i,d)rep(j,n)cin >> s[i][j];
  vector<vector<long>> cand;
  vector<long> score;
  random_device rd{};
  vector<long> yotei(d);
  vector<long> tmp(d);
  long final_ans = 0, final_index;

  rep(jj,10){

    long ans = 0;
    rep(i,n)last[i] = 0;
    rep(i,d)yotei[i] = rd()%n;
    rep(i,d){
      ccost += csum;
      ccost -= c[yotei[i]]*(i+1 - last[yotei[i]]);
      ans -= ccost;
      last[yotei[i]] = i+1;
      ans += s[i][yotei[i]];
    }
    int ii = 0;
    while(ii < 200000){
      long new_day = rd()%d, new_con;
      while(1){
        new_con = rd()%n;
        if(yotei[new_day] != new_con)break;
      }
      long pre_con = yotei[new_day];
      yotei[new_day] = new_con;
      long tmpans = 0;
      ccost = 0;
      rep(i,n)last[i] = 0;
      rep(i,d){
        tmp[i] = yotei[i];
        ccost += csum;
        ccost -= c[yotei[i]]*(i+1 - last[yotei[i]]);
        tmpans -= ccost;
        last[yotei[i]] = i+1;
        tmpans += s[i][yotei[i]];
      }
      if(tmpans < ans)yotei[new_day] = pre_con;
      else{
        ans = tmpans;
        cand.push_back(tmp);
      }
      ii++;
    }
    if(final_ans < ans){
      final_ans = ans;
      final_index = int(cand.size()-1);
    }
  }
  rep(i,d)cout << cand[final_index][i]+1 << endl;
  return 0;
}

Measured memory_bytes: 28932
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(a%b==0)
        return b;
    return gcd(b,a%b);
}
int main()
{

    int n;
    cin>>n;
    ll ans=0;
    for(ll i=1; i<=n; i++)
    {
        for(ll j=1; j<=n; j++)
        {
            for(ll k=1; k<=n; k++)
            {
                ans+=gcd(i,gcd(j,k));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
s = input()
lb = 0
lw = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == '0':
            lb += 1
        else:
            lw += 1
    else:
        if s[i] == '0':
            lw += 1
        else:
            lb += 1
print(min(lb,lw))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
using pqueg = priority_queue<int, vector<int>, greater<int>>;
using pquel = priority_queue<int, vector<int>, less<int>>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
int lcm(int a, int b){
  return a / __gcd(a, b) * b;
}
int r_int(int a, int b){
  return rand() % b + a;
}
const lint mod=1e9+7;

// 最上位桁を求める
int digit_upper(lint num){
  while(num > 9) {
    num = num / 10;
  }
  return num;
}

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

  vector<vector<int>> c(10,vector<int>(10,0));
  for(lint i=1;i<=n;i++){
    int a = digit_upper(i), b = i%10;
    c[a][b]++;
  }

  lint sum = 0;
  REP(i,10){
    REP(j,10){
      sum += c[i][j]*c[j][i];
    }
  }

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


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

dim = [0]*4

for _ in range(3):
	a, b = MAP()
	dim[a-1] += 1
	dim[b-1] += 1

c = Counter(dim)

if c[1] == 2 and c[2] == 2:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 5200
package main

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

func main() {
	sc := NewScanner()

	a := sc.NextInt()
	b := sc.NextInt()

	if a%2 == 0 || b%2 == 0 {
		fmt.Printf("Even\n")
		return
	}
	fmt.Printf("Odd\n")

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int N, K;
	cin >> N >> K;
	vector<int> dp(N+K+1, 1e9), hs(N);

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

	dp[0] = 0;

	for (int i = 0; i < N-1; i++)
		for (int k = 1; k <= K; k++)
		{
			dp[i + k] = min(dp[i + k], dp[i] + abs(hs[i] - hs[i + k]));
		}

	cout << dp[N-1] << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1024
//Use prefix sum
// dp[i][j] = j candies for first i students
// ith student can tak 0 to a[i] candies so dp[i][j]=(dp[i-1][0]+dp[i-1][1] ... dp[i-1][j]) hence use prefix sum

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
 
int main() {
	// your code goes here
	ll n,k;cin>>n>>k;
	ll a[n];
	for(int i=1;i<=n;i++)cin>>a[i];
	
	a[0]=0;
	ll M=1e9+7;
	ll dp[n+1][k+1]={0},prefix[n+1][k+1]={0};
	for(int i=0;i<=n;i++){
		for(int j=0;j<=k;j++){
			
			if(j==0){
				dp[i][j]=1;
				prefix[i][j]=1;
			}else if(i==0){
				dp[i][j]=0;
				prefix[i][j]=prefix[i][j-1];
			}else if(j>a[i]){
				dp[i][j]=(prefix[i-1][j]-prefix[i-1][j-a[i]-1])%M;
				prefix[i][j]=(prefix[i][j-1]+dp[i][j]);
			}else{
				dp[i][j]=prefix[i-1][j]%M;
				prefix[i][j]=(prefix[i][j-1]+dp[i][j]);
			}
		}
	}
 
/*	for(int i=0;i<=n;i++){
		for(int j=0;j<=k;j++){
			cout<<dp[i][j]<<" ";
		}cout<<endl;
	}
 
	for(int i=0;i<=n;i++){
		for(int j=0;j<=k;j++){
			cout<<prefix[i][j]<<" ";
		}cout<<endl;
	}
 */
 
 cout<<dp[n][k]<<endl;
 
	/*
	if(sum<k){
		cout<<0<<endl;
	}else{
 
	}
	*/
	return 0;
}

Measured memory_bytes: 161320
#include <stdio.h>
#include <string.h>
int main(){
    int a[5],k,i,j,ok=1;
	for(i=0;i<5;i++)scanf("%d",&a[i]);
	scanf("%d",&k);
    for(i=0;i<4;i++){
        for(j=i+1;j<5;j++){
            if(a[j]-a[i]<=k)ok*=1;
            else ok*=0;
        }
    }
   if(ok==1) printf("Yay!");
   else printf(":(");
	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int                     long long   
#define double                  long double
#define endl                    "\n"
#define pb                      push_back
#define PI                      3.1415926535897932384626433832795l
#define F                       first
#define S                       second
#define mp                      make_pair
#define f(i,n)                  for(int i=0;i<n;i++)
#define fastio                  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)                  (v).begin(),(v).end()
#define rall(v)                 (v).rbegin(),(v).rend()
#define gcd(a,b)                __gcd((a),(b))
#define fill(a,value)           memset(a,value,sizeof(a));
#define minn(v)                 *min_element(v.begin(), v.end());
#define maxx(v)                 *max_element(v.begin(), v.end());
#define print(x)                cout<<(x)<<endl;
#define sum(v)+x                accumulate(v.begin(), v.end(),x);
#define debug(x)                cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int>           pii;
typedef vector<int>             vi;
 
int dig(int x)
{
    int ans=0;
    while(x>0)
    {
        ans++;
        x/=10;
    }
    return ans;
}
signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int d,s,t;
    cin>>d>>t>>s;
    if(t*s>=d)print("Yes")
    else print("No")
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int >

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); 
    int n, m;
    cin >> n >> m;
    string s[n];    
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    vector<vector<pii>> r(n), c(m);
    for (int i = 0; i < n; i++) {
        if (s[i][0] == '.') {
            r[i].push_back({0, 0});
        }
        for (int j = 1; j < m; j++) {
            if (s[i][j] == '.') {
                if (s[i][j - 1] == '.')
                    r[i].back().se++;
                else
                    r[i].push_back({j, j});
            }
        }
    }

    for (int j = 0; j < m; j++) {
        if (s[0][j] == '.') {
            c[j].push_back({0, 0});
        }
        for (int i = 1; i < n; i++) {
            if (s[i][j] == '.') {
                if (s[i - 1][j] == '.')
                    c[j].back().se++;
                else 
                    c[j].push_back({i, i});
            }
        }
    }
    vector<vector<int>> cnt_r(n, vector<int>(m, 0)), cnt_c(n, vector<int>(m, 0));
    for (int i = 0; i < n; i++) {
        for (auto &range : r[i]) {
            for (int j = range.fi; j <= range.se; j++) {
                cnt_r[i][j] = range.se - range.fi + 1;
            }
        }
    }
    for (int j = 0; j < m; j++) {
        for (auto &range : c[j]) {
            for (int i = range.fi; i <= range.se; i++) {
                cnt_c[i][j] = range.se - range.fi + 1;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans = max(ans, cnt_c[i][j] + cnt_r[i][j] - 1);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 99328
#include<iostream>
#include<cstdio>
#include<cstring>
#define MAX 2000200
#define MIN -2000000300
#define INF 1<<30
using namespace std;
int n;
int A[1000][1000];
int d[1000];
bool used[1000];
 
void Init(int n){
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      A[i][j] = INF;
    }
  }
}
 
int prime(){
  for(int i=0;i<n;i++){
    d[i] = INF;
    used[i]=false;
  }
  int ans=0;
  d[0] = 0;
 
  while(true){
    int v = -1;
    for(int i=0;i<n;i++){
      if(!used[i] && (v == -1 || d[v] > d[i]))v = i;
    }
    if(v == -1)break;
    ans+=d[v];
    used[v] = true;   
 
    for(int i=0;i<n;i++){
      d[i] = min(d[i],A[v][i]);
    }
 
  }
  return ans;
}
 
int main(){
  scanf("%d",&n);
  //  Init(n);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      scanf("%d",&A[i][j]);
      if(A[i][j] == -1)A[i][j] = INF;
    }
  }
  
  printf("%d\n",prime());
  
 
  return 0;
}

Measured memory_bytes: 3532
S = int(input())

L =[]
for _ in range(10**6):
  L.append(0)

for i in range(10**6):
  L[S-1] += 1
  #print(L)
  if L[S-1] > 1:
    print(i+1)
    break
  
  if S%2 == 0:
    S = S//2
  else :
    S = S*3 + 1

Measured memory_bytes: 10904
use std::io::*;
// use std::collections::HashMap;
fn read_int(s: &mut StdinLock) -> usize {
    s.by_ref().bytes().map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .skip_while(|c| c.is_whitespace())
        .fold(0, |a, x| (x as u8 - b'0') as usize + a * 10)
}
fn read_line_split_int(s: &mut StdinLock, n: usize) -> Vec<usize> {
    (0..n).map(|_| read_int(s)).collect()
}
enum Paint {
    PaintToRed,
    PaintToGreen,
    NotPaint,
}
fn main() {
    let s = stdin();
    let mut s = s.lock();
    let x = read_int(&mut s);
    let y = read_int(&mut s);
    let a = read_int(&mut s);
    let b = read_int(&mut s);
    let c = read_int(&mut s);
    let mut q_a = read_line_split_int(&mut s, a);
    q_a.sort_by(|i, j| j.cmp(i));
    q_a.split_off(x);
    let mut q_b = read_line_split_int(&mut s, b);
    q_b.sort_by(|i, j| j.cmp(i));
    q_b.split_off(y);
    let mut r_c = read_line_split_int(&mut s, c);
    r_c.sort();
    let mut paint: Paint;
    let mut ans: usize = 0;
    loop {
        if r_c.len() < 1 {
            break;
        }
        let len_a = q_a.len();
        let len_b = q_b.len();
        paint = Paint::NotPaint;
        for i in 0..std::cmp::max(len_a, len_b) {
            if len_a < i + 1 {
                if q_b.last().unwrap() < r_c.last().unwrap() {
                    paint = Paint::PaintToGreen;
                }
                break;
            } else if len_b < i + 1 {
                if q_a.last().unwrap() < r_c.last().unwrap() {
                    paint = Paint::PaintToRed;
                }
                break;
            } else if q_a[len_a-1-i] < q_b[len_b-1-i] {
                if q_a.last().unwrap() < r_c.last().unwrap() {
                    paint = Paint::PaintToRed;
                }
                break;
            } else if q_a[len_a-1-i] > q_b[len_b-1-i] {
                if q_b.last().unwrap() < r_c.last().unwrap() {
                    paint = Paint::PaintToGreen;
                }
                break;
            }
        }
        match paint {
            Paint::PaintToRed => {
                q_a.pop().unwrap();
                ans += r_c.pop().unwrap();
            },
            Paint::PaintToGreen => {
                q_b.pop().unwrap();
                ans += r_c.pop().unwrap();
            },
            Paint::NotPaint => break,
        }
    }
    println!("{}", 
        ans + q_a.iter().fold(0, |acc, i| i + acc) + q_b.iter().fold(0, |acc, i| i + acc));
}

Measured memory_bytes: 8444
import java.util.Scanner;

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

		Integer kInteger = new Integer(scanner.next());
		Integer sInteger = new Integer(scanner.next());

		for(int x = 0;x<=kInteger;x++) {
			for(int y = 0;y<=kInteger;y++) {
			if(kInteger>=(sInteger - x-y) && 0<=(sInteger - x-y))
				output++;
			}
		}
		System.out.println(output);
		scanner.close();
	}
}


Measured memory_bytes: 58324
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define INF 1000000000000000LL
#define SIZE 200005

using namespace std;
typedef long long ll;

ll count_num(ll a, int num){
	if(num == 0 || num == 4)
    	return a;
  	if(num == 1 || num == 3){
    	if(a == 0) return 2;
      	return a%2;	
    }
  	return (a+1)%2;
}

int main()
{
	int L;
  	ll A[SIZE];
  	cin >> L;
  	for(int i = 0; i < L; i++){
    	cin >> A[i];
    }
  	ll dp[SIZE][5];
  	//初期化
  	for(int i = 0; i <= L; i++){
    	for(int j = 0; j < 5; j++){
        	if(i == 0) dp[i][j] = 0;
          	else dp[i][j] = INF;
        }
    }
  	//dp更新
  	for(int i = 0; i < L; i++){
    	for(int j = 0; j < 5; j++){
        	if(j > 0) dp[i][j] = min(dp[i][j], dp[i][j-1]);
          	dp[i+1][j] = min(dp[i+1][j],dp[i][j] + count_num(A[i], j));
        }
    }
  	ll ans = INF;
  	for(int i = 0; i < 5; i++){
      	//cerr << dp[L][i] << endl;
    	ans = min(ans, dp[L][i]);
    }
  	cout << ans << endl;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define N 100
void Up(int B[],int min,int max);
int C[N];
int main(void){
	int n,i,j,k,B[N],sum,num,min,max;
	char s[N],str[N],*line,A[N];


	for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
		sscanf(str,"%c%c%c%c%c%c%c%c%c%c",&A[0],&A[1],&A[2],&A[3],&A[4],&A[5],&A[6],&A[7],&A[8],&A[9]);
	for(i=0;i<10;i++){
		B[i]=(A[i]-'\0')%48;
	}
	min=0; max=9;
	for(i=0;i<10;i++){
		Up(B,min,max);
		max--;
	}
	printf("%d\n",B[0]);
	}
	return 0;
}

void Up(int B[],int min,int max){
	int i;
	for(i=min;i<max;i++)
		C[i]=(B[i]+B[i+1])%10;
	for(i=min;i<max;i++)
		B[i]=C[i];
}

Measured memory_bytes: 552
def c(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
s=int(input())
mod=10**9+7
ans=0
for i in range(1,s//3+1):
    a=s-3*i
    ans+=c(a+i-1,i-1)
    ans%=mod
print(ans)

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)

const int M=1e9+7;
int mod(int n){
    n%=M;
    return (n+M)%M;
}

int modInv(int a) //extended euclid
{
    int m=M;
    int m0 = m;
    int y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}
const int N=2*1e5+7;
int f[N];

void fact(){
    f[0]=1;
    for(int i=1;i<N;i++)
        f[i]=mod(f[i-1]*i);
}

int nCr(int n,int r){
    int ans=f[n];
    ans=mod(ans*modInv(f[r]));
    ans=mod(ans*modInv(f[n-r]));
    return ans;
}

int32_t main()
{
    boost;
 
    fact();
    int n,k;
    cin>>n>>k;
    int ans=0;
    for(int i=0;i<=min(n-1,k);i++){
        ans=mod(ans+mod(nCr(n,i)*nCr(n-1,i)));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll dp[110][101000];

int main() {
    
    ll n,w;
    cin >> n >> w;
    vector<ll> we(n);
    vector<ll> v(n);
    rep(i,n)    cin >> we[i] >> v[i];

    rep(i,n) {
        for(int sum_w = 0; sum_w <= w; sum_w++) {
            //dp[i][sum_w-we[i]]←ここが負になる場合はダメなのでifをつける
            if(sum_w - we[i] >= 0) {
                dp[i+1][sum_w] = max(dp[i][sum_w], dp[i][sum_w-we[i]] + v[i]);
            }
            else {
                dp[i+1][sum_w] = dp[i][sum_w];
            }
        }
    }

    cout << dp[n][w] << endl;

 return 0;
}

Measured memory_bytes: 79360
#include <iostream>
#include <algorithm>
#include <string> 
#include <string.h>
#include <set>
#include <stdlib.h>
using namespace std; 
int main()
{
	string s;
	cin>>s;
	for (int i=0;i<s.size();i++)
	{
		if (i%2==0) cout<<s[i];
	 } 
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000;
vector<vector<long long>> binom(1001, vector<long long>(1001, 1));
pair<int, long long> dfs(vector<vector<int>> &ch, int v){
  int deg = ch[v].size();
  vector<int> cnt;
  long long ans = 1;
  vector<long long> a;
  for (int w : ch[v]){
    pair<int, long long> tmp = dfs(ch, w);
    cnt.push_back(tmp.first);
    ans *= tmp.second;
    ans %= MOD;
  }
  int sum = 0;
  for (int i = 0; i < deg; i++){
    sum += cnt[i];
  }
  int tmp = sum;
  for (int i = 0; i < deg; i++){
    ans *= binom[tmp][cnt[i]];
    ans %= MOD;
    tmp -= cnt[i];
  }
  sum++;
  return make_pair(sum, ans);
}
int main(){
  int N;
  cin >> N;
  vector<int> cnt(N, 0);
  vector<vector<int>> ch(N);
  for (int i = 0; i < N - 1; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    cnt[b]++;
    ch[a].push_back(b);
  }
  bool ok = true;
  int root = -1;
  for (int i = 0; i < N; i++){
    if (cnt[i] == 0){
      root = i;
    }
    if (cnt[i] >= 2){
      ok = false;
    }
  }
  if (!ok){
    cout << -1 << endl;
  } else {
    for (int i = 2; i <= 1000; i++){
      for (int j = 1; j < i; j++){
        binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j]) % MOD;
      }
    }
    cout << dfs(ch, root).second << endl;
  }
}


Measured memory_bytes: 10640
#include <stdio.h>
#include <stdlib.h>
long int cnt = 0;

void shellSort(int *A, int n, int g){
    int v;
    int j;
    int i;
    for (i = g; i < n; i++){
        v = A[i];
        j = i - g;
        while (A[j] > v && j >= 0){
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
}

int main(void){
    int n;
    int *A;
    int *G;
    int m;
    int i, j;

    A = (int *)malloc(sizeof(int) * 1000000);
    G = (int *)malloc(sizeof(int) * 1000000);

    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }

    m = 0;
    j = 0;

    if (n == 1){
        G[0] = 1;
        m = 1;
    }
    
    if (n > 1 ){
        m = 0;
        for (i = n/2; i >= 1; i = i/2){
            G[m] = i;
            m++;
            if (m == 100){
                G[m] = 1;
                break;
            }
        }
    }

    for (i = 0; i < m; i++){
        shellSort(A, n, G[i]);
    }
    
    printf("%d\n", m);
   
    for (i = 0; i < m - 1; i++){
            printf("%d ", G[i]);
    }
    printf("%d\n", G[m-1]);
    
    printf("%ld\n", cnt);

    for (i = 0; i < n; i++){
        printf("%d\n", A[i]);
    }

    free(A);
    return 0;

}

Measured memory_bytes: 5472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>
inline T read(T&x){
	x=0;int f=0;char ch=getchar();
	while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x=f?-x:x;
}
const int N=1e5+10;
int a[3],idx[3],mn=1e9;
int main(){
	for (int i=0;i<3;i++) read(a[i]),idx[i]=i;
	do{
		int res=0;
		for (int i=1;i<3;i++){
			res+=abs(a[idx[i]]-a[idx[i-1]]);
		}
		mn=min(mn,res);
	}while(next_permutation(idx,idx+3));
	printf("%d\n",mn);
	return 0;
}

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

using namespace std;

#define ll long long

const int mod  = 1e9 + 7;
const ll INF = 1e14;

void solve(){

    string s1, s2;
    cin >> s1 >> s2;
    int count = 0;
    for(int i = 0; i < s1.length(); ++i){
        if(s1[i] == s2[i]) ++count;
    }

    cout << ((int)s1.length()-count);

}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    //int test; cin >> test;
    //for(int t = 1; t <= test; ++t){
        solve();    
    //}

	return 0;
}



Measured memory_bytes: 3804
n=int(input())
a=list(map(int,input().split()))

q=int(input())

bc=[list(map(int,input().split())) for i in range(q)]

lis=[0 for i in range(10**5)]

for i in a:
    lis[i-1]+=1

s=0
for i in range(10**5):
    s+=(i+1)*lis[i]


for i in range(q):
    bi,ci=bc[i]
    s+=lis[bi-1]*(ci-bi)
    print(s)
    lis[ci-1]+=lis[bi-1]
    lis[bi-1]=0

Measured memory_bytes: 32892
n = gets.to_i

inputs = gets.split.map(&:to_i)

min = inputs.inject(:+)
(1..(n - 1)).each do |i|
  diff = (inputs.slice(0, i).inject(:+) - inputs.slice(i, n - i).inject(:+)).abs
  min =  [diff, min].min
end

puts min


Measured memory_bytes: 1788
/**
*    author:  souzai32
*    created: 08.08.2020 00:00:45
**/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {

    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> AC(n);
    int countAC=0;

    rep(i,n-1){
        if(s.at(i)=='A'&&s.at(i+1)=='C') countAC++;
        AC.at(i)=countAC;
    }
    AC.at(n-1)=AC.at(n-2);
    //rep(i,n) cout << AC.at(i) << endl;

    int l,r;
    int ans;
    rep(i,q){
        cin >> l >> r;
        l--;
        r--;
        ans=AC.at(r)-AC.at(l);
        if(l!=n-1){
            if(s.at(l)=='A'&&s.at(l+1)=='C') ans++;
        }
        if(r!=n-1){
            if(s.at(r)=='A'&&s.at(r+1)=='C') ans--;
        }
        cout << ans << endl;
    }
    

    return 0;
}

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

vector<ll> solve(ll D, ll M, vector<ll>& C, vector<vector<ll>>& S, vector<int>& T) {
    vector<ll> V(D), L(M);
    ll v = 0;
    for ( int d = 0; d < D; d++ ) {
        int t = T[d];
        v += S[d][t];
        for ( int i = 0; i < M; i++ ) {
            if ( i != t ) {
                L[i] += C[i];
            } else {
                L[i] = 0;
            }
            v -= L[i];
        }
        V[d] = v;
    }
    return V;
}

int main() {
    ll D, M = 26;
    cin >> D;
    vector<ll> C(M);
    for ( int i = 0; i < M; i++ ) {
        cin >> C[i];
    }
    vector<vector<ll>> S(D, vector<ll>(M));
    for ( int i = 0; i < D; i++ ) {
        for ( int j = 0; j < M; j++ ) {
            cin >> S[i][j];
        }
    }
    vector<int> T(D);
    for ( int i = 0; i < D; i++ ) {
        cin >> T[i];
        T[i]--;
    }
    vector<ll> V = solve(D, M, C, S, T);
    for ( int i = 0; i < D; i++ ) {
        cout << V[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3692
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var n=arr.shift()-0;
var v=arr.shift().split(" ").map(Number);
var cnt=1;
for(var i=0;i<n-1;i++){
   if(v[i]>=v[i+1])cnt++;
}
console.log(cnt);
console.log(n);


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}
int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll a_c = (a - 1) / c;
    ll a_d = (a - 1) / d;
    ll a_cd = (a - 1) / (lcm(c, d));
    ll b_c = b / c;
    ll b_d = b / d;
    ll b_cd = b / (lcm(c, d));
    // debug(a_c);
    // debug(a_d);
    // debug(a_cd);
    // debug(b_c);
    // debug(b_d);
    // debug(b_cd);
    ll ans = (b - a + 1) - ((b_c - a_c) + (b_d - a_d) - (b_cd - a_cd));
    out(ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int i = 1;
		Scanner sc = new Scanner(System.in);
		while (true) {
			int x = sc.nextInt();
			if (x == 0) {
				break;
			} else {
				System.out.println("Case " + i + ": " + x);
				i++;
			}
		}
		sc.close();
	}

}



Measured memory_bytes: 42804
#include <iostream>
#include <vector>
#include <random>
using namespace std;
typedef long long ll;
int D;
int v=27;
vector<int> c(v,0);
vector<vector<int>> s;
vector<int> t;
vector<int> last(v,0);

void init(){
    cin >> D;
    s.resize(D+1);
    t.resize(D+1);
    for(int i=0;i<D+1;i++){
        s[i].resize(v);
    }

    for(int i=1;i<27;i++){
        cin >> c.at(i);
    }
    for(int i=1;i<D+1;i++){
        for(int j=1;j<27;j++){
            cin >> s.at(i).at(j);
        }
    }
/*
    for(int i=1;i<D+1;i++){
        cin >> t.at(i);
    }
*/

}

void init_last(){
  for(int i=0;i<v;i++){
    last.at(i) = 0;
  }
}

ll calc(){
    ll ans=0;
    init_last();
    for(int i=1;i<D+1;i++){
        ans += s.at(i).at(t.at(i));
        last.at(t.at(i)) = i;
        for(int j=1;j<v;j++){
            ans -= c.at(j) * (i - last.at(j));
        }
    }
    return ans;
}

int main(){
    init();

    std::random_device rd;

    std::mt19937 mt(rd());

    for(int i=1;i<D+1;i++){
        t.at(i) = mt() % 26 + 1;
    }

    ll sol = calc();
    ll trial = 100000;
    for(int i=0;i<trial;i++){
        int d,q;
        d = mt()%365 + 1;
        q = mt()%26 + 1;
        int old = t.at(d);
        t.at(d) = q;
        if(sol > calc()){
            t.at(d) = old;
        }
    }

    for(int i=1;i<D+1;i++){
        cout << t.at(i) << endl;
    }
  
  	return(0);
}


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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int popcount(int N){
  return __builtin_popcount(N);
}

int main(){
  int N, M;
  while(cin >> N >> M && N){
    vector<int> L(N);
    REP(i, N) cin >> L[i];
    static int dp[1000][1 << 12] = {};
    memset(dp, -1, sizeof(dp));
    for(int S = 0; S < 1 << M; S++){
      if(popcount(S) == L[0]) dp[0][S] = 0;
    }
    int mask = (1 << M) - 1;
    for(int i = 1; i < N; i++){
      for(int S = 0; S < 1 << M; S++){
        if(dp[i - 1][S] != -1){
          int NS = S << 1 & mask;
          if(popcount(NS) == L[i]) dp[i][NS] = S;
          NS |= 1;
          if(popcount(NS) == L[i]) dp[i][NS] = S;
        }
      }
    }
    int CRS = -1;
    for(int S = 0; S < 1 << M; S++) if(dp[N - 1][S] != -1) CRS = S;
    if(CRS == -1){
      cout << "Goofy" << endl;
      continue;
    }
    vector<int> ans;
    for(int i = N - 1; i >= 0; i--){
      ans.push_back(CRS & 1);
      if(i != 0) CRS = dp[i][CRS];
    }
    for(int i = 1; i < M; i++) ans.push_back(CRS >> i & 1);
    reverse(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); i++) cout << ans[i];
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 17244
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
 double pi = 3.141592653589793238;

int main() {
 double a,b,h,m,x,y;
  cin>>a>>b>>h>>m;
  x=a*a+b*b-2*a*b*cos(((5.5*m-30*h)/180)*pi);
  y=sqrt(x);
 
cout << fixed << setprecision(20) << y << endl;
  
  
}



Measured memory_bytes: 4228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,n,s,t;
    cin>>h>>w>>n>>s>>t;
    string a,b;
    cin>>a>>b;
    int g,now;
    g=w-t+1;//右に行ってクリアするため
    now=t;
    rep(i,n){
      if(a[i]=='R'){
        now++;
        if(now>w){
          cout<<"NO"<<endl;
          return 0;
        }
      }
      if(b[i]=='L' && now>=2){
        now--;
      }
    }
    g=t;//左に行ってクリアするため
    now=t;
    rep(i,n){
      if(a[i]=='L'){
        now--;
        if(now<1){
          cout<<"NO"<<endl;
          return 0;
        }
      }
      if(b[i]=='R' && now<w){
        now++;
      }
    }
    g=s;//上に行ってクリアするため
    now=s;
    rep(i,n){
      if(a[i]=='U'){
        now--;
        if(now<1){
          cout<<"NO"<<endl;
          return 0;
        }
      }
      if(b[i]=='D' && now<h){
        now++;
      }
    }
    g=h-s+1;//下に行ってクリアするため
    now=s;
    rep(i,n){
      if(a[i]=='D'){
        now++;
        if(now>h){
          cout<<"NO"<<endl;
          return 0;
        }
      }
      if(b[i]=='U' && now>=2){
        now--;
      }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 920
N, K = map(int, input().split())

result = [0]*N
ans = 0

for i in range(K):
  p = input()
  tmp = list(map(int, input().split()))
  #print(tmp)
  
  for j in tmp:
    result[j-1] = 1
  
for i in result:
  if i == 0:
    ans += 1

print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);//this works only
    cin.tie(NULL);// when first all inputs are from user
    cout.tie(NULL);//you will see all outputs afterwards
    int h,w,dp[1005][1005];
    cin>>h>>w;
    for (int i = 1; i <=h; ++i)
    {
 		string s;
 		cin>>s;
 		for(int j=1;j<=w;j++)
 		{
 			if(s[j-1]=='.') dp[i][j]=-1;
 			else dp[i][j]=0;
 		}   
    }
    for(int i=0;i<=max(h,w);i++)
    {
    	if(i<=w) dp[0][i]=0;
    	if(i<=h) dp[i][0]=0;
    }
    /*for (int i = 0; i <=h; ++i)
    {
    	for (int j = 0; j <=w; ++j)
    	{
    		cout<<dp[i][j]<<" ";
    	}
    	cout<<"\n";
    }*/
    dp[1][1]=1;
    for(int i=1;i<=h;i++)
    {
    	for(int j=1;j<=w;j++)
    	{
    		if(dp[i][j]!=-1) continue;
    		dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
    		//cout<<dp[i][j]<<" ";
    	}
    	//cout<<endl;
    }
    cout<<dp[h][w]<<endl;
    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define REP(i, vec) for(auto i = vec.begin(); i != vec.end(); ++i)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T> inline T LCM(T a, T b) { return (a + (b - 1)) / b; }

int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int a, b, q;
	cin >> a >> b >> q;

	vl s(a), t(b), x(q), dist(a + b), nor;
	vll all;

	rep(i, a) {
		cin >> s[i];
		all.push_back({ s[i],0 });
		nor.push_back(s[i]);
	}
	rep(i, b) {
		cin >> t[i];
		all.push_back({ t[i],1 });
		nor.push_back(t[i]);
	}
	rep(i, q) {
		cin >> x[i];
	}

	sort(ASC(s));
	sort(ASC(t));
	sort(ASC(all));
	sort(ASC(nor));

	rep(i, a + b) {
		pair<ll, ll> p = all[i];

		// p = shrine
		if (p.second == 0) {
			int idx = upper_bound(ASC(t), p.first) - t.begin();

			ll mn = INF, mx = INF;
			if (idx != 0) {
				mn = abs(t[idx - 1] - p.first);
			}
			if (idx != b) {
				mx = abs(t[idx] - p.first);
			}

			dist[i] = min(mn, mx);
		}
		else {
			int idx = upper_bound(ASC(s), p.first) - s.begin();

			ll mn = INF, mx = INF;
			if (idx != 0) {
				mn = abs(s[idx - 1] - p.first);
			}
			if (idx != a) {
				mx = abs(s[idx] - p.first);
			}

			dist[i] = min(mn, mx);
		}
	}

	rep(i, q) {
		int idx = upper_bound(ASC(nor), x[i]) - nor.begin();

		ll mn = INF, mx = INF;
		ll ans1 = INF, ans2 = INF;
		if (idx != 0) {
			mn = abs(nor[idx - 1] - x[i]);
			ans1 = mn + dist[idx - 1];
		}
		if (idx != a + b) {
			mx = abs(nor[idx] - x[i]);
			ans2 = mx + dist[idx];
		}
		
		cout << min(ans1, ans2) << endl;
	}
}

Measured memory_bytes: 12268
#include<stdio.h>

int main()
{
    int A, B, C;

    scanf("%d %d %d", &A, &B, &C);

    if(((A==B)&&(A!=C))||((A==C)&&(A!=B))||((B==C)&&(B!=A)))printf("Yes");
    else printf("No");

    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n-1; i >= 0; i--)
#define FOR(i, n, m) for(int i = n; i < (int)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define PI 3.14159265358979

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

ll MOD = 1000000007;

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main()
{
    string S;
    cin >> S;
    ll N = S.length();
    vector<vector<mint>> dp(N+1, vector<mint>(13, 0));
    dp[0][0] = 1;
    REP(i, N) {
        ll t = S[i] - '0';
        if (S[i] == '?') {
            t = -1;
        }
        REP(j, 13) {
            REP(k, 10) {
                if (t != -1 && t != k) continue;
                dp[i+1][(j*10 + k)%13] += dp[i][j];
            }
        }
    }
    PRINT(dp[N][5]);
    return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	cin >> n >> s;

	long long r, g, b;
	r=count(s.begin(),s.end(),'R');
	g=count(s.begin(),s.end(),'G');
	b=count(s.begin(),s.end(),'B');

	long long ans=r*g*b;
	for(int i=0; i<n; ++i){
		for(int j=1; j<n; ++j){
			if(i+j+j<n && s[i]!=s[i+j] && s[i]!=s[i+j+j] && s[i+j]!=s[i+j+j]){
				--ans;
			}
		}
	}
	// for(int i=0; i<n-2; ++i){
	// 	for(int j=i+1; j<n-1; ++j){
	// 		int k=2*j-i;
	// 		if(k>=n) break;
	// 		if(s[i]!=s[j] && s[i]!=s[k] && s[j]!=s[k]) --ans;
	// 	}
	// }

	cout << ans << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int r,g,b;
    cin >> r >> g >> b;

    int num = r*100 + g*10 + b;
    if(num % 4 == 0){
        cout << "YES";
    }else{
        cout << "NO";
    }
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main()
{
    ll a;
    int b = 0;
    cin >> a;
    char tmp;
    while (cin >> tmp){
        if (tmp == '.')
            continue;
        b *= 10;
        b += tmp - '0';
    }
    ll rem = a % 100;
    a /= 100;
    cout << a * b + (rem*b/100) << endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 100000

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N,A;
    cin >> N >> A;
    cout << N * N - A << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int n, k;
string s;

int main() {
	cin >> n >> k >> s;
	
	int j = 0, ans = 0, c = 0;
	inc(i, n) {
		if(s[i] == '0' && (i == 0 || s[i - 1] == '1')) { c++; }
		if(c <= k) { setmax(ans, i - j + 1); } else {
			while(c > k) {
				if(s[j] == '0' && (j == n - 1 || s[j + 1] == '1')) { c--; }
				j++;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512