akhauriyash/Code-Regression huggingface dataset:
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#define REP(i, N) for(int i=0; i<N; i++)
using namespace std;

//#include "atcoder.hpp"

int gcd(int a, int b) {
    if (a>b) swap(a,b);
    
    auto r = b % a;
    
    return (r ? gcd(r, a) : a);
}

int main() {
    int N, num_minus = 0;
    
    cin >> N;
    
    vector<int> a(N);
    long long mina = LONG_LONG_MAX, sum = 0LL;
    for (auto& i : a)
       cin >> i;

     vector<int> gcdf = {a.front()}, gcdr = {a.back()};
   
    for (auto i : a) {
        gcdf.push_back(gcd(gcdf.back(), i));
    }
    for (auto it = a.rbegin(); it != a.rend(); ++it) {
        gcdr.push_back(gcd(gcdr.back(), *it));
    }
    
    int r = max(gcdr[N - 2 + 1], gcdf[N - 2 + 1]);
    
    for (int i = 1; i < N - 1; i++) {
        r = max(r, gcd(gcdf[i - 1 + 1], gcdr[N - i - 2 + 1]));
    }

    cout << r << endl;
    
    return 0;
}





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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int x, y; cin >> x >> y;
  VI gr{0,1,3,1,2,1,2,1,1,2,1,2,1};
  cout << (gr[x] == gr[y]?"Yes":"No") << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
l = [[0,0]]*n
for i in range(n):
    l[i] = [a[i],i+1]
l.sort()
ans = [0]*n
for i in range(n):
    ans[i] = str(l[i][1])
print(' '.join(ans))

Measured memory_bytes: 28416
#include <iostream>

using namespace std;

int main()
{
    int n,k,s;
    cin>>n>>k>>s;
    for(int i=0;i<k;++i){
        cout<<s<<" ";
    }
     for(int j=0;j<(n-(k));++j){
        if(s!=1000000000){
            cout<<(s+1)<<" ";
        }else{
            cout<<(s-1)<<" ";
        }
    }
    cout<<endl;
    return 0;
}

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

int main() {
  ll a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  ll d=min(a+b,2*c);
  if(x>=y){cout<<d*y+(x-y)*min(a,2*c);}
  else{cout<<d*x+(y-x)*min(b,2*c);}
}
      



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String[] s = sc.next().split("");

        String preColor = "";
        int result = 0;
        for (int i = 0; i < n; i++) {
            if (!preColor.equals(s[i])) {
                result++;
            }
            preColor = s[i];
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 32760
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 50;
vector<int> g[N];
bitset<N> vis;
bool mark[N][N];

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n, m, u, v;
    cin >> n >> m;
    vector<pii> edges;
    fore(i,0,m) {
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
        edges.pb({u, v});
    }
    int cnt = 0;
    for (auto &e : edges) {
        mark[e.F][e.S] = mark[e.S][e.F] = true;
        vis = 0;
        dfs(0);
        if (vis.count() < n) cnt++;
        mark[e.F][e.S] = mark[e.S][e.F] = false;
    }
    cout << cnt << endl;
}


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

using ll = long long;

// 区間の情報を二分木で管理
struct LazySegmentTree{
    // 配列サイズを 2 べきにしたときのサイズ
    int sz;
    // 1-indexed で管理
    vector<ll> data;
    vector<ll> lazy;

    LazySegmentTree(int n){
        sz = 1;
        while(sz < n)   sz <<= 1;
        data.assign(sz << 1, 0);
        lazy.assign(sz << 1, 0);
    }

    void set(int idx, const int& x){
        data[idx + sz] = x;
    }

    // k : セグメント木上のインデックス
    //     (set された配列のどの区間かを表す)
    void build(){
        for(int k = sz - 1; k >= 0; --k){
            data[k] = max(data[k << 1], data[k << 1 | 1]);
        }
    }

    // 子ノードへの伝播
    void propagate(int k){
        if(lazy[k] == 0)    return;

        if(k < sz){
            lazy[k << 1] += lazy[k];
            lazy[k << 1 | 1] += lazy[k];
        }
        data[k] += lazy[k];
        lazy[k] = 0;
    }

    // [a, b) の各要素に対して x を一様加算
    ll update(int a, int b, const ll& x, int k = 1, int l = 0, int r = -1){
        if(r == -1) r = sz;
        
        propagate(k);

        // 更新する範囲が今見ている区間内にない
        if(b <= l || r <= a)    return data[k];

        // 更新する区間が今見ている区間を内包している
        else if(a <= l && r <= b){
            lazy[k] += x;
            propagate(k);
            return data[k];     // 子ノードの更新は遅延させる
        }

        else{
            return data[k] = max(update(a, b, x, k << 1, l, (l + r) >> 1),
                                update(a, b, x, k << 1 | 1, (l + r) >> 1, r));
        }
    }

    // [a, b) における最大値を取得
    ll query(int a, int b, int k = 1, int l = 0, int r = -1){
        if(r == -1) r = sz;
        
        propagate(k);
        
        if(b <= l || r <= a)    return 0;
        else if(a <= l && r <= b)   return data[k];
        else{
            return max(query(a, b, k << 1, l, (l + r) >> 1),
                        query(a, b, k << 1 | 1, (l + r) >> 1, r));
        }
    }

    ll operator[](const int& idx){
        return query(idx, idx + 1);
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int>>> table(n + 1);
    for(int i = 0; i < m; ++i){
        int l, r, a;
        cin >> l >> r >> a;
        table[r].emplace_back(l, a);
    }
    LazySegmentTree dp(n + 1);
    for(int i = 1; i <= n; ++i){
        dp.update(i, i + 1, dp.query(0, i));
        for(auto p : table[i]){
            int l = p.first;
            ll a = p.second;
            dp.update(l, i + 1, a);
        }
    }
    cout << dp.query(0, n + 1) << endl;
}

Measured memory_bytes: 19328
#include<stdio.h>

int main(void)
{
    int a,b;
    char op;
    
    while(1){
        scanf("%d %c %d",&a,&op,&b);
    if( op =='?')
       break;
    else if( op == '+')
        printf("%d\n",a+b);
    else if( op == '-')
        printf("%d\n",a-b);
    else if( op == '*')
        printf("%d\n",a*b);
    else if( op == '/')
        printf("%d\n",a/b);
    }
	return 0;
}


Measured memory_bytes: 2060
#!/usr/bin/env ruby

N = gets.chomp.to_i

arr = []
i = 1
while line = gets do
  tmp = [i] + line.chomp.split
  tmp[2] = tmp[2].to_i
  arr << tmp
  i = i + 1
end

# p i
# p arr


arr2 = arr.sort { |a, b|
  res = a[1] <=> b[1]

  res == 0 ? -1 * (a[2] <=> b[2]) : res
}

arr2.each do |a|
  puts a[0]
end


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N - 1);
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for(int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  for(int i = 0; i < N - 1; i++) {
    cin >> C.at(i);
  }
  int S = 0;
  for(int i = 0; i < N; i++) {
    S += B.at(i);
  }
  for(int i = 0; i < N - 1; i++) {
    if(A.at(i + 1) ==A.at(i) + 1) {
      S += C.at(A.at(i) - 1);
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
//using System.Linq;
class Program
{
	static void Main(string[] args)
	{
		// 入力フェーズ
        string[] input = Console.ReadLine().Split(' ');
				int N = int.Parse(input[0]);
				int M = int.Parse(input[1]);

				// Mの約数のうちM/N以下の物を探す

				// Mの約数を探す
				int max = (int)Math.Sqrt(M);
				List<int> div = new List<int>();
				//div.Add(1);
				for(int i=1; i<= max; i++)
				{
					if(M%i == 0)
					{
						div.Add(i);
						div.Add(M/i);
					}
				}

				div.Sort();

				for(int i=div.Count - 1; i>=0; i--)
				{
					if(div[i] <= M/N)
					{
						Console.WriteLine(div[i] + "");
						break;
					}
				}
    }

		class point
		{
			public int x{set; get;}
			public int y{set; get;}
			public int h{set; get;}
		}
}


Measured memory_bytes: 13140
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

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

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	A, _ := sc.nextInt(), sc.nextInt()
	S := sc.nextStr()

	ok := true
	for i := 0; i < len(S); i++ {
		if i == A && S[i] != '-' {
			ok = false
		}
		if i != A && S[i] == '-' {
			ok = false
		}
	}
	if ok {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}
	wtr.Flush()
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll = int long long;
map <int ,int> mpa,mpb;

int main (){
  ll N;
  cin  >> N;
  ll a[N];
  ll ans=0;
  ll l=0,r=0;
  for(ll i=0;i<N;i++){
    cin >> a[i];
  }
  sort(a,a+N);
  ll k=1;
  ll tmp;
  for(ll i=1;i<N;i++){
    if(a[i-1]==a[i]){
      k++;
      l=a[i];
      if(k>=4){
        l=r=a[i];
      }
      continue;
    }
    else{
      if(l>r){
        tmp=l;
        l=r;
        r=tmp;  
      }
      k=1;
    }
  }
  ans=l*r;
  cout << ans;
}

Measured memory_bytes: 1024
//Volume2-0205
import java.util.Scanner;

class Main {

	private static int[] cnt,
             		     player,
		                 result;

	public static void main(String[] args){
		int   victory,loss;

		Scanner sc = new Scanner(System.in);

		while(true){
			cnt    = new int[4];
			player = new int[5];
			result = new int[5];
			player[0] = sc.nextInt();
			if(player[0] == 0){break;}
			cnt[player[0]]++;
			for(int i=1;i<5;i++){
				player[i] = sc.nextInt();
				cnt[player[i]]++;
			}
			scape : {
				if(cnt[1] == 5 || cnt[2] == 5 || cnt[3] == 5 ||
				  (cnt[1] != 0 && cnt[2] != 0 && cnt[3] != 0    )){
					for(int j=0;j<5;j++){result[j] = 3;}
					break scape;
				}
				victory = 0; loss = 0;
				if       (cnt[1] != 0 && cnt[2] != 0){
					victory = 1;
					loss    = 2;
				} else if(cnt[2] != 0 && cnt[3] != 0){
					victory = 2;
					loss    = 3;
				} else if(cnt[1] != 0 && cnt[3] != 0){
					victory = 3;
					loss    = 1;
				}
				for(int j=0;j<5;j++){
					if        (player[j] == victory){
						result[j] = 1;
					} else if (player[j] == loss){
						result[j] = 2;
					}
				}
			}
			for(int i:result){System.out.println(i);}
		}
	}
}

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

int main(){
  long long  x,k,d,n;
  cin >> x >> k >> d;
  if(x < 0){
    x *= -1;
  }
n = x/d;

if(k <= n){
  x -= k*d;
  cout << x << endl;
}else{
  if((n-k)%2 == 0){
      x -= n*d;
  cout << x << endl;
  }else{
    if(llabs(x%d-d) < x%d+d){
      x -= (n+1)*d;
      cout << llabs(x) << endl;
    }else{
      x -= (n-1)*d;
        cout << x << endl;
    }

  }
}

  return 0;
}

Measured memory_bytes: 3564
#include<stdio.h>
#include<stdlib.h>

#define MAX_N 200001

void merge_sort (long int array[], int left, int right) {
  int i, j, k, mid;
  long int work[MAX_N];  
  if (left < right) {
    mid = (left + right)/2; 
    merge_sort(array, left, mid);  
    merge_sort(array, mid+1, right);  
    for (i = mid; i >= left; i--) { work[i] = array[i]; } 
    for (j = mid+1; j <= right; j++) {
      work[right-(j-(mid+1))] = array[j]; 
    }
    i = left; j = right;
    for (k = left; k <= right; k++) {
      if (work[i] < work[j]) { array[k] = work[i++]; }
      else                   { array[k] = work[j--]; }
    }
  }
}

int main(void){

    int N,K,i;
    long int H[MAX_N],ans = 0;

    scanf("%d %d",&N,&K);
    for(i = 0;i < N;i++){
        scanf("%ld",&H[i]);
    }

    merge_sort(H,0,N-1);

    for(i = N-1;i >= 0;i--){
        //printf("%ld ",H[i]);
        if(K > 0){
            H[i] = 0;
            K--;
        }else{
            ans += H[i];
        }
    }

    printf("\n%ld\n",ans);
    return 0;
}

Measured memory_bytes: 29824
N,M=map(int,input().split())
ks=[list(map(int,input().split())) for _ in range(M)]
p=list(map(int,input().split()))
ans=0
for s in range(1<<N):
    for j in range(M):
        cnt=0
        for h in ks[j][1:]:
            h-=1
            if (s>>h)&1:
                cnt+=1
                cnt%=2
        if cnt!=p[j]:
            break
    else:
        ans+=1
print(ans)


Measured memory_bytes: 3064
def bomb(x,y):
    s=M[y]
    if s[x]=="0":return
    M[y]=s[:x]+"0"+s[x+1:]
    for e in [-3,-2,-1,1,2,3]:
        bomb(x+e,y)
        bomb(x,y+e)
    return

A=range(14)
B=range(3,11)
M=["00000000000000" for i in A]
z="000"
n=input()+1
for i in range(1,n):
    s=raw_input()
    for j in B:
        M[j]=z+raw_input()+z
    x=input()+2
    y=input()+2
    bomb(x,y)
    print "Data %d:" %(i)
    for j in B:
        print M[j][3:-3]

Measured memory_bytes: 4284
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    char a;
    cin >> a;

    if(a >= 'a' && a <= 'z'){
        cout << "a" << endl;
    } else {
        cout << "A" << endl;
    }

    
    return 0;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0119
"""
import sys
from collections import deque


def bfs(u, result, out_edge, in_degree, processed):
    q = deque()
    q.append(u)
    processed[u] = True
    while q:
        u = q.popleft()
        result.append(u)
        for e in out_edge[u]:
            in_degree[e] -= 1   #  ?????¨?????????????????????(u)?????????????????¨???u?????\?¶????(e)????????\????¬???°???1???????????¨?????????
            if in_degree[e] == 0 and processed[e] == False: #  ??\????¬???°???1??????????????????0???????????°??????????????????????¬??????????????£??????????
                processed[e] = True
                q.append(e)


def solve(m, in_degree, out_edge):
    result = []
    processed = [False for _ in range(m+1)] #  ???????????????????????????????????????????????°

    for i, u in enumerate(in_degree[1:], start=1):
        if u == 0 and processed[i] == False: #  ??\????¬???°???0???????????????
            bfs(i, result, out_edge, in_degree, processed)
    return result


def main(args):
    m = int(input())
    n = int(input())
    in_degree = [0 for _ in range(m+1)] #  ????????????????????\????¬???°
    out_edge = [[] for _ in range(m+1)] #  ???????????????????????????(??\?¶?)?????????????????????
    for _ in range(n):
        s, t = [int(x) for x in input().split(' ')]
        out_edge[s].append(t)
        in_degree[t] += 1

    result = solve(m, in_degree, out_edge)
    print('\n'.join(map(str, result)))

if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8084
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int k,n,m,l,o,z=0;
	cin>>k>>n;
	cin>>l;
	o=l;
	bool r=1;
	n--;
	while(n--)
    {
        cin>>m;
        z=max(z,m-o);
        o=m;
    }
    z=max(z,l+k-o);
    cout<<k-z<<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
count = 0
flag = True
while flag:
    flag = False
    for j in range(n -1 , 0, -1):
        if a[j] < a[j-1]:
            a[j],a[j-1] = a[j-1],a[j]
            count += 1
            flag = True
print(*a)
print(count)


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

int main(){
  string a;
  int i = 0;
  
  cin >> a;
  
  if (a[0] == '1') i += 1;
  if (a[1] == '1') i += 1;
  if (a[2] == '1') i += 1;
  
  cout << i;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <cstring>

#define NOT_DEFINED 2
#define NORMAL 1
#define IRREGULAR 0

using namespace std;

typedef struct {
    int battery;
    int motor;
    int cable;
    bool hasSucceeded;
} Query;

struct IsSuccess {
    bool operator()(Query &a, Query &b) const {
        return (a.hasSucceeded < b.hasSucceeded);
    }
};


char parts[300];

int main() {
    while (1) {
        int i, a, b, c;
        int N;
        priority_queue<Query, vector<Query>, IsSuccess> queries;

        scanf("%d %d %d", &a, &b, &c);
        if (a == 0 && b == 0 && c ==0) {
            return 0;
        }

        scanf("%d", &N);
        for (i=0;i<N;i++) {
            int i, j, k ,r;
            Query query;

            scanf("%d %d %d %d", &i, &j, &k, &r);
            query.battery = i-1;
            query.motor = j-1;
            query.cable = k-1;
            query.hasSucceeded = r;

            queries.push(query);
        }

        memset(parts, NOT_DEFINED, 300);

        while (!queries.empty()) {
            int i, j, k, r;
            Query query = queries.top();

            i = query.battery;
            j = query.motor;
            k = query.cable;
            r = query.hasSucceeded;

            if (r) {
                parts[i] = NORMAL;
                parts[j] = NORMAL;
                parts[k] = NORMAL;
            } else {
                if (parts[i] == NORMAL && parts[j] == NORMAL) {
                    parts[k] = IRREGULAR;
                }

                if (parts[j] == NORMAL && parts[k] == NORMAL) {
                    parts[i] = IRREGULAR;
                }

                if (parts[k] == NORMAL && parts[i] == NORMAL) {
                    parts[j] = IRREGULAR;
                }
            }

            queries.pop();
        }

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

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

int main()
{
    string s, t;
    cin >> s >> t;
    cout << (s.size() + 1 == t.size() && s == t.substr(0, s.size()) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>

int main(){
  int a,b,k,r=0,i;
  scanf("%d%d%d",&a,&b,&k);
  for(i=a;i<=b;i++){
    if(i%k==0){r++;}
  }
  printf("%d\n",r);
  return 0;
}

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

int main(){
  long long n,a,b;
  cin >> n >> a >> b;
  if((n==1&&b-a>=2) || a>b){
    cout << 0 << endl;
  }
  else{
    cout << (n-2)*(b-a)+1 << endl;
  } 
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math


def main():
  a, b, x = map(int, input().split())
  x = x / a

  if x > a * b * 0.5:
    t = math.atan((2 * (a * b - x)) / (a ** 2))
  else:
    t = math.atan((b ** 2) / (2 * x))

  print(t * 180 / math.pi)


if __name__ == '__main__':
  main()


Measured memory_bytes: 38384
W,H,N=map(int,input().split())
d=[]
for i in range(H):
  d.append([1]*W)
for j in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    for i1 in range(H):
      for x1 in range(x):
        d[i1][x1]=0
  elif a==2:
    for i2 in range(H):
      for x2 in range(x,W):
        d[i2][x2]=0
  elif a==3:
    for i3 in range(y):
      for y1 in range(W):
        d[i3][y1]=0
  else:
    for i4 in range(y,H):
      for y2 in range(W):
        d[i4][y2]=0
ans=0
for k in d:
  ans+=sum(k)
print(ans)


Measured memory_bytes: 9244
n = int(input())
s = []
for i in range(n):
    s.append(input())
m = int(input())
t = []
for i in range(m):
    t.append(input())
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
s_t = s + t
s_t_unique = get_unique_list(s_t)
results = []
for i in range(len(s_t_unique)):
    s_count = s.count(s_t_unique[i])
    t_count = t.count(s_t_unique[i])
    result = s_count - t_count
    results.append(result)
if max(results) >= 0:
    print(max(results))
else: 
    print(0)


Measured memory_bytes: 3064
def check(l,P):
    f = 0
    for i in P:
        if l[i[1]-1] - l[i[0]-1] == i[2]:
            f += i[3]
    return f
def main():
    A,B,C = map(int,input().split())
    P = [list(map(int,input().split())) for i in range(C)]
    L = [[1]]
    for i in range(2,A+1):
        L2 = []
        for j in L:
            for k in range(j[-1],B+1):
                L2.append(j+[k])
        L = L2[:]
    res = 0
    for i in L:
        res = max(res,check(i,P))
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 20488
#include<stdio.h>
int main(void)
{
	int a[3],i,j,swap;

	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	
	for(i=0;i<2;i++){
		for(j=2;j>i;j--){
			if(a[j-1]>a[j]){
				swap=a[j];
				a[j]=a[j-1];
				a[j-1]=swap;
			}
		}
	}

	printf("%d %d %d\n",a[0],a[1],a[2]);

	return 0;
}

Measured memory_bytes: 596
n, c, k = map(int, input().split())
t = sorted([int(input()) for _ in range(n)])
ans = 1
busNin = 0
busFirstp = 0
for i in range(n):
    if t[i]-t[busFirstp] > k or busNin == c:
        ans += 1
        busNin = 1
        busFirstp = i
        continue
    busNin += 1
print(ans)


Measured memory_bytes: 8280
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
def inv_mod(a, p=10**9+7):
    p = abs(p)
    a %= p
    stack = []
    p0 = p
    while a > 1:
        d, a, p = p//a, p%a, a
        stack.append(d)
    x, y = 1, 0
    while stack:
        d = stack.pop()
        x, y = y-d*x, x
    return x % p0
MOD = 10**9 + 7

N = int(input())
x = inpl()
d = [x[i+1]-x[i] for i in range(N-1)]

fac = 1
for i in range(2,N):
    fac = fac * i % MOD
inv = [ inv_mod(i,MOD) for i in range(1,N)]

ans = 0
s = 0
for i in range(N-1):
    s += inv[i]
    ans += d[i]*s
    ans %= MOD
ans = ans * fac % MOD
print(ans)

Measured memory_bytes: 63488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto e : s) os << e; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += b % mod) %= mod; if (a < 0) a += mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

using pci = pair<char, int>;
vector<pci> runlength(string s) {
  vector<pci> ret;
  int cnt = 1;
  int n = sz(s);
  rep3(i, 1, n) {
    if (s[i] == s[i - 1]) ++cnt;
    else { ret.eb(s[i - 1], cnt); cnt = 1; }
  }
  ret.eb(s[n - 1], cnt);
  return ret;
}

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  auto r = runlength(s);
  cout << sz(r) << endl;
}


Measured memory_bytes: 4464
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
	Scanner in = new Scanner();

	class Scanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

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

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}

	void run() {
		for (;;) {
			int n = in.nextInt();
			if (n == 0)
				return;
			System.gc();
			Map<Integer, Integer> HM = new HashMap<Integer, Integer>();
			boolean judge = false;
			for (int i = 0; i < n; i++) {
				int str = in.nextInt();
				if (HM.containsKey(str))
					HM.put(str, HM.get(str) + 1);
				else
					HM.put(str, 1);
			}
			for (Entry<Integer, Integer> entry : HM.entrySet()) {
				if (entry.getValue() > n / 2) {
					System.out.println(entry.getKey());
					judge = true;
					break;
				}
			}
			if (!judge) {
				System.out.println("NO COLOR");
			}
		}

	}

	public static void main(String[] args) {
		new Main().run();
	}

	static public void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, m, q;
  cin >> n >> m >> q;
  vector<array<int,4>> inp(q);
  for (auto&[a,b,c,d] : inp)
    cin >> a >> b >> c >> d;
  int ans = 0;
  vector<int> arr(n);
  function<void(int,int)> f = [&](int ind, int prev) {
    if (ind == n) {
      int score = 0;
      for (auto [a,b,c,d] : inp) {
	if (arr[b-1]-arr[a-1] == c) score += d;
      }
      ans = max(ans, score);
      return;
    }
    for (int v = prev; v <= m; v++) {
      arr[ind] = v;
      f(ind+1, v);
    }
  };
  f(0, 1);
  cout << ans << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  cin >> S >> T;
  for (int i =0; i<S.size(); i++){
  	if(S.at(i) !=T.at(i)){
     cout << "No" << endl;
     return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3632
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type Abbreviation ---------- */
using ll = long long;

/* ---------- Constants ---------- */
const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */
template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

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

    int ret = -1;

    for (int i = 0; i < N - 1; i++) {
        for (int j = i+1; j < N; j++) {
            ret = max(ret, abs(A[i] - A[j]));
        }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}
template<typename T> T lcm(T a,T b){return a*b/gcd(a, b);}


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
int main() {
    ll l,r;
    cin >> l >> r;
    ll ans = INF;
    for (ll i = l; i<r; i++) {
        for (ll j = i+1; j<=r; j++) {
            chmin(ans, i*j%2019);
            if (ans == 0) {
                goto finish;
            }
        }
    }
finish:
    COUT(ans);
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <algorithm>
using namespace std;


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

	vector<int> x,y;
	for(int i=0;i<n;i++){
		int a,b;
		cin >> a >> b;
		x.push_back(a);
		y.push_back(b);
	}

	int ans = n+1;
	if(n==1){
		ans = 1;
	}else{
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				int p, q;
				p = x[i] - x[j];
				q = y[i] - y[j];
				if(p==0 && q==0)
					continue;

				int now = n;
				vector<int> taked(n, -1);
				for(int k=0;k<n;k++){
					for(int l=0;l<n;l++){
						if(taked[l]==-1 && x[l] == x[k] - p && y[l] == y[k] - q){
							taked[l] = 1;
							now--;
						}
					}
				}

				if(ans > now){
					ans = now;
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long [] a = new long[n + 1];
        for (int i = 1; i <= n; ++i) {
            a[i] = scanner.nextLong();
        }
        long[] value = new long[n + 1];
        int[] symbol = new int[n + 1];
        symbol[1] = 1;
        for (int i = 2; i <= n; ++i) {
            value[i] = a[i - 1] - value[i - 1];
            symbol[i] = -1 * symbol[i - 1];
         //   System.out.println("value[" + i + "]: " + value[i] + " sym: " + symbol[i]);
        }
        long[] ans = new long[n + 1];
        ans[1] = (a[n] - value[n]) / (symbol[n] + 1);
        for (int i = 2; i <= n; ++i) {
            ans[i] = value[i] + symbol[i] * ans[1];
        }
        for (int i = 1; i <= n; ++i) {
            System.out.print(2 * ans[i] + " ");
        }
    }
}


Measured memory_bytes: 66964
S = list(input())

if S[0] != "A":
    print("WA")
elif "C" in S[2:-1]:
    S.remove("C")
    del S[0]
    S = str(S)
    if S.islower():
        print("AC")
    else:
        print("WA")
else:
    print("WA")

Measured memory_bytes: 3060
//      https://youtu.be/X_hMZYDMps4

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

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;    // 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nl                  "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define pf                  push_front
#define all(x)              x.begin(),x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"

int main()
{
    fast;
    ll t,i,j,k,l,m,n,o,p,q,temp,ans=0,flag=0,mod=1000000007;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>temp;
        if(temp!=i) ans++;
    }
    if(ans<=2) cout<<"YES";
    else cout<<"NO";
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<math.h>

int main()
{
    long long int n,a[105],b[505],i,j,k,mx=-101,mn=101,s=0;

    scanf("%lld",&n);

    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    for(i=0;i<n;i++){
        if(a[i]>=mx){
            mx=a[i];
        }
    }
    for(i=0;i<n;i++){
        if(a[i]<=mn){
            mn=a[i];
        }
    }
    for(i=mn,k=1;i<=mx;i++,k++){
        for(j=0;j<n;j++){
            s=s+(a[j]-i)*(a[j]-i);
        }
        b[k]=s;
        s=0;
    }
    s=100000000000000000;
    for(i=1;i<k;i++){
        if(b[i]<=s){
            s=b[i];
        }
    }
    printf("%lld\n",s);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n , m;
char s[N][N];
int cnt[N];
int main() {
    scanf("%d%d" , &n , &m);
    for (int i = 0 ; i < n ; ++ i) {
        scanf("%s" , s[i]);
        for (int j = 0 ; j < m ; ++ j) {
            ++ cnt[s[i][j] - 'a'];
        }
    }
    int odd = 0;
    int has = 0;
    for (int i = 0 ; i < 26 ; ++ i) {
        if (cnt[i] % 2 == 1) {
            ++ odd;
        }
        if (cnt[i]) {
            ++ has;
        }
    }
    if (n % 2 == 0 && m % 2 == 0) {
        for (int i = 0 ; i < 26 ; ++ i) {
            if (cnt[i] % 4) {
                puts("No");
                return 0;
            }
        }
        puts("Yes");
    } else if (n % 2 == 1 && m % 2 == 1) {
        if (!odd || odd > 1) {
            puts("No");
        } else {
            int p = 0;
            for (int i = 0 ; i < 26 ; ++ i) {
                if (cnt[i] % 4 != 0) {
                    ++ p;
                }
            }
            puts(p > (n + 1) / 2 + (m + 1) / 2 - 1 ? "No" : "Yes");
        }
    } else if (n % 2 == 0 && m % 2 == 1) {
        if (odd) {
            puts("No");
        } else {
            int p = 0;
            for (int i = 0 ; i < 26 ; ++ i) {
                if (cnt[i] % 4 == 2) {
                    ++ p;
                }
            }
            puts(p > n / 2 ? "No" : "Yes");
        }
    } else {
        if (odd) {
            puts("No");
        } else {
            int p = 0;
            for (int i = 0 ; i < 26 ; ++ i) {
                if (cnt[i] % 4 == 2) {
                    ++ p;
                }
            }
            puts(p > m / 2 ? "No" : "Yes");
        }
    }
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long X, long long N, std::vector<long long> p);

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    long long X;
    scanf("%lld",&X);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(X, N, std::move(p));
}

void solve(long long X, long long N, std::vector<long long> p){
    vec<bool> num(102);
    REP(i, N){
        num[p[i]] = true;
    }
    int mm = -1;
    for(int i=X; i>=0; i--){
        if(!num[i]){
            mm=i;break;
        }
    }
    int nn = 101;
    FOR(i, 101, X){
        if(!num[i]){
            nn=i;break;
        }
    }
    if(abs(nn-X) < abs(mm-X)){
        mm = nn;
    }
    cout << mm << el;
}



Measured memory_bytes: 3720
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int a[100005],b[100005],c[100005];

int main()
{
    int n;

    scanf("%d",&n);

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

    for (int i = 0;i < n;i++)
        scanf("%d",&b[i]);

    for (int i = 0;i < n;i++)
        scanf("%d",&c[i]);

    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);

    long long sum = 0;

    for (int i = 0;i < n;i++)
    {
        int p1 = lower_bound(a,a+n,b[i]) - a;
        int p2 = upper_bound(c,c+n,b[i]) - c;

        if (p1 >= n) p1--;

        while (a[p1] >= b[i]) p1--;

        if (p1 < 0) continue;
        if (p2 >= n) break;

        sum += (long long)(p1 + 1) * (n - p2);

        //printf("%d %d\n",p1 + 1,n - p2);
    }

    printf("%lld\n",sum);

    return 0;
}


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

using namespace std;
using Int = long long;

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

	vector<int> cb(N + 1, 0), cw(N + 1, 0);
	int cnt;
	cnt = 0;
	for (int i = 0; i < N; i++)
	{
		cb[i] = cnt;
		if (S[i] == '#') {
			cnt++;
		}
	}
	cb[N] = cnt;

	cnt = 0;
	cw[N] = cnt;
	for (int i = N - 1; i >= 0; i--)
	{
		if (S[i] == '.') {
			cnt++;
		}
		cw[i] = cnt;
	}

	int ans = N+1;
	for (int i = 0; i <= N; i++)
	{
		ans = min(ans, cb[i] + cw[i]);
	}

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


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

n = int(input())
s = []
t = []

for i in range(n):
    a = input().split()
    s.append(a[0])
    t.append(int(a[1]))

x = input()

ind = s.index(x)
if ind == n-1:
    print(0)
else:
    print(sum(t[ind+1:]))

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define mod 1000000009
#define int long long 
#define garou ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int pow(int p,int r){
	int ans=1;
	while(r>0){
     if(r&1){
		 ans=((ans%mod)*(p%mod))%mod;
	 }
	 r=r>>1;
     p=((p%mod)*(p%mod))%mod;
	}
	return ans;
}
signed main() {
    garou;
    int n,k;
	cin>>n>>k;
	if(n%k==0){
	cout<<0;
	return  0;
	}
	while(1){
		if(k>n)
		break;
		n%=k;
	}
	int mn=n;
	mn=min(mn,abs(n-k));
	cout<<mn;
}

Measured memory_bytes: 3556
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

int n;
int chain[10000];

int calc(int v){
	int res = 0;
	int l = v, r = v;
	while(0 <= l && r < n){
		if(chain[l] != chain[r]) return res;
		int c = l == r ? -1 : 0, t = chain[l];
		while(0 <= l && chain[l] == t) l--, c++;
		while(r < n && chain[r] == t) r++, c++;
		if(c >= 4) res += c;
	}
	return res;
}

int main(){
	while(cin >> n && n){
		int cnt = 0;
		rep(i, n){
			cin >> chain[i];
			chain[i]--;
		}
		rep(i, n){
			int c = chain[i];
			rep(j, 3){
				chain[i] = j;
				cnt = max(calc(i), cnt);
			}
			chain[i] = c;
		}
		cout << n - cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
bitset<4000001> S;

int main()
{
    int i,n,x;
    cin >> n;
    S[0] = true;
    int sum = 0,rs=0;
    for(i=0;i<n;i++)
    {
        cin >> x;
        sum += x;
        S = S|(S<<x);
    }
    rs = (sum+1)/2;
    //cout << sum << " " << rs<< " ";
    for(i=rs;i<=sum;i++)
    {
        if(S[i])
            break;
    }
    //cout << S[2] << " ";
    cout << i << endl;
return 0;}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
const int MAXN = 1001020;
int prime[MAXN+1]; // n 以下の素数のうち i 番目の素数
bool is_prime[MAXN+1]; // 整数 i が素数であるかどうか
int sieve(int n = MAXN) {
    int res = 0;
    fill(is_prime, is_prime + MAXN, true);
    is_prime[0] = is_prime[1] = false; // 0 と 1 は素数ではない。
    reps(i,2,n+1) {
        if(!is_prime[i]) continue;
        prime[res++] = i;
        for(int j = 2*i ; j<=n ; j+=i ) is_prime[j] = false; // 素数 i の倍数は素数ではない (ふるい(篩)にかける)
    }
    return res;
}

//--MAIN-----------------------------------
void Main() {
    ll X; cin>>X;
    int res = sieve();
    reps(i,X,1000000){
        if(is_prime[i]){cout<< i <<"\n"; return;}
    }
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 1536
N,M,Q,*as=$<.read.split.map(&:to_i)
abcds = as.each_slice(4).sort

max = 0
(1..M).to_a.repeated_combination(N) do |arr|
    sum = 0
    abcds.each do |a,b,c,d|
        sum += d if arr[b-1] - arr[a-1] == c
    end
    max = sum if max < sum
end
ret = max
puts ret


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

signed main() {
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i*i < N; i++){
        int x = N - i;
        int m = x / i;
        if(N % m == N / m) ans += m;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//Bismillahir Rahman-ir Rahim
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000002
#define PI acos(-1)
#define debug(x) cout << '>' << #x << " : " << x << endl;
//#define m (pow(10, 9)+7)
typedef unsigned long long ull;
typedef long long ll;

bool palindrome(string str){
    int i = 0, j = str.size() - 1;
    while(i < j) {
        if(str[i] != str[j]) return false;
        i++;
        j--;
    }
    return true;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string str, str2 = "", str3 = "";
    cin >> str;
    int n = str.size();

    if(!palindrome(str)){
        cout << "No" << endl;
        return 0;
    }
    int endind = (n-1)/2 - 1;
    for(int i = 0; i <= endind; i++){
        str2 += str[i];
    }
    //cout << str2 << endl;
    if(!palindrome(str2)){
        cout << "No" << endl;
        return 0;
    }
    int startind = (n+3)/2 - 1;
    for(int i = startind; i < n; i++){
        str3 += str[i];
    }
    //cout << str3 << endl;

    if(!palindrome(str3)){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;


    return 0;
}



Measured memory_bytes: 256