akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
vector<int>g[100005];
int deg[100005];
ll ans[100005];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a>> b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }
    vector<ll>c(n);
    rep(i,n)cin >> c[i];
    sort(c.begin(),c.end());
    queue<int>q;
    rep(i,n)if(deg[i]==1)q.push(i);
    ll sum = 0;
    int pos = 0;
    while(q.size()){
        int x = q.front();
        q.pop();
        if(deg[x] != 1)continue;
        ans[x] = c[pos];
        pos++;
        sum += ans[x];
        for(int b : g[x]){
            deg[b]--;
            if(deg[b] == 1)q.push(b);
        }
    }
    rep(i,n)if(!ans[i])ans[i] = c[pos];
    cout << sum << endl;
    rep(i,n){
        if(i)cout << " ";
        cout << ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 3328
X = int(input())

if 400<=X<600:
    ans = 8

elif 600<=X<800:
    ans = 7

elif 800<=X<1000:
    ans = 6

elif 1000<=X<1200:
    ans = 5

elif 1200<=X<1400:
    ans = 4

elif 1400<=X<1600:
    ans = 3

elif 1600<=X<1800:
    ans = 2

elif 1800<=X<2000:
    ans = 1

print(ans)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define int long long
using namespace std;

signed main(){
	int a,b,ans=0;
	cin>>a;
	f(i,a){
		cin>>b;
		if(b%2-1) ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3104
from sys import stdin
input = stdin.readline

n, m = map(int, input().split())
h = [int(x) for x in input().split()]

h.insert(0, 0)

c = [[0] for x in range(n + 1)]

for _ in range(m):
    a, b = map(int, input().split())

    c[a].append(h[b])
    c[b].append(h[a])

cnt = 0

for x in range(1, n + 1):
    if h[x] > max(c[x]):
        cnt += 1

print(cnt)

Measured memory_bytes: 26104
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  lol n, a, b;
  cin >> n >> a >> b;
  lol na = b * (n - 1);
  lol su = a *(n - 1);
  na += a;
  su += b;
  if(su > na){
    cout << "0\n";
  } else {
    cout << na - su + 1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		long N = sc.nextLong();

		long[] a = new long[5];
		for (int i = 0; i < 5; i++) a[i] = sc.nextLong();
		Arrays.sort(a);
		System.out.println((long)Math.ceil((double)N/a[0])+4);
	}
}


Measured memory_bytes: 22100
(function (input) {
    var inputs = input.replace(/\r/g, '').split("\n");

    while(true) {
        var cards = [],
            line = inputs.shift().split(" "),
            n = parseInt(line[0]),
            r = parseInt(line[1]);

        if ( n === 0 && r === 0 ) break;

        for ( var i = n; i > 0; i-- ) {
            cards.push(i);
        }

        // シャッフルする回数分だけ
        while(r--) {
            var line = inputs.shift().split(" "),
                p = parseInt(line[0]) - 1,  // 添字なので
                c = parseInt(line[1]),
                tmp;

            tmp = cards.splice(p, c);
            cards = tmp.concat(cards);
        }

        console.log(cards.shift());
    }
})(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 10840
def main():
    from collections import Counter
    n = int(input())
    s = [input() for _ in range(n)]
    ss = set(s)
    m = int(input())
    t = [input() for _ in range(m)]
    res = 0
    for i in ss:
        tmp = s.count(i) - t.count(i)
        res = max(tmp,res)
    print(res)

if __name__ == '__main__':
    main()



Measured memory_bytes: 38256
import java.util.Scanner
import scala.annotation.tailrec

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val a = Seq.fill(n)(BigInt(sc.nextLong))
  val maxNum = BigInt("1000000000000000000")

  if (a.contains(BigInt(0))) {
    println(0)
  } else {
    println(loop(BigInt(1), a))
  }

  @tailrec def loop(acc: BigInt, li: Seq[BigInt]): BigInt = li match {
    case _ if (acc > maxNum) => BigInt(-1)
    case x::xs => loop(acc * x, xs)
    case _ => acc
  }
}

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

//ABC169D
//ABC169C
//ABC169B
//ABC169A
int main(void) {
  int n, k, i, cou=0, tmp;
  scanf("%d %d", &n, &k);
  printf("%d", n*k);
}


Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> P;
#define F first
#define S second
int n;
vector<P>g[100005];
P m;
void dfs(int v,int p,int d){
    if(m.S<d){
        m.F=v;
        m.S=d;
    }
    for(int i=0;i<g[v].size();i++){
        if(g[v][i].F!=p)dfs(g[v][i].F,v,d+g[v][i].S);
    }
}
int main(void){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b,w;
        cin>>a>>b>>w;
        g[a].push_back(P(b,w));
        g[b].push_back(P(a,w));
    }
    dfs(0,-1,0);
    dfs(m.F,-1,0);
    cout<<m.S<<endl;
}



Measured memory_bytes: 13268
package main

import (
	"fmt"
	"sort"
)

type HS []uint64

func (h HS) Len() int {
	return len(h)
}

func (h HS) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h HS) Less(i, j int) bool {
	return h[i] > h[j]
}

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)

	Hs := make([]uint64, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&Hs[i])
	}

	sort.Sort(HS(Hs))

	var attackCount uint64
	for i := 0; i < N; i++ {
		if K > 0 {
			K--
			continue
		}
		attackCount += Hs[i]
	}

	fmt.Println(attackCount)
}


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

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

    static class BBiteEating {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            int l = sc.nextInt();
            int sum = 0;
            for (int i = 0; i < n; i++) {
                sum += (l + i);
            }
            int diff = Math.abs(sum - (sum - l));
            int ans = sum - l;
            for (int i = 1; i < n; i++) {
                if (diff > Math.abs(sum - (sum - l - i))) {
                    ans = sum - l - i;
                    diff = Math.abs(sum - (sum - l - i));
                }
            }
            out.println(ans);
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

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

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

    }
}



Measured memory_bytes: 21588
n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
for i in range(n):
    for j in range(i+1,n):
        k=2*j-i
        if k>=n:
            continue
        if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
            ans-=1
print(ans)


Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    long long A, B, C;
    scanf("%lld %lld %lld", &A, &B, &C);
    if(A < B){
        swap(A, B);
    }
    if(A < C){
        swap(A, C);
    }
    if(A % 2 == 0 || B % 2 == 0 || C % 2 == 0){
        printf("0\n");
        return 0;
    }else{
        printf("%lld\n", B * C);
    }
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    map<long long, int> M;
    long long a;
    for(int i = 0; i < N; i++){
        cin >> a;
        M[a]++;
    }

    vector<long long> A;
    for(auto p : M){
        if(p.second >= 4){
            A.push_back(p.first);
            A.push_back(p.first);
        }else if(p.second >= 2){
            A.push_back(p.first);
        }
    }

    sort(A.begin(), A.end());

    long long ans;
    if(A.size() >= 2){
        ans = A[A.size()-1] * A[A.size()-2];
    }else{
        ans = 0;
    }

    cout << ans << endl;


    return 0;
}

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

int main() {
    int n;
    cin >> n;
    map<string, ll> mp;
    rep(i,n) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    } 
    ll ans = 0;
    for (auto x : mp) {
        ll y = x.second;
        ans += y*(y-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11444
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int M, D;
    cin >> M >> D;

    int ans = 0;

    rep(m, 1, M + 1) {
        rep(d, 1, D + 1) {
            if (d % 10 >= 2 && d / 10 >= 2 && (d % 10) * (d / 10) == m) {
                ans++;
            }
        }
    }

    write(ans);
}

Measured memory_bytes: 256
// Aizu Vol-5 0505: Questionnaire
// 2017.8.30 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

typedef struct { int m, c; } T;
T p[1002];
	
int cmp(T *a, T *b) { if (b->c - a->c) return b->c - a->c; return a->m - b->m; }

int main()
{
	int n, m;
	int i, a;

	while (scanf("%d%d", &n, &m) && n) {
		for (i = 1; i <= m; i++) p[i].m = i, p[i].c = 0;
		while (n-- > 0)
			for (i = 1; i <= m; i++) scanf("%d", &a), p[i].c += a;
		qsort(p+1, m, sizeof(T), cmp);
		printf("%d", p[1].m);
		for (i = 2; i <= m; i++) printf(" %d", p[i].m);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 608
from collections import defaultdict as dd
H,W,N=map(int,input().split())
ab = [tuple(map(int,input().split())) for _ in range(N)]
tpl = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),(0,1),(1,-1),(1,0),(1,1)]
edge_WtoB = dd(int)
edge_BtoB = dd(int)
node_B = set(ab)
# node_W = set()
res = dd(int)
# 今見てるマスが黒
for a,b in ab:
    for s,t in tpl:
        tgt = (a+s,b+t)
        # 隣接マスも黒
        if tgt in node_B:
            if not (1 < a < H and 1 < b < W):
                continue
            edge_BtoB[(a,b)] += 1
        # 隣接マスは白
        else:
            if not (1 < a + s < H and 1 < b + t < W):
                continue
            edge_WtoB[tgt] += 1
            # node_W.add(tgt)
for val in edge_WtoB.values():
    res[val] += 1
for val in edge_BtoB.values():
    res[val] += 1
zero = (H-2)*(W-2)
for j in range(1,10):
    zero -= res[j]
res[0] = zero
for j in range(10):
    print(res[j])

Measured memory_bytes: 165748
N = int(input())
A = []
for i in range(N):
    s,p = input().split()
    p = int(p)
    A.append((i+1,s,p))
A = sorted(A,key=lambda x:x[2],reverse=True)
A = sorted(A,key=lambda x:x[1])
for i in range(N):
    print(A[i][0])

Measured memory_bytes: 38512
n, m, l = map(int, input().split())
n_m_matrix = [list(map(int, input().split())) for _ in range(n)]
m_l_matrix = [list(map(int, input().split())) for _ in range(m)]
result = []

for i in range(n):
    tmp_list = []
    for k in range(l):
        tmp = 0
        for j in range(m):
            tmp += n_m_matrix[i][j] * m_l_matrix[j][k]
        tmp_list.append(tmp)
    result.append(tmp_list)

[print(result[i][j]) if j == (l - 1) else print(result[i][j], end=' ') for i in range(n) for j in range(l)]



Measured memory_bytes: 7156
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

// UnionFind 構造体 for tree
type UnionFind struct {
	par []int
}

/*コンストラクタ*/
func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.par = make([]int, N)
	for i := range u.par {
		u.par[i] = -1
	}
	return u
}
func (u UnionFind) root(x int) int {
	if u.par[x] < 0 {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}
func (u UnionFind) unite(x int, y int) {
	xr := u.root(x)
	yr := u.root(y)
	if xr == yr {
		return
	}
	u.par[yr] += u.par[xr]
	u.par[xr] = yr
}
func (u UnionFind) same(x, y int) bool {
	if u.root(x) == u.root(y) {
		return true
	}
	return false
}
func (u UnionFind) size(x int) int {
	return -u.par[u.root(x)]
}

var mod int = 1000000007

type pair struct {
	fi int
	se int
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	//予備
	a := iScan()
	b := iScan()
	fmt.Println((a + b) % 24)
}

Measured memory_bytes: 1776
N,M = map(int,input().split())

B = [1 for i in range(N)]
P = set([1])
for i in range(M):
    x,y = map(int,input().split())
    B[x-1] -= 1
    B[y-1] += 1
    if x in P:
        P.add(y)
    if B[x-1] == 0 and x in P:
        P.remove(x)
        
print(len(P))

Measured memory_bytes: 12808
A, B, C, X, Y = input().split(' ')
A = int(A)
B = int(B)
C = int(C)
X = int(X)
Y = int(Y)
if A > 2*C:
  A = 2*C
if B > 2*C:
  B = 2*C
if A + B <= 2*C:
  print(A*X+B*Y)
else:
  if X > Y:
    sum = (X-Y)*A + Y*2*C
  else:
    sum = (Y-X)*B + X*2*C
  print(sum)

Measured memory_bytes: 9104
#include <bits/stdc++.h> 
#define forn(i,a,b) for(int i=a; i<=b; i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define pb push_back
#define mp make_pair
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	int cost=0;
	if(n<=k) cost+=(x*n);
	else cost+=((x*k) + (y*(n-k)));
	cout<<cost<<endl; 
}

Measured memory_bytes: 3632
import sys
from sys import stdin

mod = 1000000007

n = int(stdin.readline().rstrip())
# s = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]

a = sorted(a)
predict = [n - (((n - i + 1) // 2) * 2) + 1 for i in range(0, n)]
if a != predict:
    print(0)
    sys.exit()
print(pow(2, (n // 2), mod))
# print(*data, sep='\n')


Measured memory_bytes: 56556
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
using namespace std;

int main(){
	int a[101] = {};
	int n,res1 = 0,res2 = 0,m = 1000;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		res1 += a[i];
	}

	for(int i = 0;i < n;i++){
		res1 -= a[i];
		res2 += a[i];
		if(res1 > res2){
			m = min(m, res1-res2);
		}
		else{
			m = min(m, res2-res1);
		}
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  ll N;
  cin >> N;
  vector<int> a;
  int i=0;
  while(N>0){
    N -= 1;
    a.push_back(N%26);
    N/=26;
  }
  
  for(ll j=a.size()-1;j>=0;j--){
    cout << char('a'+a[j]);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3096
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int W = sc.nextInt();
    int[] w = new int[N];
    int[] v = new int[N];

    for (int i = 0; i < N; i++) {
      w[i] = sc.nextInt();
      v[i] = sc.nextInt();
    }

    sc.close();

    long[][] dp = new long[N+1][W+1];

    for (int i = N - 1; 0 <= i; i--) {
      for (int j = 0; j <= W; j++) {
        if (j < w[i]) {
          dp[i][j] = dp[i + 1][j];
        } else {
          dp[i][j] = Math.max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
        }
      }
    }

    System.out.println(dp[0][W]);

  }

}


Measured memory_bytes: 127316
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a, T b){return (a < b ? a = b, true : false);}
template<typename T>inline bool chmin(T &a, T b){return (a > b ? a = b, true : false);}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const long double EPS = 1e-9;

struct Monoid {
    Monoid() {}
    using T = int;
    T operator()(const T& a, const T& b) {
        return a + b;
    }
    T identity() {return 0;}
};
class SegmentTree {
private:
    using T = Monoid::T;
    std::vector<T> seg;
    Monoid ope;
    const int size;
    const int cap;
public:
    SegmentTree() : size(0), cap(0) {}
    SegmentTree(const int &sz) : size(sz), cap(sz << 1), seg(sz << 1, ope.identity()) {}
    void update(int idx, const T &val) {
        /* ???????????????????????§??? */ 
        seg[idx += size] += val;
        /*******************/
        while (idx >>= 1) seg[idx] = ope(seg[idx << 1], seg[(idx << 1) + 1]);
    }
    // range is [left, right) !!!!!!!!
    T get(int left, int right) {
        T leftRes = ope.identity(), rightRes = ope.identity();
        for (left += size, right += size; left < right; left >>= 1, right >>= 1) {
            if (left & 1) leftRes = ope(leftRes, seg[left++]);
            if (right & 1) rightRes = ope(rightRes, seg[--right]);
        }
        return ope(leftRes, rightRes);
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree st(n);
    while (q--) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com) {
            cout << st.get(x - 1, y) << endl;
        } else {
            st.update(x - 1, y);
        }
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
using llong = long long;

const llong INF = 1ll << 60ll;
llong n, s;

llong f(llong b, llong n) {
    if (n < b) return n;
    return f(b, n / b) + n % b;
}

int main() {
    
    cin >> n >> s;

    llong ans = INF;

    if (n == s) ans = n + 1;

    for (llong d = 1; d * d < n; d++) {
        llong m = s - d;
        llong b = (n - m) / d;

        if (b > 1 && m >= 0 && b > m && b > d && d * b + m == n) ans = min(ans, b);
    }

    for (llong b = 2; b * b <= n; b++) {
        if (f(b, n) == s) ans = min(ans, b);
    }

    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}


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

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

  vector<string> ans;

  for (int i = 0; i <= int(S.size() - T.size()); i++) {
    bool b = 1;
    for (int j = 0; j < T.size(); j++) {
      if (S.at(j + i) != T.at(j) && S.at(j + i) != '?') b = 0;
    }
    if (b) {
      string s = S;
      for (int j = 0; j < T.size(); j++) s.at(j + i) = T.at(j);
      for (int j = 0; j < s.size(); j++) {
        if (s.at(j) == '?') s.at(j) = 'a';
      }
      ans.push_back(s);
    }
  }

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

  cout << ((ans.size()) ? ans.at(0) : "UNRESTORABLE") << "\n";
}

Measured memory_bytes: 256
def readinput():
    n=int(input())
    return n

def getKeta(n):
    m=n-1
    base=0
    keta=1
    base+=26**keta
    while(m>=base):
        keta+=1
        base+=26**keta
    return keta

def naming(keta,n):
    alph='abcdefghijklmnopqrstuvwxyz'
    geta=26*(26**(keta-1)-1)//25
    m=n-geta-1
    name=''
    for _ in range(keta):
        r=m%26
        m=m//26
        name=alph[r]+name
    return name

def main(n):
    keta=getKeta(n)
    #print(keta)
    
    name=naming(keta,n)

    return name



if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)


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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    REP(i,0,n)cin >> vec[i];
    bool judge=false;
    bool one_judge=true;
    REP(k,0,n-1){
        if(vec[k]>vec[k+1])one_judge=false;
    }
    if(one_judge){
        judge=true;
        goto LABEL;
    }

    REP(i,0,n){
        REP(j,i+1,n){
            swap(vec[i],vec[j]);
            one_judge=true;
            REP(k,0,n-1){
                if(vec[k]>vec[k+1])one_judge=false;
            }
            if(one_judge){
                judge=true;
                goto LABEL;
            }
            swap(vec[i],vec[j]);
        }
    }
    LABEL:
    if(judge){
        P("YES");
    }else{
        P("NO");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#include<tuple>
#define all(c) c.begin(),c.end()
#define tr(x,n) for(int i=x;x<n?i<n:i>=n;x<n?i++:i--)
#define ll long long int
#define pb push_back
#define em emplace_back
#define mp make_pair
#define mt make_tuple
#define debug(c) cout<<c<<endl;
#define isro ios_base::sync_with_stdio(false);
#define find(v,x) find(all(v),x)!=v.end()


using namespace std;
typedef vector<ll>vi;
typedef vector<vi>vii;
typedef pair<ll,ll>pi;
typedef tuple<ll,ll,ll>ti;

ll mod=1e9;

int main(){
    isro;

    ll a,b,c;
    cin>>a>>b>>c;
    cout<<min(a+b,min(b+c,c+a));
}

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

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))


int main(void)
{
	//変数の宣言
	int n;
	static int t[100010];
	static int x[100010];
	static int y[100010];
	
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int sum=0;
	llong int temp,temp1,temp2;
	int max,min;
	//int len;
	//データの読み込み
	
	scanf("%d",&n);
	
	for(i=1;i<=n;i++){
		scanf("%d %d %d",&t[i],&x[i],&y[i]);
	}
	t[0]=0;
	x[0]=0;
	y[0]=0;
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	flag=1;
	for(i=1;i<=n;i++){
//		printf("%d %d\n",t[i]-t[i-1],abs(x[i]-x[i-1])+abs(y[i]-y[i-1]));
		if(t[i]-t[i-1]<abs(x[i]-x[i-1])+abs(y[i]-y[i-1])||(t[i]-t[i-1]-abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))%2==1){
//			printf("i=%dでflag変化\n",i);
			flag=0;
		}
	}
	
//	printf("計算部分終了\n");
	//出力
	
	if(flag==0){
		printf("No");
	}else{
		printf("Yes");
	}
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
  else if (A+B >= C+D) {
    cout << "Left" << endl;
  }
  else if (A+B <= C+D) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
/*-----------------------------------------------,
|  __                                       __   |
| |  |--.-----.---.-.----.----.-----.-----.|  |_ |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _||
| |_____|_____|___._|____|____|_____|   __||____||
|                                   |__|         |
`-----------------------------------------------*/
#define DEBUG
#include<algorithm>
#include<array>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<tuple>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long ll; using namespace std;
#define INF 1000000000000
#define MOD 10000007
#define REP(counter, limit) for (long long counter = 0; counter < limit; counter++)
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){cin.tie(0);ios::sync_with_stdio(0); /*cout<<fixed<<setprecision(20);*/};}setupios;
int main() {

  int n,t;
  cin>>n>>t;
  vector<int> r(n);
  REP(i,n)cin>>r[i];
  int ans=0;
  REP(i,n-1){
    if(r[i+1]-r[i]>t){
      ans+=t;
    }else{
      ans+=r[i+1]-r[i];
    }
  }
  cout<<ans+t<<endl;


}


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

void show(int arr[], int N){
	for(int i=0; i<N; i++)
		if(i<N-1)
			cout<<arr[i]<<' '<<flush;
		else
			cout<<arr[i]<<flush;
	cout<<endl;
}

int ShellSort(int*, int);
int InsertionSort_r(int*, int, int);

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

	int* arr=new int[N];

	for( int i=0; i<N; i++)
		cin>>arr[i];
	
	int cnt=ShellSort(arr, N);

	cout<<cnt<<endl;

	for( int i=0; i<N; i++)
		cout<<arr[i]<<endl;

	delete[] arr;
}


int ShellSort(int arr[], int N)
{
	vector<int> range;

	for( int g=1; g <= N;){
		range.push_back(g);
		g=g*3+1;
	}

	cout<<range.size()<<endl;
	for( int i=range.size() -1; i>=0; i--) 
		cout<<range[i]<<' '<<flush;
	cout<<endl;


	int count;
	for( int i=range.size() -1; i>=0; i-- )
		count=InsertionSort_r(arr, N, range[i]);

	return count;
}


int InsertionSort_r(int arr[], int N, int r)
{
	static int cnt=0;
	bool changed=false;
	for( int compindex=r; compindex<N; compindex++) {

		int comp= arr[compindex];

		int j=compindex - r;

		for( ; j>=0; j-=r ) {
			if(arr[j] > comp){
				arr[ j+r ]=arr[j];
				cnt++;
				changed=true;
			}
			else
				break;
		}

		arr[ j+r ] =comp;


		changed=false;
	}
	return cnt;
}
				




	
	


	

Measured memory_bytes: 4896
read n
read pstr
declare -a p=($pstr)

count=0
tigai=0
for i in ${p[@]}
do
count=$((count+1))
if test $count -ne $i
then
  tigai=$((tigai+1))
fi
done

if test $tigai -ge 3
then
  echo NO
else
  echo YES
fi



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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  if(N % 2 == 0) {
    if(N / 2 >= K) cout << "YES" << endl;
    else cout << "NO" << endl;
  } else {
    if(N / 2 + 1 >= K) cout << "YES" << endl;
    else cout << "NO" << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int K, S;
  cin >> K >> S;

  long long count = 0;
  rep(x, K+1) {
    rep(y, K+1) {
      int z = S - x - y;
      if (0 <= z && z <= K) count++;
    }
  }

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


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

int main() {
  int N = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int tmp = 0;
    cin >> tmp;
    
    if (tmp % 2 == 0) {
      if (tmp % 3 != 0 and tmp % 5 != 0) {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  
  cout << "APPROVED" << endl;
}

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

int main(){
  int n; cin >> n;
  vector<long long> v, e;
  e.push_back(0);
  for (int i = 0; i < n; i++) {
    long long c; cin >> c;
    v.push_back(c);
    e.push_back(c+e[i]);
  }
  int low = 0; int high = 0;
  long long ans = 0;
  long long x = 0;
  while (low != n || high != n) {
    if (x & v[high] || high == n) {
      ans += high - low;
      low++;
      x = e[high] - e[low];
    } else {
      x += v[high];
      high++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

long long MOD = 1000000007;
vector<int> C;
long long dp[200005];
long long dp2[200005];

int main(void){
    int N; cin >> N;
    for (int i = 0; i < N; i++){
        int c; cin >> c;
        C.push_back(c);
    }
    vector<int> tmp;
    for (int i = 0; i < N; i++){
        if (i == 0){
            tmp.push_back(C[i]);
        }else if (*tmp.rbegin() != C[i]){
            tmp.push_back(C[i]);
        }
        if (i == N-1) C = tmp;
    }
    dp[0] = 1;
    for (int i = 0; i < C.size(); i++){
        dp[i+1] += dp[i];
        dp[i+1] %= MOD;
        dp[i+1] += dp2[C[i]];
        dp[i+1] %= MOD;
        dp2[C[i]] += dp[i];
        dp2[C[i]] %= MOD;
    }
    cout << dp[C.size()] << endl;
    return 0;
}


Measured memory_bytes: 5356
#include<stdio.h>
int main(void){
  int a,b;
  int tmp=0;
  int cnt=2;
  
  scanf("%d",&a);
  scanf("%d",&b);
  
  while(cnt>0){
   if(a>=b){
     tmp += a;
     a--;
   }
   else{
     tmp += b;
     b--;
   }
    cnt--;
  }
  printf("%d\n", tmp);
  
  return 0;
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


void seethis(vector<ll>vect)
{
    for(ll x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

int main()
{
	FASTIO;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/
	string s;
	 cin>>s;
	 if(s=="ARC")
	 	cout<<"ABC\n";
	 else 
	 	cout<<"ARC\n";
	
	return 0;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;


const ll mod = 1e9 + 7;

const int N = 41;
const int S = 1 << 18;
ll dp[N][S];
int next_tbl[S][11];
int n, x, y, z;
int qs;

int next_state_nfa(int q, int s) {
  int lim;
  assert (q < qs);
  if (q < x) {
    lim = x;
  } else if (q < x + y) {
    lim = x + y;
  } else if (q < x + y + z) {
    lim = x + y + z;
  } else {
    return x + y + z;
  }
  
  if (q + s <= lim) {
    return q + s;
  }
  return -1;
}

int next_state(int q, int s) {
  int bits = 1;
  REP(i, 0, qs) {
    if (q & (1 << i)) {
      int r = next_state_nfa(i, s);
      if (r >= 0) bits |= 1 << r;
    }
  }
  return bits;
}

int main(void){
  cin >> n >> x >> y >> z;
  qs = x + y + z + 1;
  dp[0][1] = 1;
  REP(bits, 0, 1 << qs) {
    REP(s, 1, 11) {
      next_tbl[bits][s] = next_state(bits, s);
    }
  }
  REP(i, 1, n + 1) {
    REP(bits, 0, 1 << qs) {
      REP(s, 1, 11) {
	int next = next_tbl[bits][s];
	dp[i][next] += dp[i - 1][bits];
	dp[i][next] %= mod;
      }
    }
  }
  ll sum = 0;
  REP(bits, 1 << (qs - 1), 1 << qs) { // final states
    sum += dp[n][bits];
    sum %= mod;
  }
  cout << sum << endl;
}


Measured memory_bytes: 93440
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

const i64 NUM = 1000000007LL;

i64 mod_pow(i64 a, i64 b) {
  i64 ans = 1;
  while(b != 0) {
    if(b % 2 == 1) {
      ans *= a;
      ans %= NUM;
    }
    a = a * a;
    a %= NUM;
    b /= 2;
  }
  return ans;
}

i64 mod_C(i64 n, i64 k) {
  i64 a = 1, b = 1, i;
  REP(1, k+1, i) {
    a *= n - i + 1;
    b *= i;
    a %= NUM;
    b %= NUM;
  }
  //cout << a << " " << b << endl;
  i64 b_inv = mod_pow(b, NUM - 2);
  //cout << b_inv << " " << a * b_inv << endl;
  return (a * b_inv) % NUM;
}

int main(int argc, char *argv[]) {

  i64 n, a, b;
  cin >> n >> a >> b;
  i64 ans;
  ans = mod_pow(2, n) - 1;
  //cout << mod_C(n, a) << " " << mod_C(n, b) << endl;
  ans -= mod_C(n, a);
  ans += NUM;
  ans %= NUM;
  ans -= mod_C(n, b);
  ans += NUM;
  ans %= NUM;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{
  int n;
  int max=0;
  int ans=0;
  cin>>n;
  reps(i,n+1){
    int count=0;
    int tmp=i;
    while(tmp>0){
      tmp/=2;
      count++;
    }
    if(count>max){
      ans=i;
      max=count;
    }
  }

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


Measured memory_bytes: 3592
n=int(input())
 
 
def getSum(n):
 
    sum = 0
 
    
    while(n > 0):
        sum += int(n%10)
        n = int(n/10)
 
    return sum
if getSum(n)==1:
    print(10)
else:
    print(getSum(n))

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

int M, N;
string hata[1010];
string monsyo[2];
int di[4] = {-1, -1, 0, 0};
int dj[4] = {-1, 0, -1, 0};

int f(int i, int j, char c) {
	//printf("f(%d, %d, %c) called\n", i, j, c);

	int pre_num = 0;
	rep(k,4) {
		int ni = i + di[k];
		int nj = j + dj[k];
		if (ni >= 0 && ni+1 < M && 0 <= nj && hata[ni].substr(nj,2) == monsyo[0] && hata[ni+1].substr(nj,2) == monsyo[1]) {
			pre_num++;
		}
	}

	//printf("AAA\n");

	char pre_char = hata[i][j];
	hata[i][j] = c;
	int new_num = 0;
	rep(k,4) {
		int ni = i + di[k];
		int nj = j + dj[k];
		if (ni >= 0 && ni+1 < M && 0 <= nj && hata[ni].substr(nj,2) == monsyo[0] && hata[ni+1].substr(nj,2) == monsyo[1]) {
			new_num++;
		}
	}
	hata[i][j] = pre_char;

	//printf("BBB\n");

	return new_num - pre_num;
}

signed main()
{
	cin >> M >> N;
	rep(i,M) cin >> hata[i];
	rep(i,2) cin >> monsyo[i];

	int num = 0;
	rep(i,M-1) rep(j,N-1) {
		if (hata[i].substr(j, 2) == monsyo[0] && hata[i+1].substr(j, 2) == monsyo[1]) {
			num++;
		}
	}

	//printf("num = %d\n", num);

	int mx = -1;
	rep(i,M) rep(j,N) {
		mx = max(mx, f(i, j, 'J'));
		mx = max(mx, f(i, j, 'O'));
		mx = max(mx, f(i, j, 'I'));
	}

	cout << num + mx << endl;
}

Measured memory_bytes: 4140
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define rad M_PI/3
#define N 2147483647
#define Max 500000
#define NTL -1
#define min(a,b) ((a>b)?b:a)

int main(){
  int n,i,x=0,y=0,tmp,count,p=1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    int ch,ok=0;
    scanf("%d",&ch);
    for(x=1;x*x<ch;x++){
      if((ch-x)%(2*x+1)==0){
        ok=1;
        break;
      }
    }
    if(ok==0){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 2100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.StringTokenizer;

public class Main  implements Runnable {
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 64 * 1024 * 1024).start();
    }
    public void run() {
    	FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int m = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int ans = 0;
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= d; j++) {
				int d1 = j%10;
				int d10 = j/10;
				if(d1 >= 2 && d10 >= 2 && d1*d10 == i)
				{
					ans++;
				}
			}
		}



		out.printf("%d\n", ans);
		out.println();
		out.flush();
	}


    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }
        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }
    }
}


Measured memory_bytes: 23892
import sys

# import bisect
# from collections import Counter, deque, defaultdict

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
from operator import attrgetter, itemgetter

# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))
    pyir = [[0] * 4 for _ in range(m)]

    for i in range(m):
        p, y = list(map(int, readline().split()))
        pyir[i][0] = p
        pyir[i][1] = y
        pyir[i][2] = i

    pyir.sort(key=itemgetter(0,1))

    x = 0
    pprev = pyir[0][0]

    for i in range(m):
        if pprev != pyir[i][0]:
            x = 0
        x += 1
        pyir[i][3] = str(pyir[i][0]).zfill(6) + str(x).zfill(6)
        pprev = pyir[i][0]

    pyir.sort(key=itemgetter(2))

    for i in range(m):
        print(pyir[i][3])

if __name__ == '__main__':
    main()


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

int main(){

  int a,b;
  cin >> a >> b;

  int tmp = a - b*2;
  if (tmp < 0){
    cout << 0 << endl;
  } else {
    cout << tmp << endl;
  }

  return 0;
}


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

struct qu{
	int t;
	int f;
	char c;
};

int main(){
	string S;
	int Q;
	cin >> S >> Q;
	
	bool dir=true;
	string R="";
	string T="";
	
	vector<qu> q;
	
	for(int i=0;i<Q;i++){
		qu tfc;
		cin >> tfc.t;
		if(tfc.t==2){
			cin >> tfc.f >> tfc.c;
			tfc.f--;
		}
		q.push_back(tfc);
	}
	
	reverse(q.begin(),q.end());
	
	for(auto tfc:q){
		if(tfc.t==1)dir=(!dir);
		else{
			if(!dir)tfc.f=(tfc.f+1)%2;
			if(tfc.f==0)R+=tfc.c;
			else T+=tfc.c;
		}
	}
	
	reverse(T.begin(),T.end());
	
	if(dir)cout << R << S << T << endl;
	else{
		reverse(S.begin(),S.end());
		cout << R << S << T << endl;
	}
	
	return 0;
}

Measured memory_bytes: 4788
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int num = scan.nextInt();
      	int[] array = new int[num];
      	for(int i = 0; i < num; i++){
        	array[i] = scan.nextInt();
        }
      	int max = array[0];
      	int min = array[1];
      	for(int i = 0; i < num; i++){
        	if(max < array[i]){
            max = array[i];
            }
        }
      	for(int i = 0; i < num; i++){
        	if(min > array[i]){
            min = array[i];
            }
        }
     	System.out.print(max - min);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x, y, z; cin >> x >> y >> z;
    cout << z << " " << x << " " << y << "\n";
    return 0;
}

Measured memory_bytes: 256