akhauriyash/Code-Regression huggingface dataset:
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

func Mod(I []int, P int) int {
  N := 0
  for _, i := range I {
    N = N * 10 + i
    N %= P
  }
  return N
}

func Solve() {
  var N, P int
  NextInt(&N, &P)
  S := NextLine()
  I := make([]int, N)
  for i, s := range S {
    I[i] = int(s) - int('0')
  }
  ans := 0
  if P == 2 || P == 5 {
    for i, c := range I {
      if c % P == 0 { ans += i + 1 }
    }
  } else {
    C := make([][]int, 10)
    for i := range C {
      C[i] = make([]int, 0)
      n := i
      C[i] = append(C[i], n % P)
      n = (n * 10) % P
      for n != C[i][0] {
        C[i] = append(C[i], n)
        n = (n * 10) % P
      }
    }
    M := make([]int, P)
    M[0] = 1
    m := 0
    for s := 0; s < N; s++ {
      i := I[N - 1 - s]
      m = (m + C[i][s % len(C[i])]) % P
      ans += M[m]
      M[m]++
    }
  }
  Write(ans)
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
ll n,m,ans=0;
const ll MAX = 1000000;
const ll MOD = 1000000007;
ll fac[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
bool Main(){
    cin>>n>>m;
    COMinit();
    if(abs(n-m)>1) cout<<0<<endl;
    else if(abs(n-m)==1)cout<<(fac[n]*fac[m])%MOD<<endl;
    else cout<<(fac[n]*fac[m]*2)%MOD<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>

int main(void){

  int n;
  int w,h;
  int x,y;
  int s,t;
  int i,j,k,l;
  int p,pmax;
    
  for(;;){

    scanf("%d",&n);
    if(n==0)break;

    scanf("%d %d",&w,&h);
    
    int map[500][500]={0};
    for(i=0;i<n;i++){
      scanf("%d %d",&x,&y);
      map[x-1][y-1]=1;
    }
    
    p=0;
    pmax=0;
    scanf("%d %d",&s,&t);
    for(i=0;i<h-t+1;i++)
      for(j=0;j<w-s+1;j++){
	for(k=0;k<t;k++)
	  for(l=0;l<s;l++)
	    if(map[j+l][i+k]==1)p++;
	if(pmax<p)pmax=p;
	p=0;
      }

    printf("%d\n",pmax);

  }
  
  return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vector<Pi> dat(N);
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		dat[i] = Pi(A, i+1);
	}
	sort(begin(dat), end(dat));
	cout << dat[0].second;
	for (int i = 1; i < N; i++) {
		cout << " " << dat[i].second;
	}
	cout << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

typedef long long ll;
typedef tuple<ll, ll, ll> mytuple;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) { if (b == 0) {return a;} else {return GCD(b, a % b);} }
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long 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; }

int main() {
  ll N, K; cin >> N >> K;

  ll tp[200010] = {0};
  ll bt[200010] = {0};

  ll sum = 0;
  for(int k = 1; k <= N+1; k++) {
    tp[k] = tp[k-1] + N+1-k;
    bt[k] = bt[k-1] + (k-1);

    if(k >= K) sum = (sum + tp[k] - bt[k] + 1LL)%MOD;
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 6756
from collections import defaultdict
n, m = map(int, input().split())

penalties = defaultdict(int)
solved = set()

for _ in range(m):
    p, S = input().split()

    if p in solved:
        continue
    if S == 'WA':
        penalties[p] += 1
    else:
        solved.add(p)

print(len(solved), sum([penalties[i] for i in solved]))


Measured memory_bytes: 25188
n = int(input())
l = list(map(int,input().split()))
kuma = sum(l)-l[0]
snuke = l[0]
gap = abs(snuke-kuma)
for i in range(1,n-1):
    snuke += l[i]
    kuma -= l[i]
    gap = min(gap,abs(snuke-kuma))
print(gap)


Measured memory_bytes: 76752
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')

import numpy as np
from collections import Counter


def main():
    N = I()
    A = LI()
    Q = I()
    act_list = LLIN(Q)
    cnt = Counter(A)
    ans = sum(A)
    # print(cnt)
    for z in act_list:
        b_num = cnt[z[0]]
        cnt[z[0]] = 0
        cnt[z[1]] = cnt[z[1]] + b_num
        # print(cnt)
        # A_list = [z[1] if i == z[0] else i for i in A_list]
        # np.place(np_array, np_array == z[0], z[1])
        ans = ans - (z[0] * b_num) + (z[1] * b_num)
        print(ans)
if __name__ == '__main__':
    main()



Measured memory_bytes: 57668
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
if ls == lt:
    ans = 0
    for i in range(lt):
        if s[i] != t[i]:
            ans += 1
    print(ans)
else:
    ans = ls
    for i in range(ls-lt):
        cnt = 0
        for j in range(lt):
            if s[i+j] != t[j]:
                cnt += 1
        ans = min(ans,cnt)
    print(ans)

Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VI a(n); cin >> a;
    
    int num = 1, ans = 0;
    FOR(i, 0, n) {
        if (a[i] == num)++num;
        else ++ans;
    }

    cout << (num == 1 ? -1 : ans) << "\n";
}

Measured memory_bytes: 1024
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
const ll mod = 998244353;
#define int ll
int n, m, a[100002];

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n;
    for(int i=1; i<=n; i++) cin>>a[n-i+1];
    int l=2, r=3;
    if(a[1]!=2) return cout<<-1, 0;
    for(int i=2; i<=n; i++){
       // if(a[i]>r) return cout<<-1, 0;
        int xd=a[i];
        l=((l+xd-1)/xd)*xd;
        r=r-(r%xd)+xd-1;
        if(l>r) return cout<<-1, 0;
    }
    cout<<l<<" "<<r;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3

from sys import stdin
from fractions import gcd	# math.gcd is introduced by python 3.5
from functools import reduce

def lcm(x, y):
  """The least common multiple of x and y."""
  return x * (y // gcd(x, y))

def tuples(m, N):
  """
  List of list of m'-tuples over {1,2,3,...,N} for 0 <= m' <= m.
  Every m-tuple does not contain a multiple of some j in the tuple.
  The lcm of the m-tuple is less than or equal to N.
  """
  if m == 0: return [[()]]
  ts = tuples(m - 1, N)
  if len(ts[-1]) == 0: return ts

  ls = []
  for t in ts[-1]:
    lc = reduce(lcm, t) if len(t) > 0 else 1
    mi = min(t)         if len(t) > 0 else N + 1
    for i in range(mi - 1, 0, -1):
      if any(j % i == 0 for j in t): continue
      if lcm(lc, i) > N: continue
      ls.append((i,) + t)
  ts.append(ls)
  return ts

def value(a, t):
  """
  Total value of the jewels that are labeled a multiple of x
  for some x in t.
  """
  used = [False for i in a]
  v = 0
  for x in t:
    for i in range(x - 1, len(a), x):
      if not used[i]:
        v = v + a[i]
        used[i] = True
  return v

def remove(a, t):
  """
  Break all jewels that are labeled a multiple of x for some x in t.
  """
  for x in t:
    for i in range(x - 1, len(a), x):
      a[i] = 0

def flatten(ls):
  """Flatten a list of lists."""
  return [x for l in ls for x in l]

def solve(a):
  n = len(a)
  tl = flatten(tuples(n, n))
  tl.sort(key=lambda t: [-x for x in t])
  for t in tl:
    if value(a, t) < 0: remove(a, t)
  return sum(a)

N = int(stdin.readline())
a = [int(w) for w in stdin.readline().split()]
if len(a) != N: raise
print(solve(a))


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

int main()
{
    int N, D, X;
    int A[100];

    cin >> N >> D >> X;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += ((D - 1) / A[i] + 1);
    }
    ans += X;

    cout << ans << endl;

    return 0;
}


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

int main() {
    int N; cin >> N;
    int ma = 0;
    int po = 0;
    vector<int> L(N);
    rep(i,N) {
        cin >> L.at(i);
        if (ma < L[i]) {
            ma = L[i];
            po = i;
        }
    }
    int sum = accumulate(begin(L), end(L), 0);
    if (sum - L[po] > L[po]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

search_word = gets.chomp.downcase
strings = []

while strings[-1] != "END_OF_TEXT" do
    strings.concat(gets.split(/\W/))
end
count = 0
strings.each do |word|
    if word.downcase == search_word then
        count += 1
    end
end
puts count



Measured memory_bytes: 6888
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <climits>

using namespace std;

int main() {
	int H,W;

	cin >> H >> W;;
	
	while ((H!=0)||(W!=0)) {

		for(int i = 0; i <  H; i++) {
			for(int j = 0; j <  W;j++) {
				if ( (0<i) && (i<H-1) && (0<j) && (j<W-1))
					cout << ".";
				else
					cout << "#";
			}	
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;;
	}
	
}



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

int main(){
    ll N,T1,T2;
    ll a,b,r,i;
    cin >> N >> T1;
    for(i=1;i<N;i++){
        cin >> T2;
        a=T1;
        b=T2;
        if(a<b)swap(a,b);
        while(a%b!=0){
            r=a%b;
            a=b;
            b=r;
        }
        T1=T1/b*T2;
    }
    cout << T1;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;

int main(void){
  long long int n, a[100000];
  int i;
  int sum = 0, c = 0;
  cin >> n;
  for(i = 0; i < n; i++){
    cin >> a[i];
  }
  while(c != n){
    if(a[c] % 2 == 0){
      a[c] = a[c]/2;
      sum++;
    }
    else{
      c++;
    }
  }
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <functional>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
int main(){
    int n;
    cin >> n;
    map<int,int> mp;
    for(int i = 0;i < n;i++){
        int a;
        cin >> a;
        mp[a]++;
    }

    int ans = 0;

    for(auto p:mp){
        if(p.second > p.first)ans += (p.second - p.first);
        else if(p.second < p.first)ans += p.second;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
const ll MAXN = 3002;
double dp[MAXN][MAXN],P[MAXN];
ll vis[MAXN][MAXN],N;
double solve(ll pos,ll heads){
	if(heads < 0) return 0.0;
    if(pos == 0){
		return (heads == 0);
	}
	if(vis[pos][heads]) 
		return dp[pos][heads];
	vis[pos][heads] = 1;

	return dp[pos][heads] =  (P[pos])*solve(pos-1,heads-1) + (1.0 - P[pos])*solve(pos-1,heads);

}

int main(){

	cin >> N;
	for(ll i = 1;i<=N;i++){
		cin >> P[i];
	}

	double tot = 0;
	for(ll heads = 0;heads<=N;heads++){
		ll tails = N - heads;
		if(heads > tails) tot += solve(N,heads);
	}

	printf("%.9lf\n",tot);

	return 0;

}

Measured memory_bytes: 140672
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
int n;
int gru[4000001];
int licz[2001];
int s,k;
int main(){
	ios_base::sync_with_stdio(0);
	gru[0]=1;
	cin>>k;
	int sum=0;
	for(int i=0;i<k;i++){
		cin>>s;
		licz[s]++;
		}
	for(int i=0;i<=2000;i++){
		if(licz[i]>0)
		for(int j=sum;j>=0;j--)
			if(gru[j]!=0){
				for(int z=1;z<=licz[i];z++)
					gru[j+z*i]=1;
			}
		sum+=i*licz[i];
	}
	for(int i=(sum+1)/2;true;i++){
		if(gru[i]){
			cout<<i<<endl;
			return 0;
			}
		
	}
    return 0;
}


Measured memory_bytes: 15488
# -*- coding: utf-8 -*-
import math
import random
import time
import numpy as np

start = time.time()
limit_time = 1.8

# 整数の入力
d = int(input())
c = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for j in range(d)]

c_num = np.array(c)
s_num = np.array(s)

# d_map = {i: [] for i in range(d)}

def point(t):
    result = 0
    map = {
        0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0,
        10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0,
        20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0
    }
    for i in range(d):
        comp = t[i] - 1
        day = i + 1
        map[comp] = day
        # d_map[comp].append(day)
        result = result + s[i][comp]
        for cc in range(26):
            result = result - c[cc] * (day - map[cc])
    return result

t = np.argmax(s_num, axis=1) + 1
# t = [int(input()) for i in range(d)]

p = point(t)

# m = int(input())

# for i in range(m):
#     [d, q] = input().split()
#     list = d_map[d - 1]
#     old_q = t[d - 1]
#     index = np.searchsorted(list, d)
#
#     t[d - 1] = q


while time.time() - start < limit_time:
    new_d = math.floor(d * random.random())
    old_t = t[new_d]
    new_t = math.floor(26 * random.random()) + 1
    if old_t == new_t:
        new_t = (new_t + 1) % 26
    t[new_d] = new_t
    new_p = point(t)
    if p < new_p:
        p = new_p
    else:
       t[new_d] = old_t

print("\n".join([str(i) for i in t]))


Measured memory_bytes: 27340
gets
preorder = gets.chomp.split.map(&:to_i)
inorder = gets.chomp.split.map(&:to_i)
@postorder = []

def rec(n, inorder, preorder)
    if inorder != []
        c = preorder[n]; n += 1
        x = inorder.index(c)
        left = inorder[0...x]
        right = inorder[(x+1)..-1]
        n = rec(n, left, preorder)
        n = rec(n, right, preorder)
        @postorder << c
    end
    n
end

rec(0, inorder, preorder)
puts @postorder.join(' ')


Measured memory_bytes: 8900
#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>;

const int mod = 1'000'000'007;

ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  return n * factorial(n - 1) % mod;
}

int main() {
  ll n, m;
  cin >> n >> m;

  ll result;
  if (abs(n - m) >= 2) {
    result = 0;
  } else if (n == m) {
    result = factorial(n) * factorial(m) % mod * 2 % mod;
  } else {
    result = factorial(n) * factorial(m) % mod;
  }
  cout << result << endl;

  return 0;
}


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

int main() {
	int H, W;
	cin >> H >> W;
	
	while (H > 0 && W > 0) {
		for (int i=1; i<=H; i=i+1) {
			for (int j=1; j<=W; j=j+1) {
				if (i == 1 || i == H || j == 1 || j == W)
					cout << '#';
				else
					cout << '.';
			}
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;
	}

	return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

int main() {
	int N; cin >> N;
	vvint G(N);	
	for (int i = 0; i < N-1; i++) {
		int p, q;
		cin >> p >> q; --p, --q;
		G[p].push_back(q);
		G[q].push_back(p);
	}
	
	int maxd = 0;
	function<int(int, int)> dfs = [&](int u, int prev) {
		int ret = (int)(G[u].size() == 2);
		vint dat;
		for (auto &v : G[u]) {
			if (v != prev) dat.push_back(dfs(v, u));
		}

		sort(begin(dat), end(dat), greater<>());
		int maxv = 0;
		if (dat.size() >= 1) {
			maxv = dat[0];
			if (dat.size() >= 2) chmax(maxd, dat[0] + dat[1]);
		}
		chmax(maxd, ret + maxv);
		return (ret + maxv);
	};

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (G[i].size() == 1) {
			if (cnt == 0) {
				dfs(i, -1);
				cnt += maxd;
			}
			cnt++;
		}
	}
	cout << cnt << endl;
	return (0);
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long ll;

int main(){
    int n;
    while(cin>>n && n){
        ll cur=0;
        for(int i=0;i<n;i++){
            ll p,n;
            char c;
            cin>>p>>c>>n;
            cur+=(c=='(' ? 1 : -1)*n;
            puts(cur==0 ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 1116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int V = in.nextInt(), E = in.nextInt();
			Flow flow = new Flow(V);

			for (int i = 0; i < E; i++) {
				int u = in.nextInt();
				int v = in.nextInt();
				int c = in.nextInt();
				flow.addEdge(u, v, c);
			}

			int ans = flow.maxFlow(0, V - 1);
			out.println(ans);

		}
	}

	static class Flow {

		static int INF = 1 << 30;

		boolean[] used;
		List<Edge>[] G;
		int V;

		@SuppressWarnings("unchecked")
		public Flow(int V) {
			G = Stream.generate(ArrayList::new).limit(V).toArray(List[]::new);
			used = new boolean[V];
			this.V = V;
		}

		static class Edge {
			int to, cap, rev;
			public Edge(int to, int cap, int rev) {
				this.to = to;
				this.cap = cap;
				this.rev = rev;
			}
		}

		void addEdge(int u, int v, int c) {
			G[u].add(new Edge(v, c, G[v].size()));
			G[v].add(new Edge(u, 0, G[u].size() - 1));
		}

		int dfs(int u, int v, int f) {
			if (u == v) return f;
			used[u] = true;
			for (Edge e : G[u]) {
				if (!used[e.to] && e.cap > 0) {
					int d = dfs(e.to, v, Math.min(f, e.cap));
					if (d > 0) {
						e.cap -= d;
						G[e.to].get(e.rev).cap += d;
						return d;
					}
				}
			}
			return 0;
		}

		int maxFlow(int s, int t) {
			int flow = 0;
			while (true) {
				used = new boolean[V];
				int f = dfs(0, V - 1, INF);
				if (f == 0) break;
				flow += f;
			}
			return flow;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}



Measured memory_bytes: 49940
package main

import (
        "fmt"
)

func solution(n, t, a int, h []int) int {
        lo := 1 << 31
        out := 0
        for i := range h {
          diff := abs(1000*a - (1000*t - (h[i] * 6)))
                if lo > diff {
                        out = i
                        lo = diff
                }

        }
        return out+1
}

func abs(x int) int {
        if x < 0 {
                return -x
        }
        return x
}

func main() {
        var n, t, a int
        fmt.Scan(&n, &t, &a)
        h := make([]int, n)
        for i := range h {
                fmt.Scan(&h[i])
        }
        fmt.Println(solution(n, t, a, h))
}


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

signed main(void)
{
	int n, m, X, Y;
	cin >> n >> m >> X >> Y;
	vector<int> x(n), y(m);
	bool ok;
	
	rep(i, n) cin >> x[i];
	rep(i, m) cin >> y[i];
	sort(x.rbegin(), x.rend());
	sort(y.begin(), y.end());
	ok = false;
	for(int i = X + 1; i < Y + 1; i++)
	{
		if (x[0] < i && i <= y[0])
			ok = true; 
	}
	if (!ok)
		cout << "War" << endl;
	else
		cout << "No War" << endl;
	return 0;
}


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



int main(){
  string a,b;
  cin>>a>>b;
  int A,B;
  cin>>A>>B;
  string u;
  cin>>u;
  if(u==a) A--;
  else if(u==b) B--;
  cout<<A<<" "<<B<<endl;
  return 0;
}

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

bool dfs(vector<int>& a, int target, int idx=0, int total=0) {
    if (target == total) {
        return true;
    }
    else if ((idx == a.size()) || (total > target)) {
        return false;
    }
    else if (dfs(a, target, idx+1, total+a[idx])) {
        return true;
    }
    else if (dfs(a, target, idx+1, total)) {
        return true;
    }
    return false;
}

int main() {
    int n, q, tmp;
    vector<int> a;

    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> tmp;
        a.push_back(tmp);
    }

    cin >> q;
    for (int i=0; i<q; i++) {
        cin >> tmp;
        if (dfs(a, tmp)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<long long> T(N), A(N);
    rep(i, N) cin >> T[i] >> A[i];
    
    REP(i, N) {
        long long x = (T[i - 1] - 1) / T[i] + 1;
        long long y = (A[i - 1] - 1) / A[i] + 1;
        T[i] *= max(x, y);
        A[i] *= max(x, y);
    }
    cout << T[N - 1] + A[N - 1] << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

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

    int cnt, ans=0;
    for(int i=1; i<=n; i=i+2){
        cnt =0;
        for(int j=1; j<=i; j++){
            if(i % j == 0) cnt++;
        }
        if(cnt == 8) ans++;
    }
    cout<< ans << endl;
}

Measured memory_bytes: 3604
s = int(input())

sl = []

for i in range(4):
    sen = s // 1000
    hyaku = (s - sen * 1000) // 100
    ju = (s - sen * 1000 - hyaku * 100) // 10
    ichi = s % 10

if sen == hyaku or hyaku == ju or ju == ichi:
    print("Bad")
    exit()

print("Good")


Measured memory_bytes: 2940
# include <bits/stdc++.h>
using namespace std;
string s,saw,bol;
int q,ty[200005],k,k1,idx[200005];
char ch[200005];
int main()
{
	cin>>s;
	cin>>q;
	for (int i=1; i<=q; i++)
	{
		cin>>ty[i];
		if (ty[i]==1)
		{
			k++;	
		}	
		else
		{
			cin>>idx[i]>>ch[i];
		}
	}
	k1=0;
	bol="";
	for (int i=1; i<=q; i++)
	{
		if (ty[i]==1)
		{
			k1++;
		}
		else
		{
			if ((idx[i]==2 && k1%2==0) || (idx[i]==1 && k1%2==1))
			{
				bol+=ch[i];
			}
		}
	}
	s+=bol;
	
	reverse(s.begin(),s.end());
	bol="";
	k1=0;
	for (int i=1; i<=q; i++)
	{
		if (ty[i]==1)
		{
			k1++;
		}
		else
		{
			if ((idx[i]==2 && k1%2==1)||(idx[i]==1 && k1%2==0))
			{
				bol+=ch[i];
			}
		}
	}
	s+=bol;
	if (k1%2==0)
	{
		reverse(s.begin(),s.end());
	}
	cout<<s<<endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int S, W;
	cin >> S >> W;
	puts([&] {
		return S <= W;
	}() ? "unsafe": "safe");
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    int h[N];
    REP(i, N) cin >> h[i];

    bool done[N];
    REP(i, N) done[i] = false;

    bool f = false;
    int cur = 0;
    ll count = 0;
    while (!f) {
        int left = 0, right = N;
        int m = 1000;
        REP(i, N) {
            if (!f && !done[i]) {
                left = i;
                m = h[i];
                f = true;
            }
            else if (f && done[i]) {
                right = i;
                break;
            }
            else if (f && !done[i]) {
                m = min(m, h[i]);
            }
        }
        FOR(i, left, right) {
            h[i] -= m;
            if (h[i] == 0) {
                done[i] = true;
            }
        }
        if (f) {
            count += m;
            cur = m;
            f = false;
        }
        else break;
    }

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


Measured memory_bytes: 256
import sys


n,k=map(int,input().split())
p=list(map(int,input().split()))
for i in range(n):
    p[i]-=1
c=list(map(int,input().split()))

def smax(b,nn):
    cc=0
    bmax9=-10**20
    for i in range(nn):
#       print(b,p[b])
       b=p[b]
       cc+=c[p[b]]
#       print(i,cc,bmax9)
       bmax9=max(bmax9,cc)
    return bmax9,cc

if k<=n:
    bmax=-10**20
    for st in range(n):
        bmax9,cc=smax(st,k)
        bmax=max(bmax,bmax9)
    print(bmax)
    sys.exit()
    
bmax=-10**20
for st in range(n):
    cc=0
    b=st
    chk=[-1]*n
    chk[st]=0
    for i in range(n):
       b=p[b]
       if chk[b]>=0:
           break
       else:
           chk[b]=i+1

#    ki=chk[b]+1
#    kc=(i+1)-chk[b]
#    k2=(k-ki)%kc+ki
    ki=chk[b]
    kc=i-chk[b]+1
    k2=(k-ki-1)%kc+ki+1
#    print(st,ki,kc,k2)
    bmax1,cc1=smax(st,ki+kc)
    bmax0,cc0=smax(st,ki)
    ccc=cc1-cc0
    if ccc<=0:
        bmax9,cc=smax(st,k2+kc)
    else:
        bmax9,cc=smax(st,k2+kc)
        bmax9+=ccc*((k-ki-1)//kc-1)

    bmax=max(bmax,bmax9)
print(bmax)



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


int main() {
  int N;
  cin >> N;
  vector< pair<int,int> > A(N);
  REP(i,N) {
    cin >> A[i].first;
    A[i].second = i+1;
  }
  sort( A.begin(), A.end() );
  
  REP(i,N) {
    cout << A[i].second << " ";
  }
  cout << endl;
}


Measured memory_bytes: 1664
#include <iostream>

int main(){
    long int h,w;
    std::cin>>h>>w;
    if(h==1 || w==1)
        std::cout << 1;
    else{
        if(h*w % 2 == 1)
            std::cout<<h*w/2 + 1;
        else
            std::cout<<h*w/2;
    }
    return 0;
}

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

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

int main(){
  int a,b;
  cin >> a >> b;

  if(a>=13)cout << b;
  else if(a<=5)cout << 0;
  else cout << b/2;
}

Measured memory_bytes: 3536
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.uni;

void main()
{
  auto s = readln.chomp;
  writeln(s.map!(swapCase));
}

dchar swapCase(dchar c) {
  if (c.isLower) return c.toUpper;
  else if (c.isUpper) return c.toLower;
  else return c;
}

Measured memory_bytes: 2528
#include <stdio.h>
#define MAX 50

int fib(int n, int memo[]) {
   int ans;
   if (n == 0 || n == 1) {
	  memo[n] = 1;
	  return 1;
   }
   if (memo[n] == -1) {
	  ans = fib(n - 1, memo) + fib(n - 2, memo);
	  memo[n] = ans;
	  return ans;
   }
   else 
	  return memo[n];
}

int main() { 
   int memo[MAX];
   int n;
   int i = 0;

   while (i < MAX) {
	  memo[i] = -1;
	  ++i;
   }

   scanf("%d", &n);
   
   printf("%d\n", fib(n, memo));

   return 0;
}

Measured memory_bytes: 1852
import sys
def I(): return int(sys.stdin.readline().rstrip())

N = I()

A = [0]*10  # A[i] = i桁の七五三数の個数
for i in range(1,10):
    A[i] = 3**i-3*2**i+3

d = len(str(N))  # Nの桁数
ans = sum(A[i] for i in range(1,d))  # d桁未満の七五三数の個数
B = []  # d桁の七五三数list

from itertools import product

for a in list(product(['3','5','7'],repeat=d)):
    if len(set(a)) == 3:
        b = ''
        for i in range(d):
            b += a[i]
        B.append(int(b))

print(ans+sum(n <= N for n in B))


Measured memory_bytes: 76960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);


vi lis(vi a){
  ll size=a.size();
  vi v(size,INF);
  for(ll i:a){
    auto it=lower_bound(v.begin(),v.end(),i);
    *it=i;
  }
  vi ret; for(ll i:v) if(i==INF) break; else ret.push_back(i);
  return ret;
}

int main(){
  ll n; cin>>n;
  vi a(n); REP(i,n) cin>>a[i];
  cout<<lis(a).size()<<endl;
}

Measured memory_bytes: 6132
from fractions import gcd

N = int(input())
lisA = list(map(int,input().split()))

lisA.sort()
ans = 10**9 + 1

for num in lisA[1:]:
    tmp = gcd(lisA[0],num)
    ans = min(ans,tmp)
    if ans == 1:
        print(ans)
        exit()

print(ans)

Measured memory_bytes: 16280
def main():
    n = int(input())
    str_list = []
    for i in range(n):
        str_list.append(list(input().split() + [i+1]))

    str_list = sorted(str_list, key = lambda x:(x[0], -int(x[1])))

    for i in range(n):
        print(str_list[i][2])

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
/*
 Shahadat Hossain
 I.C.T Department
 Comilla University
 Session: 2013-2014
 */

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define valid(x,y) x>=0 && y>=0 && x<n && y<m
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define ms(a,b) memset(a, b, sizeof(a))
#define eps 1e-5
#define input freopen("/Users/shahadat/Desktop/input.txt", "r", stdin)
#define output freopen("/Users/shahadat/Desktop/output.txt", "w", stdout)
#define d(x) cout << #x << " = " << x << endl
#define dd(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define ddd(x,y,z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl
//fprintf(stdout,"\nTIME: %.3lf sec\n", (double)clock()/(CLOCKS_PER_SEC));
//int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
#define bit(n,k) (((n)>>(k))&1)
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define pr(x) {cout << (x) << '\n';  }
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define mask(i) ((1LL<<(i)))
#define endl '\n'
double const PI = acos(-1);
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}


int Check(int n, int pos){return n & (1 << pos);}
int Set(int n, int pos){return n |= (1 << pos);}


using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
int const MOD = 1e9 + 7;

int const N = 1005;
int n, m;
char str[N][N];
int dp[N][N];

void fun(){
    dp[n - 1][m - 1] = 1;
    for(int i = n - 1 ; i >= 0; i--){
        for(int j = m - 1; j >= 0; j--){
            if(str[i][j] == '#') continue;
            if(valid(i, j + 1) && str[i][j + 1] != '#')
                dp[i][j] +=  dp[i][j + 1];
            if(valid(i + 1, j) && str[i + 1][j] != '#')
                dp[i][j] += dp[i + 1][j];
            dp[i][j] %= MOD;
        }
    }
}

int32_t main(){
    cin >> n  >> m;
    for(int i = 0; i < n; i++){
        scanf("%s", str[i]);
    }
    
    fun();
    cout << dp[0][0] << endl;
}


Measured memory_bytes: 9088
"use strict";
main(require("fs").readFileSync("/dev/stdin", "UTF-8"));

function main(input) {
  input = input.trim().split("\n");

  const monsterCount = parseInt(input[0].split(" ")[0]);
  let deathblowCount = parseInt(input[0].split(" ")[1]);

  const strength = input[1]
    .split(" ")
    .map(e => parseInt(e))
    .sort((a, b) => b - a);

  let result = 0;

  while (deathblowCount < monsterCount) {
    result += strength[deathblowCount];
    deathblowCount += 1;
  }

  console.log(result);
}


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

using namespace std;

#define FastIO ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read(in) freopen("Input.txt","r",stdin)
#define write(out) freopen("Ouput.txt","w",stdout)
#define pf printf
#define sf scanf
#define fr(i,n) for(i=1 ; i<=n ; i++)
#define fr1(i,x,n) for(i=x ; i<=n ; i++)
#define sf1(val) scanf("%lld",&val)
#define sf2(val1,val2) scanf("%lld %lld",&val1,&val2)
#define INF 999999999999999999
#define Pi 2*acos(0.0)
#define len 200000

typedef long long int lli;

lli a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,sum=0,total=0,res=0,ans=0;

int main()
{
    //FastIO;

    //read(in);

    cin>>t;

    vector<char>ar;

    char ch;

    sum=t;

    while(1)
    {
        res=sum%26;

        if(res==0)  ch='z';

        else ch='a'+res-1;

        ar.push_back(ch);

        sum=sum/26;

        if(res==0)  sum--;

        if(sum<=0)     break;
    }

    f=ar.size();

    fr(i,f) cout<<ar[f-i];

    cout<<"\n";
}

Measured memory_bytes: 3608
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

void a_hotel_easy(void) {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	int sum = 0;
	
	if (n > k) {
		sum = x * k + y*(n-k);

	}
	else       sum = x * n;

	cout << sum << endl;
}

int main()
{
    a_hotel_easy();
    return 0;
}

Measured memory_bytes: 3652
n = int(input())
sp = [[0, 0, 0] for i in range(n)]
for i in range(n):
  sp[i][0], sp[i][1] = list(map(str, input().split()))
  sp[i][1] = int(sp[i][1])
  sp[i][2] = i+1
sp.sort()

c=1
for i in range(n-1):
  if sp[i][0] == sp[i+1][0]:
    c+=1
    i+=1
  else:
    for j in range(c):
      print(sp[i-j][2])
    c=1
for j in range(c):
  print(sp[n-1-j][2])

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

inline int rd() {
  int x = 0;
  bool f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return f ? -x : x;
}

int main() {
  int a = rd();
  int b = rd();
  int c = rd();
  int d = rd();
  ll ans = -inf;
  ans = max(ans, 1ll * a * c);
  ans = max(ans, 1ll * a * d);
  ans = max(ans, 1ll * b * c);
  ans = max(ans, 1ll * b * d);
  printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> S;
  rep(i,0,S.size()){
    A=S[i]-'A';
    A=(A+N)%26;
    NeOut((char)('A'+A));
  }
  Out("");
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

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

	min := exec(X)
	fmt.Println(min)

}

func exec(X []int) int {
	var sum, min int

	min = 1000000000000
	for p := 1; p <= 100; p++ {
		sum = 0
		for _, v := range X {
			sum += (v - p) * (v - p)
		}

		if sum < min {
			min = sum
		}
	}

	return min
}


Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<bits/stdc++.h>
#define ll long long  
#define d double
using namespace std;

int main()
{
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     int n;
     cin>>n;
     if(n%1000==0) {
     cout<<"0"<<endl;	
	 }
     else{
     int k=n%1000;
     cout<<abs(1000-k)<<endl;
     } 
     return 0;
}

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

using namespace std;

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

#define INF 1001001001001001001LL

long long cost[100][100];
long long  d[100];
bool used[100];
int V;

long long dijkstra(int s, int g){
    fill(d, d+V, INF);
    fill(used,used+V, false);
    d[s]=0;
    
    while(true){
        int v=-1;
        for(int u=0; u<V; u++){
            if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
        }
        if(v==-1)break;
        //cout<<"use "<<v<<" cost: "<<d[v]<<endl;
        used[v]=true;
        
        for(int u=0; u<V; u++){
            d[u]=min(d[u], d[v]+cost[v][u]);
        }
    }
    //rep(i,V)cout<<d[i]<<"\t";
    //<<endl;
    return d[g]<=100000000000000000LL?d[g]:-1;
}

int main(void){
    // Here your code !
    int k;
    while(cin>>V>>k,V||k){
        rep(i,V)fill(cost[i],cost[i]+V,INF);
        rep(i,k){
            int t;
            cin>>t;
            if(t){
                int c,d; long long e;
                cin>>c>>d>>e;
                cost[c-1][d-1]=min(e,cost[c-1][d-1]);
                cost[d-1][c-1]=min(cost[c-1][d-1],e);
            }
            else{
                int a,b;
                cin>>a>>b;
                cout<<dijkstra(a-1,b-1)<<endl;;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n, k; std::cin >> n >> k;
    std::vector<std::pair<int, int>> ans;
    for (int i = 1; i < n; i++) {
        ans.emplace_back(1, i + 1);
    }
    int cnt = (n - 1)*(n - 2)/2;
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (cnt <= k) break;
            ans.emplace_back(i + 1, j + 1);
            cnt--;
        }
    }
    if (cnt != k) {
        std::cout << -1 << std::endl;
        return 0;
    }
    std::cout << ans.size() << std::endl;
    for (auto p : ans) std::cout << p.first << " " << p.second << std::endl;
    return 0;
}


Measured memory_bytes: 384