akhauriyash/Code-Regression huggingface dataset:
class Matrix < Array
  attr_reader :n, :m
  def initialize(arr, row = false, cul = false)
    if (row and cul) or !(Array === arr[0])
      arr.flatten!
      super()
      for i in 0...row ||= arr.length
        self << [*arr[i * cul, cul]]
      end
      @n, @m = row, cul
    elsif Array === arr[0]
      super(*arr)
      @n, @m = arr.length, arr[0].length
    else
      raise
    end
  end
  
  def self.e(row = 0)
    result = []
    for i in 0...row
      result << (0...row).map{|num|num == i ? 1: 0}
    end
    return Matrix.new(result)
  end
  
  def *(other)
    if Matrix === other
      return mmul(other)
    elsif Numeric === other
      return self.map{|item|item.map{|i|i * other}}
    end
  end
  
  def dup
    return Matrix.new(super, @n, @m)
  end
  
  def **(num)
    if num == 0
      return 1
    else
      result = Matrix.e(@n)
      num.to_s(2).each_char{|c|result = result * result * self ** (c.to_i)}
      return result
    end
  end
  
  def to_s
    result = []
    for i in 0...@n
      result << self[i].join(" ")
    end
    return result
  end
  
  def to_ary
    self
  end
  
  private
  def mmul(other)
    result = []
    for i in 0... self.n
      for j in 0... other.m
        temp = 0
        for k in 0... self.m
          temp += self[i][k] * other[k][j]
        end
        result << temp
      end
    end
    return Matrix.new(result, self.n, other.m)
  end
end
n, m, l = gets.split(" ").map(&:to_i)
a = []
n.times do
  a << [*gets.split(" ").map(&:to_i)]
end
a = Matrix.new(a, n, m)
b = []
m.times do
  b << [*gets.split(" ").map(&:to_i)]
end
b = Matrix.new(b, m, l)
puts (a * b).to_s

Measured memory_bytes: 6540
#include <stdio.h>
#include <string.h>
#define MAX_NUM 1000000000000000000ll


long long FizzBuzz(long long X){ // X - 1までのfizzとbuzzの数を数え、その文字数分(4)をかけている
	return ((X - 1) / 3) * 4 + ((X - 1) / 5) * 4;
}

long long theOtherNum(long long x){ // x - 1 までに出てくる通常数字（fizzbuzz以外)を数えている
	return (x - 1) - ((x - 1) / 3 + (x - 1) / 5 - (x - 1) / 15);
}


long long theOther(long long x,long long X,long long keta){ // xは1, 10, 100, 1000 ...とカウントアップしていき,
											 // そして最終的にXを超えるようなxが出たときXの値までの通常数字だけの文字数を返す
											 // ※ketaはxの桁数を表す
	if(x * 10 - 1 < X){
		return (theOtherNum(x * 10) - theOtherNum(x)) * keta + theOther(x * 10,X,keta + 1);
	}else{
		return (theOtherNum(X) - theOtherNum(x)) * keta;
	}
}

long long headNumber(long long X){ // Xというあたいが与えられたときfizzbuzzを含む文字列を見てXの値（3か5かで割れる場合はfかb)が入るの先頭を返す関数
	return 1 + FizzBuzz(X) + theOther(1,X,1);
}

long long binarySearch(long long s){
	long long lb = 1, ub = MAX_NUM;
	while(ub - lb > 1){
		long long mid = (ub + lb) / 2;
		if(headNumber(mid) >= s){
			ub = mid;
		}else{
			lb = mid;
		}
	}
	return lb;
}


int main(void){
	long long s, thrgh, hn, i, j;
	char ans[4096];
	scanf("%lld",&s);
	thrgh = s - (headNumber(hn = binarySearch(s)));
	char *p = ans;
	for(i = hn;i < hn + 10;i++){
		if(i % 15 == 0){
			strcpy(p,"FizzBuzz");
			p+=8;
		}else if(i % 5 == 0){
			strcpy(p,"Buzz");
			p+=4;
		}else if(i % 3 == 0){
			strcpy(p,"Fizz");
			p+=4;
		}else{
			long long keta = 0;
			long long  tmp = i;
			do{
				keta++;
				tmp /= 10;
			}while(tmp != 0);
			tmp = i;
			for(j = 0;j < keta;j++){
				*(p + keta - 1 - j) = '0' + tmp % 10;
				tmp /= 10;
			}
			p += keta;
		}
	}
	*p = '\0';
	for(p = ans + thrgh;p != ans + thrgh + 20;p++){
		printf("%c",*p);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1000
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.math;

void main() {
	auto N = readln.chomp.to!int;
	auto a = ['M': 0, 'A': 1, 'R': 2, 'C': 3, 'H': 4];
	auto b = new ulong[](5);
	foreach(_; 0..N) {
		auto c = readln.chomp[0];
		if(c in a) b[a[c]]++;
	}
	auto A = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2];
	auto B = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3];
	auto C = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4];
	ulong res;
	foreach(i; 0..10) {
		 res += b[A[i]] * b[B[i]] * b[C[i]];
	}
	res.writeln;
}

// M A R C H


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
 
int main() {
	string s1,s2;
	ll pos;
	cin>>s1>>s2;
	ll flag=0;
	if(s1==s2){
		cout<<"Yes";
	}
	else if(s1.size()!=s2.size())
		cout<<"No";
	else{
		s1=s1+s1;
		size_t it = s1.find(s2);
		it = s1.find(s2);
		if(it!=string::npos)
			cout<<"Yes";
		else
			cout<<"No";
	}
	
}

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

int main() {
  string x;
  int sum;
  int i;
  while (true) {
    cin >> x;
    if (x == "0") {
      break;
    }
    sum = 0;
    for (i = 0; i < x.length(); i++) {
      sum += x.at(i) - '0';
    }
    cout << sum << endl;
  }
  return 0;
}



Measured memory_bytes: 3192
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      result = x - 500*i - 100*j - 50*k
      if result == 0:
        count += 1
print(count)

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i = 0; i < h; ++i) {
        cin >> a[i];
    }

    int dis[1010][1010];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            dis[i][j] = INF;
        }
    }

    queue<pii> que;

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (a[i][j] == '#') {
                que.push(pii(i, j));
                dis[i][j] = 0;
            }
        }
    }

    while (!que.empty()) {
        pii p = que.front();
        que.pop();
        for (int k = 0; k < 4; ++k) {
            int nx = p.first + dx[k];
            int ny = p.second + dy[k];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if (a[nx][ny] == '#' || dis[nx][ny] != INF) continue;
            que.push(pii(nx, ny));
            dis[nx][ny] = dis[p.first][p.second] + 1;
        }
    }

    int res = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            res = max(res, dis[i][j]);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 13456
from collections import Counter
n = int(input())
s = []
for _ in range(n):
        s.append(input())

m = int(input())
t = []
for _ in range(m):
        t.append(input())

ans = []

cs = Counter(s)
ct = Counter(t)

for i in range(len(cs)):
        ans.append(cs.most_common()[i][1] - t.count(cs.most_common()[i][0]))
print(max(max(ans), 0))

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

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

int main(int argc, char const *argv[])
{
    int d,n;
    cin >> d >> n;
    if (n == 100) cout << int((n + 1) * pow(100,d)) << "\n";
    else cout << int(n * pow(100,d)) << "\n";
    return 0;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline

N, W = [int(x) for x in input().split()]
wv = []
for _ in range(N):
    wv.append([int(x) for x in input().split()])

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        w, v = wv[i]
        if j >= w:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v)
        else:
            dp[i + 1][j] = dp[i][j]

print(dp[N][W])

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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

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

    int n, a[100001];
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }

    llong res_even = 0, sum_a = 0;
    rep(i, n) {
        sum_a += a[i];
        if (i % 2 == 0 && sum_a <= 0) {
            res_even += abs(sum_a) + 1;
            sum_a = 1;
        }
        if (i % 2 == 1 && sum_a >= 0) {
            res_even += sum_a + 1;
            sum_a = -1;
        }
    }

    llong res_odd = 0;
    sum_a = 0;
    rep(i, n) {
        sum_a += a[i];
        if (i % 2 == 0 && sum_a >= 0) {
            res_odd += sum_a + 1;
            sum_a = -1;
        }
        if (i % 2 == 1 && sum_a <= 0) {
            res_odd += abs(sum_a) + 1;
            sum_a = 1;
        }
    }

    cout << min(res_even, res_odd) << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((100 * a + 10 * b + c) % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

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

  bool flag_a = false, flag_b = false;
  for (int i = 0; i < 3; i++) {
    if (S[i] == 'A') {flag_a = true;}
    if (S[i] == 'B') {flag_b = true;}
  }

  cout << ( flag_a && flag_b ? "Yes" : "No" ) << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
using System.Numerics;

namespace ABC169B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = RInt;
            var A = RLongs;

            BigInteger ans = 1;
            bool ok = true;
            for (int i = 0; i < N; i++)
            {
                ans = ans * A[i];
                if (ans > 1000000000000000000) { ok = false; break; }
            }
            if (A.Contains(0)) { ok = true; ans = 0; }

            if (!ok) ans = -1;
            Console.WriteLine(ans);
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 41672
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        String hats = sc.next();
        int numOfR = 0;
        int numOfB = 0;
        for(char hat: hats.toCharArray()){
            if(hat == 'R'){
                numOfR++;
            }
            else if(hat == 'B'){
                numOfB++;
            }
        }
        if(numOfR>numOfB){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23124
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

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

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, x := nextInt(), nextInt()
	a := nextInts(n)

	ans := 0
	if d := a[0] - x; d > 0 {
		a[0] -= d
		ans += d
	}
	for i := 1; i < n; i++ {
		if d := a[i] + a[i-1] - x; d > 0 {
			a[i] -= d
			ans += d
		}
	}

	puts(ans)
}


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

const int maxn=1e5+7;

int a[maxn];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int pos;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]==1)pos=i;
    }
    int ans=0x3f3f3f3f;
    for(int i=1;i<=k;i++){
        if(pos>=i&&n-pos>=k-i)
            ans=min(ans,(int)(ceil((double)(pos-i)/(double)(k-1))+ceil((double)(n-(pos+k-i))/(double)(k-1))));
    }
    printf("%d\n",ans+1);
    return 0;
}


Measured memory_bytes: 640
/*B.c*/
#include<stdio.h>
#include <string.h>

int main(void){
    char s[200001];
    char t[200001];

    scanf("%s", s);
    scanf("%s", t);

    int r = 0;
    for (int n = 0; n < strlen(s); n++){
        if(s[n] != t[n]) {
            r++;
        }
    }

    printf("%d", r);
    return 0;
}

Measured memory_bytes: 2088
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef vector<vector<lint>> mat;

mat mul(mat &a, mat &b, lint &mod){
    int n = a.size();
    int m = b[0].size();
    mat c = vector<vector<lint>>(n, vector<lint>(m, 0));
    rep(i, n)rep(j, m){
        lint t = 0;
        rep(k, a[0].size()) t = (t + a[i][k] * b[k][j] % mod) % mod;
        c[i][j] = t;
    }
    return c;
}

mat pow(mat a, lint k, lint &mod){
    int n = a.size();
    mat ret = vector<vector<lint>>(n, vector<lint>(n, 0));
    rep(i, n) ret[i][i] = 1;
    while(k){
        if(k & 1){
            ret = mul(ret, a, mod);
            k -= 1;
        }
        else{
            a = mul(a, a, mod);
            k >>= 1;
        }
    }
    return ret;
}

lint binsearch(lint i, lint a, lint b, lint l){
    if(to_string(a).size() > i) return 0;
    if(to_string(a+b*(l-1)).size() <= i) return l-1;
    lint low = 0;
    lint high = l-1;
    while(high - low > 1){
        lint mid = (high + low) / 2;
        if(to_string(a+b*mid).size() > i) high = mid;
        else low = mid;
    }
    return low;
}

int main(){
    lint l, a, b, m;
    scanf("%lld%lld%lld%lld", &l, &a, &b, &m);
    mat v = vector<vector<lint>>(3, vector<lint>(1, 0));
    v[0][0] = 0; v[1][0] = a; v[2][0] = b;
    mat p = vector<vector<lint>>(3, vector<lint>(3, 0));
    p[0][0] = p[0][1] = p[1][1] = p[1][2] = p[2][2] = 1;
    lint num[20];
    rep(i, 20) num[i] = binsearch(i, a, b, l);
    num[0] = -1;
    For(i, 1, 20){
        p[0][0] = (p[0][0] * 10) % m;
        mat q = pow(p, num[i] - num[i-1], m);
        v = mul(q, v, m);
    }
    printf("%lld\n", v[0][0]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


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

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

    return 0;

}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] S = sc.next().toCharArray();
        String ans = "No";
        if(S[2] == S[3] && S[4] == S[5]) ans = "Yes";
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int ans, M;

signed main(){
    cin >> ans >> M;
    rep(i, M){
        int a;
        cin >> a;
        ans -= a;
    }
    if(ans < 0) cout << -1 << endl;
    else cout << ans << endl;
}

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

int main(){
    int x;
    scanf("%d",&x);
    queue<ll> number_maker;
    rep1(i,9){
        number_maker.push(i);
    }
    ll result;
    rep(i,x){
        result = number_maker.front();
        if (result % 10 != 0){
            number_maker.push(result * 10 + result % 10 - 1);
        }
        number_maker.push(result * 10 + result % 10);
        if (result % 10 != 9){
            number_maker.push(result * 10 + result % 10 + 1);
        }
        number_maker.pop();
    }
    printf("%lld",result);
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
	long long int count=1;
	int n;
	std::cin>>n;

	std::vector<int> v(n);
	for (int& x : v) {
		std::cin >> x;
	}

	int min = v[0];

	for (int i = 1; i < v.size(); i++) {
		if (min > v[i]) {
			count++;
			min = v[i];
		}
	}

	std::cout<<count<<std::endl;
	return 0;
}

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

int main(){
 int r,c;
 cin >> r >> c;

 int num;
 int input[100][100];
 int output[1000][1000];

 for( int i=0; i<r; i++ ){
  for( int j=0; j<c; j++ ){
    cin >> num;
    input[i][j] = num;
    output[i][j] = num;
  }
 }

 for( int k=0; k<r; k++ ){
  output[k][c] = 0;
  int r_sum=0;
  for( int l=0; l<c; l++ ){
    r_sum += input[k][l];
  }
  output[k][c] = r_sum;
 }

 for( int k=0; k<c; k++ ){
  output[r][k] = 0;
  int c_sum=0;
  for( int l=0; l<r; l++ ){
    c_sum += input[l][k];
  }
  output[r][k] = c_sum;
 }

 int sum=0;
 for( int m=0; m<c+1; m++ ){
   sum += output[r][m];
 }

 output[r][c] = sum;

 for( int x=0; x<r+1; x++ ){
  for( int y=0; y<c+1; y++ ){
    if( y!=c ){
      cout << output[x][y] << " ";
    }else{
      cout << output[x][y];
    }
  }
  cout << endl;
 }

 return 0;
}


Measured memory_bytes: 3444
N=int(input())
sp=[]
for i in range(1,N+1):
    s,p=input().split()
    sp.append([s,int(p),i])
    

sp.sort(reverse=False)

x=100
for i in sp:
    i.insert(1,x)
    x-=1
    

sp.sort(reverse=False)

for i in sp:
    print(i[3])


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    if(A[0] != 0){
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    repr(i,1,N){
        if(A[i-1] < A[i]-1){
            cout << -1 << endl;
            return 0;
        }
        if(A[i] > A[i-1]) ans++;
        else ans += A[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            int n = 4;
            int ans = 0;
            for (int i = 0; i < n - 1; i++)
                if (s.charAt(i) == s.charAt(i + 1)) {
                    out.println("Bad");
                    return;
                }
            out.println("Good");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 21460
import sys
import string
N = int(input())
S = input()
s = list(S)
array = string.ascii_uppercase

for I in s:
    if array.index(I) + N <= 25:
        print(array[array.index(I) + N],end='')
    else:
        print(array[(array.index(I) + N) - 26],end='')

Measured memory_bytes: 9916
#include<bits/stdc++.h>
using namespace std;
int main () {
	int n;
	cin >> n;
	int l=0;
	map<int, int> m;
	for (int i=0; i<n; i++) {
		int x; cin >> x;
		if (m[x]==0) {	
			m[x] = 1;
			l++;	
		} else {
			m[x]=0;
			l--;
		}
	}
	cout << l;
	return 0;
}

Measured memory_bytes: 8212
import sys
from collections import deque
sys.setrecursionlimit(500000)
input=sys.stdin.readline
n,q=map(int,input().split())
edge=[[] for i in range(n)]
cost=[0]*n
for i in range(n-1):
  p,s=map(int,input().split())
  p-=1;s-=1
  edge[p].append(s)
  edge[s].append(p)
for i in range(q):
  x,c=map(int,input().split())
  x-=1
  cost[x]+=c
visited=[False]*n
queue=deque([0])
visited[0]=True
while len(queue)!=0:
  a=queue.popleft()
  for i in edge[a]:
    if visited[i]==True:continue
    queue.append(i)
    visited[i]=True
    cost[i]+=cost[a]
for i in range(n):
  cost[i]=str(cost[i])
print(" ".join(cost))


Measured memory_bytes: 122316
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < t.length(); i++) {
        cout << s[i] << t[i];
    }
    if (s.length() - t.length()) cout << s[s.length() - 1] << endl;
}


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

typedef long long ll;
typedef vector<int> vi;

#define rep(var,n)  for(int var=0;var<(n);++var)
#define ALL(c)  (c).begin(),(c).end()

ll solve(int N, vi& a, vi& b) {
    ll sum = 0;
    int smallest = 2e9;

    rep(i,N) {
        sum += a[i];

        if (a[i] > b[i]) {
            smallest = min(smallest, b[i]);
        }
    }
    if (smallest == 2e9) return 0LL; // A=B
    return sum - smallest;
}

int main() {
    int N; cin >> N;
    vi a(N), b(N);
    rep(i,N) cin >> a[i] >> b[i];
    cout << solve(N,a,b) << endl;
    return 0;
}


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



 int main(){
    long long n;
    cin>>n;
  
   long long p,q;
     long long min=n;
  
  
   for(long long i=1;i*i<=n;i++){
       if(n%i == 0){
           long long a=i;
       long long b=n/i;
       long long c=a-b;
       if(c<0){
           c=-c;
       }

     if(c<min){
         min=c;
         p=a;
         q=b;

     }
       }
   }
 
   
   
cout<<(p-1)+(q-1);

     

       
 }

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

using namespace std;
const int INF = 1e9;

int minCost(int N, vector<int> h) {
	vector<int> dp(N);
	dp[0] = 0;
	
	for(int i = 1; i < N; ++i) {
		int one = abs(h[i] - h[i-1]) + dp[i - 1];
		int two = (i == 1) ? INF : abs(h[i] - h[i-2]) + dp[i - 2];
		
		dp[i] = min(one, two);
	}
	
	return dp[N - 1];
}
int main() {
	// your code goes here
	int N;
	cin >> N;
	
	vector<int> h(N, 0);
	for(int i = 0; i < N; ++i) {
		cin >> h[i];
	}
	
	cout << minCost(N, h) << endl;
	return 0;
}
	

Measured memory_bytes: 1408
// aribon2-2_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define ALL(x) x.begin(), x.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define CHAR2INT(c) (c - '0')
#define COUT(x) cout << x << endl
#define COUT_2DARR(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }

int mod_pow(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[8]={ 1, 0, -1, 0, -1, 1, -1, 1};
int dy[8]={ 0, 1, 0, -1, -1, -1, 1, 1};

struct PreMain {PreMain(){std::cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


int main() {
#ifdef LOCAL
    std::ifstream in("../arg.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;
    vector<int> C(M);
    REP(i, M) cin >> C[i];
    sort(ALL(C));

    vector<int> dp(N+1);
    REP(j, N+1){ dp[j] = j;} // 必ず1

    REPN(i, 1, M){
        REPN(j, C[i], N+1){
            dp[j] = min(dp[j], dp[j - C[i]] + 1);
        }
    }
    COUT(dp[N]);

    return 0;
}



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

signed main(void)
{
	ll n, cnt;
	cin >> n;
	ll a[n];
	rep(i, n) cin >> a[i];
	cnt = 0;
	for (int i = 1; i < n; i++)
	{
		cnt += max(a[i - 1] - a[i], (ll)0);
		a[i] += max(a[i - 1] - a[i], (ll)0);
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 5136
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <iomanip>

using namespace std;
typedef long double ll;

#define PI 3.14159265358979
int main(){
    ll n = 0;
    cin >> n;
    cout << setprecision(10) <<  (ll)2.0*PI*n << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> balls(n);
    vector<ll> ballmaps(n+1);
    rep(i,n){
        cin >> balls.at(i);
        ballmaps[balls.at(i)]++;
    }

    ll total = 0;
    rep(i,n+1) total += ballmaps[i] * (ballmaps[i]-1) / 2;

    rep(i,n){
        cout << total - (ll)ballmaps[balls[i]] + 1 << endl;
    }
} 

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

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()


#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>

void print(T x)
{
	std::cout << x << '\n';
}


int main() {
	int N,M;
	cin >> N>>M;
	vector<int>a(N);
	vector<pair<int, int>>v(M);

	rep(i, N) {
		cin >> a[i];
	}
	sort(rall(a));
	rep(i, M) {
		cin >> v[i].sec;
		cin >> v[i].fst;
	}
	sort(v.begin(), v.end(), greater<pair<int, int> >());

	long long ans = 0;
	int j = 0;
	int k = 0;
	rep (i, N) {
		if (j < M and k < N) {
			if (v[j].fst <= a[k]) {
				ans += a[k];
				k++;
			}elif(v[j].fst > a[k]) {
				ans += v[j].fst;
				if (v[j].sec == 1) j++;
				else v[j].sec--;
			}
		}
		elif(j < M and k == N) {
			ans += v[j].fst;
			if (v[j].sec == 0) j++;
			else v[i].second--;
		}elif(j == M and k < N) {
				ans += a[k];
				k++;
			}
	}

	print(ans);
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d){
    cout << "Yes" <<endl;
  } else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 3632
N, W = map(int, input().split())
dp=[[0 for i in range(W+1)]for j in range(N+1)]

values = []
weights = []

for i in range(N):
    v,w=map(int,input().split())
    values.append(v)
    weights.append(w)


for i in range(N):
  for w in range(W+1):
    if w >= weights[i]:
      dp[i+1][w] = max(dp[i][w], dp[i][w - weights[i]] + values[i])
    else:
      dp[i+1][w] = dp[i][w]

print(dp[N][W])


Measured memory_bytes: 25936
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		while(sc.hasNext()){
			double a = sc.nextDouble();
			double b = sc.nextDouble();
			
			System.out.println((a * b) /  3.305785);
			
		}	
	}
}
	

Measured memory_bytes: 27872
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

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

void shellSort(int A[],int n){
  for(int h=1; ;){
    if(h>n)break;
    G.push_back(h);
    h=3*h+1;
  }
  for(int i=G.size()-1;i>=0;i--){
    insertionSort(A,n,G[i]);
  }
}
int main(){
  cin >> n;
  for(int i=0;i<n;i++)scanf("%d",&A[i]);
  cnt = 0;
  shellSort(A,n);
cout<<G.size()<<endl;
for(int i=G.size()-1;i>=0;i--){
  printf("%d",G[i]);
  if(i)printf(" ");
}
printf("\n");
printf("%d\n",cnt);
for(int i=0;i<n;i++)
printf("%d\n",A[i]);

return 0;
}

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル

	int a;
	cin >> a;
	cout << a + a * a + a*a*a << endl;

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

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

const char* key = "keyence";
const int keylen = 7;

int main(){
  string str;
  cin >> str;
  int f, b;
  for(f=0; f < keylen; f++){
    if(key[f] != str.at(f)) break;
  }
  for(b=0; b < keylen; b++){
    if(key[keylen - b - 1] != str.at(str.length() - b - 1)) break;
  }
  cout << ((f + b) >= keylen? "YES": "NO") << endl;
  
}

Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f([], []).
f([' '|Xs], [','|Ys]) :- f(Xs, Ys), !.
f([X|Xs], [X|Ys]) :- f(Xs, Ys).

main :-
    get_chars(S),
    f(S2, S),
    string_chars(S3, S2),
    writeln(S3).


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  auto begin = chrono::system_clock::now();
  
  int d;
  cin >> d;
  
  vector<int> c(26);
  for (int i = 0; i < 26; i++) cin >> c.at(i);
  
  vector<vector<ll>> s(d, vector<ll>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }
  
  // sが最大のものを貪欲
  vector<int> t(d);
  for (int i = 0; i < d; i++) {
    int it = 0;
    for (int j = 0; j < 26; j++) {
      if (s.at(i).at(j) > s.at(i).at(it)) it = j;
    }
    t.at(i) = it;
  }
  
  vector<vector<int>> dim(d, vector<int>(26, 1));
  ll suff = 0;
  for (int i = 0; i < d; i++) {
    suff += s.at(i).at(t.at(i));
    if (i > 0) {
      for (int j = 0; j < 26; j++) dim.at(i).at(j) = dim.at(i - 1).at(j) + 1;
    }
    dim.at(i).at(t.at(i)) = 0;
    for (int j = 0; j < 26; j++) {
      suff -= c.at(j) * dim.at(i).at(j);
    }
  }
  
  auto end = chrono::system_clock::now();
  auto time = chrono::duration_cast<chrono::microseconds>(end - begin).count();
  int dd = 0;
  while (time < 1950000) {
    dd = (dd + 25) % d;
    ll keepdelta = -10000, next = -1;
    for (int q = 0; q < 26; q++) {
      if (q == t.at(dd)) continue;
      vector<vector<int>> dim2 = dim;
      ll delta = s.at(dd).at(q) - s.at(dd).at(t.at(dd));
      for (int j = dd; j < d; j++) {
        delta += c.at(q) * dim2.at(j).at(q);
        delta += c.at(t.at(dd)) * dim2.at(j).at(t.at(dd));
      }
      dim2.at(dd).at(t.at(dd)) = 1; // 仮
      dim2.at(dd).at(q) = 0;
      for (int j = dd; j < d; j++) {
      if (dim2.at(j).at(t.at(dd)) > 0 && j > 0) dim2.at(j).at(t.at(dd)) = dim2.at(j - 1).at(t.at(dd)) + 1;
        if (dim2.at(j).at(q) > 0 && j > 0) dim2.at(j).at(q) = dim2.at(j - 1).at(q) + 1;
        delta -= c.at(q) * dim2.at(j).at(q);
        delta -= c.at(t.at(dd)) * dim2.at(j).at(t.at(dd));
      }
      if (delta > keepdelta) {
        keepdelta = delta;
        next = q;
      }
    }
    if (next == -1) continue;
    
    int q = next;
    dim.at(dd).at(t.at(dd)) = 1; // 仮
    dim.at(dd).at(q) = 0;
    for (int j = dd; j < d; j++) {
      if (dim.at(j).at(t.at(dd)) > 0 && j > 0) dim.at(j).at(t.at(dd)) = dim.at(j - 1).at(t.at(dd)) + 1;
      if (dim.at(j).at(q) > 0 && j > 0) dim.at(j).at(q) = dim.at(j - 1).at(q) + 1;
    }
    t.at(dd) = q;
    suff += keepdelta;
    end = chrono::system_clock::now();
    time = chrono::duration_cast<chrono::microseconds>(end - begin).count();
  }
  //cout << suff << endl;
  for (int i = 0; i < d; i++) cout << t.at(i) + 1 << '\n';
}

Measured memory_bytes: 3856
//O(N^2)解法
//バグったら愚直解法を書いた方がいいって, はっきり分かんだね！
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>
#include <tuple>
using namespace std;
typedef tuple<int, int, int> T;
typedef pair<int, int> P;

const int DEPTH = 17;
const int INF = 11451419;

class SegTree {
public:
	int data[1 << (DEPTH + 1)];
	SegTree() { for (int i = 0; i < (1 << (DEPTH + 1)); i++) data[i] = INF; }
	void update(int pos, int x) {
		pos += (1 << DEPTH) - 1;
		data[pos] = x;
		while (pos > 0) {
			pos = (pos - 1) / 2;
			data[pos] = min(data[pos * 2 + 1], data[pos * 2 + 2]);
		}
	}
	int getMin(int l, int r, int a = 0, int b = (1 << DEPTH), int id = 0) {
		if (a >= r || b <= l) return INF;
		if (l <= a && b <= r) return data[id];
		int u = getMin(l, r, a, a + (b - a) / 2, id * 2 + 1);
		int v = getMin(l, r, a + (b - a) / 2, b, id * 2 + 2);
		return min(u, v);
	}
};

int n;
int p[200000];
SegTree a[2];
int toPos[200001];
vector<P> ans;

//p[l]～p[r-1]を一つの数列(a[0], a[1], …)とみなすとき, 偶数番目の最小値を返す
int getEvenMin(int l, int r) {
	if (l >= r) return INF;
	return a[l % 2].getMin(l / 2, (r - 1 - (l % 2)) / 2 + 1);
}

//p[l]～p[r-1]を一つの数列(a[0], a[1], …)とみなすとき, 奇数番目の最小値を返す
int getOddMin(int l, int r) {
	if (l + 1 >= r) return INF;
	return a[(l + 1) % 2].getMin((l + 1) / 2, (r - 1 - ((l + 1) % 2)) / 2 + 1);
}

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> p[i];
	for (i = 0; i < n; i++) toPos[p[i]] = i;
	for (i = 0; i < n / 2; i++) a[0].update(i, p[2 * i]);
	for (i = 0; i < n / 2; i++) a[1].update(i, p[2 * i + 1]);
	
	priority_queue<T, vector<T>, greater<T> > que;
	que.push(T(getEvenMin(0, n), 0, n));
	
	while (!que.empty()) {
		T t = que.top(); que.pop();
		if (get<1>(t) >= get<2>(t)) continue;
		
		int x = get<0>(t);
		int y = getOddMin(toPos[x], get<2>(t));
		ans.push_back(P(x, y));
		
		que.push(T(getEvenMin(get<1>(t), toPos[x]), get<1>(t), toPos[x]));
		que.push(T(getEvenMin(toPos[x] + 1, toPos[y]), toPos[x] + 1, toPos[y]));
		que.push(T(getEvenMin(toPos[y] + 1, get<2>(t)), toPos[y] + 1, get<2>(t)));
	}
	
	for (i = 0; i < ans.size(); i++) {
		cout << ans[i].first << " " << ans[i].second;
		if (i + 1 < ans.size()) cout << " ";
		else cout << endl;
	}
	return 0;
}

Measured memory_bytes: 9904
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

dist_sum = 0
for n, (x_i, y_i) in enumerate(XY[:-1]):
    for (x_j, y_j) in XY[n+1:]:
        dist_sum += ((x_i - x_j)**2 + (y_i - y_j)**2) ** 0.5
print(dist_sum * 2 / N)


Measured memory_bytes: 38384
#include<iostream>
#include<cmath>
using namespace std;
#define rep(i,a,b) for(int i = (a); i <= (b); i++)

int main(){
  long long L,R,res=2020;
  cin >> L >> R;
  if(R-L > 2019) R = L+2019;
  rep(i,L,R){
    long long i_res = i%2019;
    rep(j,i+1,R){
      long long j_res = j%2019;
      res = min((i_res*j_res)%2019,res);
    }
  }
  cout<<res<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n] = {};
    for(int i=0; i<n; i++) {
        int x;
        cin >> x;
        if(i+1 == x) {
            a[i] = 0;
        } else {
            a[i] = 1;
        }
    }
    int result=0;
    for(int i=0; i<n; i++) {
        if(a[i] == 0 && i != n-1) {
            a[i] = 1;
            a[i+1] = 1;
            result = result + 1;
        } else if(a[i] == 0 && i == n-1) {
            a[i] = 1;
            result = result + 1;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

signed main(){
	string S, T;
	cin >> S >> T;
	vector<int> v(S.size() + 1), u(T.size() + 1);
	for(int i = 0; i < S.size(); ++i) {
		v[i + 1] = v[i] + (S[i] - 'A' + 1);
	}
	for(int i = 0; i < T.size(); ++i) {
		u[i + 1] = u[i] + (T[i] - 'A' + 1);
	}
	int q;
	cin >> q;
	for(int i = 0; i < q; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		if((v[b] - v[a - 1]) % 3 == (u[d] - u[c - 1]) % 3) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 2432
def main():
    N = int(input())
    a = list(map(int, input().split()))
    avg = sum(a) / N
    min_abs = float("inf")
    min_frame = 0
    for i in range(N):
        score = abs(a[i] - avg)
        if score < min_abs:
            min_abs = score
            min_frame = i
    print(min_frame)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,num[100005],ans;
int main()
{
	cin>>n>>m;
	for (i=1;i<=n;i++) cin>>num[i];
	if (num[1]>m)
	{
		ans+=num[1]-m;
		num[1]=m;
	}
	for (i=2;i<=n;i++)
	{
		if (num[i]+num[i-1]>m)
		{
			ans+=num[i]+num[i-1]-m;
			num[i]-=num[i]+num[i-1]-m;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
/*
* @Author: Samson
* @Date:   2018-06-14 09:42:05
* @Last Modified by:   Samson
* @Last Modified time: 2018-06-14 10:06:32
*/
//   @URL : http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_B
#include<bits/stdc++.h>
#include<algorithm>
#include <cstdlib>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e3+10;

int a[MAXN][MAXN],n,d[MAXN],color[MAXN];

void dijkstra()
{
	memset(color,0,sizeof color);
	memset(d,INF,sizeof d);
	int s = 0,u,minv;
	d[s] = 0;
	while(1)
	{
		minv = INF;
		u = -1;
		for(int i = 0; i < n; ++i)
		{
			if(!color[i] && d[i] < minv)
				minv = d[i], u = i;
		}
		if(u == -1)	break;
		color[u] = 1;
		for(int v = 0; v < n; ++v)
		{
			if(!color[v] && a[u][v]!=INF)
			{
				if(d[u]+a[u][v] < d[v])
				{
					d[v] = d[u]+a[u][v];
				}
			}
		}
	}
	for(int i = 0; i < n; ++i)
		cout<<i<<' '<< (d[i]==INF?-1:d[i])<<'\n';
}
int main(void)
{
	ios::sync_with_stdio(false); 
	//cin.tie(0);
	int u,v,k,w;
	memset(a,INF,sizeof a);
	cin>>n;
	for(int i = 1; i <= n; ++i)
	{
		cin>>u>>k;
		for(int j = 1; j <= k; ++j)
		{
			cin>>v>>w;
			a[u][v] = w;
		}
	}
	dijkstra();
	return 0;
}


Measured memory_bytes: 7148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

ll fac[1000010], finv[1000010], inv[1000010];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 1000010; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

int main() {
    int N,K;
    cin >> N >> K;
    int cnt = min(N - 1,K);
    COMinit();
    ll ret = 0;
    for(int i = 0;i <= cnt;i++) {
        ret += COM(N,i) * COM(N - 1,i) % MOD;
        ret %= MOD;
    }
    cout << ret << endl;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector< ii > vii;
typedef long long LL;
int arr[10005];
int res[105][105];
int n, m;
int x, y;
void inc()
{
	if(x%2 == 0)
	{
		if(y == m-1) x++;
		else y++;
	}
	else
	{
		if(y == 0) x++;
		else y--;
	}
}
int main()
{
	int k; scanf("%d %d %d", &n, &m, &k);
	for(int i = 1; i<= k; i++) scanf("%d", arr+i);
	for(int i = 1; i<= k; i++)
	{
		while(arr[i]--)
		{
			res[x][y] = i;
			inc();
		}
	}
	for(int i = 0; i< n; i++)
	{
		for(int j = 0; j< m; j++) 
		{
			printf("%d ", res[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 384
n, m = map(int, input().split())

flag = [0] * n
WA_count = [0] * n
total_WA = 0
for i in range(m):
    P, s = input().split()
    p = int(P) - 1
    if s == "WA" and flag[p] == 0:
        WA_count[p] += 1
    elif s == "AC" and flag[p] == 0:
        flag[p] = 1
        total_WA += WA_count[p]
print(sum(flag), total_WA)

Measured memory_bytes: 51416
#include<stdio.h>
#include<string.h>
int main()
{
	int n,m,i,f=0;
	char a[111],b[111];

	scanf("%s%s",a,b);

	n=strlen(a);
	m=strlen(b);
	if(n>m)
		f=1;
	else if(n<m)
		f=-1;
	for(i=0;i<n&&f==0;i++){
		if(a[i]>b[i])
			f=1;
		else if(a[i]<b[i])
			f=-1;
	}

	if(f==1)
		puts("GREATER");
	else if(f==0)
		puts("EQUAL");
	else
		puts("LESS");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;



vector<vector<int64>> __gcdv(300, vector<int64> (300, -1));
int64 _gcd(int64 a, int64 b) {
    if (__gcdv[a][b] >= 0) return __gcdv[a][b];
    int64 GCD = gcd(a,b);
    return __gcdv[a][b] = __gcdv[b][a] = GCD;
}

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

    int64 ans = 0;
    for (int i=1; i<=k; i++) {
        for (int j=1; j<=k; j++) {
            for (int l=1; l<=k; l++) {
                ans += _gcd(i, _gcd(j,l));
            }
        }
    }

    cout << ans << endl;
}

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

int main(){
	while(true){
		int n,a=0,b=0;
		std::cin>>n;
		if(n==0){
			break;
		}
		std::vector<int> v1(n,0);
		std::vector<int> v2(n,0);
		for(int i=0;i<n;i++){
			std::cin>>v1[i]>>v2[i];
			if(v1[i]>v2[i]){
				a+=v1[i]+v2[i];
			}else if(v1[i]<v2[i]){
				b+=v1[i]+v2[i];
			}else{
				a+=v1[i];
				b+=v2[i];
			}
		}
		std::cout<<a<<" "<<b<<std::endl;
		
	}
}

Measured memory_bytes: 3180
s=input()
ans=0
if s[0]==">":
    s="<"+s
if s[-1]=="<":
    s=s+">"
s=list(s)
ls=len(s)

st=ct=gl=0
ans=0
for i in range(ls-1):
    if s[i]=="<" and s[i+1]==">":
        ct=i
    elif s[i]==">" and s[i+1]=="<":
        gl=i
    if i==ls-2:
        gl=ls-1
    if gl!=0:
        pre=((ct-st)+1)*(ct-st)/2
        pos=((gl-ct-1)+1)*(gl-ct-1)/2
        intra=max(ct-st+1, gl-ct)
        ans+=pre+pos+intra
        # 更新
        st=gl+1
        ct=gl=0

print(int(ans))
 

Measured memory_bytes: 7836
import heapq

n, m = map(int, input().split())
lst = []
for i in range(n):
    a, b = map(int, input().split())
    lst.append([a, b])

lst.sort(key=lambda x:(x[1]), reverse=True)
lst.sort(key=lambda x:(x[0]), reverse=False)

ans = 0
ind = 0
kouho = []
for i in range(1, m+1):
    tugi = True
    while tugi:
        if ind >= n:
            break
        if lst[ind][0] == i:
            heapq.heappush(kouho, -lst[ind][1])
            ind += 1
        else:
            tugi = False
    try:
        ans += heapq.heappop(kouho) * (-1)
    except:
        IndexError

print(ans)

Measured memory_bytes: 24812