akhauriyash/Code-Regression huggingface dataset:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**7)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

def cmb(n, r):
    return math.factorial(n)//(math.factorial(r)*math.factorial(n-r))

n,k = MAP()

for i in range(1,k+1):
    try:
        print(cmb(n-k+1,i)*cmb(k-1,i-1)%MOD)
    except:
        print(0)

Measured memory_bytes: 3700
#include <stdio.h>

int main()
{
    int e, y;
    scanf("%d"
          "%d",
          &e, &y);
    if (e == 0)
    {
        if (y >= 1989 && y <= 2016)
            printf("H%d\n", y - 1988);
        else if (y >= 1926 && y <= 1988)
            printf("S%d\n", y - 1925);
        else if (y >= 1912 && y <= 1925)
            printf("T%d\n", y - 1911);
        else if (y >= 1868 && y <= 1911)
            printf("M%d\n", y - 1867);
            
    }
    else if (e == 1) {
        printf("%d\n", 1867 + y);
    }
     else if (e == 2) {
        printf("%d\n", 1911 + y);
    }
     else if (e == 3) {
        printf("%d\n", 1925 + y);
    }
    else if (e == 4) {
        printf("%d\n", 1988 + y);
    }
}


Measured memory_bytes: 2104
import math

a, b, C = map(int, input().split())
h = math.sin(math.radians(C))*b
S = a*h/2
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C)))
print(S)
print(a + b + c)
print(h)

Measured memory_bytes: 7840
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll N, memo[77][5][5];

ll dfs(int d,int xm,int am){
    if(d<0) return 1;
    if(memo[d][xm][am]>=0) return memo[d][xm][am];
    
    ll ret=0;
    if(N&(1LL<<d)){
        ret+=dfs(d-1,1,min(2,am*2+1));
    }else{
        ret+=dfs(d-1,xm,min(2,am*2));
    }
    
    if(N&(1LL<<d)){
        ret+=dfs(d-1,xm,min(2,am*2));
    }else{
        if(am&&xm) ret+=dfs(d-1,xm,min(2,am*2-1));
    }
    
    if(am){
        if(N&(1LL<<d)){
            ret+=dfs(d-1,1,min(2,am*2-1));
        }else{
            ret+=dfs(d-1,xm,min(2,am*2-2));
        }
    }
    return memo[d][xm][am]=ret%MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    mem(memo,-1);
    cout1(dfs(60,0,0));
}

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

//????????????????????????hms???????????????
public class Main{

	public static void main(String[] args) throws IOException{

		Scanner in = new Scanner(System.in);
		int x=in.nextInt();
		hms(x);
		in.close();

	}

	public static void hms(int num){
		int h=num/3600;
		int m=(num%3600)/60;
		int s=(num%3600)%60;
		System.out.println(h +":"+m+":"+s+"");

	}

}

Measured memory_bytes: 26132
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define ll long long

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

    int n, w;
    cin >> n >> w;
    vector<int> wt(n), val(n);
    for (int i = 0; i < n; ++i)
        cin >> wt[i] >> val[i];

    vector<ll> dp(w + 1, 0);
    for (int i = 0; i < n; ++i)
        for (int j = w; j >= 0; --j)
            if (j - wt[i] >= 0)
                dp[j] = max(dp[j], val[i] + dp[j - wt[i]] + 0ll);

    ll sol = 0ll;
    for (int i = 0; i < w + 1; ++i)
        sol = max(sol, dp[i]);

    cout << sol << endl;

    return 0;
}

Measured memory_bytes: 3960
import java.util.Scanner;
import java.util.HashSet;
public class Main {

  /*
  // This was too slow
  public static boolean find(int[] ary, int n) {
    int low = 0;
    int high = ary.length-1;
    while (low <= high) {
      int mid = high - low / 2;
      if (ary[mid] == n)
        return true;
      if (n < ary[mid])
        high = mid - 1;
      else if (n > ary[mid])
        low = mid + 1;
    }
    return false;
  }
  */

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    HashSet<Integer> set = new HashSet<Integer>();
    for (int i = 0; i < n; i++) {
      set.add(s.nextInt());
    }
    int q = s.nextInt();
    int[] T = new int[q];
    for (int i = 0; i < q; i++) {
      T[i] = s.nextInt();
    }
    s.close();
    int count = 0;
    for (int t : T) {
      if (set.contains(t))
        count++;
    }
    System.out.println(count);
  }
}



Measured memory_bytes: 92208
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,l;
cin >> n>>l;
string s[n];
for(int i=0;i<n;i++){
cin >>s[i];
}
string ans="";
sort(s,s+n);
for(int i=0;i<n;i++){
ans+=s[i];
}
cout<<ans;
return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	for(int  i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int mn = a[0];
	reverse(a.begin(), a.end());
	int mx = a[0];
	cout << mx - mn << endl;
	
}



Measured memory_bytes: 256
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int[][] nwse={{0,0,0,0,0},{1,5,4,2,3,5},{2,1,4,6,3,1},{3,1,2,6,5,1},{4,1,5,6,2,1},{5,1,3,6,4,1},{6,2,4,5,3,2}};
        int[] dice=new int[7];
        int top=0;
        String[] str=br.readLine().split(" ");
        for(int i=1;i<=6;i++){
            dice[i]=Integer.parseInt(str[i-1]);
        }
        int t,s,e;
        int num=Integer.parseInt(br.readLine());
        for(int i=0;i<num;i++){
        	str=br.readLine().split(" ");
        	t=match(Integer.parseInt(str[0]),dice);
        	s=match(Integer.parseInt(str[1]),dice);
         	for(int j=1;j<=4;j++){
        		if(nwse[t][j]==s) {
        			e=nwse[t][j+1];
        			System.out.println(dice[e]);
        		}
        	}
        }
	}
	
	public static int match(int s,int dice[]){
		int p;
		for(p=0;p<6;p++){
			if(s==dice[p]) break;
		}
		return p;
	}
}

Measured memory_bytes: 16912
fun main(args: Array<String>) {
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }
    val sqrt = Math.sqrt(n.toDouble()).toInt() + 1
    val array = Array(sqrt * sqrt) { 0 }
    val sumQuery = SqrtDecomposition(array, IntMonoid)
    repeat(q) {
        val (com, x, y) = readLine()!!.split(" ").map { it.toInt() }
        when (com) {
            0 -> {
                val sum = y + sumQuery.get(x)
                sumQuery.update(x, sum)
            }
            1 -> { println(sumQuery.query(x, y + 1)) }
            else -> {}
        }
    }
}

interface Monoid<T> {
    fun combine(a: T, b: T): T
    fun empty(): T
}

object IntMonoid : Monoid<Int> {
    override fun combine(a: Int, b: Int): Int = a + b
    override fun empty(): Int = 0
}

class SqrtDecomposition<T>(val array: Array<T>, private val monoid: Monoid<T>) {
    private val divSize = Math.sqrt(array.size.toDouble()).toInt()
    private val bucket = (0 until divSize)
            .map {
                array.slice(it * divSize until (it + 1) * divSize)
                        .reduce { a, b -> monoid.combine(a, b) }
            }
            .toMutableList()

    init {
        require(divSize * divSize == array.size) {
            "array size must be square number. size: ${array.size}"
        }
    }

    fun get(index: Int) = array[index]

    fun query(left: Int, right: Int): T {
        // [left, right)
        require(left in (0 until right) && right <= array.size) {
            "Invalid Range [$left, $right)"
        }
        val bl = left / divSize
        val br = right / divSize
        var res = monoid.empty()
        if (bl == br) {
            (left until right).forEach { res = monoid.combine(res, array[it]) }
        } else {
            (left until (bl + 1) * divSize).forEach { res = monoid.combine(res, array[it]) }
            (bl + 1 until br).forEach { res = monoid.combine(res, bucket[it]) }
            (br * divSize until right).forEach { res = monoid.combine(res, array[it]) }
        }
        return res
    }

    fun update(index: Int, value: T) {
        array[index] = value
        val bi = index / divSize
        bucket[bi] = array.slice(bi * divSize until (bi + 1)*divSize)
                .reduce { a, b -> monoid.combine(a, b) }
    }
}



Measured memory_bytes: 259972
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std;

int f(int i){
	switch (i) {
		case 'T': return 0;
		case 'L': return 1;
		case 'U': return 2;
		case 'R': return 3;
		case 'D': return 4;
	}
}

int main(void){
	string s[10][6]={ {"wa","","nn","","wo"},{"a","i","u","e","o"},{"ka","ki","ku","ke","ko"},{"sa","si","su","se","so"},{"ta","ti","tu","te","to"},{"na","ni","nu","ne","no"},{"ha","hi","hu","he","ho"},{"ma","mi","mu","me","mo"},{"ya","","yu","","yo"},{"ra","ri","ru","re","ro"} };
	string str;
	cin>>str;
	for(int i=0;i<str.length();i+=2){
		cout<<s[str[i]-'0'][f(str[i+1])];
	}
	cout<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
const int maxn = 200005;
template <class T>
void read(T& x, T f = 1, char ch = getchar()) {
    x = 0;
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}
int n, ans;
char c[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> c[i];
    int i = 1, r = n;
    for (; i <= n; i++) {
        while (c[r] == 'W' && r > i) r--;
        if (c[i] == 'W' && i < r && c[r] == 'R') {
            swap(c[i], c[r]);
            ans++;
        }
        // for (int k = 1; k <= n; k++) cout << c[k];
        // cout << endl;
    }
    for (int j = i + 1; j <= n - 1; j++) {
        if (c[j] == 'W' && c[j + 1] == 'R') c[j] = 'W', ans++;
        // for (int k = 1; k <= n; k++) cout << c[k];
        // cout << endl;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3776
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int h, w;

        while (true) {
            h = scan.nextInt();
            w = scan.nextInt();

            if (h == 0 && w == 0)
                return;

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
                        System.out.print("#");
                    else
                        System.out.print(".");
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}


Measured memory_bytes: 36744
#include <bits/stdc++.h>
using namespace std;
int g[3][3];
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	g[0][0] = a;
	g[0][1] = b;
	g[1][1] = c;
	for(int i = -1000; i <= 1000; i++){
		bool bad = false;
		auto check = [&](int x, int y, int a, int b, int f, int t){
			g[f][t] = i - g[x][y] - g[a][b];
		};
		auto valid = [&](int x, int y, int a, int b, int f, int t){
			if(g[x][y] + g[a][b] + g[f][t] != i)
				bad = true;
		};
		check(0, 0, 0, 1, 0, 2);
		check(0, 1, 1, 1, 2, 1);
		check(0, 2, 1, 1, 2, 0);
		check(0, 0, 1, 1, 2, 2);
		check(0, 0, 2, 0, 1, 0);
		check(0, 2, 2, 2, 1, 2);
		valid(0, 0, 0, 1, 0, 2);
		valid(1, 0, 1, 1, 1, 2);
		valid(2, 0, 2, 1, 2, 2);
		valid(0, 0, 1, 0, 2, 0);
		valid(0, 1, 1, 1, 2, 1);
		valid(0, 2, 1, 2, 2, 2);
		valid(0, 0, 1, 1, 2, 2);
		valid(0, 2, 1, 1, 2, 0);
		if(!bad){
			for(int i = 0; i < 3; i++){
				for(int j = 0; j < 3; j++) cout << g[i][j] << " ";
				cout << endl;
			}
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct node{
	bool sum;
	int name;
}a[10];
int main()
{
	int n,i,j;
	for(i=1; i<=9; i++)
			cin>>a[i].name;
	cin>>n;
	for(i=1; i<=n; i++)
	{
		int x;
		cin>>x;
		for(j=1; j<=9; j++)
			if(a[j].name==x)
				a[j].sum=1;
	}
	if(a[1].sum==1 && a[2].sum==1 && a[3].sum==1)
		cout<<"Yes";
	else if(a[1].sum==1 && a[5].sum==1 && a[9].sum==1)
		cout<<"Yes";
	else if(a[4].sum==1 && a[5].sum==1 && a[6].sum==1)
		cout<<"Yes";
	else if(a[7].sum==1 && a[8].sum==1 && a[9].sum==1)
		cout<<"Yes";
	else if(a[1].sum==1 && a[4].sum==1 && a[7].sum==1)
		cout<<"Yes";
	else if(a[2].sum==1 && a[5].sum==1 && a[8].sum==1)
		cout<<"Yes";
	else if(a[3].sum==1 && a[6].sum==1 && a[9].sum==1)
		cout<<"Yes";
	else if(a[3].sum==1 && a[5].sum==1 && a[7].sum==1)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
 } 

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

work = []

for _ in range(n):
    ai, bi = map(int, input().split())
    work.append([ai, bi])

work = sorted(work, key=lambda x:x[1])

deadline = 0
total = 0
success = True

for w in work:
    deadline = w[1]
    total += w[0]
    
    if deadline < total:
        success = False
        break

print("Yes" if success else "No")

Measured memory_bytes: 39652
#include <cstdio>
using namespace std;

int main(){
  int N;
  scanf("%d",&N);
  int A[N];
  int i;
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  int n=0;
  int j;
  while(1){
    for(j=0;j<N;j++){
      if(A[j]==(A[j]/2)*2){
	A[j]=A[j]/2;
      }
      else{
	break;
      }
    }
    if(j!=N){
      break;
    }
    n+=1;
  }
  printf("%d",n);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<vector<bool>> S(N, vector<bool>(N));
    for (int i=0; i<N; i++)
    {
        string s;
        cin>>s;
        for (int j=0; j<N; j++)
            S[i][j] = s[j]!='0';
    }

    vector<int> C(N, -1);
    function<void(int, int)> f = [&](int p, int c)
    {
        if (C[p] != -1)
            return;
        C[p] = c;
        for (int i=0; i<N; i++)
            if (S[p][i])
                f(i, 1-c);
    };
    f(0, 0);

    bool ok = true;
    for (int i=0; i<N; i++)
        for (int j=0; j<N; j++)
            if (S[i][j])
                if (C[i]==C[j])
                    ok = false;
    if (!ok)
    {
        cout<<-1<<endl;
        return 0;
    }

    int ans = 2;

    for (int o=0; o<N; o++)
    {
        vector<int> C(N, -1);
        C[o] = 0;
        for (int i=0; i<N; i++)
            for (int j=0; j<N; j++)
                if (C[j]==i)
                    for (int k=0; k<N; k++)
                        if (S[j][k] && C[k]==-1)
                            C[k] = i+1;
        bool ok = true;
        int k = 0;
        for (int i=0; i<N; i++)
        {
            for (int j=0; j<N; j++)
                if (S[i][j])
                {
                    if (abs(C[i]-C[j])!=1)
                        ok = false;
                }
            k = max(k, C[i]+1);
        }
        ans = max(ans, k);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<iostream>

int main() {
	using namespace std;
	int len1, len2;
	cin >> len1;
	int* arr1 = new int[len1];
	for (int i = 0; i < len1; i++)
		cin >> arr1[i];
	cin >> len2;
	int* arr2 = new int[len2];
	for (int i = 0; i < len2; i++)
		cin >> arr2[i];
	int sum = 0;
	for (int i = 0; i < len2; i++) {
		for (int j = 0; j < len1; j++) {
			if (arr2[i] == arr1[j]) {
				sum++;
				break;
			}
		}
	}
	cout << sum << endl;
	return 0;
}


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

int main (){

 int N ;
 cin >> N ;
 string s = "No" ;

 for (int i = 1 ; i < 10 ; i++){
  for (int j = 1 ; j < 10 ; j++){
    if (i * j == N){
      s = "Yes" ;
      break;
    }
  }
  if (s == "Yes") break ;
  }
cout << s << endl ;

}  


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
long long m[1001];
long long a[100101];
void rev(int i){
  if(a[i]!=0){
  a[i]=a[i]/2;
  int M=i;
  for(int j=(i/100)*100;j<(i/100+1)*100;j++){
    if(a[j]>=a[M]){
      M=j;
    }
  }
  m[i/100]=M;
  }
}
void allmax(int N){
  int k=0;
  if(N<100){
    for(int i=0;i<N;i++){
      if(a[i]>=a[k]){
        k=i;
      }
    }
  }
  else{
    for(int j=0;j<N/100;j++){
      if(a[m[j]]>=a[k]){
        k=m[j];
      }
    }
    for(int i=(N/100)*100;i<N;i++){
      if(a[i]>=a[k]){
        k=i;
      }
    }
  }
  rev(k);
}
int main(){
  int N,M;
  cin>>N>>M;
  for(int i=0;i<(N/100+1)*100;i++){
    if(i<N){
    cin>>a[i];
    }
    if(i>=N){
      a[i]=0;
    }
    if(i%100==0){
      m[i/100]=i;
    }
    if(i%100!=0){
      if(a[i]>=a[m[i/100]]){
        m[i/100]=i;
      }
    }
  }
  for(int i=0;i<M;i++){
    allmax(N);
  }
  long long answer=0;
  for(int i=0;i<N;i++){
    answer+=a[i];
  }
  cout<<answer<<endl;
  
  return 0;
}

Measured memory_bytes: 1024
package main

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

func main() {

	N := oneInt()
	var sum int
	for i := 1; i <= N; i++ {
		if i%3 == 0 {
			continue
		}

		if i%5 == 0 {
			continue
		}
		sum += i
	}
	fmt.Print(sum)

}

func exp(val int) float64 {
	var temp float64
	for index := 1; index <= val; index++ {
		temp += float64(index)
	}
	return temp / float64(val)
}

func searchAbove(slice []int, target int, index int) int {
	for i := index + 1; i < len(slice); i++ {
		v := slice[i]
		if v >= target {
			return i
		}
	}
	return -1
}

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

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

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


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

using namespace std;

typedef long long               ll;
typedef long double             ld;

#define min3(a, b, c)           min((a), min((b), (c)))
#define max3(a, b, c)           max((a), max((b), (c)))
#define lcm(a,b)                (a / __gcd(a,b) ) *b
#define gcd(a,b)                __gcd(a,b)
#define dist(x1,y1,x2,y2)       sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define distl(x1,y1,x2,y2)      sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define sqr(a)                  ((a)*(a))
#define urs(r...)               typename decay<decltype(r)>::type
#define FOR(i,a,b)              for(urs(b) i=a;i<b;i++)
#define ROF(i,a,b)              for(urs(b) i=a;i>=b;i--)
#define REP(a,b)                for(urs(b) i=a;i<b;i++)
#define pb                      push_back
#define mk                      make_pair
#define ff                      first
#define ss                      second
#define lb                      lower_bound
#define ub                      upper_bound
#define all(a)                  a.begin(),a.end()
#define vi                      vector <int> 
#define pi                      pair <int, int> 
#define SORT(v)                 sort(v.begin(), v.end());
#define FASTIO                  ios_base::sync_with_stdio(0);cin.tie(NULL);
#define PI                      acos(-1.0)
const int MOD = 1e9 + 7;

ll fast_pow (ll n, ll p)
{
    ll res=1;
    while (p>0)
    {
        if (p&1)
            res = res * n;
        p = p>>1;
        n = n * n;
    }
    return res;
}

ll BMod(ll B,ll P,ll M)
{
    ll R=1;
    B=B%M;
    while(P)
    {
        if(P&1)
            R=(R*B)%M;
        P >>= 1;
        B=(B*B)%M;
    }
    return R;
}

ll invMOD(ll num,ll M)
{
    return BMod(num,M-2,M);
}

#ifdef Sieve
const int pSz = 50005;
bool np[pSz + 10]; vi prime; int prime_size;
void sieve(){np[0] = np[1] = 1;prime.pb(2);
for(ll i = 4; i <= pSz; i+=2) np[i] = 1;
for(ll i = 3; i <= pSz; i+=2){if(!np[i]){prime.pb(i);
for(ll j = i * i; j <= pSz; j += (i << 1)) np[j] = 1;}}prime_size = prime.size();}
#endif

#ifdef Combi
const int nSz = 2000006;
ll F[nSz + 1], tMod = MOD;
void Factorial(){ F[0] = 1; for(int i = 1; i <= nSz; i++) F[i] = (F[i - 1] * i) % tMod; }
inline ll nCr(int n, int r) { if(n < r) return 0; return (F[n] * invMOD((F[n - r] * F[r]) % tMod, tMod)) % tMod; }
 
#endif

 
//////////////////////////////////////////////////////////////////////////////
///                           M. K. BASHAR                                 ///
///                            IUT CSE'18                                  ///
//////////////////////////////////////////////////////////////////////////////

int main()
{

    string s;
    cin >> s;
    
    int sz = s.length();

    ll ac =0, c =0;

    REP (0, sz)
    {
        if (s[i] == 'A')
            ac++;
        else if (s[i] == 'B' && i+1 < sz && s[i+1] == 'C')
            c += ac, i++;
        else
            ac = 0;
    }

    cout << c;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

static const int N=100;

int main(){
  int n,p[N+1],m[N+1][N+1];
  int i,j,k,l;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=100000;
      for(k=i;k<=j;k++){
	if(m[i][j]>=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]){
	  m[i][j]=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	}
      }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}



Measured memory_bytes: 2112
N = int(input())
S = input()
 
r , g, b = S.count("R"), S.count("G"), S.count("B")
ans = r * g * b
 
for i in range(N-2):
    for d in range(N//2+1):
        j = i + d
        k = j + d
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
print(ans)

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  a = a - b;
  c = c - a;
  if(c < 0) {
    cout << 0 << endl;
  } else {
  	cout << c << endl;
  }
}

Measured memory_bytes: 3564
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define m0(x) memset(x,0,sizeof(x))
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

map<ll, ll> primeFactors(ll n)
{
    map<ll, ll> ret;
    while (n % 2 == 0)
    {
        if( ret.find(2) != ret.end() ) {
            ret[2]++;
        }
        else
        {
            ret[2] = 1;
        }
        n = n / 2;
    }
    for (ll i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            if( ret.find(i) != ret.end() ) {
            ret[i]++;
        }
        else
        {
            ret[i] = 1;
        }
            n = n / i;
        }
    }
    if (n > 2)
        {
            if( ret.find(n) != ret.end() ) {
            ret[n]++;
        }
        else
        {
            ret[n] = 1;
        }
        }
    return ret;
}

void print_map(map<char, int> mp){
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        std::cout << "key = " << itr->first           // キーを表示
                        << ", val = " << itr->second << "\n";    // 値を表示
    }
}

// Returns nCr % p
ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll N;
    cin >> N;
    ll count = 0;
    vector<ll> vec1(N);
    rep(i, N) {
        cin >> vec1.at(i);
    }
    sort(vec1.begin(), vec1.end());
    ll sum = 0;
    rep(i, N-1) {
        sum += vec1.at(i);
    }
    if (vec1.at(N-1) < sum) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<queue>
#include<assert.h>
#include<tuple>
#include<string>
#include<algorithm>
#include<iostream>
#include<map>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 2005;
const int MM = 1000000007;

ll T[2][MX], P[MX];
int N, M, K;

int main()
{
	scanf("%d%d%d", &N, &M, &K);
	int A = (N+M-1) / (K-1);
	ll *S = T[0], *E = T[1];
	S[0] = 1;
	for(int i = 1; i <= A; i++){
		for(int j = 0; j <= M; j++) E[j] = 0;
		P[0] = S[0];
		for(int j = 1; j <= M; j++) P[j] = (P[j-1] + S[j]) % MM;
		E[0] = 1;
		for(int j = 1; j <= M; j++){
			if( j <= K-1 ) E[j] = P[j];
			else E[j] = (P[j] - P[j-K] + MM) % MM;
		}
		E[K]++;
		swap(S, E);
	}
	if( N && M > 1 && (M-1)%(K-1) == 0) S[M] = (S[M] + MM-1) % MM;
	printf("%lld\n", S[M] % MM);
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

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...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    vector<ll> cnt(26);
    REP(i, 4) cnt[s[i]-'A']++;

    REP(i, 26) {
        if(cnt[i] == 1 || cnt[i] == 3 || cnt[i] == 4) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
typedef long long ll;

int main()
{
    int w, h, x, y;
    cin >> w >> h >> x >> y;

    double ans = (double) w * h / 2; //重心通れば半分にできるので
    int num = (w == x * 2 && h == y * 2) ? 1 : 0; //(x, y)が重心ならいっぱい作れる
    cout << fixed << ans << " " << num << endl;
}


Measured memory_bytes: 256
using System;

public class hello
{
    public static void Main()
    {
        var a = int.Parse(Console.ReadLine().Trim());
        var b = int.Parse(Console.ReadLine().Trim());
        var c = int.Parse(Console.ReadLine().Trim());
        var d = int.Parse(Console.ReadLine().Trim());
        var e = int.Parse(Console.ReadLine().Trim());
        int ans;
        if (a > 0) ans = (b - a) * e;
        else ans = -a * c + d + b * e;
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 9116
n, k = map(int, input().split())
p = list(map(int,input().split()))

sum_p =[0]
tmp = 0
for i in p:
    tmp += i
    sum_p.append(tmp)

max_expect = 0
for i in range(k, n+1):
    tmp = sum_p[i] - sum_p[i - k]
    max_expect = max(tmp, max_expect)

ans = (k + max_expect)/2
print(ans)


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

int main( ){

    long long ans = 0 ;

    int n ;

    cin >> n ;

    int a[n] ;

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

        cin >> a[i] ;

    }

    for( int i = 0 ; i < n - 2 ; i ++ ){

        for( int j = i + 1 ; j < n - 1; j ++ ){

            for( int k = j + 1 ; k < n ; k ++ ){

                if( a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i] && a[i] != a[j] && a[j] != a[k] && a[i] != a[k]){


                    ans ++ ;

                }

            }

        }

    }

    cout << ans << endl ;

}


Measured memory_bytes: 3616
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <random>
#include <numeric>

using namespace std;

#define INT_MAX_VALUE 2147483647
#define LONG_LONG_MAX_VALUE 9223372036854775807
#define ll long long
#define ld long double

struct XX{
    ll s;
    ll e;
};

class xxGreater {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第2条件
        if((riLeft.e) == (riRight.e)){
            return riLeft.s < riRight.s;//<:昇順(小さいものから順番)、>:降順(大きいものから順番)
            //プライオリティキューの場合は > で、top()すると値の小さいものがとれる
        }
        //第1条件
        return (riLeft.e) < (riRight.e);
    }
};


//map<long long,long long> prime_f(long long n){
//    map<long long,long long>res;
//    for(int i=2;i*i<=n;i++){
//        while(n%i==0){
//            ++res[i];
//            n/=i;
//        }
//    }
//    if(n!=1)res[n]=1;
//    return res;
//}

//int n;
////int dat[2*10000000];
////int dat2[2*10000000];
//int dat[10];
//int dat2[10];
//
//void init(int n_){
//    n=1;
//    while(n<n_)n*=2;
//    for(int i=0;i<2*n-1;i++){
//        dat[i]=0;
//        dat2[i]=0;
//    }
//}
//
//void initset(int k,int a){
//    k+=n-1;
//    dat[k]=a;
//    while(k>0){
//        k=(k-1)/2;
//        dat[k]=dat[k*2+1]+dat[k*2+2];
//    }
//}
//
////[a,b)の間を[l,r]区間で比較しアップデート
////引数のindexに注意
////nは固定。initで計算すみ
////update2(L[i],R[i]+1,0,0,n,D[i]);
//void update2(int a,int b,int k,int l,int r,int v){//v更新値、区間は0-index
//    if(r<=a || b<=l)return;
//    if(a<=l && r<=b){
//        dat[k]+=dat2[k];
//        if(r-l>1){
//            dat2[k*2+1]+=dat2[k]/2;
//            dat2[k*2+1]+=dat2[k]/2;
//        }
//        dat2[k]=v*(r-l);
//        return;
//    }else{
//        update2(a,b,k*2+1,l,(l+r)/2,v);
//        update2(a,b,k*2+2,(l+r)/2,r,v);
//        return;
//    }
//}
//
//int query(int a,int b,int k,int l,int r){
//    if(r<=a || b<=l)return 0;
//    if(a<=l && r<=b){
//        dat[k]+=dat2[k];
//        if(r-l>1){
//            dat2[k*2+1]+=dat2[k]/2;
//            dat2[k*2+1]+=dat2[k]/2;
//        }
//        dat2[k]=0;
//        return dat[k];
//    }
//    else{
//        int vl=query(a,b,k*2+1,l,(l+r)/2);
//        int vr=query(a,b,k*2+2,(l+r)/2,r);
//        return vl+vr;
//    }
//}



int main(int argc, const char * argv[])
{
    //scanf("%s",S);
    //scanf("%d",&N);
    //scanf("%lld %lld",&target1,&target2);
    //sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]);
    //getline(cin, target);
    //ifstream ifs("a.txt");//テスト用
    //ifs >> a;
    //ここから
    
    //入力高速化
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin>>s;

    if(((int)s.size())%2!=0 ^ s[0]==s[s.size()-1]){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
    
    //ここまで
    //cout << "ans" << endl;
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
    if(a+b>=a*b&&a+b>=a-b)
	{
	    printf("%d",a+b);
	}	
	else if(a*b>=a+b&&a*b>=a-b)
    {
    	printf("%d",a*b);
	}
	else if(a-b>=a*b&&a-b>=a+b)
	{
		printf("%d",a-b);
	}
	return 0;
} 

Measured memory_bytes: 256
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn func(a: usize, b: usize, x: usize) -> usize {
    (a * x / b) - a * (x / b)
}

fn solve() {
    input! {
        a: usize,
        b: usize,
        n: usize
    }
    let mut max_fn = func(a, b, n);

    if n >= b {
        let sho = n / b;
        let x = (sho - 1) * b + (b - 1);
        //println!("{}", x);
        max_fn = cmp::max(max_fn, func(a, b, x));
    }

    println!("{}", max_fn);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


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

#define		mina(a, b)	(a = min((a), (b)))

const int INF = 1e9+5;

int main(){
	int n;
	scanf("%d", &n);
	int p[n][3];
	for (int i = 0; i < n; ++i){
		scanf("%d %d %d", &p[i][0], &p[i][1], &p[i][2]);
	}
	vector <int> dpa(n, INF);
	vector <int> dpb(n, INF);
	vector <int> dpc(n, INF);
	dpa[0] = p[0][0];
	dpb[0] = p[0][1];
	dpc[0] = p[0][2];
	for (int i = 1; i < n; ++i){
		dpa[i] = max(dpb[i-1], dpc[i-1])+p[i][0];
		dpb[i] = max(dpa[i-1], dpc[i-1])+p[i][1];
		dpc[i] = max(dpa[i-1], dpb[i-1])+p[i][2];
	}
	printf("%d\n", max(dpa[n-1], max(dpb[n-1], dpc[n-1])));
	return 0;
}

Measured memory_bytes: 2560
import sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
a,b,c = map(int,readline().split())

if  a <= b <= c or a >= b >= c:
    if abs(a-b)==abs(b-c):
        print("YES")
        exit()
print("NO")

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<ll> vs(n);
    bool success = true;

    for (int i = 0; i < n; i++)
    {
        cin >> vs[i];
        vs[i] -= i;
        if (vs[i] > 0)
        {
            success = false;
        }
        if (i > 0 && vs[i - 1] < vs[i])
        {
            success = false;
        }
    }

    if (!success)
    {
        cout << -1 << endl;
    }
    else
    {
        map<ll, pair<ll, ll>> range;
        for (int i = 0; i < n; i++)
        {
            range[vs[i]].first = min(range[vs[i]].first, vs[i] + i);
            range[vs[i]].second = max(range[vs[i]].second, vs[i] + i);
        }
        ll sum = 0;
        for (auto v : range)
        {
            sum += v.second.second;
        }
        cout << sum << endl;
    }
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, ans[200000] = {0};
    cin >> n;
    for(int i=1;i<n;++i){
        int a;
        cin >> a;
        ans[a-1]++;
    }
    for(int i=0;i<n;++i) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 4444
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    string q,w,e; cin >> q >> w >> e;
    transform(q.begin(),q.end(),q.begin(),::toupper);
    transform(w.begin(),w.end(),w.begin(),::toupper);
    transform(e.begin(),e.end(),e.begin(),::toupper);
    cout << q[0]<<w[0]<<e[0]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int n,k;
  cin >> n >> k;
  int tt;
  if (n % 2 == 1) {
    tt = n / 2 + 1;
  } else {
    tt = n / 2;
  }

  if (k <= tt) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
#define fr first
#define sc second
#define pii pair<int, int>
#define all(v) v.begin(), v.end()

using namespace std;

const ll MOD = 1000000007;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    int reds = 0;
    for (char c : s)
        if (c == 'R') reds++;
    int ans = reds;
    for (int i = 0; i < reds; i++) {
        if (s[i] == 'R') ans--;
    }
    cout << ans;
    return 0;
}


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

int main(){
    int n, k;
    while(cin >> n >> k, n+k){
        // O(n^3)
        int c[n];
        for(int i = 0; i < n; i++)  cin >> c[i];
        
        auto func = [&]() -> int {
            int t = 1;
            for(int i = 0; i < k; i++)  t *= c[i];
            int tmp = t;
            for(int i = k; i < n; i++){
                tmp /= c[i-k];
                tmp *= c[i];
                t = max(t, tmp);
            }
            return t;
        };

        int t = func();
        int s = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                swap(c[i], c[j]);
                s = max(s, func());
                swap(c[i], c[j]);
            }
        }

        if(s >= t)   cout << s-t << endl;
        else        cout << "NO GAME" << endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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 x[2005][2005];
int y[2005][2005];
int xc[2005][2005];
int yc[2005][2005];

int main() {
  int h, w;
  cin >> h >> w;
  vs s(h);
  REP(i, h) cin >> s[i];
  int x_la = 0;
  REP(i, h) {
    REP(j, w) {
      x[i][j+1] = x[i][j];
      y[i+1][j] = y[i][j];
      if (s[i][j]=='#') {
        x[i][j+1]++; y[i+1][j]++;
      }else {
        xc[i][x[i][j]]++;
        yc[j][y[i][j]]++;
      }
    }
  }
  int ans = 0;
  REP(i, h) {
    REP(j, w) {
      if (s[i][j]=='#') {
        continue;
      }
      chmax(ans, xc[i][x[i][j]]+yc[j][y[i][j]]);
    }
  }
  // REP(i, h) REP(j, w) printf("%d%c", xc[i][x[i][j]]+yc[j][y[i][j]], (j==w-1?'\n':' '));
  cout << ans-1 << endl;

  return 0;
}

Measured memory_bytes: 67072
#include<bits/stdc++.h>
using namespace std;vector<int> v;int main(){int m,a,b,i,j;for(i=2;i<50000;i++){bool ok=1;for(j=0;j<v.size();j++)if(i%v[j]==0)ok=0;if(ok)v.push_back(i);}while(cin>>m>>a>>b&&m){int p=0,q=0;for(i=0;i<v.size();i++){for(j=i;j<v.size();j++){if(v[i]*v[j]>m)break;if(v[j]<=b*v[i]/a&&p*q<v[i]*v[j])p=v[i],q=v[j];}}cout<<p<<" "<<q<<endl;}return 0;}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, K;
  cin >> N >> K;
  ll power = 60;
  vector<ll> A(N);
  vector<vector<ll>> next(power, vector<ll>(N));
  for (ll i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    A.at(i) = a - 1;
    next.at(0).at(i) = A.at(i);
  }
  for (ll i = 0; i < power - 1; ++i) {
    for (ll j = 0; j < N; ++j) {
      next.at(i + 1).at(j) = next.at(i).at(next.at(i).at(j));
    }
  }
  ll now = 0;
  ll cnt = 0;
  while (K) {
    if (K & 1) {
      now = next.at(cnt).at(now);
    }
    cnt += 1;
    K = (K >> 1);
  }
  cout << now + 1 << "\n";
}


Measured memory_bytes: 100152
class Main{
    public static void main(String[] a){

    	int num;

    	for(int i = 1 ; i < 10 ; i++){
    		for(int j = 1 ; j < 10 ; j++){
    			num = i * j;
    			System.out.println(i + "x" + j + "=" + num);
    		}
    	}
    }
}

Measured memory_bytes: 24136
n,k = map(int,input().split())
a=[0 for i in range(n)]
for i in range(n):
    a[i] = int(input())
rank=[[] for i in range(n)]

ans = 1
for i in range(n):
    for r in range(ans,-1,-1):
        frag = 0
        for j in rank[r]:
            if abs(j-a[i])<=k:
                rank[r+1].append(a[i])
                ans = max(ans,r+2)
                frag =1
                break
        rank[0].append(a[i])
        if frag ==1:
            break


print(ans-1)

Measured memory_bytes: 176532
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  ui N{}, M{}; std::cin >> N >> M;

  typedef pair<ull, ui> Pair;
  vector<Pair> v(N);
  rep(0, v.size()) cin >> v[i].first >> v[i].second;

  boost::sort(v, std::less<Pair>());

  Pair res{};
  for(const Pair& p : v)
  {
    ui cnt = std::min(M - res.second, p.second);
    if(!cnt) break;

    res.second += cnt;
    res.first += cnt * p.first;
  }

  auto ans = res.first;
  cout << ans << '\n';
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1792