akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> box(n);
    vector<ll> ans;
    for(int i = n - 1; i >= 0; --i){
        ll num = i + 1;
        ll sum = 0;
        for(int j = num + num; j <= n; j += num){
            sum += box[j - 1];
        }
        if(sum % 2 != a[i]){
            box[i]++;
            ans.push_back(i + 1);
        }
    }
    print(ans.size());
    rep(i, sz(ans)){
        print(ans[i]);
    }

}


Measured memory_bytes: 5108
import math
X,N=map(int,input().split())
p = list(map(int,input().split()))
abs_list=[0]*N
for i,a in enumerate(p):
    abs_list[i]=a-X
abs_new=sorted(abs_list, key = abs)
flag1=False
flag2=False
flag=False
if N==0:
    flag=True
    print(X)
for i,a in enumerate(abs_new):
    if i%2==1:
        flag1=False
        flag2=False
    if i==0 and a!=0:
        print(X)
        flag=True
        break
    elif (math.floor((i-1)/2)+1)==a:#+がある
        flag1=True
    elif (math.floor((i-1)/2)+1)==(-a):#-がある
        flag2=True
    if i%2==0 and i!=0:
        if flag2==False:
            print(X-(math.floor((i-1)/2)+1))
            flag=True
            break
        elif flag1==False:
            print(X+math.floor((i-1)/2)+1)
            flag=True
            break
if flag==False:
    if abs_new[-1]==0:
        print(X-1)
    elif abs_new[-1]<0:
        if flag1==True:
            print(X+(abs_new[-1]-1))
        else:
            print(X-abs_new[-1])
    else:
        if flag2==True:
            print(X-(abs_new[-1]+1))
        else:
            print(X-abs_new[-1])


Measured memory_bytes: 62436
# coding: utf-8
# 66
while True:
    m,f,r = map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        break
    G = m+f
    if m==-1 or f==-1:
        print('F')
    elif G>=80:
        print('A')
    elif G>=65 and G<80:
        print('B')
    elif G>=50 and G<65:
        print('C')
    elif G>=30 and G<50:
        if r>=50:
            print('C')
        else:
            print('D')
    else:
        print('F')






Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007


void solve(void)
{

  string S;
  cin>>S;
  int len = S.size();
  int ANS = 0;
  //マスクの境界に+演算子があると思いこむのが大切。len - 1 シフトでよい

  for (int msk = 0; msk < 1<<(len -1); msk++)
  {
    int num = S[0] - '0';
    for (int i = 0; i < (len-1); i++)
    {
      if(msk & (1<<i))
      {
        ANS += num;
        num = 0;
      }
      num = num*10+(S[i+1] - '0');
    }

    ANS += num;
    
  }

  cout<<ANS<<endl;
  

  return;
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()

int main(){
	int n;
	stack<int> st;
	while(~scanf("%d",&n)){
		if( n==0 ){
			printf("%d\n",st.top());
			st.pop();
		}else{
			st.push(n);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
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;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

//for(i=0; i<N; i++) cin >> a[i];

ll N, M, K;
ll a[MAX*2], b[MAX*2];
ll sa[MAX*2], sb[MAX*2];

int main(void) {
  ll i, j, k;
  
  cin >> N >> M >> K;
  for(i=1; i<=N; i++) {
    cin >> a[i];
    sa[i]=sa[i-1]+a[i];
  }
  for(i=1; i<=M; i++) {
    cin >> b[i];
    sb[i]=sb[i-1]+b[i];
  }
  
  ll ans=0;
  for(i=0; i<=N; i++) {
    ll rem=K-sa[i];
    if(rem<0) continue;
    
    ll p=upper_bound(sb, sb+M+1, rem)-sb-1;
    chmax(ans, i+p);
    
  }
  
  pt(ans);
  
  
}
 
 




Measured memory_bytes: 9860
n,K = map(int, input().split(' '))
s = input()
ls0 = [0]
ls1 = [0]
if s[0] == "0":
    ls1[0] = -1
for i in range(n):
    if s[i] == "0":
        ls0[-1] += 1
        if ls1[-1] != 0:
            ls1.append(0)
    if s[i] == "1":
        ls1[-1] += 1
        if ls0[-1] != 0:
            ls0.append(0)
if s[0] == "0":
    ls1[0] = 0
if ls0[-1] == 0:
    del ls0[-1]
ans = []
ansmax = 0
if K>=len(ls0):
    ansmax = len(s)
else:
    ans.append(sum(ls0[0:K])+sum(ls1[0:K+1]))
    for i in range(1,len(ls0)-K+1):
        ans.append(ans[-1]+ls0[i+K-1]+ls1[i+K]-ls0[i-1]-ls1[i-1])
    else:
        ans.sort()
        ansmax = ans[-1]
print(ansmax)

Measured memory_bytes: 5552
if __name__ == "__main__":
    n = int(input())
    elements = list(map(lambda x: int(x), input().split()))
    sorted_elements = sorted(elements)
    total_cost = 0

    for i in range(n - 1):
        cost = 0
        cnt = 0
        x_idx = elements.index(sorted_elements[i])
        while i != x_idx:
            y_idx = elements.index(sorted_elements[x_idx])
            elements[x_idx], elements[y_idx] = (sorted_elements[x_idx],
                                                sorted_elements[i])
            cnt += 1
            cost += sorted_elements[x_idx] + sorted_elements[i]
            x_idx = y_idx
        if cnt:
            total_cost += min(cost,
                              (sorted_elements[i] + sorted_elements[0]) * 2 + cost
                              - (sorted_elements[i] - sorted_elements[0]) * cnt)

    print(total_cost)



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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

int main()
{
    int P, Q, R;
    cin >> P >> Q >> R;
    cout << min(P + Q, min(Q + R, R + P)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N ;i++) cin >> a[i];

    vector<int> sum(N+1);
    for (; K > 0; K--) {
        // imos
        fill(sum.begin(), sum.end(), 0);
        for (int i = 0; i < N; i++) {
            int l = max(0, i - a[i]);
            int r = min(N, i + a[i] + 1);
            sum[l]++, sum[r]--;
        }
        for (int i = 0; i < N; i++) {
            sum[i+1] += sum[i];
            a[i] = sum[i];
        }
        // 収束判定
        bool flag = false;
        for (int i = 0; i < N; i++) {
            if (a[i] != N) flag = true;
        }
        if (!flag) {
            break;
        }
    }
    for (int i = 0; i < N; i++) {
        if (i) cout << ' ';
        cout << a[i];
    }
    cout << '\n';
}


Measured memory_bytes: 4760
package main

import (
    "fmt"
    "os"
    "bufio"
    "strconv"
    // "sort"
)
var sc = bufio.NewScanner(os.Stdin)


func main() {
    sc.Split(bufio.ScanWords)
    // code goes here
    T := nextFloat()
    X := nextFloat()
    fmt.Println(T/X)
}



func nextInt() int {
    sc.Scan()
    v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}
func nextInt64() int64 {
    sc.Scan()
    v, e := strconv.ParseInt(sc.Text(), 10, 64)
    if e != nil { panic(e) }
    return v
}
func nextString() string {
    sc.Scan()
    return sc.Text()
}
func nextFloat() float64 {
    sc.Scan()
    v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}
func Max(x, y int) int { if x > y { return x }; return y }
func Min(x, y int) int { if x < y { return x }; return y }
func Abs(x int) int { if x > 0 { return x }; return -x }


Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i32,
        b: i32,
    }
    println!("{}", if a <= 9 && b <= 9 { a * b } else { -1 });
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
constexpr int MOD = 998244353;

template <int N>
struct Eratosthenes
{
    int w[N + 1];
    char sieve[N + 1];
    constexpr Eratosthenes() : w(), sieve()
    {
        w[0] = 0;
        w[1] = 1;
        for (int i = 2; i <= N; i++)
        {
            w[i] = MOD - 1LL * w[MOD % i] * (MOD / i) % MOD;
        }
        for (int p = 2; p <= N; p++)
        {
            if (sieve[p] == 0)
            {
                for (int k = N / p; k > 1; --k)
                {
                    sieve[k * p] = 1;
                    w[k * p] -= w[k];
                    if (w[k * p] < 0)
                    {
                        w[k * p] += MOD;
                    }
                }
                w[p] -= w[1];
            }
        }
    }
};

int main()
{
    constexpr int M = 1000000;
    constexpr auto prime = Eratosthenes<M>();
    long long N, ans = 0;
    int a[1000001] = {};
    cin >> N;
    for (int i = 0, j; i < N; i++)
    {
        cin >> j;
        a[j] += j;
        if (a[j] >= MOD)
        {
            a[j] -= MOD;
        }
        ans -= j;
        if (ans < 0)
        {
            ans += MOD;
        }
    }
    for (int p = 2; p <= M; p++)
        if (prime.sieve[p] == 0)
            for (int k = M / p; k > 0; --k)
                if ((a[k] += a[k * p]) >= MOD)
                    a[k] -= MOD;
    for (int i = 1; i <= M; i++)
    {
        ans += 1LL * a[i] * a[i] % MOD * prime.w[i] % MOD;
    }
    ans %= MOD;
    if (ans & 1)
        ans = (ans + MOD) >> 1;
    else
        ans = ans >> 1;
    cout << ans << endl;
}


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

int main() {
  int A = 0, B = 0;
  cin >> A >> B;
  int i = A,t = 0,ans = 0;
  int x[5] = {0,0,0,0,0};
  
  while(i <= B){
    t = i;
    for(int j = 0; j < 5; j++){
      x[j] = t % 10;
      t = t / 10;
    }
    if( (x[0] == x[4]) && (x[1] == x[3])){
      ans++;
    }
    i++; 
  }
  cout << ans;
}

Measured memory_bytes: 3608
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>

using namespace std;

int main() {


    int A,B;
    cin>>A>>B;

    string a,b;
    a=std::to_string(A);
    b=std::to_string(B);

    string c,d;

    for(int i=0;i<B;i++){
        c+=a;

    }
    for(int i=0;i<A;i++){
        d+=b;

    }

    if(c==d){
        cout<<c<<endl;
    }
    else if(c<d){
        cout<<c<<endl;
    }
    else{
        cout<<d<<endl;
    }


}


Measured memory_bytes: 256
package main

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

var (
    read = bufio.NewReader(os.Stdin)
    write = bufio.NewWriter(os.Stdout)
    sc = bufio.NewScanner(os.Stdin)
)

func main() {
    defer write.Flush()

    var n int
    fmt.Fscan(read, &n)

    s := make(map[string]int)

    sc.Split(bufio.ScanWords)
    max := 0
    for i := 0; i < n; i++ {
        var str string
        fmt.Fscan(read, &str)
        _, ok := s[str]
        if ok {
            s[str]++
        } else {
            s[str] = 1
        }
        if max < s[str] {
            max = s[str]
        }
    }

    var a []string
    for key := range s {
        a = append(a, key)
    }


    sort.Strings(a)

    for i := 0; i < len(a); i++ {
        if s[a[i]] == max {
            fmt.Printf("%s\n", a[i])
        }
    }

}



//===========================
//
// Library
//
//===========================

//====================
//  round(12.54, 0) -> 13.0
//  round(12.54, -1) -> 12.5
//====================

func round(num float64, digit uint) float64 {
    d := float64(digit)
    return float64(int(num * math.Pow(10, d) + 0.5)) / math.Pow(10, d)
}

func max(a, b int) int {
    return int(math.Max(float64(a), float64(b)));
}

func min(a, b int) int {
    return int(math.Min(float64(a), float64(b)));
}

func gcd(x, y int) int {
    if y == 0 {
        return x
    }

    return gcd(y, x%y)
}

//====================
//  var q Queue
//  q.Enqueue(n)
//  n := q.Dequeue()
//====================
type Queue struct {
    data []int
}

func (q *Queue) Enqueue(n int) {
    q.data = append(q.data, n)
}

func (q *Queue) Dequeue() int {
    tmp := q.data[0]
    q.data = q.data[1:]
    return tmp
}

// 数値を桁区切りのスライスにする
func digit(n int, list []int) []int {
   if n > 0 {
       return digit(n/10, append(list, n%10))
   }
   return list
}

func sortIntsRev(list []int) {
    sort.Sort(sort.Reverse(sort.IntSlice(list)))
}

func strReverse(s string) string {
    runes := []rune(s)
    for i := 0; i < len(s)/2; i++ {
        runes[i], runes[len(s)-1-i] = runes[len(s)-1-i], runes[i]
    }
    return string(runes)
}

func nextInt() int {
    sc.Scan()
    i, _ := strconv.Atoi(sc.Text())
    return i
}

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



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

int main(){
    int n;
    int a[30];
    int b[60];
    int c[60];

    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) cin >> b[i];
    for(int i = 1; i <= n-1; i++) cin >> c[i];

    int ans = 0;
    for(int i = 1; i <= n ; i++){
        ans += b[a[i]];
        // cout << b[a[i]] << endl;
        if(i > 0 && a[i+1] == a[i] + 1){
            ans += c[a[i]];
            // cout << c[a[i]] << endl;
        }
    }

    cout << ans << endl;


}

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

int main() {
string s;
cin >> s;
bool ok = true;
for(int i=0; i<s.size(); i++){
    if(i%2 == 0 && s.at(i) == 'L'){ok = false;}
    if(i%2 == 1 && s.at(i) == 'R'){ok = false;}
}
    if(ok){puts("Yes");} else{puts("No");}

    
}

Measured memory_bytes: 256
fun main() {
    val N = readLine()!!.toInt()
    val S = readLine()!!

    val R = IntArray(N)
    val G = IntArray(N)
    val B = IntArray(N)

    when (S[0]) {
        'R' -> {
            R[0] = 1
        }
        'G' -> {
            G[0] = 1
        }
        'B' -> {
            B[0] = 1
        }
    }
    for (i in 1..S.lastIndex) {
        val c = S[i]
        when (c) {
            'R' -> {
                R[i] = R[i - 1] + 1
                G[i] = G[i - 1]
                B[i] = B[i - 1]
            }
            'G' -> {
                R[i] = R[i - 1]
                G[i] = G[i - 1] + 1
                B[i] = B[i - 1]
            }
            'B' -> {
                R[i] = R[i - 1]
                G[i] = G[i - 1]
                B[i] = B[i - 1] + 1
            }
        }
    }

    var sum = 0L
    for (i in 0..S.lastIndex - 2) {
        for (j in i + 1..S.lastIndex - 1) {
            if (S[i] == S[j]) {
                continue
            }
            val a = arrayOf(S[i], S[j])
            sum += when {
                !a.contains('R') -> {
                    var n = R[S.lastIndex] - R[j]
                    if ((j + (j - i)) <= S.lastIndex && S[j + (j - i)] == 'R') {
                        n--
                    }
                    n
                }
                !a.contains('G') -> {
                    var n = G[S.lastIndex] - G[j]
                    if ((j + (j - i)) <= S.lastIndex && S[j + (j - i)] == 'G') {
                        n--
                    }
                    n
                }
                !a.contains('B') -> {
                    var n = B[S.lastIndex] - B[j]
                    if ((j + (j - i)) <= S.lastIndex && S[j + (j - i)] == 'B') {
                        n--
                    }
                    n
                }
                else -> throw IllegalStateException("")
            }


        }
    }
    println(sum)
}



Measured memory_bytes: 55596
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    List<Integer> list = new ArrayList<Integer>();
    while (true) {
      if (N % (-2) == -1) {
        list.add(1);
        N = N / (-2) + 1;
      } else {
        list.add(N % (-2));
      	N = N / (-2);
      }
     
      if (N == 0) {
        break;
      }
    }
    for (int i = list.size() - 1; i >= 0; i--) {
      System.out.print(list.get(i));
    }
  }
}


Measured memory_bytes: 23124
import itertools

N = int(input())
march_d = dict()
for c in "MARCH":
  march_d[c] = 0
for _ in range(N):
  name = input()
  if name[0] in "MARCH":
    march_d[name[0]] += 1
    
#頭文字の選び方１０通り
ans = 0
for n1, n2, n3 in itertools.combinations("MARCH", 3):
  ans += march_d[n1] * march_d[n2] * march_d[n3]

print(ans)

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

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int x[] = {A, B, C};

    sort(x, x+3);

    for(int i = 1; i <= K; i++) {
        x[2] *= 2;
    }

    int ans = x[0] + x[1] + x[2];

    cout << ans;

    cout << endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//実行部
void Main()
{
  ll i = 1;
  while(i <= 12)
  {
    char a;
    cin >> a;
    cout << a;
    if(i == 4) blank("")
    if(i == 12) fin("")
    i++;
  }
  return;
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int rc[10000];
	int t_row[100];
	int t_col[100];
	int r, c;
	cin >> r >> c;
	for (int i = 0; i < r; i++)
	{
		t_row[i] = 0;
		for (int j = 0; j < c; j++)
		{
			int t;
			cin >> t;
			rc[i * c + j] = t;
			t_row[i] += t;
		}
	}

	for (int j = 0; j < c; j++)
	{
		t_col[j] = 0;
		for (int i = 0; i < r; i++)
		{
			t_col[j] += rc[i * c + j];
		}
	}
	for (int i = 0; i < r; i++)
	{
		for (int j = 0; j < c; j++)
		{
			cout << rc[i * c + j] << " ";
		}
		cout << t_row[i] << endl;

	}
	int t = 0;
	for (int j = 0; j < c; j++)
	{
		cout << t_col[j] << " ";
		t += t_col[j];
	}
	cout << t << endl;
	return 0;
}


Measured memory_bytes: 3128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#define ll long long
using std::pair;
using std::make_pair;
using std::queue;
int k;
const int N = 1e5+1e3;
int dis[N];
int main(){
	scanf("%d",&k);
	std::deque<pair<int,int> > q;
	q.push_back(make_pair(1,1));
	while(!q.empty()){
		pair<int,int> now=q.front();q.pop_front();
		if(dis[now.first])
			continue;	
		dis[now.first]=1;
		if(now.first==0){
			printf("%d",now.second);
			return 0;
		}
		q.push_front((make_pair((now.first*10)%k,now.second)));
		q.push_back((make_pair((now.first+1)%k,now.second+1)));		
	}
	return 0;
} 

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main() {
	int a, b, c;

	cin >> a >> b >> c;

	if (a != b && b != c && c != a) {
		cout << "3" << endl;
	}
	else if (a == b && b == c) {
		cout << "1" << endl;
	}
	else {
		cout << "2" << endl;
	}


}

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

#define printLn(X) cout << X << endl
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

int a[100000];
int b[100000];
int main(){
	int N, H;
	cin >> N >> H;
	rep(i, N){
		cin >> a[i] >> b[i];
	}
	sort(a, a + N);
	sort(b, b + N);
	reverse(b, b + N);
	int maxA = a[N - 1];
	int ans = 0;
	rep(i, N){
		if(b[i] <= maxA){
			break;
		}
		ans++;
		H -= b[i];
		if(H <= 0){
			printLn(ans);
			return 0;
		}
	}
	ans += (H + maxA - 1) / maxA;
	printLn(ans);
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main() {
  vector<int> vec1;

  string tmp;
  while (getline(cin, tmp)) {
    stringstream ss(tmp);
    string tmp2;
    while (getline(ss, tmp2, ','))
      vec1.push_back(atoi(tmp2.c_str()));
  }

  int n = sqrt(vec1.size());
  vector<vector<int>> vec2(n + 1, vector<int>(n + 1));
  int k = 0;
  for (int i = 0; i < 2 * n - 1; ++i)
    for (int j = 0; j < i + 1; ++j)
      if (i - j < n && j < n)
        vec2[i - j + 1][j + 1] = vec1[k++];

  vector<vector<int>> vec3(n + 1, vector<int>(n + 1, INT_MAX));
  for (int i = 0; i <= n; ++i)
    vec3[i][0] = vec3[0][i] = 0;

  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      vec3[i][j] = max({vec3[i][j - 1], vec3[i - 1][j]}) + vec2[i][j];

  cout << vec3[n][n] << endl;
}


Measured memory_bytes: 3208
N, M, X = gets.split.map(&:to_i)
A = []

N.times do
    tmp = gets.split.map(&:to_i)
    tp = {
        c: tmp[0],
        nb: tmp[1..-1]
    }
    A.push(tp)
end

ans = 10000000

N.times do |i|
    N.times.entries.combination(i + 1).each do |d|
        tmp = Array.new(M, 0)
        tmp_c = 0
        # puts "1. #{d}"
        d.each do |e|
            bk = A[e]
            tmp_c += bk[:c]
            # puts "2. #{tmp_c} #{bk}"
            M.times do |cd|
                tmp[cd] += bk[:nb][cd]
            end
        end
        flag = true
        tmp.each do |l|
            if l < X
                flag = false
                break
            end
        end
        if flag then
            ans = tmp_c if tmp_c < ans
        end
    end
end

if ans == 10000000
    puts -1
else
    puts ans
end


Measured memory_bytes: 14564
#include<stdio.h>
struct card_data{
  int value;
  char suit;

};

int main(void){
  int n;
  scanf("%d", &n);
  struct card_data card1[n];
  struct card_data card2[n];
  for(int i=0; i<n; i++){
    scanf(" %c%d", &card1[i].suit, &card1[i].value);
    card2[i].value=card1[i].value;
    card2[i].suit=card1[i].suit;

  }
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){


    }
  }

  //バブル
  int flag = 1;
  int temp;
  char temp_c;
  int i =0;
  while(flag==1){
    flag=0;
    for(int j=n-1; j>=i+1; j--){
      if(card1[j].value<card1[j-1].value){
        temp=card1[j].value;
        temp_c=card1[j].suit;
        card1[j].value=card1[j-1].value;
        card1[j].suit=card1[j-1].suit;
        card1[j-1].value=temp;
        card1[j-1].suit=temp_c;
        flag=1;
      }
    }
    i++;
  }

  for(int i=0; i<n-1; i++){
    printf("%c%d ", card1[i].suit,card1[i].value);
  }
  printf("%c%d\n", card1[n-1].suit,card1[n-1].value);
  printf("Stable\n");



  //選択

  for(int i=0; i<n; i++){
    int minj = i;
    for(int j=i; j<n; j++){
      if(card2[j].value<card2[minj].value){
          minj = j;
      }


    }
    if(i!=minj){
      temp =card2[i].value;
      temp_c =card2[i].suit;
      card2[i].value=card2[minj].value;
      card2[i].suit=card2[minj].suit;
      card2[minj].value=temp;
      card2[minj].suit=temp_c;


    }

  }

  for(int i=0; i<n-1; i++){
    printf("%c%d ", card2[i].suit,card2[i].value);
  }
  printf("%c%d\n", card2[n-1].suit,card2[n-1].value);
  int count = 0;
  for(int i=0; i<n; i++){
    if(card1[i].suit!=card2[i].suit){
      printf("Not stable\n");
      break;
    }
    count++;
    if(count==n){
      printf("Stable\n");
    }
  }

  return 0;



}



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

int main () {
    string a,b;
    cin >> a >> b;
    string N = a+b;
    istringstream iss(N);
    int num = 0;
    iss >> num;
    int rtnum = sqrt(num);
    if (num == pow(rtnum, 2)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int N, M;
    std::cin >> N >> M;
    std::vector< int > A(N);
    for(int i=0; i<N; i++){
        std::cin >> A[i];
    }
    
    std::sort(A.begin(), A.end());
    
    int index = A.size() - 1;
    for(int i=0; i<M; i++){
        if(A[index] < A[A.size() - 1]){
            std::sort(A.begin(), A.end());
            index = A.size() - 1;
        }
        A[index] /= 2;
        index--;
        if(index < 0){
            index = A.size() - 1;
        }
    }
    
    long long ans = 0;
    for(int i=0; i<N; i++){
        ans += A[i];
    }
    
    std::cout << ans << std::endl;
    
    
    return 0;
}



Measured memory_bytes: 640
while True:
    H, W = map(int, input().split())
    if H == 0:
        break
    for i in range(H):
        S = ""
        for j in range(W):
            if (i+j) % 2 == 0:
                S += "#"
            else:
                S += "."
        print(S)
    print()


Measured memory_bytes: 5612
import math
a,b,h,m = list(map(int,input().split()))
hd = h*30
md = m*6
hd += (m/60)*30
angle = abs(hd-md)
cos = math.cos((angle/180)*math.pi)
print (math.sqrt(a**2 + b**2 - 2*a*b*cos))


Measured memory_bytes: 9428
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt64()
	p := readInt64()

	m := make(map[int64]int64)
	i := int64(2)
	q := p
	for q%i == 0 {
		q /= i
		m[i]++
	}
	i++
	for q != 1 && i*i < p {
		for q%i == 0 {
			q /= i
			m[i]++
		}
		i += 2
	}
	if q != 1 {
		m[q]++
	}
	//eprintln(m)
	var ans int64 = 1
	for x, y := range m {
		for i := n; i <= y; i += n {
			ans *= x
		}
	}
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,q;
    cin>>n>>q;
    string st;
    cin>>st;
    vector<pair<string,string>> vec(q);
    cin>>vec;
    reverse(all(vec));
    int l=0,r=n-1;
    REP(i,q){
        if(vec[i].se=="L"){
            if(st[l]==vec[i].fi[0]){
                l++;
            }
            if(r+1<n&&st[r+1]==vec[i].fi[0]){
                r++;
            }
        }else{
            if(l&&st[l-1]==vec[i].fi[0]){
                l--;
            }
            if(st[r]==vec[i].fi[0]){
                r--;
            }
        }
    }
    cout<<max(0,r-l+1)<<endl;
    return 0;
}

Measured memory_bytes: 22276
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    ll N,K,a=0,b=0;
    cin>>N>>K;
    for(ll i=1;i<=N;i++){
        if(i%K==0) a++;
        else if(K%2==0&&i%(K/2)==0) b++;
    }
    cout<<a*a*a+b*b*b<<endl;
}

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

int32_t main()
{

	double d, t, s;
	cin >> d >> t >> s;

	double time = d / s;
	//cout << time << endl;


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


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

int main(){
  vector<int> a(3);
  for(int i = 0;i<3;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  if(a[0] == a[1])cout << a[2] << endl;
  else cout << a[0] << endl;
}


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

const int INF=1e9;
struct edge{
    int to, cost;
};
string a[105], b[105];
int c[105];
vector<edge> G[210];

bool dfs(int v, vector<int> &dist)
{
    for(edge e:G[v]){
        if(dist[e.to]==INF){
            dist[e.to]=dist[v]+e.cost;
            if(!dfs(e.to, dist)) return false;
        }else{
            if(dist[e.to]!=dist[v]+e.cost){
                return false;
            }
        }
    }
    return true;
}

int main()
{
while(true)
{
    int N; cin>>N;
    if(N==0) break;

    vector<string> vs;
    for(int i=0;i<N;i++){
      int x,y;
      string s1,s2,s3,s4;
      cin>>x>>s1>>s2>>s3>>s4;
      lp(i,s3.size()){
        if(s3[i]=='^'){
          s3=s3.substr(i+1,s3.size()-i-1);
          y=stoi(s3);
          break;
        }
      }
      a[i]=s1;
      b[i]=s4;
      c[i]=y;
      vs.push_back(a[i]);
      vs.push_back(b[i]);
      //cout<<a[i]<<' '<<b[i]<<' '<<c[i]<<endl;
    }
    sort(vs.begin(), vs.end());
    vs.erase(unique(vs.begin(), vs.end()), vs.end());

    map<string, int> mp;
    for(int i=0;i<vs.size();i++){
        mp[vs[i]]=i;
    }

    int V=vs.size();
    for(int i=0;i<V;i++){
        G[i].clear();
    }
    for(int i=0;i<N;i++){
        int v=mp[a[i]];
        int u=mp[b[i]];
        G[v].push_back({u, c[i]});
        G[u].push_back({v, -c[i]});
    }
/*
    for(int i=0;i<V;i++){
        cout<<i<<' ';
        for(edge e:G[i]){
            cout<<e.to<<' '<<e.cost<<endl;
        }
        cout<<"----------"<<endl;
    }
*/
    vector<int> dist(V, INF);
    bool ok=true;
    for(int i=0;i<V;i++){
        if(dist[i]!=INF) continue;
        dist[i]=0;
        if(!dfs(i, dist)){
            ok=false;
        }
    }
    cout<<(ok? "Yes":"No")<<endl;
}
}





Measured memory_bytes: 3268
#include <iostream>
#include <queue>

using namespace std;

typedef long long ll;

struct Square {
    int i;
    int j;
};

int main()
{
    int H, W;
    char s[51][51];
    int memo[51][51] = {};

    cin >> H >> W;

    int blackNum = 0;
    for (int i = 1; i <= H; ++i)
    {
        for (int j = 1; j <= W; ++j)
        {
            cin >> s[i][j];
            if (s[i][j] == '#') ++blackNum;
        }
    }

    queue<struct Square> q;
    struct Square first = {1, 1};
    q.push(first);
    memo[1][1] = 1;
    while (!q.empty())
    {
        struct Square cur = q.front();
        q.pop();

        int i = cur.i;
        int j = cur.j;

        if (i == H && j == W) break;

        if (i > 1 && memo[i-1][j] == 0 && s[i-1][j] == '.')
        {
            memo[i-1][j] = memo[i][j] + 1;
            struct Square next = {i-1, j};
            q.push(next);
        }
        if (i < H && memo[i+1][j] == 0 && s[i+1][j] == '.')
        {
            memo[i+1][j] = memo[i][j] + 1;
            struct Square next = {i+1, j};
            q.push(next);
        }
        if (j > 1 && memo[i][j-1] == 0 && s[i][j-1] == '.')
        {
            memo[i][j-1] = memo[i][j] + 1;
            struct Square next = {i, j-1};
            q.push(next);
        }
        if (j < W && memo[i][j+1] == 0 && s[i][j+1] == '.')
        {
            memo[i][j+1] = memo[i][j] + 1;
            struct Square next = {i, j+1};
            q.push(next);
        }
    }

    if (memo[H][W] == 0)
    {
        cout << -1 << endl;
        return 0;
    }

    cout << H*W - memo[H][W] - blackNum << endl;

    return 0;
}

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

int main() {
   int N;int l,r;
   cin>>N;
   int sum=N;
   for(int i=0;i<N;i++){
      cin>>l;
      cin>>r;
      sum=sum+r-l;
  }cout<<sum<<endl;
}

Measured memory_bytes: 256
t[3000];c;f(x,i){if(!--t[x])for(;i;f(x+="33h6h25"[--i]-52,8));}main(h){for(;scanf("%d%d",t,&h)*h;printf("%d\n",c)){for(;h;--h)for(c=*t;c;)scanf("%d",c---~h*52+t);for(;++h<3e3;f(h,8))c+=t[h]>0;}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 5000
using namespace std;
int n,ans,t1,t2,a1[N+5],a2[N+5];char s1[N+5],s2[N+5];
I void Calc()
{
	RI i,j,Mn=1e9,res;for(i=1;i<=t2;++i)
	{
		for(res=0,j=1;j^i;++j) res+=a2[j];
		for(j=i;j-i+1<=t1&&j<=t2;++j) res+=abs(a1[j-i+1]-a2[j]);
		W(j-i+1<=t1) res+=n-a1[j-i+1],++j;W(j<=t2) res+=n-a2[j],++j;Mn=min(Mn,res);
	}
	for(i=1;i<=t1;++i)
	{
		for(res=0,j=1;j^i;++j) res+=a1[j];
		for(j=i;j<=t1&&j-i+1<=t2;++j) res+=abs(a1[j]-a2[j-i+1]);
		W(j<=t1) res+=n-a1[j],++j;W(j-i+1<=t2) res+=n-a2[j-i+1],++j;Mn=min(Mn,res);
	}ans+=Mn;
}
int main()
{
	RI i;if(scanf("%d%s%s",&n,s1+1,s2+1),n==1) return putchar(48|(s1[1]^s2[1])),0;
	if(n==2&&s1[1]==s1[2]&&s2[1]==s2[2]) return putchar(48+2*(s1[1]^s2[1])),0;
	for(t1=0,i=1;i^n;++i) s1[i]=='0'&&s1[i+1]=='1'&&(a1[++t1]=i);
	for(t2=0,i=1;i^n;++i) s2[i]=='0'&&s2[i+1]=='1'&&(a2[++t2]=i);Calc();
	for(t1=0,i=1;i^n;++i) s1[i]=='1'&&s1[i+1]=='0'&&(a1[++t1]=i);
	for(t2=0,i=1;i^n;++i) s2[i]=='1'&&s2[i+1]=='0'&&(a2[++t2]=i);Calc();
	return printf("%d\n",ans),0;
}

Measured memory_bytes: 3736
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  int n, cnt[3] = {}, k, l, r;
  cin >> n >> k;
  vector<ll> a(n), p, m;
  ll ans = 1LL;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cnt[1]++;
      p.push_back(a[i]);
    } else if (a[i] < 0) {
      m.push_back(a[i]);
      cnt[0]++;
    } else {
      cnt[2]++;
      p.push_back(a[i]);
    }
  }
  sort(a.begin(), a.end());
  sort(p.begin(), p.end());
  sort(m.begin(), m.end());
  if (k > cnt[0] + cnt[2]) {
    cout << 0 << endl;
    return 0;
  }
  if (n == k) {
    for (int i = 0; i < n; i++) {
      if (a[i] < 0) {
        ans *= (a[i] + MOD);
      } else {
        ans *= a[i];
      }
      ans %= MOD;
    }
    if (ans < 0) {
      ans += 10000LL * MOD;
      ans %= MOD;
    }
    cout << ans << endl;
    return 0;
  }
  if (k % 2 == 1 && cnt[0] == n) {
    for (int i = 0; i < k; i++) {
      ans *= (a[n - 1 - i] + MOD);
      ans %= MOD;
    }
    if (ans < 0) {
      ans += 10000LL * MOD;
      ans %= MOD;
    }
    cout << ans << endl;
    return 0;
  }
  if (k % 2 == 1 && cnt[2] == 0) {
    cout << 0 << endl;
    return 0;
  }
  l = 0;
  r = n - 1;
  for (int i = 0; i < k; i++) {
    if (i < k - 1 && a[l] * a[l + 1] > a[r] * a[r - 1]) {
      ans *= (a[l] + MOD);
      ans %= MOD;
      ans *= (a[l + 1] + MOD);
      ans %= MOD;
      l += 2;
      i++;
    } else {
      ans *= (a[r] + MOD) % MOD;
      ans %= MOD;
      r--;
    }
  }
  cout << (ans + MOD) % MOD << endl;
}

Measured memory_bytes: 6872
#include <iostream>
#include <algorithm>

using namespace std;

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

	int p[n] = {0};

	for (int i = 0; i < 2 * m; i++)
	{
		int tmp;
		cin >> tmp;
		p[tmp - 1]++;
	}
	for (int i = 0; i < n; i++)
	{
		if (p[i] % 2 != 0)
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC159 D - Banned K
// 2020.06.27
// n(n-1)/2

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> A(N);
  map<int, ll> mp;
  REP(i, N){
    cin >> A[i];
    mp[A[i]]++;
  }
  ll ans = 0;
  for(auto i : mp){
    ans += i.second*(i.second-1)/2;
  }
  for(auto i : A){
    if(mp[i] >= 2){
      ll res = ans;
      res -= mp[i]*(mp[i]-1)/2;
      res += (mp[i]-1)*(mp[i]-2)/2;
      cout << res << endl;
    }else{
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 11884
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF 1e9+7
#define LLINF 1e18
// #define int ll
using namespace std;
const int MOD = 1e9 +7;

int prime[100010];

bool is_prime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return n!=1;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sum[100010];
    int q,l[100010],r[100010];
    cin>>q;
    rep(i,q) cin>>l[i]>>r[i];
    rep2(i,2,50000){
        if(is_prime(i) && is_prime(i*2-1)) prime[i*2-1]++;
    }
    rep(i,100000){
        sum[i+1] =sum[i] + prime[i+1];
    }
    rep(i,q){
        cout<<sum[r[i]]-sum[l[i]-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    ll M, K;
    cin >> M >> K;
    if (M == 1) {
        if (K == 0) {
            puts("0 0 1 1");
        }
        else {
            puts("-1");
        }
        return 0;
    }
    if (K < (1 << M)) {
        for (int i = 0; i < (1 << M); i++) {
            if (i == K) continue;
            cout << i << endl;
        }
        cout << K << endl;
        for (int i = (1 << M)-1; i >= 0; i--) {
            if (i == K) continue;
            cout << i << endl;
        }
        cout << K << endl;
    }
    else {
        puts("-1");
    }
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

map<ll, ll> mp;
queue<ll > que;
vector<ll > ans;

int main(){

    ll N;
    cin >> N;

    for(ll i = 1; i <= 9; i++){
        que.push(i);
    }

    for(;;){
        if(ans.size() >= 100000) break;
        
        ll in = que.front();
        ans.push_back(in);
        string c = to_string(in);
        que.pop();
        for(ll j = 0; j <= 9; j++){
            if(abs(c[c.length()-1] - ('0' + j)) <= 1){
                char tt = '0' + j;
                string tmp = c + tt;
                ll num = stoll(tmp);
                que.push(num);
                //cout << num << endl;
            }
        }        
    }

    // for(ll i = 0; i < N; i++){
    //     cout << ans[i] << endl;
    // }
    cout << ans[N-1] << endl;

}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
//#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll x;

int main(){
	cin>>x;
	ll ans=x/11;
	ll am=x%11;
	ans*=2;
	if(am==0){
	}else if(am<=6){
		ans++;
	}else{
		ans+=2;
	}
	cout<<ans<<endl;
}

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

int main(){
	int a,b,c,yakusu,i;
	yakusu=0;
	cin>>a>>b>>c;
	for(i=a;i<=b;i++){
		if(c%i==0){
			yakusu+=1;
		}
	}
	cout<<yakusu<<endl;
}


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

#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;


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

    cout << max(a-2*b, 0) << endl;
    return 0;
}



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	h := nextInt()
	w := nextInt()
	m := nextInt()

	hArr := make([]int, h)
	wArr := make([]int, w)
	save := map[[2]int]int{}
	hMax := 0
	wMax := 0
	hIndexArr := []int{}
	wIndexArr := []int{}
	for i := 0; i < m; i++ {
		hh := nextInt()
		ww := nextInt()
		save[[2]int{hh - 1, ww - 1}] = 1
		hArr[hh-1]++
		if hArr[hh-1] >= hMax {
			if hArr[hh-1] == hMax {
				hIndexArr = append(hIndexArr, hh-1)
			} else {
				hMax = hArr[hh-1]
				hIndexArr = []int{hh - 1}
			}
		}
		wArr[ww-1]++
		if wArr[ww-1] >= wMax {
			if wArr[ww-1] == wMax {
				wIndexArr = append(wIndexArr, ww-1)
			} else {
				wMax = wArr[ww-1]
				wIndexArr = []int{ww - 1}
			}
		}
	}

	xx := 1
	for _, v := range hIndexArr {
		for _, vv := range wIndexArr {
			if save[[2]int{v, vv}] == 0 {
				xx = 0
				break
			}
		}
		if xx == 0 {
			break
		}
	}

	fmt.Println(wMax + hMax - xx)
}

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


Measured memory_bytes: 51660
fun main(args: Array<String>) {
	readLine()
	val input = (readLine()?:return).toCharArray()
	var count = 0
	for (c in input)
		count += if (c == 'R') 1 else -1

	if (count > 0)
		println("Yes")
	else
		println("No")
}

Measured memory_bytes: 31652
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100000
int n,Q;
int u,v,ans;
int cnt[MAXN+5],red[MAXN+5];
int main()
{
	scanf("%d%d",&n,&Q);
	red[1]=1;
	while(Q--)
	{
		scanf("%d%d",&u,&v);
		if(red[u])
		{
			if(!cnt[u])red[u]=0;
			red[v]=1;
		}
		cnt[u]--,cnt[v]++;
	}
	for(int i=1;i<=n;i++)if(red[i])ans++;
	printf("%d",ans);//
}

Measured memory_bytes: 1024