akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

namespace ABC166C
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ');
            var n = int.Parse(nm[0]);
            var m = int.Parse(nm[1]);
            var inputs = Console.ReadLine().Split(' ');

            var heigth = new Dictionary<string, int>();
            var good = new Dictionary<string, bool>();

            for (var i = 1; i <= n; i++)
            {
                heigth.Add(i.ToString(), int.Parse(inputs[i-1]));
                good.Add(i.ToString(), true);
            }
            for (var j = 1; j <= m; j++)
            {
                var ab = Console.ReadLine().Split(' ');
                if (heigth[ab[0]] < heigth[ab[1]])
                {
                    good[ab[0]]=false;
                }else if (heigth[ab[0]] == heigth[ab[1]])
                {
                    good[ab[0]] = false;
                    good[ab[1]] = false;
                }
                else
                {
                    good[ab[1]] = false;
                }

            }
            var ans = 0;
            foreach (var value in good.Values)
            {
                ans = value ? ans+1 : ans;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 45012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){

    int N;string S;cin>>N>>S;
    int x=0,y=0;
    for(int i=0;i<N;i++){
        if('A'<=S[i]&&S[i]<='M') x++;
        else if('N'<=S[i]&&S[i]<='Z') x--;
        else if('a'<=S[i]&&S[i]<='m') y++;
        else y--;
    }
    
    cout<<abs(x)+abs(y)<<endl;
    
    for(int i=0;i<abs(x);i++){
        if(x>0) cout<<'A';
        else cout<<'N';
    }
    for(int i=0;i<abs(y);i++){
        if(y>0) cout<<'a';
        else cout<<'n';
    }
    
    cout<<endl;
}




Measured memory_bytes: 3336
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    ll ans=0;
    rep(i,n){
        ans+=a.at(i)-1;
    }
    cout << ans << endl;

}


Measured memory_bytes: 3588
#include<iostream>
#include<string.h>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<functional>
using namespace std;
typedef long long LL;
LL l, k, dp[200][2],wa,i;//1bai 0hei
int main() {
	cin >> l >> k;
	wa = 1;
	memset(dp, 0, sizeof(dp));
	dp[1][1] = 0;
	dp[1][0] = 1;
	dp[k][0] = 1;
	for (i = 2; i <= l; i++) {
		dp[i][1] += dp[i - 1][0];
		dp[i][0] += dp[i - 1][1];
		if (i - k >= 0)dp[i][0] += dp[i - k][1];
	}
	for (i = 2; i <= l; i++)wa += dp[i][0];
	//printf("%lld\n", wa);
	cout << wa << endl;
}


Measured memory_bytes: 3120
#include <stdio.h>

int main(void) {

  long a,b;
  scanf("%ld %ld", &a, &b);
  if (a > 0) {
    printf("Positive\n");
  } else if (a <= 0 && b >= 0) {
    printf("Zero\n");
  } else {
    if ((b-a)%2 == 0) {
      printf("Negative\n");
    } else {
      printf("Positive\n");
    }
  }

  return 0;
}

Measured memory_bytes: 128
//
// Created by moono on 2018/10/27.
//

#include <iostream>
#include <string>
using namespace std;


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

    int n = b - a, height = 0;
    for (int i = 0; i < n; ++i) {
        height += i;
    }

    cout << height - a << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        string inputBuf = Console.ReadLine();
        char[] input = inputBuf.ToCharArray();
        bool isEasy = true;
        for (int i = 0; i < input.Length; i++)
        {
            if (i % 2 == 0)
            {
                // 奇数
                if (input[i] == 'R' || input[i] == 'U' || input[i] == 'D')
                    isEasy = true;
                else
                {
                    isEasy = false;
                    break;
                }
            }
            else
            {
                // 偶数
                if (input[i] == 'L' || input[i] == 'U' || input[i] == 'D')
                    isEasy = true;
                else
                {
                    isEasy = false;
                    break;
                }
            }
        }
        if (isEasy)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}


Measured memory_bytes: 13140
#include <stdio.h>

int main(int argc, char const *argv[]) {
	char str[101];
	int n, m;

	fgets(str, 100, stdin);
	sscanf(str, "%d %d\n", &n, &m);

	printf("%d\n", (n-1)*(m-1));

	return 0;
}


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

int main() {
    string o, e;
    cin >> o >> e;

    char s[101] = {};
    for (int i = 0;; i++) {
        if (i >= o.size()) break;
        s[i * 2 + 0] = o[i];
        if (i >= e.size()) break;
        s[i * 2 + 1] = e[i];
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<pair<int,int>> jobs;
bool comp(pair<int,int> const &a,pair<int,int> const &b){
    return a.second < b.second;
}
int32_t main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        jobs.push_back({a,b});
    }
    sort(jobs.begin(),jobs.end(),comp);
    int s = 0;
    for(pair<int,int> p : jobs){
        s+=p.first;
        if(s>p.second){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


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

using namespace std;
typedef long long lint;

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

    vector<lint> A(N), B(N + 1, 0);
    B[0] = 0;
    lint i;
    for (i = 0; i < N; ++i) //N=6
    {
        cin >> A[i];
        //cout << "i=" << i;
        B[i + 1] = A[i] + B[i];
        //cout << B[i + 1];
    }

    sort(B.begin(), B.end());
    //cout << "\n";

    map<lint, lint> index_nums;
    for (i = 0; i < N + 1; i++)
    {
        index_nums[B[i]]++;
    }
    //iterator 反復子->添え字
    lint ans = 0;
    for (auto iterator : index_nums)
    {
        lint num = iterator.second;
        ans += num * (num - 1) / 2;
    }
    cout << ans;
    return 0;
}

//6.
//[0 1 2  3 4  5]
//  1 3 -4 2 2 -2
//0 1 4 0 2 4 2
//[0 1 2 3 4 5 6]

//if B[i] 3 -7 8 -9 2 3 -7 7

/*
    for(i=0;i<N;i++){
        pos_index[i]=0;
        neg_index[i]=0;
    }
    */

/*
    for (i = 0; i < N + 1; i++)
    {
        cout << "B[" << i << "]=" << B[i] << "\n";
        //cout << B[i + 1];
    }
    */

/*
    vector<lint> neg_index(9999), pos_index(9999);
    for (i = 0; i < N + 1; i++)
    {
        if (B[i] >= 0)
        {
            //cout << "is here?";
            pos_index[B[i]]++;
            //cout << "pos_index=" << pos_index[i];
            //cout << pos_index[B[i]] << "\n";
        }
        else
        {
            neg_index[abs(B[i])]++;
        }
    }
    for (i = 0; i < pos_index.size(); i++)
    {
        if (pos_index[i] > 1)
        {
            ans += pos_index[i] * (pos_index[i] - 1) / 2;
        }
    }
    for (i = 0; i < pos_index.size(); i++)
    {
        if (neg_index[i] > 1)
        {
            ans += neg_index[i] * (neg_index[i] - 1) / 2;
        }
    }
*/

Measured memory_bytes: 15872
#include <stdio.h>

int main(void){
	int w=0, n=0;
	int a=0, b=0, t=0;
	int c[30];

	scanf("%d", &w);
	scanf("%d", &n);

	for(int i=0;i<w;++i){
		c[i] = i+1;
	}
	for(int i=0;i<n;++i){
		scanf("%d,%d", &a, &b);
		t = c[b-1];
		c[b-1] = c[a-1];
		c[a-1] = t;
	}
	for(int i=0; i<w;++i){
		printf("%d\n", c[i]);
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main(){
    for(int i = 0; i < 9; i++){
        string a;
        cin >> a;
        int x,y;
        scanf("%d%d",&x,&y);
        cout << a << ' ' << (x+y) << ' ' << (x*200)+(y*300) << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if (abs(x - a) < abs(x - b)) {
    cout << "A" << endl;
  } else {
    cout << "B" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
    int len,i;
    int isClr=0;
    char s[101];
    char c[1] =  "C";
    char f[1] =  "F";
    int cNum=-1,fNum=0;
    
    // 文字列の入力
    scanf("%s",s);
    
    len = strlen(s);
    for(i=0;i<len; i++) {
        if(s[i] == c[0]){
            cNum = i;
        }
        if(cNum<i && cNum>=0){
            if(s[i] == f[0]){
                isClr=1;
            }
        }
    }
    // 出力
    if(isClr){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 128
n, a, b = gets.split.map(&:to_i)

if n == 1
  if a == b
    puts 1
  else
    puts 0
  end
elsif n == 2
  puts 1
elsif a > b
  puts 0
else
  puts (b * (n-1) + a) - (a * (n-1) + b) + 1
end

Measured memory_bytes: 1788
/*ex4_3
ryo_1129*/
#include<stdio.h>
//プロトタイプ宣言、引数は2つの塔の見えている高さ
int snowhight(int a,int b);

int main(void){
    //変数宣言
    int a,b,ans;
    //入力
    scanf("%d %d",&a,&b);
    //積雪量を出す関数の呼び出し
    ans = snowhight(a,b);
    //出力
    printf("%d\n",ans);

    return 0;
}
//n番目の木の高さを出す関数、等差数列の和
int snowhight(int a,int b){
    int talla,n,snowhight;
    //n番目とn+1番目の木の高さの違い(b-a)はn+1である。
    n = b-a-1;
    //aの高さを出す。n番目の高さは
    talla = (n)*(n+1)/2;
    //積雪量は（aの高さ-埋まらずに見えている高さ）
    snowhight = talla-a;
    return snowhight;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
vector<int>p[2010];
struct point
{
	int d,p;
}ul,uf;
priority_queue<point>q;
bool operator <(point a,point b){return a.d<b.d;}
inline int gcd(int x,int y)
{
	if(x==0)return y;
	else return gcd(y%x,x);
}
struct node
{
	int x,y,next;
}a[8000010];int len,last[2010];
inline void ins(int x,int y)
{
	len++;
	a[len].x=x;a[len].y=y;
	a[len].next=last[x];last[x]=len;
}
int du[2010],w[2010];
bool v[2010];
inline void dfs(int x)
{
	v[x]=true;
	for(int i=0;i<p[x].size();i++)
	{
		int y=p[x][i];
		if(v[y])continue;
		du[y]++,ins(x,y);
		dfs(y);
	}
}
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n=read();
	for(int i=1;i<=n;i++)w[i]=read();
	sort(w+1,w+n+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(gcd(w[i],w[j])==1)continue;
			p[i].push_back(j),p[j].push_back(i);
		}
	}
	for(int i=1;i<=n;i++)if(!v[i])dfs(i);
	for(int i=1;i<=n;i++)if(!du[i]){ul.p=i,ul.d=w[i];q.push(ul);}
	while(!q.empty())
	{
		uf=q.top();q.pop(),pr1(uf.d);
		int x=uf.p;
		for(int k=last[x];k;k=a[k].next)
		{
			int y=a[k].y;
			du[y]--;if(!du[y]){ul.p=y,ul.d=w[y];q.push(ul);}
		}
	}puts("");
	return 0;
}

Measured memory_bytes: 17664
# ????????¨?????????????????????????±???????????????°??????
import sys

# ?¨??????\?????????????????????????????????
def read_data():
    n, m = [int(i) for i in sys.stdin.readline().strip().split(' ')]
    matrix = []
    for _ in range(n):
        matrix.append([int(num) for num in sys.stdin.readline().strip().split(' ')])

    vector = []
    for _ in range(m):
        vector.append(int(sys.stdin.readline().strip()))

    return matrix, vector

# ??????x????????????????¨????
def multiple(matrix, vector):
    n = len(matrix)
    m = len(vector)
    ans = []

    for i in range(n):
        sum = 0
        for j in range(m):
            sum += (matrix[i][j] * vector[j])

        ans.append(sum)

    return ans

# ???????????¢??°
def main():
    matrix, vector = read_data()
    ans = multiple(matrix, vector)
    for i in ans:
        print(i)
        
if __name__ == '__main__':
    main()
    

Measured memory_bytes: 8008
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<algorithm>
#include<vector>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i32 n;
cin >> n;
vector<P> ab(n);
rep(i,n){
    i64 A,B;
    cin >> A >> B;
    ab[i].first = A - B;
    ab[i].second = A + B;
}
i64 ans = 0;
sort(all(ab));
vector<i64> con(n);
ans = max(ans,ab.back().first - ab.front().first);
rep(i,n){
    swap(ab[i].first,ab[i].second);
}
sort(all(ab));
    ans = max(ans,ab.back().first - ab.front().first);
cout << ans << endl;
}

Measured memory_bytes: 7956
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    int x = in.ni(), y = in.ni(), a = in.ni(), b = in.ni(), c = in.ni();
    List<Long> red = new ArrayList<>(), green = new ArrayList<>(), white = new ArrayList<>();
    for (int i = 0; i < a; i++) red.add(in.nl());
    for (int i = 0; i < b; i++) green.add(in.nl());
    for (int i = 0; i < c; i++) white.add(in.nl());
    red.sort(Comparator.reverseOrder());
    green.sort(Comparator.reverseOrder());
    white.sort(Comparator.reverseOrder());

    List<Long> eat = new ArrayList<>();
    for (int i = 0; i < x; i++) eat.add(red.get(i));
    for (int i = 0; i < y; i++) eat.add(green.get(i));

    eat.sort(Comparator.naturalOrder());

    List<Long> eatPrefix = new ArrayList<>();
    eatPrefix.add(eat.get(0));
    for (int i = 1; i < eat.size(); i++) {
      eatPrefix.add(eatPrefix.get(i - 1) + eat.get(i));
    }
    List<Long> whitePrefix = new ArrayList<>();
    whitePrefix.add(white.get(0));
    for (int i = 1; i < white.size(); i++) {
      whitePrefix.add(whitePrefix.get(i - 1) + white.get(i));
    }
    long result = eatPrefix.get(x + y - 1);
    for (int i = 1; i <= Math.min(x + y, white.size()); i++) {
      result = Math.max(result, whitePrefix.get(i - 1) + eatPrefix.get(eatPrefix.size() - 1) - eatPrefix.get(i - 1));
    }
    out.println(result);
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  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();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,K,P[202020];
deque<ll> mndq, mxdq;
ll i, j, k;
int main(){
    scanf("%lld%lld", &N,&K);
    fornum(i,0,N){
        scanf("%lld", &P[i]);
    }
    fornum(i,0,K){
        while(mndq.size()&&mndq.back()>P[i]){
            mndq.pop_back();
        }
        mndq.push_back(P[i]);
        while(mxdq.size()&&mxdq.back()<P[i]){
            mxdq.pop_back();
        }
        mxdq.push_back(P[i]);
    }
    ll ans = 1;
    fornum(i,i,N){
        ll ers = mndq.front();
        if(mndq.front()==P[i-K]){
            mndq.pop_front();
        }
        if(mxdq.front()==P[i-K]){
            mxdq.pop_front();
        }
        if(ers>=mndq.front()||mxdq.front()>=P[i]){
            ans++;
        }
        while(mndq.size()&&mndq.back()>P[i]){
            mndq.pop_back();
        }
        mndq.push_back(P[i]);
        while(mxdq.size()&&mxdq.back()<P[i]){
            mxdq.pop_back();
        }
        mxdq.push_back(P[i]);
    }
    j = 1;
    fornum(i,1,N+1){
        //printf("%lld ", j);
        if(P[i-1]<P[i]){
            j++;
        }else{
            if(j>=K)
                k++;
            j = 1;
        }
    }

    if(k>0){
        ans -= k - 1;
    }

    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/reversed.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
using boost::adaptors::reversed;
struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int n;
    cin >> n;
    vector<int> a(n), ans(n);
    cin >> a;
    for (int i : irange(0, n)) ans[0] += ((i % 2 == 0) ? a[i] : -a[i]);
    for (int i : irange(1, n)) ans[i] = 2 * a[i-1] - ans[i-1];
    cout << ans << nl;
}


Measured memory_bytes: 2176
<?php

function input() {
    return trim(fgets(STDIN));
}
function input_array() {
    return explode(' ', input());
}

class Stack
{
    private $_stack = [null];
    private $_top = 0;
    public function push($x) {
        $this->_top++;
        $this->_stack[$this->_top] = $x;
    }
    public function pop() {
        $this->_top--;
        return $this->_stack[$this->_top + 1];
    }
}

$s = input_array();
$stack = new Stack();

for ($i = 0, $count = count($s); $i < $count; $i++) {
    switch ($s[$i]) {
        case '+':
            $a = $stack->pop();
            $b = $stack->pop();
            $stack->push($a + $b);
            break;
        case '-':
            $b = $stack->pop();
            $a = $stack->pop();
            $stack->push($a - $b);
            break;
        case '*':
            $a = $stack->pop();
            $b = $stack->pop();
            $stack->push($a * $b);
            break;
        default:
            $stack->push($s[$i]);
            break;
    }
}

echo $stack->pop() . "\n";


Measured memory_bytes: 9420
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] kigo = str.split("");
        int sum=0;
        for(int i=0;i<kigo.length;i++){
            if(kigo[i].equals("+")){
                sum=sum+1;
            }else{
                sum=sum-1;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
W, H, N = map(int, input().split())

x1, y1 = 0, 0
x2, y2 = W, H

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y1 = max(y1, y)
    elif a == 4:
        y2 = min(y2, y)

dx = max(0, (x2 - x1))
dy = max(0, (y2 - y1))

print(dx * dy)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int L, R, d, ans = 0;
    cin >> L >> R >> d;
    for(int i = L; i <= R; ++i){
        if(i % d == 0) ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main()
{
        while(true)
        {
                int a,b;
                cin >>a >>b;
                if ((a ==0)&&(b==0)) break;
                cout << ((b-a)%500)/100 <<" "<< ((b-a)%1000-(b-a)%500)/500<< " " << ((b-a)-(b-a)%1000)/1000 <<endl;
        }
        return 0;
}

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

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

const long long INF = 1LL << 60;

int n;
ll h[100010];
ll dp[100010];
int main(void){
	cin >> n;
	rep(i,n)cin >> h[i];
	rep(i,n)dp[i] = INF;
	dp[0] = 0;
	rep(i,n){
		if(i==0)continue;
		chmin(dp[i],dp[i-1]+abs(h[i-1]-h[i]));
		if(i==1)continue;
		chmin(dp[i],dp[i-2]+abs(h[i-2]-h[i]));
	}
	cout << dp[n-1] << endl;
	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
#define MOD 998244353 //1000000007

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

    // solution comes here
    ll N, t0=0, t1, x0=0, x1, y0=0, y1;
    cin >> N;
    rep(i, N) {
        cin >> t1 >> x1 >> y1;
        if(t1-t0 < abs(x1-x0) + abs(y1-y0)){
            cout << "No" << nl;
            return 0;
        }
        if( ( t1-t0-abs(x1-x0)-abs(y1-y0) )%2 == 1){
            cout << "No" << nl;
            return 0;
        }
        t0 = t1;
        x0 = x1;
        y0 = y1;
    }
    cout << "Yes" << nl;
}

Measured memory_bytes: 256
n = int(input())
v = list(map(int,input().split()))

v.sort()

#print(v)

while len(v) > 2:
    v.append((v[0] + v[1]) / 2)
    v.remove(v[0])
    v.remove(v[0])
    v.sort()
    #print(v)

print((v[0] + v[1]) / 2)

Measured memory_bytes: 3060
#include <iostream>
#include <bitset>
#define ll long long
using namespace std;
const int MDSZ = 1;
const int MD[4] = {1009, 1069696919, 701, 1018199999};
int n, k, ar[5001] = {}, rs = 0, a = 0, b = 0;
int dp[5001][MDSZ] = {};
void outDP(string s)
{
	cout << s << " : \n";
	for (int i = 0; i < k; i++)
	{
		cout << i << " " << dp[i][0] << "\n";
	}
}
int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k; rs = n;
	for (int i = 0; i < n; i++) 
	{
		cin >> ar[i];
		if (ar[i] >= k) {a++;}
	}
	rs -= a;
	for (int i = 0; i < MDSZ; i++) {dp[0][i] = 1;}
	for (int i = 1; i <= n; i++)
	{
		for (int j = k - 1; j >= ar[i - 1]; j--) 
		{
			for (int kk = 0; kk < MDSZ; kk++)
			{
				dp[j][kk] += dp[j - ar[i - 1]][kk];
				dp[j][kk] %= MD[kk];
			}
		}
	}
	//outDP("ALL");
	for (int i = 1; i <= n; i++)
	{
		if (ar[i - 1] < k)
		{
			for (int j = ar[i - 1]; j < k; j++)
			{
				for (int kk = 0; kk < MDSZ; kk++)
				{
					dp[j][kk] -= dp[j - ar[i - 1]][kk];
					dp[j][kk] %= MD[kk];
					dp[j][kk] = (dp[j][kk] + MD[kk]) % MD[kk];
				}
			}
			//outDP("REM" + to_string(i));
			for (int j = k - ar[i - 1]; j < k; j++)
			{
				bool ck = 1;
				for (int kk = 0; kk < MDSZ; kk++) {ck &= (dp[j][kk] > 0);}
				if (ck) {rs--; break;}
			}
			for (int j = k - 1; j >= ar[i - 1]; j--) 
			{
				for (int kk = 0; kk < MDSZ; kk++)
				{
					dp[j][kk] += dp[j - ar[i - 1]][kk];
					dp[j][kk] %= MD[kk];
				}
			}
			//outDP("FIX" + to_string(i));
		}
	}
	cout << rs << "\n";
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
using namespace std;
//long long int pow(long long int a,long long int p) {
//	long long int n = 1;
//	for (int i = 0; i < p; i++)
//		n *= a;
//	return n;
//}
int main(void)
{
	long long int N, P, P2, i = 2, j = 1, ans = 1;
	cin >> N >> P;
	P2 = P;
	/*while (i <= P2 / 2) {
		if (P%i == 0) {
			cnt++;
			P /= i;
		}
		else {
			i++;
		}
		if (cnt == N) {
			ans *= i;
			cout << ans << " " << i << endl;
			cnt = 0;
		}
	}
	if (P%P2==0)ans *= P2;*/
	if (N == 1) {
		cout << P << endl;
	}
	else if (P == 1) {
		cout << "1" << endl;
	}
	else if (N > 64) {
		cout << "1" << endl;
	}
	else {
		for (i = 2, j = (long long)pow(i, N); j <= P; i++, j = (long long)pow(i, N)) {
			if (P%j == 0) {
				ans = i;
			}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int long long int
#define all(x) (x).begin(), (x).end()
#define present(c,x) (c.find(x) != c.end())
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'

const int INF=1e9+5;

void solve(){
	int h,w;
	cin>>h>>w;
	vector<string>grid(h);
	for(int i=0;i<h;i++){
		cin>>grid[i];
	}
	vector<vector<int>>dp(h,vector<int>(w,INF));
	dp[0][0]=(grid[0][0]=='#');
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(i!=0){
				dp[i][j]=min(dp[i][j],dp[i-1][j]+(grid[i][j]=='#'&&grid[i-1][j]=='.'));
			}
			if(j!=0){
				dp[i][j]=min(dp[i][j],dp[i][j-1]+(grid[i][j]=='#'&&grid[i][j-1]=='.'));
			}
		}
	}
	int ans=dp[h-1][w-1];
	cout<<ans<<endl;
}

int32_t main(){

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

	solve();
}

Measured memory_bytes: 384
idCards, gates = input().split(" ")
idCards = int(idCards)
gates = int(gates)
minNum = []
maxNum = []

for count in range(0, gates, 1):
    num1, num2 = input().split(" ")
    minNum.append(int(num1))
    maxNum.append(int(num2))

minId = max(minNum)
maxId = min(maxNum)
if minId > maxId:
    print("0")
else:
    print((maxId - minId) + 1)

Measured memory_bytes: 11036
function Main(input){
 const a = input.split('\n');
  if (a[0] == 1){
  return 'Hello World';
  }
  if (a[0] == 2){
  return Number(a[1]) + Number(a[2])
  }
}
console.log(Main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7372
from collections import Counter as C
n=int(input())
s=[input()  for i in  range(n)]
m=int(input())
t=[input()  for i in  range(m)]

sd=C(s)
td=C(t)

max=0
for k in sd:
  if sd[k]-td[k]>max:
    max=sd[k]-td[k]
print(max)

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

ll x = 1e9 + 7; 
const int INF = 1001001001;

bool f(string s) {
  string sr = s;
  //cout << sr << endl;
  reverse(sr.begin(), sr.end());
  //cout << sr << endl;
  if (sr == s) return true;
  else return false;
}

int main() {
  string s;
  cin >> s;
  if (!f(s)) {
    cout << "No" << endl;
    return 0; 
  }
  string s2 = s.substr(0, s.size()/2);
  if (!f(s2)) {
    cout << "No" << endl;
    return 0; 
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3612
n,k=map(int,input().split())

ans=0
l=[]

for i in range(1,n+1):
        a=i
        for j in range(0,20):
                if a<=k-1:
                        a=a*2
                else:
                        l.append(j)
                        break
for k in l:
        ans+=(1/n)*(1/2)**k
print(ans)

        




Measured memory_bytes: 3864
#include<bits/stdc++.h>
/*#include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<climits>*/
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define rep1(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>(b);--i)
#define per1(i,a,b) for(int i=a;i>=(b);--i)
#define LL long long
#define inf 0x7f7f7f7f
#define N 35
using namespace std;

int main()
{
	int n,q,time,t,laps=0,x;
	string name;
	queue< pair<string,int> > Q;
	pair<string,int> temp;
	
	scanf("%d %d",&n,&q);
	
	rep(i,0,n)
	{
		cin>>name>>t;
		Q.push(make_pair(name,t));
	}
	
	
	while(!Q.empty())
	{
		temp=Q.front();
		Q.pop();
		x=min(q,temp.second);
		temp.second-=x;
		laps+=x;
		if(temp.second>0)
		{
			Q.push(temp);
		}
		else
		{
			cout<<temp.first<<' '<<laps<<endl;
		}
	}
}


Measured memory_bytes: 6348
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll H, W, N;
  cin >> H >> W >> N;
  ll po = N / max(H, W);
  if (po * max(H, W) < N)
    cout << po + 1 << endl;
  else
    cout << po << endl;
  return 0;
}


Measured memory_bytes: 256
N, X = (int(i) for i in input().split())
t = [1]
p = [1]

for i in range(N):
    t.append(2 * t[i] + 3)
    p.append(2 * p[i] + 1)

def burger(L, E):
    if L == 0:
        return 1
    if E == 1:
        return 0
    elif E <= t[L-1] + 1:
        return(burger(L-1, E-1))
    elif E == t[L-1] + 2:
        return(p[L-1] + 1)
    elif E <= 2 * t[L-1] + 2:
        return(p[L-1] + 1 + burger(L-1, E-2-t[L-1]))
    else:
        return(2 * p[L-1] + 1)

print(burger(N, X))


Measured memory_bytes: 3064
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <iostream>
#include <utility>
#include <sstream>
#include <cstring>
#include <bitset>
#include <climits>
 
using namespace std;
#define  AS(arr)  (sizeof(arr)/sizeof(arr[0]))
#define ALL(c) (c).begin(),(c).end() 
#define SIZE(a) int((a).size())
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define REP(i,n) for(int i=0;i<(int)n;++i)
typedef vector<int> VI;
typedef vector<string> VS;
typedef long long LL;
int main(void){
    int N;
    cin >> N;
    int ret = 0;
    REP(i, N)
    {
        ret += i+1;
    }
    cout << ret << endl;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {

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

	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			ans += d[i] * d[j];
		}

	}

	printf("%d", ans);



}






Measured memory_bytes: 128
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import math,sys

n = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split()))
#n = int(input())
#a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(2,n):
    g = math.gcd(g,a[i])
M = max(a)
acc = a[0]
for i in range(n):
    acc = math.gcd(acc,a[i])
if acc != 1:
    print("not coprime")
    exit()

LIMIT=max(a)
minPrime = [0]*(LIMIT+1)
minPrime[1] = 1
def make():
    for i in range(2,LIMIT+1):
        if minPrime[i] == 0:
            minPrime[i] = i
            #print(i)
            for j in range(i+i,LIMIT+1,i):
                #print(i,j)
                if minPrime[j] == 0:
                    minPrime[j] = i
make()
def factrial(N):
     ret = []
     while minPrime[N] != N:
         ret.append(minPrime[N])
         N = N//minPrime[N]
     if N != 1:
         ret.append(N)
     return ret

judge = set([])
pc = True

for i in a:
    if not pc:
        break
    asf = set(factrial(i))

    if judge & asf != set():
        pc = False
    judge |= asf
if pc:
    print("pairwise coprime")
elif g == 1:
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 203692
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    std::string S, T, U;
    int64_t A, B;
    std::cin >> S >> T >> A >> B >> U;

    if (S == U) A--;
    else B--;

    std::cout << A << " " << B << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=1e5+10;
int idx[mx];
uli sz[mx];
uli val[mx];
uli inc[mx];
vector<int>bag[mx];
int main(){
  int n;
  scanf("%d",&n);
  vector<tuple<uli,int,int> >edges;
  for(int i=0;i<n-1;i++){
    int u,v;
    uli c;
    scanf("%d %d %lld",&u,&v,&c);  
    edges.push_back(make_tuple(c,--u,--v));
  }
  sort(edges.begin(),edges.end(),greater<tuple<uli,int,int> >());
  for(int i=0;i<n;i++){
    idx[i]=i;
    sz[i]=1;
    inc[i]=0;
    bag[i]={i};
  }
  for(auto e:edges){
    int u,v;
    uli w;
    tie(w,u,v)=e;
    int x=idx[u],y=idx[v];
    if(sz[x]<sz[y])swap(x,y);
    inc[x]+=w*sz[y];
    inc[y]+=w*sz[x];
    for(int z:bag[y]){
      bag[x].push_back(z);
      idx[z]=x;
      val[z]+=inc[y]-inc[x];
    }
    sz[x]+=sz[y];
  }
  int x=idx[0];
  for(int i=0;i<n;i++)val[i]+=inc[x];
  for(int i=0;i<n;i++){
    printf("%lld\n",val[i]);
  }
  return 0;
}


Measured memory_bytes: 15216
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    scanf("%d",&a);
    while(a!=0)
    {
        if(a%10==9)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        a/=10; 
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
// in the name of Allah

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

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

#define inf 1e9
#define max_n 123456
#define mod 1000000007

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

ll n, k;
ll a[55][55], b[55][55], c[55][55];

void go() {
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) {
			b[i][j] = 0;
			for(int k=0; k<n; k++) {
				b[i][j] = add(b[i][j], mul(a[i][k], c[k][j]));
			}
		}
	}
	for(int i=0; i<n; i++) for(int j=0; j<n; j++) c[i][j] = b[i][j];
}

void goo() {
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) {
			b[i][j] = 0;
			for(int k=0; k<n; k++) {
				b[i][j] = add(b[i][j], mul(a[i][k], a[k][j]));
			}
		}
	}
	for(int i=0; i<n; i++) for(int j=0; j<n; j++) a[i][j] = b[i][j];
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin >> a[i][j];
	for(int i=0; i<n; i++) c[i][i] = 1;
	while(k) {
		if(k&1) go();
		goo();
		k/=2;
	}
	ll ans = 0;
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) {
			ans = add(ans, c[i][j]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n;
  string s;
  cin>>n>>s;
  map<char,int>mp;
  mp['R']=0;
  mp['G']=1;
  mp['B']=2;

  vector<int>r(n+1),g(n+1),b(n+1);
  for(int i=n-1;i>=0;i--){
    r[i]=r[i+1];
    g[i]=g[i+1];
    b[i]=b[i+1];
    if(s[i]=='R')r[i]++;
    if(s[i]=='G')g[i]++;
    if(s[i]=='B')b[i]++;
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(s[i]==s[j])continue;
      int x=3-mp[s[i]]-mp[s[j]];
      if(x==0){
        ans+=r[j+1];
      }
      else if(x==1){
        ans+=g[j+1];
      }
      else ans+=b[j+1];
      int d=j-i;
      if(j+d<n&&x==mp[s[j+d]])ans--;
    }
  }
  cout<<ans<<endl;
  return(0);
}
      


Measured memory_bytes: 3688
H, W = map(int, input().split())
X = [[[0, 1][a=="#"] for a in input()] for i in range(H)]
Y = [[0] * W for _ in range(H)]
Y[0][0] = 1
P = 10**9+7
for i in range(H):
    for j in range(W):
        if X[i][j] == 0:
            if i > 0:
                Y[i][j] += Y[i-1][j]
            if j > 0:
                Y[i][j] += Y[i][j-1]
            Y[i][j] %= P

print(Y[-1][-1])

Measured memory_bytes: 51376
package main

import "fmt"

func main() {
	var H, W int
	fmt.Scan(&H, &W)
	S := make([]string, H)
	for i := range S {
		fmt.Scan(&S[i])
	}
	dx := [8]int{-1, 0, 1, -1, 1, -1, 0, 1}
	dy := [8]int{-1, -1, -1, 0, 0, 1, 1, 1}
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if S[i][j] == '#' {
				fmt.Print("#")
				continue
			}
			bomb := 0
			for d := 0; d < 8; d++ {
				ni := i + dy[d]
				nj := j + dx[d]
				if ni < 0 || H <= ni {
					continue
				}
				if nj < 0 || W <= nj {
					continue
				}
				if S[ni][nj] == '#' {
					bomb++
				}
			}
			fmt.Print(bomb)
		}
		fmt.Println()
	}
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            //var line = consoleReader.SplitInt();
            var s = consoleReader.Int();
            int left, right;
            left = Math.DivRem(s, 100, out right);

            bool mmyy, yymm;
            mmyy = 1 <= left && left <= 12;
            yymm = 1 <= right && right <= 12;

            if (mmyy && yymm)
                return "AMBIGUOUS";
            else if (mmyy)
                return "MMYY";
            else if (yymm)
                return "YYMM";
            else
                return "NA";
        }

        public const int mod = 1000000007;
        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

    #region Console
    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int() => int.Parse(String()); public long Long() => long.Parse(String()); public ulong ULong() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt() => String().Split().Select(int.Parse).ToArray(); public long[] SplitLong() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitULong() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt(int count) { for (int i = 0; i < count; i++) yield return Int(); } public IEnumerable<long> RepeatLong(int count) { for (int i = 0; i < count; i++) yield return Long(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt(int count) { for (int i = 0; i < count; i++) yield return SplitInt(); } }
    #endregion
}

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

using namespace std;

class UF_tree{

    vector<int> par;
    vector<int> rank;
    vector<int> sz;

public:
    UF_tree(){}
    UF_tree(int n){
        par = rank = sz = vector<int>(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }

    int find(int x){
        if(par[x] == x) return x;
        else return find(par[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y)  return;

        if(rank[x] < rank[y]){
            par[x] = y;
            sz[y] += sz[x];
        }
        else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
            sz[x] += sz[y];
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int size(int x){
        return sz[find(x)];
    }

};

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    int a, b;
    int nei[N]; fill(nei, nei + N, 0);
    int blo[N]; fill(blo, blo + N, 0);
    UF_tree uff(N);
    for(int i=0; i<M; i++){
        cin >> a >> b;
        a--; b--;
        uff.unite(a, b);
        nei[a]++; nei[b]++;
    }
    for(int i=0; i<K; i++){
        cin >> a >> b;
        a--; b--;
        if(uff.same(a, b)){
            blo[a] ++;
            blo[b] ++;
        }
    }
    for(int i=0; i<N; i++){
        cout << uff.size(i) - nei[i] - 1 - (blo[i]);
        if(i != N-1) cout << " ";
    } cout << endl;
    return 0;

}

Measured memory_bytes: 2816
import java.util.Scanner;

public class Main {

  public static final String FIRST = "First";
  public static final String SECOND = "Second";

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    sc.close();

    int count = 0;
    if (s.charAt(0) == s.charAt(s.length() - 1)) {
      count = s.length() - 3;
    } else {
      count = s.length() - 2;
    }
    String result = count % 2 == 1 ? FIRST : SECOND;
    System.out.println(result);
  }
}


Measured memory_bytes: 24916
object Main {
  def main(args:Array[String]) {
    val AB = readLine().split(' ').map(_.toInt)
    val A = AB(0)
    val B = AB(1)
    var K = 0

    var flag = true
    while(flag) {
      if(math.abs(A - K) == math.abs(B - K)) {
        flag = false
        println(K)
      }
      if(A < K && B < K) {
        flag = false
        println("IMPOSSIBLE")
      }
      K += 1
    }
  }
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

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


int main(){
  int a,b,c; cin >> a >> b >> c;
  cout << (c%gcd(a,b)==0?"YES":"NO") << endl;
}



Measured memory_bytes: 3596