akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
  Scanner sc;

  Main() {
    sc = new Scanner( System.in );
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    HashSet<Character> set = new HashSet<Character>();
    for ( char c = 'h'; c <= 'p'; ++c ) {
      set.add( c );
    }
    set.add( 'y' );
    set.add( 'u' );

    for (; ; ) {
      char[] str = sc.next().toCharArray();
      if ( str[ 0 ] == '#' ) break;

      int cnt = 0;
      int buf = set.contains( str[ 0 ] ) ? 1 : 0;
      for ( char c : str ) {
        int nxt = set.contains( c ) ? 1 : 0;
        cnt += buf ^ nxt;
        buf = nxt;
      }

      System.out.println( cnt );
    }
  }

  int ni() {
    return sc.nextInt();
  }

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }
}

Measured memory_bytes: 19944
fun main(args: Array<String>) {
    val (x, y) = readIntegerList()
    if (y * 2 < x || x * 2 < y || (x + y) % 3 != 0) {
        println(0)
        return
    }

//    y = -x + b
//    b = y1 + x1
//    y = -x + x1 + y1
//    -----------
//    y = x / 2
//    -2x + 2x1 + 2y1 = x
//    x = 2 * (x1 + y1) / 3
//    y = (x1 + y1) / 3
    val lowX = 2 * (x + y) / 3
    val lowY = (x + y) / 3
    val cX = lowX / 2
    val cY = y - lowY
    val table = Combination(1000000)
    println(table.value(cX, cY))

}

/** n <= 1000000 */
class Combination(n: Int, val MOD: Long = 1000000007L) {
    val fact = LongArray(n + 1)
    val ifact = LongArray(n + 1)
    
    /** O(n) */
    init {
        fact[0] = 1L
        for (i in 1..n) { fact[i] = (fact[i - 1] * i) % MOD }
        ifact[n] = inverse(fact[n], MOD)
        for (i in n downTo 1) { ifact[i - 1] = (ifact[i] * i) % MOD }
    }

    /** O(1) */
    fun value(n: Int, k: Int) = if (k < 0 || k > n) 0 else (((fact[n] * ifact[k]) % MOD) * ifact[n-k]) % MOD
    
    /** O(log(m)) */
    fun pow(n: Long, m: Long, MOD: Long): Long {
        var ret = 1L
        var x = n
        var k = m
        while (k > 0) {
            if ((k and 1L) == 1L) { ret = (ret * x) % MOD }
            x = (x * x) % MOD
            k = k shr 1
        }
        return ret
    }

    /** O(log(MOD)) */
    fun inverse(n: Long, MOD: Long) = pow(n, MOD - 2L, MOD)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 54460
#include <iostream>
using namespace std;
int main() {
	int a[4];
	int b[4];

	while(cin >> a[0] >> a[1] >> a[2] >> a[3]) {
		cin >> b[0] >> b[1] >> b[2] >> b[3];
		int hit = 0, brow = 0;
		for(int i = 0; i < 4; i++) {
			if(a[i] == b[i]) {
				hit++;
			}
		}
		for(int i = 0; i < 4; i++) {
			if(a[i] == b[(i + 1) % 4]) {
				brow++;
			}
			if(a[i] == b[(i + 2) % 4]) {
				brow++;
			}
			if(a[i] == b[(i + 3) % 4]) {
				brow++;
			}
		}
		cout << hit << " " << brow << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;

    ll ans = 0;
    auto f = [&](int x){
        ll ret = 0;
        reps(i,x){
            if(x % i == 0)ret++;
        }
        return ret;
    };
    reps(i,n){
        if(i <= 1)continue;
        if(f(i) == 8 && i % 2 == 1)ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  for(int i=0;i<3;i++){
  string s;
  cin >> s;
  if(s == "RRR"){
    cout << 3 << endl;
    break;
  }
  else if(s == "RRS"){
    cout << 2 << endl;
     break;
  }
  else if(s == "SRR"){
    cout << 2 << endl;
     break;
  }
  else if(s== "SSS"){
    cout << 0 << endl;
     break;
  }
  else{
    cout << 1 << endl;
    break;
  }
  }
}

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

int main(){
  string S;
  cin>>S;
  vector<char> fuga(4);
  for(int i=0; i<4; i++){
    fuga[i]=S[i];
  }
  sort(fuga.begin(),fuga.end());
  int cnt=0;
  for(int i=0; i<3; i++){
    if(fuga[i]==fuga[i+1]){
      cnt++;
    }
  }
  cout<<(cnt==2?"Yes":"No");
}
       
           

Measured memory_bytes: 3600
from collections import Counter
mod=998244353
n=int(input())
D=list(map(int,input().split()))
if D[0]!=0:
    print(0)
    exit()
for d in D[1:]:
    if d==0:
        print(0)
        exit()
C=Counter(D)
m=max(D)
ans=1
for i in range(2,m+1):
    ans*=pow(C[i-1],C[i],mod)
    ans%=mod
print(ans)

Measured memory_bytes: 62828
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long e = sc.nextLong();
        long f = Math.min(a,Math.min(b,Math.min(c,Math.min(d,e))));
        if(n%f==0){System.out.println(4+n/f);}
        else{System.out.println(5+n/f);}		
  }
}


Measured memory_bytes: 23764
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, res = 0;
    cin >> n;
    FOR(i,1,n) {
        int x;
        cin >> x;
        res += (x % 2 != 0 && i % 2 != 0);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int mod = 1e9 + 7;
int cnt[1000][1000];

int main(){
    int H, W;
    cin >> H >> W;

    vector<string> a(H);

    for(int i = 0; i < H; i++){
        cin >> a[i];
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(i == 0 && j == 0){
                cnt[i][j] = 1;
            }
            else{
                if(a[i][j] == '#'){
                    cnt[i][j] = 0;
                }
                else{
                    int temp = 0;
                    if(0 <= i - 1){
                        temp = (temp + cnt[i - 1][j]) % mod;
                    }
                    if(0 <= j - 1){
                        temp = (temp + cnt[i][j - 1]) % mod;
                    }
                    cnt[i][j] = temp;
                }
            }
        }
    }

    cout << cnt[H - 1][W - 1] << endl;

    return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <utility>

using namespace std;

int Euclid(int a,int b){
    if(a%b == 0)return b;
    else return Euclid(b,a%b);
    return 0;
}

int main(){
    long long int a,b,c,d,g,a1,ans;
    cin >> a >> b >> c >> d;
    ans = b;

    if(c < d) g = Euclid(d,c);
    else g = Euclid(c,d);

    g = (c*d)/g;
    a1 = a-1;
    ans -= (b/c)+(b/d)-(b/g);
    ans -= a1-((a1/c)+(a1/d)-(a1/g));

    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)


typedef long long ll;
typedef unsigned long long int llt;

const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}

llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}



int main()
{
  string s;
  cin>>s;
  int r, p;
  r = p =0;
  rep(i, 0, s.length())
  {
    if(s[i] == 'g') r++;
    else p++;
  }
  int n =s.length();
  int rr = n/2 + (n%2==0?0:1);
  if(rr >= r)
  {
    int ans = r - rr;
    cout<<ans<<endl;
  }
  else
  {
    int ans = r - rr;
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   int a,b;
   cin>>a>>b;
   int x1=0,x2=0;
   string s1,s2;
   for(int i=0;i<b;i++)
   {
       s1=s1+(char)a;
       x1=x1*10+a;
   }
   for(int i=0;i<a;i++)
   {
       s2=s2+(char)b;
       x2=x2*10+b;
   }
  if(s1<=s2)
    cout<<x1<<endl;
  else
    cout<<x2<<endl;

    return 0;
}




Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    char c[] = new char[3];
    for(int i=0 ; i<3 ; i++){
      c[i] = s.charAt(i);
    }
    Arrays.sort(c);
    String t = new String(c);
    if(t.equals("ooo")){
      System.out.println("1000");
    }else if(t.equals("oox")){
      System.out.println("900");
    }else if(t.equals("oxx")){
      System.out.println("800");
    }else if(t.equals("xxx")){
      System.out.println("700");
    }
  }
}


Measured memory_bytes: 23380
package main

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

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

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

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}

func max(v int, values ...int) int {
	l := len(values)
	m := v

	for i := 0; i < l; i++ {
		if m < values[i] {
			m = values[i]
		}
	}

	return m
}

func min(v int, values ...int) int {
	l := len(values)
	m := v

	for i := 0; i < l; i++ {
		if m > values[i] {
			m = values[i]
		}
	}

	return m
}

var s []byte
var n int

func canMove(from, to int) bool {
	path := make([]int, n)
	path[from] = 1

	for i := from + 1; i <= to; i++ {
		if s[i] == '#' { // 岩ならNG
			path[i] = 0
		} else if path[i-1] == 1 { // 一つ前が通れるならOK
			path[i] = 1
		} else if i >= 2 && path[i-2] == 1 { // 2つ前が通れるならOK
			path[i] = 1
		}
	}

	return path[to] == 1
}

func main() {
	n = nextInt()
	a := nextInt() - 1
	b := nextInt() - 1
	c := nextInt() - 1
	d := nextInt() - 1
	s = nextBytes()

	if !canMove(a, c) {
		fmt.Println("No")
		return
	}
	if !canMove(b, d) {
		fmt.Println("No")
		return
	}

	if c < d { // AがBを飛び越さないケースはこのまま
		fmt.Println("Yes")
		return
	}

	// AがCに行くまでの途中に3マス連続のマスが必要
	for i := b; i <= d; i++ {
		if s[i-1] == '.' && s[i] == '.' && s[i+1] == '.' {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
int main() {
  int X;
  cin >> X;
  int a = X / 500;
  int b = (X - 500*a) / 5;
  cout << a * 1000 + b * 5;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H,W=MAP()
h,w=MAP()

print((H-h)*(W-w))


Measured memory_bytes: 6408
import math
N=int(input())
risuto=list(map(int,input().split()))
ans=1
kari=0
if 0 in risuto:
    print(0)
else:
    for j in range(N):
        kari+=math.log10(risuto[j])

    if kari<18:
        for i in range(N):
            ans*=risuto[i]
        print(ans) 
    elif kari==18:
        for i in range(N):
            ans*=risuto[i]
        if ans>10**18:
            print(-1)
        else:
            print(ans)
    else:
        print(-1)


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

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner s = new Scanner(System.in);

		int n = s.nextInt();
		
		int max = -2000000000;
		int min = s.nextInt();
		
		for (int i = 1; i < n; i++) {
			int r = s.nextInt();
			max = Math.max(max, r-min);
			min = Math.min(min, r);
		}
		
		System.out.println(max);
	}
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL<<60);

int main(){

    ll n, k, h; cin >> n >> k;
    ll ans = 0;
    rep(i, n){
        cin >> h;
        if(h>=k) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3576
K, A, B = (int(i) for i in raw_input().split(' '))

action = K
cookie = 1

if A + 3 > B:
    cookie += K
    print(cookie)
else:
    init_break_n = min(action, A - cookie)
    action += -(init_break_n)
    cookie += init_break_n
    if action > 0:
        trade_n = int(action/2)
        cookie += (B-A)*trade_n
        if action % 2 == 1:
            cookie += 1
    print(cookie)


Measured memory_bytes: 2568
#include <iostream>
#include <string>
using namespace std;
string s, p, r;
int main() {
    getline(cin, s);
    r = s + s;
    getline(cin, p);
    if (r.find(p) == string::npos) {
        cout << "No";
    } else {
        cout << "Yes";
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3168
n, k, q = map(int,input().split())
a = []
for i in range(q):
    b = int(input())
    a.append(b)
pnt = [0] * n
for x in a:
    pnt[x-1] += 1
for j in range(n):
    if pnt[j] > q-k:
        print('Yes')
    else:
        print('No')

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author OmarYasser
 */
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);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner sc, PrintWriter out) {
            int n = sc.nextInt(), m = sc.nextInt();
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    a[i][j] = sc.nextInt() - 1;
            boolean[] removed = new boolean[m];
            int best = n;
            for (int c = 0; c < m; c++) {
                int[] cnt = new int[m];
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < m; j++) {
                        if (!removed[a[i][j]]) {
                            cnt[a[i][j]]++;
                            break;
                        }
                    }
                int most = 0;
                for (int i = 1; i < m; i++)
                    if (cnt[i] > cnt[most])
                        most = i;
                best = Math.min(best, cnt[most]);
                removed[most] = true;
            }
            out.println(best);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader f) {
            br = new BufferedReader(f);
        }

        public String next() {
            while (st == null || !st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 31060
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(int h, int[] a, int[] b) {
    b.sort!"a > b";

    int amax = a.reduce!max;
    long ans = (h + amax - 1) / amax; // 振るだけで倒す場合
    long acc = 0;
    for (int i = 0; i < b.length; i++) {
        // ダメージの大きい順から刀を i 本なげる
        acc += b[i];
        // 残りのダメージ分は振る
        long rest = h - acc;
        // 振る回数
        long cnt = rest <= 0 ? 0 : (rest + amax - 1) / amax;
        ans = min(ans, cnt + i + 1);
    }
    return ans;
}

void main() {
    auto nh = readints;
    int n = nh[0], h = nh[1];
    int[] a, b;
    for (int i = 0; i < n; i++) {
        auto ab = readints;
        a ~= ab[0];
        b ~= ab[1];
    }
    writeln(calc(h, a, b));
}


Measured memory_bytes: 3964
#include <cstdio>
int h, w, c;
char a[55][55];
int main() {
	int i, j, x, y;
	scanf("%d%d", &h, &w);
	for(i=1; i<=h; i++) scanf("%s", &a[i][1]);
	for(i=1; i<=h; i++, puts("")) for(j=1; j<=w; j++) {
		if(a[i][j]=='#') {putchar('#'); continue;}
		c = 48;
		for(x=i-1; x<=i+1; x++) for(y=j-1; y<=j+1; y++) c += (a[x][y]=='#');
		putchar(c);
	}
	return 0;
}


Measured memory_bytes: 128
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ld long double
#define pi pair<int,int>
#define pd pair<ld,ld>
#define ft first
#define sd second
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define FOR(i,a,b) for(int i=(a); i<=(b);i++)
#define F(i,a,b) FOR(i,(a),(b)-1)
#define REV(i,a,b) for(int i=(a); i>=(b);i--)
#define VI vector<int>
#define VPI vector<pi>
#define VPD vector<pd>
#define PI 3.14159265
#define all(x) (x).begin(), (x).end()
#define sz(a) (int)((a).size())
#define int long long

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
mt19937 r(chrono::steady_clock::now().time_since_epoch().count());
int rand_range(int a, int b)
{
    assert(a<=b);
    return a+r()%(b-a+1);
}
const long long K = 1000;
const long long KK = K*K;
const long long MIL = KK*K;
const long long INF = MIL*MIL;
const long long MOD = MIL+7;
const long long N = 2e6 + 10, M=10;


void solve(){
    int n, m;
    cin>>n>>m;
    VPI v(n);
    vector<VI> kub(KK);
    F(i,0,n)
        cin>>v[i].ft>>v[i].sd;
    F(i,0,n)
        kub[v[i].ft].eb(v[i].sd);
    FOR(i,0,m)
        sort(all(kub[i]), greater<int>());
    multiset<int> s;
    REV(i,m,0) {
        s.insert(0);
        F(j,0,sz(kub[i])) {
            if (*s.begin() < kub[i][j]) {
                s.erase(s.begin());
                s.insert(kub[i][j]);
            }
        }
    }
    int res =0;
    for(auto i : s)
        res+=i;
    cout<<res<<"\n";


}

int32_t main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);
    cerr.tie(0);
    cout<<setprecision(9)<<fixed;
    cerr<<setprecision(6)<<fixed;
    int test = 1, f;
    //cin>>test;
    F(_test, 0, test){
        //cout<<"Case #"<<_test + 1<<": ";
        solve();
//		if(_test == 1)
//            return 0;
    }
}
/*
1
WSSWW
*/


Measured memory_bytes: 32768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;
ll a[100100];
vector<ll> vl;
map<ll, ll> mll;

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		if (a[i] <= -1)vl.push_back(a[i]);
	}
	sort(ALL(vl));
	if (vl.size() % 2 == 1)vl.pop_back();
	for (int i = vl.size() - 1; i >= 0; i -= 2) {
		if (vl[i] == -1 && vl[i - 1] == -1) {
			vl.pop_back();
			vl.pop_back();
		}
		else break;
	}
	rep(i, vl.size()) {
		mll[vl[i]]++;
	}
	vector<ll> ans;
	rep(i, n) {
		if (a[i] > 1)ans.push_back(i);
		else if (a[i] <= -1) {
			if (mll[a[i]] > 0) {
				mll[a[i]]--;
				ans.push_back(i);
			}
		}
	}
	cout << ans.size() << endl;
	rep(i, ans.size()) {
		cout << ans[i] + 1 << endl;
	}
}


Measured memory_bytes: 3168
#include<stdio.h>
#include<algorithm>
using   namespace   std;

int main()
{
    int i,j,a[10];
    for(i=0;i<10;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+10);
    printf("%d\n%d\n%d\n",a[9],a[8],a[7]);
    return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		new Main().solve();
	}
	
	int MOD=1000000000+7;
	void solve(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		
		long ans;
		
		if(Math.abs(N-M)>1)System.out.println(0);
		else if(Math.abs(N-M)==1){
			ans=kaijou(N)*kaijou(M)%MOD;
			System.out.println(ans);
		}else if(N==M){
			ans=kaijou(N)*kaijou(M)*2%MOD;
			System.out.println(ans);
		}
	}
	long kaijou(int n){
		long ans=1;
		for(int i=1;i<=n;i++){
			ans*=i;
			ans%=MOD;
		}
		return ans;
	}
	
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  string s;
  cin >> s;

  if(s.back() == 's'){
    cout << s+"es" << "\n";
  }
  else{
    cout << s+"s" << "\n";
  }

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  for(int i=0;i<n;i++){
    cin >> l.at(i);
  }
  sort(l.begin(),l.end());
  int ans=0;
  for(int j=0;j<n-2;j++){
    for(int k=j+1;k<n-1;k++){
      for(int m=k+1;m<n;m++){
        if(l.at(j)!=l.at(k)&&l.at(k)!=l.at(m)&&
           l.at(j)+l.at(k)>l.at(m)){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

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

int ctoi(char c)
{
  return (int)(c - '0');
}

int main()
{
  int A, B, C, D;
  string s;

  cin >> s;
  A = ctoi(s[0]);
  B = ctoi(s[1]);
  C = ctoi(s[2]);
  D = ctoi(s[3]);

  if (A + B + C + D == 7)
    cout << A << '+' << B << '+' << C << '+' << D << "=7" << endl;
  else if (A + B + C - D == 7)
    cout << A << '+' << B << '+' << C << '-' << D << "=7" << endl;
  else if (A + B - C + D == 7)
    cout << A << '+' << B << '-' << C << '+' << D << "=7" << endl;
  else if (A + B - C - D == 7)
    cout << A << '+' << B << '-' << C << '-' << D << "=7" << endl;
  else if (A - B + C + D == 7)
    cout << A << '-' << B << '+' << C << '+' << D << "=7" << endl;
  else if (A - B + C - D == 7)
    cout << A << '-' << B << '+' << C << '-' << D << "=7" << endl;
  else if (A - B - C + D == 7)
    cout << A << '-' << B << '-' << C << '+' << D << "=7" << endl;
  else if (A - B - C - D == 7)
    cout << A << '-' << B << '-' << C << '-' << D << "=7" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl '\n'
#define minimum(a,b) if(a>b) a=b;
typedef vector<vector<ll>> matrix;
const ll INF = 1e18;
const int MAX = 2e5+4;
const int MOD = 1e9+7;
vector<vector<ll>> dp(MAX,vector<ll>(3));

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n+1);
	for(int i=1;i<=n;i++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		dp[i][0]=a+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=c+max(dp[i-1][0],dp[i-1][1]);
	}
	cout << max({dp[n][0],dp[n][1],dp[n][2]});
	return 0;
}

Measured memory_bytes: 11648
using System;
using System.Text.RegularExpressions;

namespace algorithm
{
	class Program
	{
		static void Main(string[] args)
		{
			string inp = Console.ReadLine();

			int max =0;
			MatchCollection results = Regex.Matches(inp, "[ATCG]*");
			foreach (Match m in results)
			{
				if (max < m.Value.Length)
				{
					max = m.Value.Length;
				}
			}

			Console.WriteLine(max);

		}

	}
}


Measured memory_bytes: 15832
N = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())

# A : ドングリと金属に変える
# B : 全部ドングリに変える
# B : ドングリと金属に変える（無駄な操作でロスがないので、いったんドングリ化してよい）
# A : ドングリに変える

dp1 = list(range(N + 1))  # dp1[巣から持ってきたドングリ数] = 取引所 B で持てる最大ドングリ数
dp1[0] = 0
for i in range(N + 1):
    if i >= ga:
        dp1[i] = max(dp1[i], dp1[i - ga] + gb)
    if i >= sa:
        dp1[i] = max(dp1[i], dp1[i - sa] + sb)
    if i >= ba:
        dp1[i] = max(dp1[i], dp1[i - ba] + bb)

N = dp1[N]
dp2 = list(range(N + 1))  # dp2[取引所 B から持ってきたドングリ数] = 巣に持ち帰れる最大ドングリ数
for i in range(N + 1):
    if i >= gb:
        dp2[i] = max(dp2[i], dp2[i - gb] + ga)
    if i >= sb:
        dp2[i] = max(dp2[i], dp2[i - sb] + sa)
    if i >= bb:
        dp2[i] = max(dp2[i], dp2[i - bb] + ba)
print(dp2[N])


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

#define ll long long
#define ar array
#define INF INT_MAX

void solve(){
	int n,k;
	cin>>n>>k;
	int h[n],dp[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>h[i];
	}
	dp[0]=0;
	for (int i = 1; i < n; ++i)
	{
		dp[i]=INF;
		for (int j = max(0,i-k); j < i; ++j)
		{
			dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
		}
	}
	cout<<dp[n-1]<<endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}
	

Measured memory_bytes: 4436
N,L = map(int,input().split())
val = []
for i in range(N):
    val.append(L+i)

s = sum(val)
small = 10000
for i in val:
    if abs(i) < small:
        small = abs(i)
        memo = i

if memo < 0:
    print(s+small)
else:
    print(s-small)

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

/* */

int main(){
    // 入力スタンダード
    long long x;
    cin >> x;

    int year = 1;
    long long val = 100;

    
    while(true){
        val += val/100;
        if(val>=x) {
            break;
        } else {
            year++;
        }
    }
    

    cout << year <<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a<=b)
	{
		if (c<=b)
		{
			printf("%d\n", 10*b+c+a);
		}
		else
		{
			printf("%d\n", 10*c+a+b);
		}
	}
	else
	{
		if (c<=a)
		{
			printf("%d\n", 10*a+b+c);
		}
		else
		{
			printf("%d\n", 10*c+a+b);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>
#include<random>
#include<set>
 
#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
#define Sort(X) sort(X.begin(), X.end())
#define RSort(X, T) sort(X.begin(), X.end(), greater<T>())
//#define MOD 998244353
#define MAX 100000
 
typedef long long int ll;
typedef unsigned long long int ull;
 
using namespace std;
 
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; }
 
map<ll, ll> yaku_factor(ll N) {
	map<ll, ll> ret;
	ret[1] = 1;

	for (ll i = 2; i * i <= N; i++) {
		if (N % i == 0) {
			ret[i]=1;
			if (i != N / i) {
				ret[N / i] = 1;
			}
		}
	}
	if (N != 1)ret[N] = 1;
	return ret;

}

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
 
	return gcd(b, a%b);
}
 
int main() {

	ll A, B;
	cin >> A >> B;

	ll a = gcd(A, B);
	auto k = yaku_factor(a);

	ll cnt = 0;

	for (auto m : k) {
		auto yaku = yaku_factor(m.first);
		if (yaku.size() <= 2)cnt++;
	}

	cout << cnt << endl;


	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>

int main(){
    int n,m,k,i,j,a[201],b[201];
    scanf("%d",&n);
    for (i=1;i<=2*n;i++) {
        a[i]=i;
    }
    scanf("%d",&m);
    for (i=0;i<m;i++) {
        scanf("%d",&k);
        if (k==0) {
            for(j=1;j<=2*n;j++) {
                if (j<=n) {
                    b[2*j-1]=a[j];
                }
                if (j>n) {
                    b[(j-n)*2]=a[j];
                }
            }
        }
        if (k!=0) {
            for (j=1;j<=k;j++) {
                b[2*n-k+j]=a[j];
            }
            for (j=k+1;j<=2*n;j++) {
                b[j-k]=a[j];
            }
        }
        for (j=1;j<=2*n;j++) {
            a[j]=b[j];
        }
    }
    for (j=1;j<=2*n;j++) {
        printf("%d\n",a[j]);
    }
    return 0;
}

Measured memory_bytes: 1028
using System;
using System.Linq;
using System.Collections.Generic;

namespace AOJ
{
    class Program
    {
        static void Main()
        {
            for(int count = int.Parse(Console.ReadLine()); count > 0; --count) {
                bool success = true;
                int[] top = new[] { 0, 0 };
                foreach(int item in Console.ReadLine().Split().Select(q => int.Parse(q)).ToArray()) {
                    if(top[0] < item) {
                        top[0] = item;
                    }
                    else if(top[1] < item) {
                        top[1] = item;
                    }
                    else {
                        success = false;
                        break;
                    }
                }
                Console.WriteLine(success ? "YES" : "NO");
            }
        }
    }
}

Measured memory_bytes: 5692
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    n = int(input())
    A = list(map(int, input().split()))

    for i in range(n):
        if A[i]%2 == 0:
            if not(A[i]%3==0 or A[i]%5==0):
                print('DENIED')
                return
    print('APPROVED')


if __name__ == '__main__':
    main()


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> x(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }

    ll ans = 1000000000000000LL;
    for (int i = K - 1; i < N; i++) {
        int j = i - K + 1;
        ans = min(ans, min(abs(x[i]), abs(x[j])) + x[i] - x[j]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  o <- getLine
  e <- getLine
  putStrLn $ solve o e

solve :: String -> String -> String
solve o e = reverse $ if length o > length e then last o : tmp else tmp
  where
    tmp = foldl' (\a x -> (snd x) : (fst x) : a) "" (zip o e)

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

toTup2 :: [[a]] -> [(a, a)]
toTup2 = map (\ys -> case ys of y : z : zs -> (y, z))

encIdx2 :: Int -> (Int, Int) -> Int
encIdx2 mx (y, x) = y * mx + x

decIdx2 :: Int -> Int -> (Int, Int)
decIdx2 mx idx = (idx `div` mx, idx `mod` mx)

encIdx3 :: (Int, Int) -> (Int, Int, Int) -> Int
encIdx3 (my, mx) (z, y, x) = z * my * mx + y * mx + x

decIdx3 :: (Int, Int) -> Int -> (Int, Int, Int)
decIdx3 (my, mx) idx = (z, y, x)
  where
    basez = my * mx
    z = idx `div` basez
    y = (idx `mod` basez) `div` mx
    x = idx `mod` mx

while :: Monad m => m Bool -> m () -> m ()
while cond body = do
  b <- cond
  when b $ do
    body
    while cond body


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define M 100005
vector<int>d[2][M];
bool mk1[M],mk2[M],vs[2][M];
int l,r,zs,mx;
void dfs(int x,int p,int dp){
	if(vs[p][x])return;
	vs[p][x]=1;mx=max(mx,dp);
	if(!p)++l;
	else ++r;
	for(int i=0;i<(int)d[p][x].size();++i){
		int v=d[p][x][i];zs++;
		dfs(v,1-p,dp+1);
	}
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1,a,b;i<=n;++i){
		scanf("%d%d",&a,&b);
		d[0][a].push_back(b);
		d[1][b].push_back(a);
		mk1[a]=mk2[b]=1;
	}long long ans=0;
	for(int i=1;i<M;++i)if(mk1[i]){
		l=r=zs=mx=0;dfs(i,0,0);
		ans+=1ll*r*l-zs/2;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 11392
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define SZ(a) (int)(a).size()
typedef long long ll;

int n;
vector<int> a;
vector<vector<int>> al;

ll dfs(int u, int p) {
	auto k = a[u];
	// printf("%d %d\n", u, k);
	if (SZ(al[u]) == 1 && p != -1) {
		return k;
	}
	auto s = 0ll;
	auto mx = 0ll;
	for (auto v: al[u]) {
		if (v == p) {
			continue;
		}
		auto x = dfs(v, u);
		if (x == -1ll) {
			return -1ll;
		}
		s += x;
		mx = max(mx, x);
	}
	if (k < mx || s < k || 2*k < s) {
		return -1ll;
	}
	return 2*k-s;
}

int main() {
	cin.sync_with_stdio(false);
	cin >> n;
	a.resize(n);
	for (auto& x: a) {
		cin >> x;
	}
	al.assign(n, {});
	for (auto i = 0; i < n-1; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		al[u].push_back(v);
		al[v].push_back(u);
	}
	auto x = dfs(0, -1);
	auto ans = x == 0 || SZ(al[0]) == 1 && x >= 0;
	puts(ans ? "YES" : "NO");
	return 0;
}


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

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

const double EPS = 1e-10;

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

ll dp[100010][2];

int main(){
    string L; cin >> L;
    int n = L.size();
    dp[0][0] = 1;
    rep(i,n){
        dp[i+1][1] += dp[i][1]*3%MOD;
        dp[i+1][1] %= MOD;
        if(L[i] == '0'){
            dp[i+1][0] += dp[i][0];
            dp[i+1][0] %= MOD;
        }
        else{
            dp[i+1][0] += dp[i][0]*2%MOD;
            dp[i+1][0] %= MOD;
            dp[i+1][1] += dp[i][0];
            dp[i+1][1] %= MOD;
        }
    }
    cout << (dp[n][0]+dp[n][1])%MOD << endl;
}


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

int main() {
    string S,T,U;
    cin >> S >> T;
    int A,B;
    cin >> A >> B;
    cin >> U;
    int countS=A, countT=B;
    if (S==U) {
        countS--;
    }
    else if (T==U) {
        countT--;
    }
    cout << countS << " " << countT << endl;
}

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

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

    int t = 1;
    auto sum2n = [](int n) { return n * (n + 1) / 2; };

    while(true) {
        if (sum2n(t-1) < x && x <= sum2n(t))
        {
            break;
        }
        else
        {
            t++;
        }
    }

    cout << t << endl;
}


Measured memory_bytes: 256
def main():
    s = input()
    seq = [0]*26
    for i in range(len(s)):
        seq[ord(s[i])-ord('a')] += 1

    cnt = len(s)*(len(s)-1)//2

    for i in filter(lambda x:x!=0, seq):
        cnt -= i*(i-1)//2

    print(cnt+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3500
#include<stdio.h>

int integer_a[105][105],integer_b[10000+50];

int main ()
{
    int h,m;
    while(scanf("%d %d",&h,&m)!=EOF)
    {
        int i,j,t,k=0;
        scanf("%d",&t);
        for(i=0;i<t;i++)
            scanf("%d",&integer_b[i]);
        for(i=0;i<h;i++)
        {
            if(i%2==0)
                for(j=0;j<m;j++)
                {
                    integer_a[i][j]=k+1;
                    integer_b[k]--;
                    if(integer_b[k]==0)
                        k++;
                }
            if(i%2==1)
                for(j=m-1;j>=0;j--)
                {
                    integer_a[i][j]=k+1;
                    integer_b[k]--;
                    if(integer_b[k]==0)
                        k++;
                }
        }
        for(i=0;i<h;i++)
        {
            for(j=0;j<m-1;j++)
                printf("%d ",integer_a[i][j]);
            printf("%d\n",integer_a[i][m-1]);
        }
    }
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if (a > 0) {
		cout << "Positive" << endl;
	}
	else {
		if (b > 0) cout << "Zero" << endl;
		else {
			if ((b - a) % 2)cout << "Positive" << endl;
			else cout << "Negative" << endl;
		}
	}

}


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

int c[10][10];
int main(){
    int n;
    cin >> n;
    int ans=0;
    string S;
    for(int i=1;i<=n;i++){
        S=to_string(i);
        c[S[0]-'0'][S[S.length()-1]-'0']++;
    }
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            ans+=c[i][j]*c[j][i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque

n, m = map(int, input().split())
link = [ [] for i in range(n)]
for i in sys.stdin.readlines():
    a, b = map(int, i.split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)

d = deque([0])
ans = [-1]*n
ans[0] = 0
while d:
    p = d.pop()
    for v in link[p]:
        if ans[v] == -1:
            ans[v] = p+1
            d.appendleft(v)

if -1 in ans:
    print("No")
else:
    print("Yes")
    print("\n".join(map(str, ans[1:])))


Measured memory_bytes: 47500
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
if n % 2 != 0:
    if a[0] != 0:
        print(0)
        quit()
    for i in range(n-1):
        if a[i+1] != (((i // 2) + 1) * 2):
            print(0)
            quit()
    for i in range((n-1) // 2):
        ans = (ans * 2) % (10**9 + 7)
    print(ans)
else:
    for i in range(n):
        if a[i] != (((i//2)*2)+1):
            print(0)
            quit()
    for i in range(n // 2):
        ans = (ans * 2) % (10**9 + 7)
    print(ans)

Measured memory_bytes: 14008
N=int(input())
x=1
while 26**x<N:
    N-=26**x
    x+=1
a=[0]*x
N-=1
for i in range(x):
    a[i]=N//(26**(x-i-1))
    N%=(26**(x-i-1))
print(''.join([chr(c+ord('a')) for c in a]),sep='\n')

Measured memory_bytes: 9196
n, k = map(int, input().split())
p = list(map(int, input().split()))
nums = []
elm = 0
for num in p:
    elm += (num * (num + 1) / 2) * (1 / num)
    nums.append(elm)
maxVal = nums[k-1]
for i in range(n - k):
    if nums[i + k] - nums[i] >= maxVal:
        maxVal = nums[i + k] - nums[i]
    else:
        continue
print(maxVal)


Measured memory_bytes: 24812
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long

vector< ll > g[222222];
ll visited[222222];
ll cnt[222222];
void dfs(ll t,ll c){
    visited[t]=1;
    cnt[t]+=c;
    for(auto itr=g[t].begin();itr!=g[t].end();++itr){
        if(visited[*itr]==0)dfs(*itr,cnt[t]);
    }
    return ;
}

int main(){
    ll N,Q;
    cin >> N >> Q;
    ll i;
    ll a,b;
    for(i=0;i<N-1;i++){
        cin >> a >> b;
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
    }
    for(i=0;i<N;i++){
        cnt[i]=0;
        visited[i]=0;
    }
    for(i=0;i<Q;i++){
        cin >> a >> b;
        cnt[a-1]+=b;
    }
    dfs(0,0);
    for(i=0;i<N;i++){
        cout <<cnt[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 23424
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<double> V(N);
    for(int i=0;i<N;i++){
        int x;
        cin >> x;
        V.at(i) = (double)x;
    }
    sort(V.begin(),V.end());
    reverse(V.begin(),V.end());
    for(int i=N-1;i>0;i--){
        double x,y;
        x = V.at(i);y=V.at(i-1);
        V.pop_back();V.pop_back();
        V.push_back((x+y)/(double)2);
    }
    double ans = V.at(0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=1; i<n; ++i)
#define all(c) begin(c),end(c)
/*
*/
int main(){
  ll N; cin>>N;
  vector<ll> ans(10010,0);
  rep(x,101) rep(y,101) rep(z,101){
    ll d=x*x+y*y+z*z+x*y+y*z+z*x;
    if(d > 10000) break;
    if(d <= 10000) ans[d]++;
  }
  rep(i,N+1) cout<<ans[i]<<endl;
}

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

using namespace std;

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

  int a, b;
  cin >> a >> b;
  string s1 = string(a, '0'+b);
  string s2 = string(b, '0'+a);

  cout << min(s1, s2) << endl;

	return 0;
}



Measured memory_bytes: 256