akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);

    int n = Integer.parseInt(r.readLine());
    
    String s;
    String sl[];
    
    int x[] = new int[123];
    int y[] = new int[123];
    int h[] = new int[123];
    int k = 0;
    
    for(int i = 0; i < n; i++)
    {
      s = r.readLine();
      sl = s.split(" ");

      x[i] = Integer.parseInt(sl[0]);
      y[i] = Integer.parseInt(sl[1]);
      h[i] = Integer.parseInt(sl[2]);
      
      if(h[i] > 0)
      {
        k = i;
      }
    }
    
    for(int cx = 0; cx <= 100; cx++)
    {
      for(int cy = 0; cy <= 100; cy++)
      {
        int ch = h[k] + Math.abs(cx - x[k]) + Math.abs(cy - y[k]);
        boolean f = true;
        for(int i = 0; i < n; i++)
        {
          int z = ch - Math.abs(cx - x[i]) - Math.abs(cy - y[i]);
          if((z < 0 ? 0 : z) != h[i])
          {
            f = false;
            break;
          }
        }
        if(f)
        {
          System.out.printf("%d %d %d\n", cx, cy, ch);
          System.exit(0);
        }
      }
    }
  }

}

Measured memory_bytes: 22996
n = gets.chomp.to_i
s = gets.chomp.chars

i, j = 0, n - 1

answer = 0
while i < j do
  if s[i] == 'W' && s[j] == 'R'
    s[i] = 'R'
    s[j] = 'W'
    answer += 1

    i += 1
    j -= 1
  else
    i += 1 if s[i] == 'R'
    j -= 1 if s[j] == 'W'
  end
end

puts answer


Measured memory_bytes: 35592
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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 int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

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

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

ans = 0
lis = [0] *(10**5 +1)

for i in range(n):
    a, b = map(int, input().split())
    lis[a] += b

tmp = 0
for j in range(len(lis)):
    tmp += lis[j]
    if tmp >= k:
        print(j)
        break

Measured memory_bytes: 77064
#-*- coding: utf-8 -*-# 
a = int(input())   # Nを取得
b = [] 
for i in range(a):  
    b.append(int(input()))
c = [0] * (100+1)  # バケツを用意
for i in b:
    c[i] = i  # バケツにb1,b2...bnを整列された状態で入れる
d = [] 
for g in c:
    if g != 0:
        d.append(g)  # バケツから0以外の要素を取得
print(len(d))   


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
 
int main(){
    int N; cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    REP(i,N) {
        cin >> A[i]; A[i] --;
        B[A[i]] ++;
    }
    vector<int> cnt(N+2,0);
    REP(i,N) {
        cnt[B[i]]++;
    }
    for(int i=N-1; i>=1; --i) {
        cnt[i] += cnt[i+1];
    }
    for(int i=2; i<=N; ++i) {
        cnt[i] += cnt[i-1];
    }
    for(int i=1; i<=N; ++i) {
        int ub = N+1;
        int lb = 0;
        int mid;
        while (ub-lb>1) {
            mid = (ub + lb) / 2;
            if((long long)cnt[mid] >= (long long)mid*i) lb = mid;
            else ub = mid;
        }
        cout << lb << endl;
    }
    return 0;
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC100
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] DN = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ans = DN[1] * (int)(Math.Pow(100,DN[0]));
            if (DN[1] == 100) { ans = (DN[1] + 1) * (int)(Math.Pow(100, DN[0])); }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

void solve() {
	string s;
	cin >> s;
	if (s == "RRR")
		cout << 3;
	else if (s == "SSS")
		cout << 0;
	else if ((s[0] == s[1] && s[0] == 'R') || (s[1] == s[2] && s[1] == 'R'))
		cout << 2;
	else
		cout << 1;
}

int32_t main() {
	int t = 1;
//	cin >> t;
	while (t--) {
		solve();
	}
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#define LINE_BUF_SIZE 128

int main(){

    int i,j,k;
    long int N;
    char line[LINE_BUF_SIZE];
    char S[LINE_BUF_SIZE];

    fgets(line,sizeof(line),stdin);
    sscanf(line,"%d", &N);

    fgets(S,sizeof(S),stdin);

    int max = 0;
    int count = 0;

    while(strncmp(&S[i],"\0",1) != 0){
        if(strncmp(&S[i],"I",1) == 0)count += 1;
        if(strncmp(&S[i],"D",1) == 0)count -= 1;
        if(max < count)max = count;
        i ++;
    }

    printf("%d",max);

    return 0;

}

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

using namespace std;

int main() {

  double a, b;
  double ave;

  cin >> a >> b ;

  ave = (a + b) / 2;
  double v = (ave / 0.1);

  int n = v;
  n = n % 10;

  if (5 <= n && n <= 9) { n = 1; }
  else { n = 0; }

  int c;
  
  if (n == 1) {
    c = ave;
    c += 1;
  } else if (n == 0) {
    c = ave;
  }

  cout << c << endl;  

  return(0);
}

Measured memory_bytes: 3608
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<deque>
using namespace std;

int main(){
    long long N, M;
    long long A, B;
    long long ans = 0, tmp, count, tmp_find, nextf;
    vector<long long> v_temp;
    deque<long long> friend_sagasu;
    std::cin >> N >> M;
    map<long long, vector<long long>> f_list;
    vector<long long> hito(N,0); //カウント済みがどうかを確認するようの配列
    for(long long i = 0; i < M; i++){
        std::cin >> A >> B;
        if(f_list.count(A)){
            //既にある場合
            f_list[A].push_back(B);
        }else{
            f_list[A] = {B};
        }
        //逆もやる
        if(f_list.count(B)){
            //既にある場合
            f_list[B].push_back(A);
        }else{
            f_list[B] = {A};
        }
    }
    //インプット完了
    if(M == 0){
        ans = 1;
    }else{
        std::map<long long, vector<long long>>::iterator iter = f_list.begin();
        for(int i = 0; i < f_list.size(); i++){
            //フレンドリスト順に
            tmp = iter->first;
            if(hito[tmp - 1] == 0){
                //まだ登録されていなければそいつをもとに探索開始
                friend_sagasu.push_back(tmp);
                count = 1;
                hito[tmp - 1] = 1;
                while(friend_sagasu.size()!=0){
                    tmp_find = friend_sagasu[0];
                    friend_sagasu.pop_front();
                    for(int j = 0; j < f_list[tmp_find].size(); j++){
                        //友達を追加，カウント増加，カウントフラグ建て
                        nextf = f_list[tmp_find][j];
                        if(hito[nextf - 1] == 0){
                            friend_sagasu.push_back(nextf);
                            count++;
                            hito[nextf - 1] = 1;
                        }

                    }
                }
                //グループを作り終わる
                if(count > ans){
                    ans = count;
                }
            }
            //初期化とかする
            iter++;



        }
    }
    std::cout << ans;

}


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

 

int main()
{
    int a[100];
    int n, i;
    
    cin >> n;
    for(i=0; i<n; i++)
        cin >> a[i];
        
    for(i=n-1; i>=1; i--)
        cout << a[i] << " ";
    cout << a[0] << endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int a, b, k;

int main() {
	cin >> a >> b >> k;
	
	int c = 0;
	dec1(i, max(a, b)) {
		if(a % i == 0 && b % i == 0) { c++; }
		if(c == k) { cout << i << endl; return 0; }
	}
	
	UR;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Diagnostics;
using static System.Math;
using static System.Array;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N;
        static string[] S;
        

        public static void Input()
        {
            var cin = new Scanner();
            N = int.Parse(Console.ReadLine());
            S = new string[N];
            for(var i = 0; i < N; i++)
            {
                S[i] = Console.ReadLine();
            }
        }

        static void Main(string[] args)
        {
            Input();

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            long ans = 0;
            long[] c = new long[5];
            c[0] = cnt('M');
            c[1] = cnt('A');
            c[2] = cnt('R');
            c[3] = cnt('C');
            c[4] = cnt('H');

            for(var bit = 0; bit < (1 << 5); bit++)
            {
                int count = 0;
                long add = 1;
                for(var i = 0; i < 5; i++)
                {
                    if ((bit & (1 << i)) != 0)
                    {
                        count++;
                        add *= c[i];
                    }
                }
                if (count != 3) { continue; }

                ans += add;
            }

            Console.WriteLine(ans);
            //Console.Out.Flush();

        }

        public static long cnt(char c)
        {
            return S.Count(x => x[0] == c);
        }




    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }

    public class Graph
    {
        
    }
}

    



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

const int MAX_CAILLOUX = 100005;
const long long INFINI = 1000000001;

int carte[MAX_CAILLOUX];
long long dp[MAX_CAILLOUX];

int K;
int nCailloux;

void init()
{
    scanf("%d %d", &nCailloux, &K);
    for(int iCaillou = 0; iCaillou < nCailloux; iCaillou++)
    {
        scanf("%d", &carte[iCaillou]);
        dp[iCaillou] = INFINI;
    }
    dp[0] = 0;
}

int main()
{
    init();

    for(int iCaillou = 1; iCaillou < nCailloux; iCaillou++)
    {
        for(int diff = max(0,iCaillou - K); diff < iCaillou; diff++)
        {
            dp[iCaillou] = min(dp[iCaillou],dp[diff] + abs(carte[diff]-carte[iCaillou]));
           // printf("dp[%d] = %d\n", iCaillou, dp[iCaillou]);
        }
    }

    printf("%lld", dp[nCailloux-1]);
}

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

int main(){
    int c[3][3];
    int b[3];
    for(int i=0;i<3;i++)for(int j=0;j<3;j++){
        cin>>c[i][j];
        if(i==0){
            b[j]=c[i][j];
        }
    }
    int a[3]={};
    a[1]=c[1][0]-b[0];
    a[2]=c[2][0]-b[0];
    for(int i=1;i<3;i++){
        if(c[1][i]!=a[1]+b[i]){
            cout<<"No"<<endl;
            return 0;
        }
        if(c[2][i]!=a[2]+b[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;


}

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

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int a[] = new int[m];
            for (int i = 0; i < m; i++) {
                a[i] = Integer.parseInt(in.next());
            }

            for (int i = 0; i < m; i++) {
                n -= a[i];
            }

            // 出力
            if (n < 0) {
                out.println(-1);
            } else {
                out.println(n);
            }

        }

    }
}



Measured memory_bytes: 41624
# -*- coding: utf-8 -*-
import sys
from heapq import heappop, heappush
from itertools import accumulate


def dijkstra(n, edges, start, *, adj_matrix=False, default_value=float('inf')):

    inf = float('inf')
    costs = [inf] * n
    costs[start] = 0
    pq, rem = [(0, start)], n - 1

    while pq and rem:
        tmp_cost, tmp_node = heappop(pq)
        if costs[tmp_node] < tmp_cost:
            continue
        rem -= 1

        nxt_edges = ((node, cost) for node, cost in enumerate(edges[tmp_node]) if cost != default_value) \
                    if adj_matrix else edges[tmp_node]

        for nxt_node, nxt_cost in nxt_edges:
            new_cost = tmp_cost + nxt_cost
            if costs[nxt_node] > new_cost:
                costs[nxt_node] = new_cost
                heappush(pq, (new_cost, nxt_node))

    return costs


n, m, s, t = map(int, input().split())

# faster #####################################################################
yen_edges = [[] for _ in range(n)]
snuke_edges = [[] for _ in range(n)]
for l in sys.stdin.readlines():
    u, v, yen, snuke = map(int, l.strip().split())
    yen_edges[u - 1].append((v - 1, yen))
    yen_edges[v - 1].append((u - 1, yen))
    snuke_edges[u - 1].append((v - 1, snuke))
    snuke_edges[v - 1].append((u - 1, snuke))

yen_costs = dijkstra(n, yen_edges, s - 1)
snuke_costs = dijkstra(n, snuke_edges, t - 1)

# slower ####################################################################
# yen_edges = [[float('inf') if __ != _ else 0 for __ in range(n)]
#              for _ in range(n)]
# snuke_edges = [[float('inf') if __ != _ else 0 for __ in range(n)]
#                for _ in range(n)]
# for l in sys.stdin.readlines():
#     u, v, yen, snuke = map(int, l.strip().split())
#     yen_edges[u - 1][v - 1] = yen
#     yen_edges[v - 1][u - 1] = yen
#     snuke_edges[u - 1][v - 1] = snuke
#     snuke_edges[v - 1][u - 1] = snuke

# yen_costs = dijkstra(n, yen_edges, s - 1, adj_matrix=True)
# snuke_costs = dijkstra(n, snuke_edges, t - 1, adj_matrix=True)

final_costs = list(
    accumulate([yen + snuke
                for yen, snuke in zip(yen_costs, snuke_costs)][::-1],
               min))[::-1]
asset = 10**15
for final_cost in final_costs:
    print(asset - final_cost)


Measured memory_bytes: 87020
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

map<string, string> mp, mpg,mpa;

/*--------------------template--------------------*/

char a[55][55] = { 0 };
char b[55][55] = { 0 };

int main()
{
	cin >> n >> m;
	FOR(i, 1, n + 1)
	{
		FOR(j, 1, m + 1)
		{
			cin >> c;
			a[i + 1][j + 1] = c;
		}
	}
	

	FOR(i, 1, n + 2)
	{
		FOR(j, 1, m + 2)
		{
			cnt = 0;
			if (a[i][j] == '#') {
				b[i][j] = '#';
			} else {
				if (a[i - 1][j] == '#') {
					cnt++;
				}
				if (a[i + 1][j] == '#') {
					cnt++;
				}
				if (a[i - 1][j - 1] == '#') {
					cnt++;
				}
				if (a[i][j - 1] == '#') {
					cnt++;
				}
				if (a[i + 1][j - 1] == '#') {
					cnt++;
				}
				if (a[i - 1][j + 1] == '#') {
					cnt++;
				}
				if (a[i][j + 1] == '#') {
					cnt++;
				}
				if (a[i + 1][j + 1] == '#') {
					cnt++;
				}
				b[i][j] = cnt + '0';
			}

		}
	}
	
	FOR(i, 1, n + 1)
	{
		FOR(j, 1, m + 1)
		{
			cout << b[i + 1][j + 1];
		}
		cout << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int *a, *b, s, t, c;
	int p, q;
	a = &p;
	b = &q;
	while(cin >> p >> q){
		s = *a;
		t = *b;
		c = 1;
		for(int tmp = (*a > *b)? *b : *a, i = 2; i <= tmp; i++){
			while(s%i == 0 && t%i == 0){
				s /= i;
				t /= i;
				tmp /= i;
				c *= i;
			}
		}
		cout << c << " " << ((*a)/c*(*b)) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<cctype>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;

int main(){
  string s;
  while(cin >> s){
    if(s == "#")break;

    bool SAT = false;
    rep(i,s.size()){
      if(s[i] == '('){
	i++;
	string clause;
	while(s[i]!=')')clause += s[i++];

	vector<char> pos, neg;
	rep(j,clause.size()){
	  if(isalpha(clause[j]))pos.push_back(clause[j]);
	  else neg.push_back(clause[++j]);
	  j++;
	}

	bool f = true;
	rep(x,pos.size()){
	  rep(y,neg.size()){
	    if(pos[x] == neg[y])f = false;
	  }
	}
	SAT |= f;
      }
      if(SAT)break;
    }

    if(SAT)cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

Measured memory_bytes: 1208
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  string str;
  cin>>str;
  int n=str.size();
  int r=n;
  vector<string> ss{"dream","dreamer","erase","eraser"};
  while(r){
    int f=0;
    for(const string &s:ss){
      if(r>=s.size() && str.substr(r-s.size(),s.size())==s){
	r-=s.size();
	f=1;
      }
    }
    //cout<<str.substr(r)<<endl;
    if(f==0) break;
  }
  cout<<(r?"NO":"YES")<<endl;
  return 0;
}


Measured memory_bytes: 512
# coding:utf-8

import math
import re

def main(params):
    n,k = params[0].split()
    s = list(params[1])
    k = int(k)
    s[k-1] = s[k-1].lower()
    print ''.join(s)

if __name__ == "__main__":
    cnt = 2 # TODO: edit here
    params = []
    for i in range(cnt):
        param = raw_input()
        params.append(param)
    main(params)



Measured memory_bytes: 2568
#include <iostream>
#include <vector>
#include <cmath>
#define INF 1e+9
using namespace std;

typedef pair<int,int> P;

int main(){
	int n,m;
	int ki;
	vector<P> stone[150];
	int dp[150][10][80];
	while(1){
		cin >> n >> m;
		if(!n && !m) break;
		for(int i = 0;i < n;i++){
			stone[i].clear();
			for(int j = 0;j < 10;j++){
				for(int k = 0;k <= m;k++) dp[i][j][k] = INF;
			}
		}
		for(int i = 0;i < n;i++){
			cin >> ki;
			for(int j = 0;j < ki;j++){
				int a,b;
				cin >> a >> b;
				stone[i].push_back(P(a - 1,b));
			}
		}
		for(int i = 0;i < stone[0].size();i++){
			dp[0][i][0] = 0;
		}
		for(int i = 0;i < stone[1].size();i++){
			dp[1][i][1] = 0;
		}
		for(int i = 1;i < n;i++){
			for(int j = 0;j < stone[i].size();j++){
				for(int k = 0;k <= m;k++){
					for(int l = 0;l < stone[i - 1].size();l++){
						dp[i][j][k] = min(dp[i][j][k],dp[i - 1][l][k] + (stone[i][j].second + stone[i - 1][l].second) * abs(stone[i][j].first - stone[i - 1][l].first));
					}
					if(i >= 2 && k >= 1){
						for(int l = 0;l < stone[i - 2].size();l++){
							dp[i][j][k] = min(dp[i][j][k],dp[i - 2][l][k - 1] + (stone[i][j].second + stone[i - 2][l].second) * abs(stone[i][j].first - stone[i - 2][l].first));
						}
					}
				}
			}
		}
		int mi = INF;
		for(int i = 0;i < stone[n - 1].size();i++){
			for(int j = 0;j <= m;j++){
				mi = min(mi,dp[n - 1][i][j]);
			}
		}
		if(m){
			for(int i = 0;i < stone[n - 2].size();i++){
				for(int j = 0;j < m;j++){
					mi = min(mi,dp[n - 2][i][j]);
				}
			}
		}
		cout << mi << endl;
	}
	return 0;	
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  ll s,w; cin >> s >> w;
  if(w>=s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
int main()
{
    char ch;
    scanf("%c", &ch);

    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' ||
       ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
        {
            printf("vowel\n", ch);
        }
    else
        {
            printf("consonant\n", ch);
        }
    return 0;
}

Measured memory_bytes: 128
#include <ctype.h>
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

char rbuf[4200021]; int rbufl;
#define getchar() rbuf[rbufl++]
//#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void printint(int32_t x){ if(x<0){x=-x; putchar('-');}else if(x==0){putchar('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar(s[i]); putchar('\n'); }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

int a[300000][2];
int cx[300000], cy[300000];
int main(void){
	read(STDIN_FILENO, rbuf, sizeof(rbuf));
	int h=nextint();
	int w=nextint();
	int n=nextint();
	for(int i=0; i<n; i++){
		a[i][0]=nextint()-1;
		a[i][1]=nextint()-1;
		cx[a[i][0]]++;
		cy[a[i][1]]++;
	}
	int bxm=0, bym=0;
	int bx=0, by=0;
	for(int x=0; x<h; x++){
		if(cx[x]>bxm){
			bxm=cx[x];
			bx=1;
		}else if(cx[x]==bxm){
			bx++;
		}
	}
	for(int y=0; y<w; y++){
		if(cy[y]>bym){
			bym=cy[y];
			by=1;
		}else if(cy[y]==bym){
			by++;
		}
	}
	if(bx*by>n){
		int ans=bxm+bym;
		printint(ans);
	}else{
		int s=0;
		for(int i=0; i<n; i++){
			if(cx[a[i][0]]==bxm && cy[a[i][1]]==bym){
				s++;
			}
		}
		if(s==bx*by){
			int ans=bxm+bym-1;
			printint(ans);
		}else{
			int ans=bxm+bym;
			printint(ans);
		}
	}
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

char mp[1111][1111];
int a[1111][1111];

bool check(int h, int w, int mid){
	REP(i, h){
		REP(j, w){
			if(mp[i][j] == '#')a[i][j] = mid;
			else a[i][j] = 0;
		}
	}

	int now = 0;
	for(int i = 0;i < h;i++){
		now = 0;
		for(int j = 0;j < w;j++){
			now = max(now - 1, a[i][j]);
			now = max(now, 0);
			a[i][j] = now;
		}
	}
	for(int i = 0;i < h;i++){
		now = 0;
		for(int j = w-1;j >= 0;j--){
			now = max(now - 1, a[i][j]);
			now = max(now, 0);
			a[i][j] = now;
		}
	}
	for(int j = 0;j < w;j++){
		now = 0;
		for(int i = 0;i < h;i++){
			now = max(now - 1, a[i][j]);
			now = max(now, 0);
			a[i][j] = now;
		}
	}
	for(int j = 0;j < w;j++){
		now = 0;
		for(int i = h-1;i >= 0;i--){
			now = max(now - 1, a[i][j]);
			now = max(now, 0);
			a[i][j] = now;
		}
	}

	REP(i, h)REP(j, w)if(a[i][j] <= 0)return false;
	return true;
}

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

	int h, w;cin >> h >> w;
	REP(i, h)REP(j, w)cin >> mp[i][j];

	int l = -1;
	int r = 2222;

	while(r - l > 1){
		int mid = (l + r) / 2;
		if(check(h, w, mid))r = mid;
		else l = mid;
	}

	cout << r-1 << endl;

	return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << H * W - (H * w + W * h - h * w) <<endl;
}


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

using namespace std;

int main(){

    int n;
    cin >> n;
    if(n<1000){
        cout << 1000 - n%1000 << endl;
    } else {
        if(n%1000==0){
            cout << n%1000 << endl;
        } else {
            cout << 1000 - n%1000 << endl;
        }
    }
	return 0;
}


Measured memory_bytes: 3632
H,W,A,B = map(int, input().split())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
n = 3*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

L = []
i = H-A
j = B+1
while i > 0 and j <= W:
    L.append((i, j))
    i -= 1
    j += 1
    
ans = 0
for t in L:
    i = t[0]
    j = t[1]
    ans += (cmb(i+j-2, i-1, mod) * cmb(H-i+W-j, H-i, mod)) % mod
    ans %= mod
    
print(ans)

Measured memory_bytes: 51284
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//typedef pair<int,int> P;
const int INF=2e9;
struct P{int a,b,c;};
int main(){
      int n;
      int a[100][2];
      int dp[100][2];
      while(cin>>n&&n){
            REP(i,100)REP(j,2)dp[i][j]=INF;
            REP(i,n)cin>>a[i][0];
            REP(i,n)cin>>a[i][1];
            queue<P> Q;
            Q.push((P){0,1,0});
            Q.push((P){0,0,0});
            while(!Q.empty()){
                  P p=Q.front();Q.pop();
                  if(p.a>=n)continue;
                  int k=p.a;
                  if(a[p.a][p.b]==1){
                        while(a[k][p.b]==1&&k<n){
                              int kk=k+1;
                              if(kk>=n)break;
                              if(a[kk][p.b]!=1)break;
                              k++;
                        }
                  }else if(a[p.a][p.b]==2){
                        while(a[k][p.b]==2)k--;
                  }
                  if(dp[k][p.b]<=p.c)continue;
                  dp[k][p.b]=p.c;
                  Q.push((P){k,p.b^1,p.c+1});
                  Q.push((P){k+1,p.b^1,p.c+1});
                  Q.push((P){k+2,p.b^1,p.c+1});
            }
            if(dp[n-1][1]==INF&&dp[n-1][0]==INF)cout<<"NA"<<endl;
            else cout<<min(dp[n-1][1],dp[n-1][0])<<endl;
      }
}

Measured memory_bytes: 1216
#include<stdio.h>

int n, s;

int dfs(int now, int manyused, int sum){
	//?????£?????°???n???????????£?????´???sum???s??¨?????????????????????
	if (manyused == n){
		return sum == s;
	}
	//now???10?????£?????´??????sum???s???????????£?????´?????¢?´¢???????????????
	if (now == 10 || sum > s){
		return 0;
	}
	//now????????£?????´?????¨??????????????£?????´????????°???????¨??????????????????§?????°??¨??????
	return dfs(now + 1, manyused + 1, sum + now) + dfs(now + 1, manyused, sum);
}

int main(){
	while (~scanf("%d %d", &n, &s) && n){
		printf("%d\n", dfs(0, 0, 0));
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 


int main()
{
    const int USED = -1;

    int N;
    cin >> N;

    int cnt = 1;
    cnt <<= N;

    vector<int> S(cnt);
    for (int i = 0; i < cnt; ++i) {
        cin >> S[i];
    }

    sort(S.begin(), S.end(), greater<int>());

    vector<int> curr;
    curr.push_back(S[0]);
    S[0] = USED;
    int scanHead = 1;

    bool ok = true;
    for (int i = 0; ok && i < N; ++i) {
        // cout << "Generation " << i << endl;
        // dump(S);
        // dump(curr);
        while (S[scanHead] == USED && scanHead < cnt-1) ++scanHead;
        vector<int> prev = curr;
        sort(prev.begin(), prev.end(), greater<int>());
        int j = scanHead;
        for (int k = 0; ok && k < prev.size(); ++k) {
            int n = prev[k];
            bool found = false;
            for (; ok && !found && j < cnt; ++j) {
                if (S[j] != USED && S[j] < n) {
                    // cout << '\t' << n << " => " << S[j] << endl;
                    curr.push_back(S[j]);
                    S[j] = USED;
                    found = true;
                }
            }
            if (!found) {
                ok = false;
            }
        }
    }

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}


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

using namespace std;

void dfs(int curr,vector<vector<int>>& adjlist,vector<bool>& visited, int &count)
{
    visited[curr] = true;
    count++;
    for(int j:adjlist[curr])
    {
        if(!visited[j])
        {
            dfs(j,adjlist,visited,count);
        }
    }

    return;
}

int main()
{
    int n,m;
    cin>>n>>m;
    vector<vector<int>> adjlist(n+1);

    while(m--)
    {
        int x,y;
        cin>>x>>y;
        adjlist[x].push_back(y);
        adjlist[y].push_back(x);
    }

    vector<bool> visited(n+1);
    int ans = 1;
    
    int count = 0;
    for(int i = 1;i<=n;i++)
    {
        if(!visited[i])
        {
            dfs(i,adjlist,visited,count);
            ans = max(ans,count);
            count = 0;
        }
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 26664
package main

import "fmt"

func main() {
	var a, b, ans, total int
	fmt.Scan(&a, &b)
	if b == 1 {
		fmt.Println("0")
		return
	}
	ans = 1
	total = a
	for {
		if total >= b {
			fmt.Println(ans)
			return
		}
		ans++
		total += a - 1
	}
}


Measured memory_bytes: 512
import sys
n = int(sys.stdin.readline().rstrip())
d = dict()
num = list(map(int, sys.stdin.readline().rstrip().split()))
res = "YES"
for i in range(n):
    try:
        if d[num[i]] >= 1:
            res = "NO"
            break
    except:
        d[num[i]] = 1
print(res)

Measured memory_bytes: 101236
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  char s[110];
  int k, n, ans = 0;
  scanf("%s", s);
  scanf("%d", &k);
  n = strlen(s);
  int dp0[110][5] = {}, dp1[110][5] = {};
  for (int i = 1; i <= 9; i++) {
    if (i < s[0] - '0') {
      dp0[1][1]++;
    } else if (i == s[0] - '0') {
      dp1[1][1]++;
    }
  }
  dp0[1][0] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < 4; j++) {
      dp0[i][j] += dp0[i - 1][j];
      dp0[i][j + 1] += 9 * dp0[i - 1][j];
      if (s[i - 1] - '0') {
        dp0[i][j + 1] += (s[i - 1] - '0' - 1) * dp1[i - 1][j];
        dp1[i][j + 1] += dp1[i - 1][j];
        dp0[i][j] += dp1[i - 1][j];
      } else {
        dp1[i][j] += dp1[i - 1][j];
      }
    }
  }
  printf("%d\n", dp0[n][k] + dp1[n][k]);
}

Measured memory_bytes: 128
N,A = map(int,input().split())
x = [0] + list(map(int,input().split()))
X = max(x[1:])
y = [0] + list((i-A) for i in x[1:] )
dp = [[0]*(2*N*X+1) for _ in range(N+1)]

for j in range(N+1):
    for t in range(2*N*X+1):
        if j == 0 and t == N*X:
            dp[j][t] = 1
        elif j >= 1 and (t-y[j] < 0 or t - y[j] > 2*N*X):
            dp[j][t] = dp[j-1][t]
        elif j >= 1 and (t-y[j] >= 0 and t-y[j] <= 2*N*X):
            dp[j][t] = dp[j-1][t] + dp[j-1][t-y[j]]
        else:
            dp[j][t] = 0
print(dp[N][N*X]-1)

Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll k,x;
	cin >> k >> x;
	cout << (500*k>=x?"Yes\n":"No\n");
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, Q;
    string s;
    cin >> N >> Q >> s;
    vector<char> t(Q), d(Q);
    for (ll i = 0; i < Q; i++) {
        cin >> t[i] >> d[i];
    }

    //[left, right]にあるものは生き残る
    ll left = 0, right = N - 1;

    for (ll i = Q - 1; i >= 0; i--) {
        if (d[i] == 'L') {
            if (t[i] == s[left]) {
                left++;
            } 
            if (right < N - 1 && t[i] == s[right + 1]) {
                right++;
            }
        } else {
            if (t[i] == s[right]) {
                right--;
            } 
            if (left > 0 && t[i] == s[left - 1]) {
                left--;
            }
        }
    }

    cout << max(right - left + 1, (ll)0) << endl;
}

Measured memory_bytes: 900
#include <iostream>
#include <cstring>

using namespace std;
int dp[18][301][301];
int hoge;
int main(){
    memset(dp,0,sizeof(dp));
    for(int i=0;i<301;++i) dp[0][i][i] = 1;
    
    for(int i=1;i<18;i++){
        for(int j=0;j<301;j++){
            for(int k=0;k<301;++k){
                int cnt=0;
                while((i+1)*(i+1)*cnt+k<301){
                    dp[i][j+cnt][(i+1)*(i+1)*cnt+k] += dp[i-1][j][k];
                    cnt++;
                }
            }
        }
    }

    int n;
    while(cin >> n && n){
        int ret=0;
        for(int i=0;i<301;++i) ret+= dp[17][i][n];
        cout << ret << endl;
    }
}

Measured memory_bytes: 7124
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
mod = 200003; INF = float("inf")

import numpy as np

def fft_np(a, b, n):
	N = 2 ** ((n - 1).bit_length() + 1) - n
	a = np.append(a, [0] * N)
	b = np.append(b, [0] * N)
	A = np.fft.fft(a)
	B = np.fft.fft(b)
	C = A * B
	c = np.fft.ifft(C)
	c = np.rint(c).astype(int)

	return c

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	B = np.array([0] * mod)
	conv = defaultdict(int)
	num = 2
	for i in range(1, mod):
		conv[num] = i
		num = (num * 2) % mod

	for i in range(N):
		if A[i] == 0:
			continue
		x = conv[A[i]]
		B[x] += 1

	# print(B)

	C = fft_np(B, B, mod)
	# print(C)
	M = len(C)
	ans = 0
	for i in range(M):
		ans += C[i] * pow(2, i, mod)

	for i in range(mod):
		ans -= B[i] * pow(2, 2 * i, mod)

	print(ans // 2)



if __name__ == '__main__':
	main()








Measured memory_bytes: 123556
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    string s;
    cin >>n >>s;
    int ans = 1;
    char c = s[0];
    for(int i = 1; i < n; i++){
        if(c != s[i]){
            c = s[i];
            ans++;
        }
    }
    cout <<ans;
    return 0;
}


Measured memory_bytes: 512
#!venv/bin/python
#from collections import defaultdict 
from itertools import combinations
import math

N, K = [int(x) for x in input().split()]
ELEMENT = 10 ** 9 + 7
L = N - K # 赤の数


def homo(n,r):
    #print("homo")
    #print(n,r)
    return combi(n+r-1,r)

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

for i in range(K):
    #print ("i: {}".format(i))
    con = combi(K-1,i)
    if L-i < 0:
        print(0)
    else:
        ho = homo(i+2,L-i)
        print(con*ho % ELEMENT)

Measured memory_bytes: 3316
from collections import Counter
from heapq import heapify, heappop, heappush


class Data:
    def __init__(self, value, count):
        self.value = value
        self.count = count

    def __lt__(self, other):
        return self.value > other.value
    # 降順に取り出す


N, M = map(int, input().split())
a = list(map(int, input().split()))

q = list()
heapify(q)
for v, c in Counter(a).items():
    heappush(q, Data(v, c))

for _ in range(M):
    c, v = map(int, input().split())
    heappush(q, Data(v, c))

ans = 0
cnt = 0
while cnt < N:
    d = heappop(q)
    # print(d.value, d.count)
    chg = min(N - cnt, d.count)
    ans += chg * d.value
    cnt += chg

print(ans)


Measured memory_bytes: 48452
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pie 3.142857143
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)

void solve()
{
	int n;
	cin >> n;
	int a[n];
	fr(i, 0, n)
	cin >> a[i];
	int d[n];
	d[0] = 0;
	d[1] = abs(a[1] - a[0]);
	fr(i, 2, n)
	{
		d[i] = min(d[i - 1] + abs(a[i] - a[i - 1]), d[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << d[n - 1] << endl;

}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	//cin>>t;
	t = 1;
	while (t--)
	{
		solve();
	}


	return 0;
}

Measured memory_bytes: 4344
#include <iostream>

using namespace std;

int dp[101][4][4][4];

enum {
    A,G,C,T
};

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

    const int mod = 1e9 + 7;

    // 0: A
    // 1: G
    // 2: C
    // 3: T
    dp[0][3][3][3] = 1;

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 4; j++) {
            for(int k = 0; k < 4; k++) {
                for(int l = 0; l < 4; l++) {
                    for(int m = 0; m < 4; m++) {
                        if (k == A && l == G && m == C) continue;
                        if (k == A && l == C && m == G) continue;
                        if (k == G && l == A && m == C) continue;
                        if (j == A && l == G && m == C) continue;
                        if (j == A && k == G && m == C) continue;
                        dp[i + 1][k][l][m] += dp[i][j][k][l];
                        dp[i + 1][k][l][m] %= mod;
                    }
                }
            }
        }
    }

    int ans = 0;
    for(int j = 0; j < 4; j++) {
        for(int k = 0; k < 4; k++) {
            for(int l = 0; l < 4; l++) {
                ans += dp[N][j][k][l];
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] in = Stream.of(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();

		List<Integer> list = Arrays.asList(in[0] + in[1], in[0] - in[1], in[0] * in[1]);
		Optional<Integer> ans = list.stream().max(Comparator.naturalOrder());
		
		System.out.println(ans.get());
	}
}

Measured memory_bytes: 28628
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
      string s1,s2;
      cin>>s1>>s2;
      if(s1[0]==s2[2] && s1[1]==s2[1] && s1[2]==s2[0])
      cout<<"YES";
      else
      cout<<"NO";
      
    } 
    return 0;
}


Measured memory_bytes: 3644