akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int n, a[101010];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a,a+n, greater<int>());
	
	i64 ans = 1;
	int ok = 0;
	for(int i = 1; i < n; i++){
		if(a[i-1] == a[i]){
			ans *= a[i];
			ok++;
			i++;
			if(ok == 2) break;
		}
	}
	if(ok) cout << ans << endl;
	else cout << 0 << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 640
// {{{ Template
// Author:  wenxing
// Date:    2018-01-07 20:04 +0800
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, l, r) for (int i = l; i < r; ++i)
#define per(i, r, l) for (int i = r; i >= l; --i)
#define repv(ele, vec) for (auto &ele : vec)
#define zero(mem) memset(mem, 0, sizeof(mem))
#define sd(_) scanf("%d", &_)
#define sdd(_, __) scanf("%d%d", &_, &__)
#define sddd(_, __, ___) scanf("%d%d%d", &_, &__, &___)
#define sdddd(_, __, ___, ____) scanf("%d%d%d%d", &_, &__, &___, &____)

#define sf(_) scanf("%f", &_)
#define sff(_, __) scanf("%f%f", &_, &__)
#define sfff(_, __, ___) scanf("%f%f%f", &_, &__, &___)
#define sffff(_, __, ___, ____) scanf("%f%f%f%f", &_, &__, &___, &____)

#define sl(_) scanf("%ld", &_)
#define sll(_, __) scanf("%ld%ld", &_, &__)
#define slll(_, __, ___) scanf("%ld%ld%ld", &_, &__, &___)
#define sc(_) scanf("%c", &_)
#define ss(_) scanf("%s", _)
#define mid(a, b) (((a) + (b)) >> 1)
#define lft(x) x << 1
#define rht(x) x << 1 | 1
#define inf 0x3f3f3f3f
#define mod 19260817
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
// }}}

// - Pseudocode -

// {{{ Global Variables
int n, d[200], cnt = 0, x;
// }}}

int main() {
    sd(n);
    zero(d);
    rep(i, 0, n) {
        sd(x);
        if (!d[x]) {
            d[x] = 1;
            ++cnt;
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,ans1=0,ans2=0,ans=0,ansf=10000;
  cin >> N;
  vector<int> d(N);
  for(int i=0;i<N;i++){ 
    cin >>d[i];
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<i+1;j++){
      ans1+=d[j];
    }
    for(int k=i+1;k<N;k++){
      ans2+=d[k];
    }
    ans=ans2-ans1;
    if(ans<0)ans*=-1;
    if(ansf>ans)ansf=ans;
    ans1=0;
    ans2=0;
    ans=0;
  }
  cout << ansf<< endl;
}

Measured memory_bytes: 256
package main

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

func print(a, b, c int) {
	if a > b {
		a, b = b, a
	} // a < b

	if c > b {
		fmt.Println(a, b, c)
	} else if c > a {
		fmt.Println(a, c, b)
	} else {
		fmt.Println(c, a, b)
	}
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(1)
	}
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	a := nextInt(scanner)
	b := nextInt(scanner)
	c := nextInt(scanner)
	print(a, b, c)
}



Measured memory_bytes: 1084
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

ll powmod(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}
ll inv(ll n) {
    return powmod(n, P - 2);
}

vector<int> f0, f1;
void init(int n) {
    f0.resize(n + 1);
    f0[0] = 1;
    for (int i = 1; i <= n; i++) {
        f0[i] = (ll)f0[i - 1] * i % P;
    }
    f1.resize(n + 1);
    f1[n] = inv(f0[n]);
    for (int i = n; i > 0; i--) {
        f1[i - 1] = (ll)f1[i] * i % P;
    }
}
ll fact(int k) {
    return f0[k];
}
ll comb(int n, int k) {
    if (n < k || k < 0) return 0;
    return (ll)f0[n] * f1[k] % P * f1[n - k] % P;
}

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

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    init(n);

    ll t = 0;
    for (int i = k - 1; i < n; i++) {
        t += comb(i, k - 1) * a[i] % P;
    }
    reverse(a.begin(), a.end());
    for (int i = k - 1; i < n; i++) {
        t -= comb(i, k - 1) * a[i] % P;
    }
    t %= P;
    if (t < 0) t += P;

    cout << t << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n;
    string s,t;
    cin >> n >> s >> t;

    int ans = 2*n;
    for (int i=0; i<n; i++) {
        int j = 0;
        bool f = true;
        while (j < n) {
            if (i+j >= n) break;
            if (s[i+j] != t[j]) {
                f = false;
                break;
            }
            j++;
        }
        if (f) ans = min(ans, i+n);
    }

    cout << ans << endl;
}


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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

const int MAX_N = 1000;
//const int MAX_M = 2000;
int n,m;

namespace bellman_ford {
  struct edge { int from, to, cost; };
  vector<edge> es;
  i64 d[MAX_N];
  int n,m;
  const i64 INF = INT64_MAX;

  void init(int a, int b)
  {
    n = a, m = b;
  }

  void add_edge(int f, int t, int c)
  {
    es.push_back((edge){f,t,c});
  }

  bool calc(int s)
  {
    fill_n(d,n,INF);
    d[s] = 0;
    for (int j = 0; j < n; j++) {
      bool ud = false;
      for (int i = 0; i < m; i++) {
        edge e = es[i];
        if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
          d[e.to] = d[e.from] + e.cost;
          ud = true;
          if (j+1==n && e.to == n-1) return false;
        }
      }
      if (!ud) break;
    }
    return true;
  }
}

int main()
{
  cin >> n >> m;
  bellman_ford::init(n,m);
  int a,b,c;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b >> c;
    bellman_ford::add_edge(a-1, b-1, -c);
  }

  bool found = bellman_ford::calc(0);

  if (!found)
    cout << "inf" << endl;
  else
    cout << -bellman_ford::d[n-1] << endl;

  return 0;
}


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

typedef long long ll;
const int N = 404, mod = 998244353;
int fac[N], inv[N];
inline int qpow(int b, int p) {
  int r = 1;
  for (; p; p >>= 1, b = (ll) b * b % mod) if (p & 1) {
    r = (ll) r * b % mod;
  }
  return r;
}
int n, p, s, a[N], b[N], f[N][N];

int main() {
  scanf("%d", &n);
  fac[0] = fac[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i < N; i++) {
    fac[i] = (ll) fac[i - 1] * i % mod;
    inv[i] = mod - (ll) mod / i * inv[mod % i] % mod;
  }
  for (int i = 2; i < N; i++) {
    inv[i] = (ll) inv[i] * inv[i - 1] % mod;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
  }
  f[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = p; j >= 0; j--) {
      int p1 = (ll) j * qpow(j + a[i], mod - 2) % mod, p2 = (mod + 1 - p1) % mod;
      for (int k = 0, c1 = 1; k <= s; k++, c1 = (ll) c1 * p1 % mod) if (f[j][k]) {
        for (int l = 0, c2 = 1; l < b[i]; l++, c2 = (ll) c2 * p2 % mod) {
          f[j + a[i]][k + l] = (f[j + a[i]][k + l] + mod - (ll) f[j][k] * fac[k + l] % mod * inv[k] % mod * inv[l] % mod * c1 % mod * c2 % mod) % mod;
        }
      }
    }
    p += a[i];
    s += b[i] - 1;
  }
  int ans = 0;
  for (int j = 1; j <= p; j++) {
    int c = qpow(j, mod - 2);
    for (int k = 0; k <= s; k++) if (f[j][k]) {
      ans = (ans + (ll) f[j][k] * p % mod * c) % mod;
    }
  }
  printf("%d\n", (mod - ans) % mod);
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <limits>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <memory>
//#include <tuple>

constexpr long long mod = static_cast<long long>(1e9 + 7);


int main() {
    int N, K;
    std::cin >> N >> K;
    std::unordered_map<int, int> map;
    while(N--) {
        int val;
        std::cin >> val;
        auto itr = map.find(val);
        if(itr == end(map)) map.insert(std::make_pair(val, 1));
        else ++itr->second;
    }

    std::vector<std::pair<int, int>> vec;
    vec.reserve(map.size());
    for(auto& val: map)
        vec.push_back(std::make_pair(val.second, val.first));
    std::sort(begin(vec), end(vec));

    int ans = 0;
    int i = 0;
    int sub = vec.size() - K;
    while(sub > 0) {
        ans += vec[i].first;
        ++i;
        --sub;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 10056
N = int(input())
A = list(map(int,input().split()))

R, B, G = 0, 0, 0
ans = 1

for a in A:
    if R == a:
        if B == a and G == a:
            ans *= 3
        elif B == a or G == a:
            ans *= 2
        else:
            ans *= 1
        R += 1
    elif B == a:
        if G == a:
            ans *= 2
        else:
            ans *= 1
        B += 1
    elif G == a:
        ans *= 1
        G += 1
    else:
        print(0)
        exit()
    
    ans %= 10**9+7

print(ans)

Measured memory_bytes: 84112
package main

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

func main() {
	sc = initScanner(os.Stdin)
	a, b := scanInt(sc), scanInt(sc)
	fmt.Println(solve(a, b))
}

func solve(a, b int) int {
	for n:=1;n<1300;n++ {
		if int(float64(n) * 0.08) == a && int(float64(n) * 0.10) == b {
			return n
		}
	}
	return -1
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanFloat64(sc *bufio.Scanner) float64 {
	sc.Scan()
	f, _ := strconv.ParseFloat(sc.Text(), 64)
	return f
}

func scanFloat64Slice(sc *bufio.Scanner, n int) []float64 {
	fs := make([]float64, n)
	for i := 0; i < n; i++ {
		fs[i] = scanFloat64(sc)
	}

	return fs
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}


Measured memory_bytes: 1780
n,s = map(int,input().split())
a = list(map(int,input().split()))
dp = [[0 for i in range(s+1)] for j in range(n+1)]
dp[0][0] = 1
mod = 998244353
for i in range(1,n+1):
  x = a[i-1]
  for j in range(s+1):
    dp[i][j] += dp[i-1][j]*2
    dp[i][j] %= mod
  for j in range(x,s+1):
    dp[i][j] += dp[i-1][j-x]
    dp[i][j] %= mod
print(dp[-1][-1])

Measured memory_bytes: 147084
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
    
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        String t = sc.next();
        int N = s.length();
        int M = t.length();
        char[] S = s.toCharArray(); //String sをchar型で配列に格納
        char[] T = t.toCharArray(); //String tをchar型で配列に格納
        
        //辞書順に文字列を並び替え
        Arrays.sort(S);
        Arrays.sort(T);
        
        //文字列を生成。ただし、Sは昇順、Tは降順とする。
        String ss = "";
        String tt = "";
        for(int i = 0; i < N; i++) ss += S[i];
        for(int i = 0; i < M; i++) tt += T[(M - 1) -i];

        //生成した文字列をcompareTo()で比較
        System.out.println(ss.compareTo(tt) < 0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 21844
N, A, B, C = gets.chomp.split(" ").map(&:to_i)
L = Array.new(N).map{gets.to_i}

K = Array.new(4).map{Array.new}
ANS = []
D = [A, B, C]

def solve(n)
  (calc; return) if n == -1
  4.times{|i|
    K[i].push(n)
    solve(n-1)
    K[i].pop
  }
end

def calc
  return if K[0].empty? || K[1].empty? || K[2].empty?
  ANS << (0..2).to_a.inject(0){|r, i|
    r + (D[i] - K[i].inject(0){|r, k| r + L[k]}).abs + 10 * (K[i].size - 1)
  }
end

solve(N-1)

puts ANS.min


Measured memory_bytes: 4348
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner (System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		System.out.println((H * W) - (h * W) - (w * H) + (w * h));
		
	}

}


Measured memory_bytes: 27060
import java.util.Scanner;

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

        final int n = scanner.nextInt();
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();

        System.out.println(Math.min(n * a, b));
    }
}

Measured memory_bytes: 21844
import numpy as np

mod = 998244353


def sum_mod(v):
    ans = 0
    for i in range(1, len(v)):
        ans = (ans + v[i]) % mod
    return ans


n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
A = sum(a)

dp = np.zeros((n + 1, A + 1), dtype=int)
dp2 = np.zeros((n + 1, A + 1), dtype=int)
dp[0][0] = 1
dp2[0][0] = 1
for t in range(1, n + 1):
    dp[t, :] = dp[t - 1, :] * 2 % mod
    dp2[t, :] = dp2[t - 1, :] % mod
    dp[t, a[t - 1]:] += dp[t - 1, :-a[t - 1]] % mod
    dp2[t, a[t - 1]:] += dp2[t - 1, :-a[t - 1]] % mod
#print(dp)

ans = 3 ** n % mod
ans -= np.sum(dp[n][(A + 1) // 2:]) * 3 % mod
if A % 2 == 0:
    ans += dp2[n][A // 2] * 3 % mod
print(ans % mod)

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

int main() {
	int N, K; cin >> N >> K;
	string S; cin >> S;
	vector<int> v;
	int now=0;
	char p='1';
	for(int i=0; i<N; ++i){
	    if(p==S[i]) ++now;
	    else{
	        v.push_back(now);
	        now=1;
	        p=S[i];
	    }
	}
	v.push_back(now);
	v.push_back(0);
	if(v.size()<=1+K*2){
	    cout << N << endl;
	    return 0;
	}
	int chn=0;
	for(int i=0; i<1+K*2; ++i) chn += v[i];
	int ans=chn;
	for(int i=1+K*2; i+1<v.size(); i+=2){
	    chn += v[i]+v[i+1]-v[i-2*K-1]-v[i-2*K];
	    ans=max(ans, chn);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1020
N = int(input())

A = [0] + [int(_) for _ in input().split()]
ans = [0] * (N + 1)

for i in range(N, 0, -1):
    ans[i] = A[i]
    j = i * 2
    while j <= N:
        ans[i] += ans[j]
        j += i
    ans[i] = ans[i] % 2

# print(ans)
spam = [i for i in range(1, N + 1) if ans[i]]
print(len(spam))
if spam:
    print(*spam)

Measured memory_bytes: 14132
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
char buf[1000];
pair<pair<string,int>, int > data[100];
int res[100];
int main(){
  int i, j, k;
  rd(N);
  for(i=0;i<N;i++){
    rd(buf);
    rd(k);
    data[i].second = i;
    data[i].first = make_pair((string)buf, -k);
  }
  sort(data, data+N);
  for(i=0;i<N;i++){
    res[i] = data[i].second + 1;
  }
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      wt_L(res[Lj4PdHRW]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20190526-1

// --- original code ---
// int N;
// char buf[1000];
// 
// pair<pair<string,int>, int > data[100];
// int res[100];
// 
// {
//   int i, j, k;
// 
//   rd(N);
//   rep(i,N){
//     rd(buf, k);
//     data[i].second = i;
//     data[i].first = make_pair((string)buf, -k);
//   }
//   sort(data, data+N);
//   rep(i,N) res[i] = data[i].second + 1;
// 
//   wtLn(res(N));
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  ldouble a, b, c;
  cin >> a >> b >> c;
  bool d = 0;
  if(sqrt(a) + sqrt(b) + 1e-14 < sqrt(c) || d) cout << "Yes" << endl;
  else cout <<  "No" << endl;
  return 0;
}

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

int main(){
  
  int n, m;
  
  cin >> n;
  vector<int> A(n);
  for(int i = 0;i < n;i++) cin >> A[i];
  
  cin >> m;
  vector<int> B(m);
  for(int i = 0;i < m;i++) cin >> B[i];
  
  cout << lexicographical_compare(A.begin(), A.end(), B.begin(), B.end()) << endl;
  
  return 0;
}


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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main()
{
	init();
	solve();
}

string S;

void init()
{
	cin >> S;
}

void solve()
{
	int t = 0;
	int s = 0;
	rep(i, S.length()) {
		if (S[i] == 'T') {
			if (s) {
				s--;
			} else {
				t++;
			}
		}
		if (S[i] == 'S') {
			s++;
		}
	}
	cout << t * 2 << endl;
}



Measured memory_bytes: 640
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=2e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;
 	
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();	
 	
 	string a;
 	int n,p;
 	cin>>n>>p>>a;

 	 if (p == 5 || p == 2) {
	        ll ans = 0;
	       for(int i=0;i<n;i++){
	            if ((a[i] - '0') % p == 0) {
	                ans += i+1;
	            }
	        }
	        cout << ans << endl;
	        return 0;
    	}

 	std::vector<int> occ(p);

 	reverse(all(a));

 	ll pw = 1;
 	ll curr = 0;
 	for(int i=0;i<n;i++){
 		curr=(curr+((a[i]-'0')*pw)%p)%p;
 		pw=(pw*10)%p;
 		occ[curr]++;
 	}
 	ll ans = 0;
 	for(int i=0;i<p;i++){
 		ans += (ll)occ[i]*(occ[i]-1)/2;
 	}

 	cout<<ans+occ[0]<<endl;
}		


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

int main() {
    int N, As = 0, Bs = 0;
    cin >> N;

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

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

    for (int i = 0; i < N; i++) {
        if(i % 2 == 0) {
            As += A.at(i);
        }

        else {
            Bs += A.at(i);
        }
    }

    cout << As - Bs << endl;
}

Measured memory_bytes: 256
N = int(input())
F = [int(''.join(list(input().split())), 2) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]

ans = -float('inf')

for i in range(1, 2**10):
    res = 0
    for k in range(N):
        p = i & F[k]
        cnt = 0
        for j in range(10):
            if (p >> j) & 1:
                cnt += 1
        res += P[k][cnt]
    ans = max(ans, res)

print(ans)

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

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

    int n; cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) cin >> d[i];

    for (int i = 1; i < n; i++) {
        d.push_back(d[i-1]*10 + d[i]);
    }
    for (int i = 2; i < n; i++) {
        d.push_back(d[i-2]*100 + d[i-1]*10 + d[i]);
    }
    sort(d.begin(), d.end());


    if (n != 1 && d[0] == 0) {
        for (int i = 1; i < d.size(); i++) {
            if (d[i] != d[i-1] && d[i] != d[i-1]+1) {
                cout << d[i-1]+1 << endl;
                break;
            }
        }
    } else {
        if (d[0] == 0) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
    }

    return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define gcda(x,y) gcd(abs(x),abs(y))

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i,n){
      cin >> a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll ans = 0;
    
    deque<ll> com;
    com.push_back(a[0]);
    
    for(int i=1; i<n; i++){
      int x = a[i];
      ans += com[0];
      com.push_back(x);
      com.push_back(x);
      com.pop_front();
    }

    cout << ans << endl;
}


Measured memory_bytes: 6412
n = int(input())
ans=[0]*(n+1)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            a = x * x + y * y + z * z + x * y + y * z + z * x
            if n >= a >= 1:
                ans[a] += 1
print(*ans[1:],sep="\n")

Measured memory_bytes: 9144
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

typedef long long ll;

const int kMaxN = 2000;
const int kMaxA = 1000000000;

int N, Z, W;
int a[kMaxN];
int ans;

int main() {
  cin >> N >> Z >> W;
  REP(i, N) { cin >> a[i]; }

  if (N == 1) {
    ans = abs(a[0]-W);
  } else {
    ans = max(abs(a[N-1]-W), abs(a[N-2]-a[N-1]));
  }

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


Measured memory_bytes: 384
/* package codechef; // don't place package name! */

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;
import java.util.*; 
import java.lang.*; 
import java.io.*;
import java.math.BigInteger; 
import java.math.*;

public  class Main {
    
	public static void main(String[] args) {
		
		InputStream inputStream = System.in;

		InputReader sc = new InputReader(inputStream);

				
	
	
	    int n=sc.nextInt();
	    int t=sc.nextInt();
	    int w[]= new int[n];
	    long v[]= new long[n];
	    for(int i=0;i<n;i++){
	     w[i]=sc.nextInt();
	     v[i]=sc.nextLong();
	    }
	    long dp[][]= new long[n+1][t+1];
	   
	 for(int i=0;i<=n;i++){
	   for(int j=0;j<=t;j++){
	     if(i==0 || j==0){
	       dp[i][j]=0;
	     }
	     else if(w[i-1]<=j){
	       dp[i][j]=Math.max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
	     }
	     else{
	       dp[i][j]=dp[i-1][j];
	     }
	   }
	 }
	  
System.out.println(dp[n][t]);
	    
	}
	

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public float nextFloat() {
			return Float.parseFloat(next());
		}
		
		
	}
}

Measured memory_bytes: 128468
import sys
n, k = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
memo_ls = [-1 for i in range(k+1)]
memo_ls[0] = -1
for i in range(1, k+1):
    for a in a_ls:
        if a > i:
            continue
        memo_ls[i] = max(memo_ls[i - a] * (-1), memo_ls[i])
ans = ["","First", "Second"]
print(ans[memo_ls[-1]])

Measured memory_bytes: 45040
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int func(int n);

int main() {
	int n,fn;
	cin >> n;
	fn=func(n);
	//cout << fn << endl;

	if (n%fn == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

int func(int n) {
	int sum = 0;
	if (n < 10) {
		return n;
	} else {
		while(1) {
			sum += n % 10;
			if (n < 10)break;
			n /= 10;
		};
		return sum;
	}
	
}

Measured memory_bytes: 256
import java.math.BigInteger

fun main() {
    val a = readInt()
    println(a + (a `**` 2) + (a `**` 3))
}

infix fun Int.`**`(exponent: Int): Int {
    return BigInteger.valueOf(this.toLong()).pow(exponent).toInt()
}

// Input Reader
private fun readLn() = readLine()!!

private fun readInt() = readLn().toInt()


Measured memory_bytes: 34564
import itertools

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

pp = list(itertools.permutations(p))
qq = list(itertools.permutations(q))

pp.sort()
qq.sort()

a = 0
b = 0

for i in range(len(pp)):
    if pp[i] == tuple(p):
        a = i + 1

for i in range(len(qq)):
    if pp[i] == tuple(q):
        b = i + 1

print(abs(a - b))

Measured memory_bytes: 12788
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_e
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

vector<string> s;

int ans = INF_INT;

//文字列iと文字列jがk文字分ズレている時、
//それを重ねてもいいかどうかをd[i][j][k]とおく
bool d[3][3][2000];

void solve(){
	sort(s.begin(),s.end());
	//next_permutation(引数はvector型の変数.begin()とend())
	//をdo~whileの継続条件に入れると
	//この3つの文字列の考えうる並び順を全部試せる
	//これを使うと例えば
	//元々s[0],s[1],s[2]と入っていたものが
	//s[0]=s[2];s[1]=s[0];s[2]=s[1];
	//を実行したときのような感じで入れ替えられる
	do{
		//2つの文字列を取ってきて、
		//それらのズレ幅を固定した時に
		//それが可能かどうかを調べる
		for(int i=0;i<3;i++){//文字列s[i]
			for(int j=0;j<3;j++){//文字列s[j]
				if(i>=j) continue;
				//k文字分ズレているとする
				//ズレは最大でもs[i]の文字列長にしかならない
				for(int k=0;k<s[i].size();k++){
					bool ok = true;
					//S[i]のk文字目から末尾までを調べる
					for(int ni=k;ni<s[i].size();ni++){
						//S[i]のk文字目を調べている時、
						//S[j]の対応する文字の位置はni-k
						int nj = ni-k;
						if(nj >= s[j].size()) break;//njがs[j]の大きさ超えたらやばい
						if(s[i][ni]=='?' || s[j][nj]=='?') continue;
						if(s[i][ni]!=s[j][nj]) ok = false;
					}
					d[i][j][k] = ok;
				}
			}
		}

		//s[i]とs[j]をk文字分ずらして重ねた時、
		//それが条件に合致するかどうかを返すラムダ式
		auto is_match = [&](int i,int j,int k){
			if(k>=s[i].size()) return true;
			return d[i][j][k];
		};

		for(int x=0;x<=2000;x++){
			for(int y=0;y<=2000;y++){
				if(!is_match(0,1,x)) continue;
				if(!is_match(1,2,y)) continue;
				if(!is_match(0,2,x+y)) continue;
				//上の3つを全部クリアしているなら
				//3つを合成してできる文字列の長さを求める
				//この文字列の始点は必ずs[0][0]と一致
				//末尾は必ずしもs[2][s[2].size()-1]とは限らない
				//s[0][s[2].size()-1]やs[1][s[2].size()-1]かもしれない
				int now = 0;//nowが今回できた文字列の長さ
				//s[0].size()
				//x+s[1].size()
				//x+y+s[2].size()
				//のうち最大のものが今回できた文字列の長さとなる
				now = max(now,(int)s[0].size());
				now = max(now,x+(int)s[1].size());
				now = max(now,x+y+(int)s[2].size());
				ans = min(ans,now);
			}
		}
	}while(next_permutation(s.begin(),s.end()));
	//next_permutation(s.begin(),s.end())
	//を実行したタイミングでvectorの要素同士の入れ替えが実行される
}
 
int main(){
	s = vector<string>(3);
	cin >> s[0];
	cin >> s[1];
	cin >> s[2];
 
	solve();

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

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
bb = inpl()
cc = inpl()
aa.sort()
bb.sort()
cc.sort()
Sc = len(cc)

ans = 0
for b in bb:
	na = bisect.bisect_left(aa,b)
	nc = Sc - bisect.bisect_right(cc,b)
	ans += na*nc
print(ans)


Measured memory_bytes: 24360
N = int(input())
count = 0
M = (N//2 if N%2 == 0 else (N+1)//2)

for i in range(M):
    Num = 2*i + 1
    Div = 0
    for j in range(1, Num + 1):
        if Num % j == 0:
            Div += 1
    if Div == 8:
        count += 1
print(count)

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

#define ll long long
#define ull unsigned long long
#define inf 0x3f3f3f3f
#define met(a, x) memset(a,x,sizeof(a))
#define mp make_pair;

using namespace std;
const int mod = 19e+7;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
int m,n;
struct rec{
    int y,nex;
}edge[2*N];
int head[N],q1[N],q2[N],q3[N];
int val[N],maxd[N];
int cnt=0;
void add(int u,int v){
    edge[++cnt].y=v;
    edge[cnt].nex=head[u];
    head[u]=cnt;
}
void dfs(int u,int d,int x){
    if(maxd[u]>=d)
        return ;
    if(!val[u])
        val[u]=x;
    if(d==0)
        return;
    maxd[u]=d;
    for(int i=head[u];i;i=edge[i].nex){
        dfs(edge[i].y,d-1,x);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        add(a,b);
        add(b,a);
    }
    int q;
    cin>>q;
    met(maxd,-1);
    met(val,0);
    for(int i=1;i<=q;i++)
        cin>>q1[i]>>q2[i]>>q3[i];
    for(int i=q;i>=1;i--){
        dfs(q1[i],q2[i],q3[i]);
    }
    for(int i=1;i<=n;i++){
        cout<<val[i]<<endl;
    }
    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Maximum Sum
            var numbers = ReadLine();
            int k = int.Parse(Console.ReadLine());

            int max = numbers.Max();
            numbers.Remove(max);

            for(int i = 1; i <= k; i++)
            {
                max *= 2;
            }

            int sum = max + numbers.Sum();
            Console.WriteLine(sum);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13280
x=int(input())

def isPrime(x):
	for i in range(2,int(x**0.5)+2):
		if i==x:
			return 1
		if x%i==0:
			return 0
	return 1

for i in range(x,x+1234567890):
	if isPrime(i):
		print(i)
		exit()

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

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D(x)         cout << #x << " - " << x << endl;
  #define  D2(x)        cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  all(x)       (x).begin(), (x).end()
  #define  D2p(x)       cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
  	ll mod = 7;
  	ll x;
  	cin >> x;
	for(int i=1;i<=5e7;i++){
		 mod = mod*10LL;
		 mod = mod%(9LL*x);
		 if(mod == 7){
		 	cout << i;
		 	return;
		 }
	}
	cout << -1;
  }

  int main(){
    IOS
    solve();
    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
	int H,W,h,w;
	cin >> H >> W;
	cin >> h >> w;
	cout << (H - h) * (W - w) << endl;
	return 0;
}

Measured memory_bytes: 256
li = [int(input()) for _ in range(5)]

time = 0
non10li = []
for i in li:
    if i%10==0:
        time+=i
    else:
        non10li.append(i)
if len(non10li)!=0:
    minili = [i%10 for i in non10li]
    ind = non10li.pop(minili.index(min(minili)))
    for i in non10li:
        time+=(i//10)*10+10

    time+=ind
print(time)


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

using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()

int main(){
    int ans=0;
    int a,b;
    cin>>a>>b;
    for(int i=a;i<=b;i++){
        string s=to_string(i);
        if(s[0]==s[4] and s[1]==s[3]) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;

public class Hello{
    public static void Main(){

        var n = int.Parse(Console.ReadLine());
        var v = n % 10;
        
        if(v == 3){
            Console.WriteLine("bon");
        }else if(v == 0 || v == 1 || v == 6 || v == 8){
            Console.WriteLine("pon");
        }else{
            Console.WriteLine("hon");
        }
    }
}


Measured memory_bytes: 27304
#include<iostream>
#include<exception>
#include<stdexcept>
#include<bits/stdc++.h>
#define int long long
using namespace std;
int fun(int a){
	int x=a; x*=a; x*=a; x*=a; x*=a;
	return x;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int x; cin>>x;
	for(int i=-1000;i<=1000;++i){
		for(int j=-1000;j<=1000;++j){
			int p=fun(i); int pp=fun(j);
			p-=pp;
			if(p==x){
				cout<<i<<" "<<j<<"\n";
				return 0;
			}
			
		}
	}
	return 0;
}

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

int main() {
    long n, a, b, temp, ans = 0;
    cin >> n >> a >> b;
    if(a > b) swap(a, b);
    temp = min(n - b, a - 1);
    if((b - a) % 2 == 1) {
        if(temp == n - b) {
            ans += (temp + 1);
            a += (temp + 1);
            b = n;
        } else {
            ans += (temp + 1);
            a = 1;
            b -= (temp + 1);
        }
    }
    if((b - a) % 2 == 0) ans += (b - a) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin>>n;
	string s;
	while(n){
		n=n-1;
		s = s + char('a' + n % 26);
		n /= 26;
	}
	reverse(s.begin(),s.end());
	cout<<s;
}

Measured memory_bytes: 3580
import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as B

solve :: [Int] -> Mint
solve as = sum $ map f [0..59] where
  f :: Int -> Mint
  f i = M one * M zro * 2^i where
    one = length $ filter (`testBit` i) as
    zro = length as - one

main=getLine>>readIntsLn>>=print.solve

modulus = 10^9+7
newtype Mint = M Int
instance Enum Mint where
  fromEnum(M a) = a
  toEnum a = M$ mod a modulus
instance Num Mint where
  (M a)+(M b) = toEnum$ a+b
  (M a)*(M b) = toEnum$ a*b
  (M a)-(M b) = toEnum$ a-b
  fromInteger = toEnum . fromInteger
  abs = id
  signum = const (M 1)
instance Show Mint where
  show (M a) = show a

readIntsLn
  = unfoldr (B.readInt . B.dropWhile(==' ')) <$> B.getLine


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

int main () {
  string s;
  cin >> s;
  cout << s[0] << s[1] << s[2] << endl;
}


Measured memory_bytes: 3632
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner yomi = new Scanner(System.in);
        String n = yomi.next();
        if (n.equals("SUN")){
            System.out.println(7);
        }else if (n.equalsIgnoreCase("MON")){
            System.out.println(6);
        }else if (n.equalsIgnoreCase("TUE")){
            System.out.println(5);
        }else if (n.equalsIgnoreCase("WED")){
            System.out.println(4);
        }else if (n.equalsIgnoreCase("THU")){
            System.out.println(3);
        }else if (n.equalsIgnoreCase("FRI")){
            System.out.println(2);
        }else if (n.equalsIgnoreCase("SAT")){
            System.out.println(1);
        }

    }
}

Measured memory_bytes: 23508
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
  int N, M, R;
  cin >> N >> M >> R;
  vector<int> r(R, 0);
  for (int i = 0; i < R; ++i) {
    cin >> r[i];
    --r[i];
  }

  vector<vector<int>> road(N, vector<int>(N, 0));
  for (int i = 0; i < M; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    road[a][b] = road[b][a] = c;
  }

  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        if (road[i][k] == 0 or road[k][j] == 0) continue;
        int c = road[i][k] + road[k][j];
        if (road[i][j] == 0 or c < road[i][j]) road[i][j] = road[j][i] = c;
      }
    }
  }

  sort(r.begin(), r.end());
  int min_cost = 0;
  do {
    int cost = 0;
    bool skip = false;
    for (int i = 1; i < R; ++i) {
      int c = road[r[i-1]][r[i]];
      if (c == 0) {
        skip = true;
        break;
      }
      cost += c;
    }
    if (skip) continue;
    if (min_cost == 0 or min_cost > cost) min_cost = cost;
  } while(next_permutation(r.begin(), r.end()));

  cout << min_cost << endl;

  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,q;
  cin>>n>>k>>q;
  int a[n+1]={0};
  for(int i=0;i<q;i++)
  {
    int x;
    cin>>x;
    a[x]++;
  }
  for(int i=1;i<n+1;i++)
  {
    if(k-q+a[i] >0)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include <stdlib.h>

int main(void) {
  int N;
  scanf("%d", &N);
  
	int *a, *b;
	a = (int *)malloc(N * sizeof(int));
	b = (int *)malloc(N * sizeof(int));


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

	int current = 1;
	int next;
	int flag = 1;
	int count = 0;
	
	while(flag){
		b[current]++;
		count++;
		next = a[current];
		if(next == 2){
			flag = 0;
		}
		if(b[current] > 1){
			printf("-1\n");
			free(a);
			return 0;
		}
		current = next;
	}
	printf("%d\n", count);
	free(a);
	free(b);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, A;
  cin >>N >>A;
  vector<int> X(N+1, 0);
  int y=0;
  for(int i=1; i<=N; i++){
    int x;
    cin >>x;
    X[i]=x;
    y=max(y,x);
  }
  y=max(y,A);
  
  vector<vector<vector<long long>>> Z(N+1, vector<vector<long long>>(N+1, vector<long long>(2500, 0)));
  for(int i=1; i<=N; i++){
    for(int j=1; j<=i; j++){
      for(int k=1; k<=i*y; k++){
        Z[i][j][k]=Z[i-1][j][k];
        if(j==1 &&X[i]==k){
          Z[i][j][k]++;
          continue;
        }
        if(k>X[i]) Z[i][j][k]+=Z[i-1][j-1][k-X[i]];
      }
    }
  }
  long long ans=0;
  for(int i=1; i<=N; i++){
    ans+=Z[N][i][i*A];
  }
  cout << ans << endl;
}

Measured memory_bytes: 52224
A,B,C,D=list(input())

op1=["+","-"]
op2=["+","-"]
op3=["+","-"]

def solve(A,B,C,D):
    for o1 in op1:
        for o2 in op2:
            for o3 in op3:
                if eval(A+o1+B+o2+C+o3+D)==7:
                    print(A+o1+B+o2+C+o3+D+"=7")
                    return
    return 

solve(A,B,C,D)

Measured memory_bytes: 38384
import java.util.*;
import java.util.Scanner;
import java.io.*;
import javax.lang.model.util.ElementScanner6; 

public class Main
{

    public static void main(String args[])
    {  

        FastReader in=new FastReader();
        PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int t=1;
     
        //t=in.nextInt();
        while(t-->0)
        {
           long a=in.nextLong();
           long b=in.nextLong();
           long c=in.nextLong();
           long d=in.nextLong();
           
                long m1=a*c;
                long m2=a*d;
                long m3=b*c;
                long m4=b*d;
                pr.println(Math.max(m1,Math.max(m2,Math.max(m3, m4))));
            

        }
        pr.flush();
    }



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

    static int lcm(int a,int b)
    {
        return (a*b)/gcd(a,b);
    }


    static boolean prime[];

    static void sieveofe()
    {
        int n=1000000;
      
        prime=new boolean[n+1];
        Arrays.fill(prime,true);
        prime[1]=false;
        for(int i=2;i*i<=n;i++)
        {
            if(prime[i]==true)
            {
                for(int j=i*i;j<=n;j+=i)
                {
                    prime[j]=false;
                }
            }
        }
      
        
    }
    
    static void sort(long[] a) {
		ArrayList<Long> l = new ArrayList<>();
		for (long i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}
    
    
	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
    }

    
    static class FastReader
    { 
        BufferedReader br; 
        StringTokenizer st; 

        public FastReader() 
        { 
            br = new BufferedReader(new
                    InputStreamReader(System.in)); 
        } 

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

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

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

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

        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 

    
   
}

Measured memory_bytes: 32904
n=int(input())
xy_list=[]
for i in range(n):
    a=int(input())
    xy=[]
    for _ in range(a):
        xy.append(list(map(int,input().split())))
    xy_list.append(xy)
ans=0
for i in range(2**n):
    i_2=format(i,"0"+str(n)+"b")
    flag=1
    for j in range(n):
        if i_2[j]=="1":
            for x,y in xy_list[j]:
                if i_2[x-1]!=str(y):
                    flag=0
    if flag==1: 
        ans=max(ans,i_2.count("1"))
print(ans)

Measured memory_bytes: 3064
{-# LANGUAGE BangPatterns #-}
main :: IO ()
main = do
  _ <- readLn :: IO Int
  xs <- getLine :: IO String    
  let ws = scanl (\ !a !x -> if x=='W' then a+1 else a) 0 xs :: [Int]
  let es = scanr (\ !x !a -> if x=='E' then a+1 else a) 0 xs :: [Int]
  print $ minimum $ zipWith (+) ws es
  



Measured memory_bytes: 73084
#include <iostream>

using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  if(a == 1 && b == 1){
    cout << "Draw" << endl;
  }else if(a == 1){
    cout << "Alice" << endl;
  }else if(b == 1){
    cout << "Bob" << endl;
  }else if(a > b){
    cout << "Alice" << endl;
  }else if(b > a){
    cout << "Bob" << endl;
  }else{
    cout << "Draw" << endl;
  }
  return 0;
}

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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  
  vector<int> x(N + 1, 0);
  for (int i = 0; i < Q; i++) {
    int A;
    cin >> A;
    x.at(A)++;
  }
  
  for (int i = 1; i <= N; i++) {
    if (x.at(i) + K > Q) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1024
main :: IO()
main = do
 [n,m] <- map read . words <$> getLine :: IO[Int]
 ak <- map read . words <$> getLine :: IO[Int]
 let ans = if length (filter (\x -> (4 * x * m) >= (sum ak)) ak) >= m then "Yes" else "No"
 putStr $ ans


Measured memory_bytes: 4240