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

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final String s = scanner.next();
        if (s.equals("RRR")) {
            System.out.println(3);
        } else if (s.startsWith("RR") || s.endsWith("RR")) {
            System.out.println(2);
        } else if (s.contains("R")) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

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

        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
    

Measured memory_bytes: 32784
#include <cassert>
#include <iostream>

const int M = 1e9 + 7;

int solve(int N) {
  long long ans = 1;
  for (int i = 1; i <= N; ++i) {
    ans = ans * i;
    if (ans % M)
      ans = ans % M;
    assert(ans != 0);
  }
  ans = ans % M;
  return ans;
}

void test() {
  assert(solve(3) == 6);
  assert(solve(10) == 3628800);
  assert(solve(100000) == 457992974);
  std::cout << "done" << std::endl;
}

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

  // test();
  std::cout << solve(N) << std::endl;
}


Measured memory_bytes: 256
import sys
N = int(input())
A = []
for _ in range(N):
    A.append(int(input())) 

# 0の時と、全部が同じ数の時の場合分け。

if N == 1:
    print(1)
    sys.exit()

if set(A) == 1:
    print(0)
    sys.exit()

A = sorted(A)


count = 1
ans = 0
firstnum = A[0] 
for i in range(1,N):
    if firstnum == A[i]:
        count = count + 1
    else:
        if count % 2 == 0:
            count = 1
        else:
            ans = ans + 1
            count = 1

    firstnum = A[i]  

if count%2 == 0:
  ans = ans +0
else:
  ans = ans + 1
print(ans)

Measured memory_bytes: 13204
import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop
INF = float("inf")
def MAIN():
    n = int(input())
    adj = [[]] * n
    for _ in range(0, n):
        U = list(map(int, readline().split()))
        adj[U[0]] = zip(U[2::2], U[3::2])
    def dijkstra():
        d = [0] + [INF] * (n - 1)
        hq = [(0, 0)]
        while hq:
            u = heappop(hq)[1]
            for v, c in adj[u]:
                alt = d[u] + c
                if d[v] > alt:
                    d[v] = alt
                    heappush(hq, (alt, v))
        print("\n".join(f"{i} {c}" for i, c in enumerate(d)))
    dijkstra()
MAIN()



Measured memory_bytes: 40156
n,*xyh=map(int,open(0).read().split())
x=xyh[0::3]
y=xyh[1::3]
h=xyh[2::3]

for cx in range(101):
    for cy in range(101):
        hmax_i = h.index(max(h))
        H = abs(cx-x[hmax_i]) + abs(cy-y[hmax_i]) + h[hmax_i]
        for i in range(0,n):
            if max(H-abs(cx-x[i])-abs(cy-y[i]),0) == h[i]:
                if i == n-1:
                    print(cx,cy,H)
                    exit()
                else:
                    continue
            else:
                break

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=3e5+5;
typedef long long ll;
char s[N],s1[N];
int vis[28];
int n,m;
ll ans;
int f[N];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	fo(i,1,n)
	{
		vis[s[i]-'a'+1]++;
	}
	fo(i,1,n)
	{
		int c=s[i]-'a'+1;
		vis[c]--;
		ans+=i-1-(vis[c]);
	}
	printf("%lld\n",ans+1);
}


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

using namespace std;

int main(){
    int q;
    cin >> q;
    vector<int> A;
    for(int i = 0; i < q; i++){
        int x;
        int y;
        cin >> x;
        if(x == 0){
            cin >> y;
            A.push_back(y);
        }else if(x == 1){
            cin >> y;
            cout << A[y] << "\n";
        }else{
            A.pop_back();
        }
    }


    return 0;
}


Measured memory_bytes: 3920
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadString()

	rem := 0
	for _, c := range n {
		ni, _ := strconv.Atoi(string(c))
		rem = (rem + ni) % 9
	}

	if rem == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// from [my library](https://github.com/ikngtty/go-contestlib)
// -   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base, exponent int) int {
	if exponent < 0 {
		panic(fmt.Sprintf("exponent (%d) should not be a minus", exponent))
	}

	answer := 1
	for i := 0; i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	if dividor == 0 {
		panic("dividor should not be 0")
	}

	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// -   sortutil

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

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// -   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}

func (sc *Scanner) ReadFloat() float64 {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.ParseFloat(text, 64)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 2440
S = input()
ans = 0
for i in range(len(S)):
    a = i
    k = 0
    while S[a] == 'A' or S[a] == 'C' or S[a] == 'G' or S[a] == 'T':
        k += 1
        a += 1
        if a == len(S):
            break
    ans = max(ans,k)
print(ans)

Measured memory_bytes: 61928
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}



ll cost[15];

ll n,m,x;

ll v[15][15];

ll All[15];

ll mx=1e18;

ll ans;

void sum(ll pos)
{
    for(ll i=0; i<m; i++)
        All[i]+=v[pos][i];

    ans+=cost[pos];
}

void check()
{
    for(ll i=0; i<m; i++)
        if(All[i]<x)return ;

    mx=min(mx,ans);


}
void allPossibleSubset(ll arr[], ll n)
{
    ll count = pow(2ll, n);

    ll a;

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

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

            if ((i & (1 << j)) != 0)
                {

                    sum(arr[j]);
                }
        }

        check();
       fill(All,All+n+1,0);
        ans=0;
        //cout << "\n";
    }
}

int main()
{

   fastread();

   ll i,j,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

      bool flag=false;

      string str;

      cin>>n>>m>>x;

      for(i=0; i<n; i++)
      {
          cin>>cost[i];

          for(j=0; j<m; j++)
          {
              cin>>v[i][j];
          }
      }

      ll ara[n+2];

      for(i=0; i<n; i++)
      {
          ara[i]=i;
      }

      allPossibleSubset(ara,n);

      if(mx==1e18)mx=-1;
      cout<<mx<<endl;



}



Measured memory_bytes: 4076
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
using namespace std;
const int MAX = 1e5 + 10;
const ll MOD = 1e9 + 7;
int N, M, K, Q;

int main()
{
	int i, j, k;
	scanf("%d%d", &N, &K);
	if ((N +1)/ (2 * K) != 0) printf("YES");
	else printf("NO");
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())[:-1]
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
A,B = map(Decimal,input().split())
if round(A) == 0 or B <= 0.005:
    print(0)
else:
    print(math.floor(A*B))
    

    





Measured memory_bytes: 10716
# 2019/05/26
# AtCoder Beginner Contest 128 - C

# Input
n, m = map(int,input().split())

ks = list()
for i in range(m):
    s = list(map(int,input().split()))
    ks.append(s)

p = list(map(int,input().split()))

ans = 0
for i in range(2**n):
    binstr = format(i, "010b")
    binlist = list()
    for j in range(10):
        binlist.append(int(binstr[j]))
    
    # Try This case
    is_on = True
    for x in range(m):
        subt = 0
        for y in range(1, ks[x][0] + 1):
            subt += binlist[10 - ks[x][y]] * 1
        
        if subt % 2 != p[x]:
            is_on = False
            break

    if is_on == True:
        ans += 1

# Output
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  int x,y,a,r;
  scanf("%d %d",&x,&y);
  if (x < y){
    a=x;
    x=y;
    y=a;
  }
  while (y > 0){
  r = x % y;
  x = y;
  y = r;
  }
  printf("%d\n",x);
  return 0;
}



Measured memory_bytes: 2048
import java.util.*;

public class Main{
	char [][] data;
	int w,h;
	int [] vx = {0,1,0,-1};
	int [] vy = {1,0,-1,0};
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			h = sc.nextInt();
			w = sc.nextInt();
			data = new char[h][w];
			for(int i = 0; i < h; i++){
				data[i] = sc.next().toCharArray();
			}
			int sum = 0;
			for(int k = 0; k < 26; k++){
				int prev = sum;
				for(int i = 0; i < h; i++){
					for(int j = 0; j < w; j++){
						if(data[i][j] == '.'){
							sum += erase(i,j);
						}
					}
				}
				if(prev == sum){
					break;
				}
			}
			
			System.out.println(sum);
		}
	}

	private int erase(int y, int x) {
		char [] panel = new char[4];
		Arrays.fill(panel, '*');
		int [][] pos = new int[4][2];
		for(int i = 0; i < 4; i++){
			int xx = x + vx[i];
			int yy = y + vy[i];
			while(true){
				if(! isOK(xx,yy)) break;
				if(data[yy][xx] != '.'){
					panel[i] = data[yy][xx];
					pos[i][0] = xx;
					pos[i][1] = yy;
					break;
				}
				xx = xx + vx[i];
				yy = yy + vy[i];
			}
		}
		int count = 0;
		for(int i = 0; i < 4; i++){
			if(panel[i] == '*') continue;
			for(int j = i + 1; j < 4; j++){
				if(i == j) continue;
				
				if(panel[i] == panel[j]){
					data[pos[i][1]][pos[i][0]] = '.';
					data[pos[j][1]][pos[j][0]] = '.';
					count+= 2;
				}
			}
		}
		return count;
	}

	private boolean isOK(int xx, int yy) {
		if(0 <= xx && xx < w && 0 <= yy && yy < h){
			return true;
		}
		return false;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

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

typedef long long ll;
const int MOD = (int)1e9 + 7;

int H, W, A, B;
vector<int> fac, inv;

int pow_mod(int a, int b) {
	int ret = 1;
	if (b == 0) 
		return ret;
	ret = pow_mod(a, b / 2);
	ret = (ll)ret * ret % MOD;
	if (b % 2 == 1)
		ret = (ll)ret * a % MOD;
	return ret;
}

int comb(int n, int m) {
	return (ll)fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}

int main(void) {
	cin >> H >> W >> A >> B;

	fac.resize(H + W, 1);
	for (int i = 2; i < H + W; ++i)
		fac[i] = (ll)fac[i - 1] * i % MOD;

	inv.resize(H + W);
	for (int i = 0; i < H + W; ++i)
		inv[i] = pow_mod(fac[i], MOD - 2);

	int xy = H + W - 2;
	int ans = comb(xy, H - 1);
	for (int i = 0; i < B; ++i)
		ans = (ans + MOD - (ll)comb(H - A - 1 + i, i) * comb(xy - (H - A - 1 + i) - 1, A - 1) % MOD) % MOD;

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1792
<?php

list($n, $a, $b) = preg_split('/ /', trim(fgets(STDIN)));

if (($b - $a) % 2 == 0) {
    print (int)(($b - $a) / 2);
} else {
    print min($n - $b, $a - 1) + 1 + ($b - $a - 1) / 2;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

struct edge { ll to, cost; };//行き先,距離
// firstは最短距離、secondは頂点の番号
ll V;//頂点数
vector<edge> G[1000000LL]; ll d[1000000LL];//G=隣接リスト,d=sからの距離
void dijkstra(ll s) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする 
	priority_queue<P, vector<P>, greater<P>> que; 
	fill(d, d + V + 1, LINF);
	d[s] = 0LL;
	que.push(P(0LL, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		for (ll i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to)); 
			}
		}	 	
	}
}

int main(){
	ll x,y;cin>>V>>x>>y;
	for(ll i = 1; i < V; i++) {
		G[i].pb(edge{i + 1,1LL});
		G[i + 1].pb(edge{i,1LL});
	}
	G[x].pb({y,1LL});
	G[y].pb({x,1LL});
	vector<ll> a(V + 1,0);
	for(ll i = 1; i <= V; i++) {
		dijkstra(i);
		for(ll j = i + 1; j <= V; j++) {
			a[d[j]]++;
		}
	}
	for(int i = 1; i < V; i++) {
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 25472
import java.util.*;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        int num = scan.nextInt();
        int[] up = new int[100001];
        int[] down = new int[100001];
        for(int i = 0; i < num; i++){
            if(i % 2 == 1){
                up[scan.nextInt()] += 1;
            } else {
                down[scan.nextInt()] += 1;
            }
        }

        // search
        int upFirst = 0;
        int upSecond = 0;
        int downFirst = 0;
        int downSecond = 0;
        for(int i = 1; i <= 100000; i++){
            if(up[i] > up[upFirst]){
                upSecond = upFirst;
                upFirst = i;
            } else if(up[i] > up[upSecond]){
                upSecond = i;
            }
            if(down[i] > down[downFirst]){
                downSecond = downFirst;
                downFirst = i;
            } else if(down[i] > down[downSecond]){
                downSecond = i;
            }
        }

        // answer
        int min = 0;
        if(upFirst != downFirst){
            min = num - up[upFirst] - down[downFirst];
        } else {
            min = num - up[upFirst] - down[downSecond];
            if(num - down[downFirst] - up[upSecond] < min){
                min = num - down[downFirst] - up[upSecond];
            }
        }    
        System.out.println(min);

    }
}

Measured memory_bytes: 53080
H,W = map(int, input().split())
A = [input() for h in range(H)]
row = H*[False]
col = W*[False]

for h in range(H):
  for w in range(W):
    if A[h][w]=="#":
      row[h] = True
      col[w] = True

for h in range(H):
  if row[h]:
    for w in range(W):
      if col[w]:
        print(A[h][w],end="")
    print()

Measured memory_bytes: 9184
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

class Seg():
    def __init__(self, n, default, func):
        i = 1
        while 2**i <= n:
            i += 1
        self.D = default
        self.H = i
        self.N = 2**i
        self.A = [default] * (self.N*2-1)
        self.F = func

    def find(self, i):
        return self.A[i + self.N - 1]

    def update(self, i, x):
        i += self.N - 1
        self.A[i] = x
        while i > 0:
            i = (i-1) // 2
            self.A[i] = self.merge(self.A[i*2+1], self.A[i*2+2])

    def merge(self, a, b):
        return self.F(a, b)

    def total(self):
        return self.A[0]

    def query(self, a, b):
        def _query(k,l,r):
            if r <= a or b <= l:
                return self.D
            if a <= l and r <= b:
                return self.A[k]
            m = (l+r)//2
            vl = _query(k*2+1,l,m)
            vr = _query(k*2+2,m,r)
            return self.merge(vl,vr)
        return _query(0,0,self.N)

def main():
    n,k = LI()
    a = [I() for _ in range(n)]

    b = [0]
    for i in range(n):
        b.append(b[-1] + a[i] - k)

    d = {}
    for c,i in zip(sorted(set(b)), range(n+1)):
        d[c] = i
    e = [d[c] for c in b]

    l = len(d)

    def f(a,b):
        return a+b

    seg = Seg(l, 0, f)
    for c in e:
        seg.update(c, seg.find(c) + 1)

    r = 0
    for c in e[::-1]:
        t = seg.query(0,c+1)
        r += t-1
        seg.update(c, seg.find(c) - 1)

    return r

print(main())



Measured memory_bytes: 113584
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

//#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

typedef pair<int, int> P;

// 素因数分解 x = a^p * b^q * c^r ...
// 各素因子で何回割り切れるかを表すペアの配列を返す
// vectorじゃなくてmapでもいい
vector<pair<ll, ll>> prime_factorize(ll x) {
    vector<pair<ll, ll>> res;
    // 素因子2から始める
    for (ll p = 2; p <= x; p++) {
        if (x % p != 0) continue;
        int num = 0;
        // 割り切れる回数をカウント
        while (x % p == 0) {
            num++;
            x /= p;
        }
        res.push_back(make_pair(p, num));
    }
    return res;
}

//  x = a^p * b^q * c^r ... のとき
// x の約数の個数は、(p+1) * (q + 1) * (r + 1)...となる
ll divisor_count(const vector<pair<ll,ll>>& x_primes) {
    ll num = 1;
    for (auto p : x_primes) {
        num *= (p.second + 1);
        num %= MOD;
    }
    return num;
}

ll fact(ll n) {
    if (n <= 1) return 1;
    else return n * fact(n - 1);
}

int main()
{
    ll N; cin >> N;
    map<ll, ll> cnt;
    ll n = N;
    // 階乗を求めながら素因数分解
    for (ll i = 2; i <= n; i++) {
        ll q = i;
        for (ll j = 2; j <= q; j++) {
            if (q % j != 0) continue;
            while (q % j == 0) {
                cnt[j]++;
                q /= j;
            }
        }
    }

    // 約数の個数をMODしながら算出
    ll ans = 1;
    for (auto p : cnt) {
        ans = ans * (p.second + 1) % MOD;
    }
    cout << ans << endl;
}

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

int n   = 0;
int cnt = 0;

void dfs(ll s, bool three, bool five, bool seven) {
  if (s > n) { return; }

  if (three && five && seven) cnt++;

  dfs(s * 10 + 3, true, five, seven);
  dfs(s * 10 + 5, three, true, seven);
  dfs(s * 10 + 7, three, five, true);
}

int main() {
  cin >> n;
  dfs(0, false, false, false);
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main ()
{
	int n;cin >> n;
	int cnt1 = 0,cnt2 = 0,cnt3 = 0,cnt4 = 0;
	while (n--)
	{
		string s;cin >> s;
		if (s == "AC")
		{
			++cnt1;
		}
		else if (s == "WA")
		{
			++cnt2;
		}
		else if (s == "TLE")
		{
			++cnt3;
		}
		else if (s == "RE")
		{
			++cnt4;
		}
	}
	cout << "AC" << " x " << cnt1 << endl;
	cout << "WA" << " x " << cnt2 << endl;
	cout << "TLE"<< " x " << cnt3 << endl;
	cout << "RE" << " x " << cnt4 << endl;
	return 0;
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner scn=new Scanner(System.in);
        long a=scn.nextLong();
        long b=scn.nextLong();
        long c=scn.nextLong();
        long k= scn.nextLong();
        if(k%2==1)
        {
            System.out.println(b-a);
        }
        else
        {
            System.out.println(a-b);
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    string s;
    cin >> s;
    cout << 700 + count(All(s), 'o')*100 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,arr[22],ans;
int main(){
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&arr[i]);
    for(i=2;i<n;i++){
        ans+=(arr[i-1]<arr[i] && arr[i]<arr[i+1]);
        ans+=(arr[i+1]<arr[i] && arr[i]<arr[i-1]);
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long int a=1,b=1,c=1,ans;
    for(int i=0;i<n;i++){
        a=(a*10)%1000000007;
        b=(b*9)%1000000007;
        c=(c*8)%1000000007;
    }
    ans=(a-2*b+c)%1000000007;
    ans=(ans+1000000007)%1000000007;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3624
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Algorithm
{
    class Program
    {
        const string Key = "AC";

        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(w => int.Parse(w)).ToArray();
            var s = Console.ReadLine().ToCharArray();

            for (var i = 0; i < line[0]-1; i++)
            {
                if (s[i] == 'A' && s[i + 1] == 'C') s[i] = 'a';
            }

            var t = new int[line[0]];

            for (var i = 0; i < line[0]-1; i++)
            {
                if (s[i] == 'a') t[i + 1] = t[i] + 1;
                else t[i + 1] = t[i];
            }

            for (var i = 0; i < line[1]; i++)
            {
                var b = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
                var l = b[0] - 1;
                var r = b[1] - 1;
                Console.WriteLine(t[r] - t[l]);
            }
        }
    }
}


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

int main() {
    string str;
    cin >> str;
    if(str.at(0) == str.at(1) && str.at(1) == str.at(2)){
        cout << "No" << endl;
        return 0;
    }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int mod_inv(int X){
	int a = X, b = MOD, u = 1, v = 0;
	while(b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	if(u < 0) u += MOD;
	return u;
}

vector<int> fact,factinv;

void nCr_init(int N){
	N = min(N,(int)MOD);
	fact.resize(N + 1);
	factinv.resize(N + 1);
	fact[0] = 1;
	for(int i = 1;i <= N;i++) fact[i] = fact[i - 1] * i % MOD;
	factinv[N] = mod_inv(fact[N]);
	for(int i = N;i >= 1;i--) factinv[i - 1] = factinv[i] * i % MOD;
}

int nCr(int ncr_n,int ncr_r){
	if(ncr_n >= MOD) return nCr(ncr_n % MOD, ncr_r % MOD) * nCr(ncr_n / MOD, ncr_r / MOD) % MOD;
	return ncr_r > ncr_n ? 0 : fact[ncr_n] * factinv[ncr_n - ncr_r] % MOD * factinv[ncr_r] % MOD;
}

signed main(){
	int n,a[100001],cnt[100000] = {},num,x = -1,y;
	cin >> n;
	nCr_init(n + 1);
	for(int i = 0;i < n + 1;i++) {
		cin >> a[i];
		cnt[a[i] - 1]++;
	}
	for(int i = 0;i < n;i++) {
		if(cnt[i] == 2) num = i + 1;
	}
	for(int i = 0;i < n + 1;i++) {
		if(a[i] == num){
			if(x == -1) x = i;
			else y = n - i;
		}
	}
	for(int i = 0;i < n + 1;i++){
		if(i) printf("%lld\n",(nCr(n + 1,i + 1) + MOD - nCr(x + y,i)) % MOD);
		else cout << n << endl;
	}
	return 0;
}

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

int main() {
  
  string S;
  cin >> S;
  int N = S.size();

  int num0 = 0,num1=0;

  for(int i = 0;i < N; i++) {
      if(S.at(i) == '0') num0++;
      else num1++; 
  }

  cout << 2 * min(num0,num1) << endl;

}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
	int id;
	int xu;
	bool operator <(const node o)const
	{
		return xu<o.xu;
	}
}a[100010];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].xu;
		a[i].id=i;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	cout<<a[i].id<<" ";
	return 0; 
}

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

int main(){
  long long N, M; cin >> N >> M;
  if(N==1){
    if(M==1){
      cout << 1 << endl;
    }else{
      cout << M-2 << endl;
    }
  }else{
    if(M==1){
      cout << N-2 << endl;
    }else{
      cout << (N-2)*(M-2) << endl;
    }
  }
}

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

int main()
{
    int s;
    cin >> s;
    int a, b;
    a = s / 100; //右
    b = s % 100; //左

    if (a > 0 && a <= 12 && b > 0 && b <= 12)
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if (a > 0 && a <= 12)
    {
        cout << "MMYY" << endl;
    }
    else if (b > 0 && b <= 12)
    {
        cout << "YYMM" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
from itertools import combinations as cmb
N = []
X = []
while True:
  n, x = map(int, input().split())
  if n != 0:
    N.append(n)
    X.append(x)
  else:
    break


for n, x in zip(N, X):
  counter = 0
  for nums in cmb(list(range(1, n+1)), 3):
    if sum(nums) == x:
      counter += 1
  print(counter)


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

struct food{
	string n;
	int w;
	int s;
	int used;
};

int main(){
	int n;
	while(cin >> n){
		vector<food> vf;
		if(n == 0 ) break;
		for(int i = 0; i < n; i++){
			food f;
			cin >> f.n >> f.w >> f.s;
			f.used = 0;
			vf.push_back(f);
		}
		int weight = 0;
		for(int i = 0; i < n; i++) weight += vf[i].w;
		for(int i = 0; i < n; i++){
			vector<int> vi;
			for(int j = 0; j < n; j++){
				if(!vf[j].used && vf[j].s >= weight - vf[j].w){
					vi.push_back(j);
				}
			}
			int wmax = -1;
			int u;
			for(int j = 0; j < vi.size(); j++){
				if(wmax <vf[vi[j]].w){
					wmax = vf[vi[j]].w;
					u = vi[j];
				}
			}
			cout << vf[u].n << endl;
			vf[u].used = 1;
			weight -= vf[u].w;
		}
	}
	return 0;
}

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

typedef long long ll;
const int MN = 610, mod = 1e9+7;

typedef unsigned long long HASH_T;
char cad[1000];
HASH_T S[MN][MN];
HASH_T HH[MN][MN],
          HV[MN][MN], primo = 31;
int N;

HASH_T pot[MN];

HASH_T getHashH(int i, int j){
    HASH_T tmp = HH[i][j+N-1] - pot[N]*HH[i][j-1];
    return tmp;
}

HASH_T getHashV(int i, int j){
    HASH_T tmp = HV[i+N-1][j] - pot[N]*HV[i-1][j];
    return tmp;
}

bool isSimmetric(int x, int y){
    for (int i=0; i < N; i++)
        if (getHashH(i+x,y) != getHashV(x,i+y))
            return false;
    return true;
}

int main()
{
    #ifdef ACMTUYO
    //cout << "In ACM\n";
    freopen("a.in","r",stdin);
    #else
    cin.tie(0); ios_base::sync_with_stdio(0);
    #endif // ACMTUYO

    pot[0] = 1;
    for (int i=1; i < MN; i++)
        pot[i] = primo*pot[i-1];

    cin >> N;

    for (int i=1; i<=N; i++){
        cin >> cad;
        for (int j=1; j <= N; j++){
            S[i][j] = cad[j-1]-'a'+1;
            S[i+N][j] = S[i][j];
            S[i][j+N] = S[i][j];
            S[i+N][j+N] = S[i][j];
        }
    }

    for (int i=1; i<=2*N; i++){
        for (int j=1; j <= 2*N; j++){
            HH[i][j] = primo*HH[i][j-1] + S[i][j];
            HV[i][j] = primo*HV[i-1][j] + S[i][j];
        }
    }

    int cont=0;
    for (int i=1; i <= N; i++){
        if (isSimmetric(i,1)){
            cont+=N;
        }
    }

    cout << cont << "\n";

    return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int hen(vector<ll> p){
    int ans = 1;
    ll mi = p[1];
    rep(i,2){
        if (mi > p[i+2]){
            mi = p[i+2];
            ans = i+2;
        }
    }
    return ans;
}

int main() {
    int n, t; cin >> n >> t;
    int ans = INF;
    rep(i,n){
        int a, b; cin >> a >> b;
        if (b <= t) ans = min(ans,a);
    }
    if (ans == INF) cout << "TLE" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <iomanip>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>
#include <random>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define endl '\n'

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(1e6) + 17;

int n, k;
int a[MAXN];

bool read() {
    if (!(cin >> n >> k))
        return false;

    forn (i, n)
        cin >> a[i];

    return true;
}

void solve() {
    int ans = 2 * INF;

    for (int i = 0; i + k <= n; ++i)
        if (a[i + k - 1] <= 0)
            ans = min(ans, -a[i]);
        else if (a[i] >= 0)
            ans = min(ans, a[i + k - 1]);
        else
            ans = min(ans, a[i + k - 1] - a[i] + min(-a[i], a[i + k - 1]));

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');

    while (read())
        solve();

    return 0;
}



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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int run = 0;
vi seen(100);

bool find(vi& took, int lim, int inx) {
    if (inx == sz(took)) {
        ++run;

        for (int i = 0; i < sz(took); i++) {
            if (seen[took[i]] == run) return false;
            else seen[took[i]] = run;

            for (int j = 0; j < i; j++) {
                if (seen[took[i] + took[j]] == run) return false;
                else seen[took[i] + took[j]] = run;
            }
        }

        return true;
    }

    int low = inx ? took[inx - 1] : 0;
    for (took[inx] = low + 1; took[inx] + low < lim; took[inx]++) {
        if (find(took, lim, inx + 1))
            return true;
    }
    return false;
}

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

    vi lim = { 0, 2, 4, 7, 12, 20, 32, 44, 64, 81 };

    int N;
    cin >> N;

    vvll dist(N, vll(N));

    ll mv = 1;
    for (int n = 1; n < N; n++) {
        vi took(n);
        find(took, lim[n], 0);
        for (int i = 0; i < n; i++)
            dist[i][n] = mv * took[i];
        mv *= lim[n];
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (j) cout << " ";
            cout << dist[min(i, j)][max(i, j)];
        }
        cout << "\n";
    }

    return 0;
}



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

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;

int main() {

	SINT32 N = 0;
	SINT64 SUM = 0;
	SINT64 SUM2 = 0;

	cin >> N;

	vector<SINT32> DATA(N);
	vector<SINT32> DATA2(N);
	
	for (SINT32 i = 0; i < N; i++) {
		cin >> DATA[i];
		DATA2[i] = DATA[i]-1-i;
		DATA[i] = DATA2[i];
	}
	
	sort(DATA.begin(),DATA.end());
	SUM = DATA[DATA.size()/2];


	for (SINT32 i = 0; i < N; i++) {
		SUM2 = SUM2 + ABS(DATA2[i] - SUM);
	}


	cout << SUM2 << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();

Measured memory_bytes: 1792
#include <iostream>
#include<vector>
#include<string>
#include<bits/stdc++.h>
#include<algorithm>
#include<stdio.h>
#include<bits/stdc++.h>
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

using namespace std;

/*ll ma=998244353;
ll power(ll v,ll ti){
if(ti==1)
    return v;
ll x=power(v,ti/2);
x=(x*x)%ma;
if(ti%2==1)
    x=(x*v)%ma;
return x;

}
struct t{
int a,b;
};
vector<vector<t > >g;
vector<int> v;


ll n;


void dfs(int i,int sum){
v[i]=1;


for(int j=0;j<go[i].size();j++){
    int x=go[i][j].a;
    int y=go[i][j].b;
    if(v[x]==0){
        dfs(x,min(y,sum));

    }

}

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

        p[i][j]=0;
    }
}
for(int i=0;i<h;i++)
    cin>>a[i];
queue<pair<int,int> >q;
for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)
        if(a[i][j]=='#')
        {

            q.push(mp(i,j));
            p[i][j]=1;
        }
}
int ans=0;
while(!q.empty()){
        pair<int,int> x=q.front();
q.pop();
int i=x.ff;
int j=x.ss;
if(i-1>-1 && p[i-1][j]==0)
{
    q.push(mp(i-1,j));
    p[i-1][j]=p[i][j]+1;
    ans=max(ans,p[i][j]+1);
}
    if(j-1>-1 && p[i][j-1]==0)
{
    q.push(mp(i,j-1));
    p[i][j-1]=p[i][j]+1;
    ans=max(ans,p[i][j]+1);
}
if(i+1<h && p[i+1][j]==0)
{
    q.push(mp(i+1,j));
    p[i+1][j]=p[i][j]+1;
    ans=max(ans,p[i][j]+1);
}
if(j+1<w && p[i][j+1]==0)
{
    q.push(mp(i,j+1));
    p[i][j+1]=p[i][j]+1;
    ans=max(ans,p[i][j]+1);
}
}
if(ans==0)
    cout<<0<<endl;
else
cout<<ans-1<<endl;

 }


Measured memory_bytes: 13456
#include<stdio.h>
int main(void)
{
	int n[10],a[10],s,d,f,g,w,x,i,j;
	for(i=0;i<4;i++){
		n[i]=0;
		a[i]=0;
	}	
	for(i=0;i<4;i++){
		scanf("%d",&n[i]);
	}
	for(i=0;i<2;i++){
		scanf("%d",&a[i]);
	}
	s=0;
	d=0;
	f=0;
	x=0;
	for(i=0;i<3;i++){
		for(j=i+1;j<4;j++){
			if(n[i]<n[j]){
				s=n[i];
				n[i]=n[j];
				n[j]=s;
			}
		}
	}
	for(i=0;i<1;i++){
		d=n[i];
		f=n[i+1];
		x=n[i+2];
	}
	g=0;
	for(i=0;i<2;i++){
		if(g<a[i]){
			g=a[i];
		}
	}
	w=d+f+x+g;
	printf("%d\n",w);
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m, p, y;
	cin >> n >> m;
	unordered_map<int, vector<pair<int, int>>> py;
	vector<pair<int, long long int>> ans;
	ans.reserve(m);
	for (int i = 0; i < m; ++i) {
		cin >> p >> y;
		if (py.find(p) == py.end()) py.emplace();
		py[p].emplace_back(y, i);
	}
	for (auto&& pyv : py) {
		sort(pyv.second.begin(), pyv.second.end());
		int i = 0;
		for (auto&& v : pyv.second) {
			++i;
			ans.emplace_back(v.second, pyv.first * 1000000L + i);
		}
	}
	sort(ans.begin(), ans.end());
	for(auto&& a : ans) cout << setfill('0') << setw(12) << a.second << endl;
	return 0;
}


Measured memory_bytes: 11812
N,A,B = (int(i) for i in input().split())

total = 0
for i in range(1,N+1):
    s = str(i)
    num = 0
    for j in range(len(s)):
        num += int(s[j])
    if num <= B and num >= A:
        total += i

print(total)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define debug(x) cout << #x << " = " << x << endl
#define pb push_back
#define F first
#define S second

int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);


    string s;
    int n, aux = 0, cantB = 0, i = 0;
    ll ans = 0;
    cin >> s;
    n = s.size();
    while(i < n){
        char c = s[i];
        if(c == 'B')cantB++;
        else if(cantB > 0){
            ans += cantB;
        }
        i++;
    }

    cout << ans << "\n";




}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod=1e9+7;         
const int N=1e5+4;
int main()                  
{
    int a,b;
    scn(a);scn(b);
    int ans=max(a+b,a-b);
    ans=max(ans,a*b);
    pri(ans);
}

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

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

    tmp = 0
    ans = 0
    for i in range(n):
        mon = max(0, a[i] - tmp)

        if b[i] <= mon:
            ans += b[i] + tmp
            tmp = 0
        else:
            ans += a[i]
            tmp = b[i] - mon
            
    if tmp <= a[i + 1]:
        ans += tmp
    else:
        ans += a[i + 1]
    print(ans)

if __name__ == "__main__":
    main()

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

struct Edge {
    int id;
    int to;
    int color;
    Edge(int i, int t, int c) : id(i), to(t), color(c) { }
};
using Graph = vector<vector<Edge>>;

int N;

void bfs(Graph& G, int s) {
    queue<int> que;
    que.push(s);

    while (!que.empty()) {
        vector<bool> colors(N-1, false);  // 最大でもN-1色あればOK。
        
        int v = que.front();
        que.pop();

        // cout << v << endl;
        
        for (Edge& next_e : G[v]) {
            if (next_e.color != -1) {
                colors[next_e.color] = true;
            }
        }

        for (Edge& next_e : G[v]) {
            if (next_e.color == -1) {
                int color = -1;
                rep(i, N-1) {
                    if (colors[i] == false) {
                        color = i;
                        colors[i] = true;
                        break;
                    }
                }
                next_e.color = color;
                // 逆向きの色も塗る。
                for (Edge &ne : G[next_e.to]) {
                    if (ne.to == v) ne.color = color;
                }

                que.push(next_e.to);
            }
        }
    }
}

int main() {
    cin >> N;

    Graph G(N);
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back({i, b, -1});
        G[b].push_back({i, a, -1});
    }

    bfs(G, 0);

    int K = 0;
    vector<P> ans;
    rep(i, N) {
        for (auto next_e : G[i]) {
            K = max(K, next_e.color);
            ans.push_back({next_e.id, next_e.color});
        }
    }

    // sort(ans.begin(), ans.end());

    map<int, int> mp;
    rep(i, N) {
        for (auto next_e : G[i]) {
            mp[next_e.id] = next_e.color;
        }
    }

    // cout << "here?" << endl;
    cout << K + 1 << endl;
    // for (auto a : ans) {
    //     cout << a.second + 1 << endl;
    // }

    for (auto p : mp) {
        cout << p.second + 1 << endl;
    }
}

Measured memory_bytes: 15968
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a,b;
  cin >> a >> b;
  if(a == 'H' && b == 'H')
    cout << 'H' << endl;
  else if(a == 'D' && b == 'D')
    cout << 'H' << endl;
  else
    cout << 'D' << endl;
}


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

const int MAX = 1e5+5;
int arr[MAX][3];
int dp[MAX][3];

int solve(int i, int j){
    if(dp[i][j]!=-1) return dp[i][j];
    if(i==0){
        return dp[i][j]=arr[i][j];
    }
    int a = (j+1)%3;
    int b = (j+2)%3;
    return dp[i][j]=max(solve(i-1, a), solve(i-1, b))+arr[i][j];
}


int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>arr[i][j];
        }
    }
    memset(dp, -1, sizeof dp);
    int res = max(solve(n-1, 0), max(solve(n-1, 1), solve(n-1, 2)));
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  for(int i = 0; i < N; ++i) cin >> B[i];
  int ans = 0, mask = 0;
  for(int i = 0; i < 29; ++i){
    mask |= (1<<i);
    vector<int> a(N), b(N);
    for(int j = 0; j < N; ++j) a[j] = A[j]&mask;
    for(int j = 0; j < N; ++j) b[j] = B[j]&mask;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    long long c = 0;
    for(auto e : a){
      int l = (1<<i)-e, r = (1<<(i+1))-e;
      // count {bi | l <= bi < r}
      c += lower_bound(b.begin(), b.end(), r)
        - lower_bound(b.begin(), b.end(), l);
      l += (1<<(i+1));
      r += (1<<(i+1));
      c += lower_bound(b.begin(), b.end(), r)
        - lower_bound(b.begin(), b.end(), l);
    }
    
    if(c%2) ans |= (1<<i);
  }
  cout << ans << endl;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
	ull n, k;
	cin >> n >> k;
	cout << ( n >= 2 * k - 1 ? "YES" : "NO" ) << endl;
	return 0;
}

Measured memory_bytes: 256