akhauriyash/Code-Regression huggingface dataset:
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!(n: usize, d: usize,);
    let ans = (n + d * 2) / (d * 2 + 1);
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<unordered_map>

using namespace std;
typedef long long LL;
const int  mod = 2019;

LL l, r;
LL res = 2020;
int st[40000];

int main()
{
    scanf("%lld%lld", &l, &r);
    if(l > 2019)
    {
        if(r - l >= 2019) printf("0");
        else
     {
        for(int i = l; i <= r;i ++)
    {
       for(int j = i + 1; j <= r; j ++)
        res = min((LL)i * j % 2019, res);
    }
     printf("%lld", res);
     }
     
    }
   else if(l == 2019) printf("0");
   else if(r >= 2019) printf("0");
   else if(r < 2019)
   {
       for(int i = l; i <= r;i ++)
    {
       for(int j = i + 1; j <= r; j ++)
        res = min((LL)i * j % 2019, res);
    }
     printf("%lld", res);
   }
    
    
  
    
   return 0;
}

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

int main(){
  int  N, K;
  cin >> N >> K;
  
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int ansMax = 0;
  
  for (int i = 0; i < K; i++) {
    ansMax += vec.at(i);
  }
  
  cout << ansMax << endl;
  
}

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

#define ll long long

ll a[100005], k, n;

ll ans=INT_MAX;

ll dp[100005];

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

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

	for(int i=0;i<100001;i++)
		dp[i]=1e9;

	dp[0]=0;
	dp[1]= abs(a[1]-a[0]);

	for(int i=0;i<n;i++)
	{
		for(int j=1;j<=k;j++)
			if(i+j <n)
				dp[i+j]=min(dp[i+j], dp[i]+abs(a[i]-a[i+j]));
	}

	cout << dp[n-1] << endl;

	return 0;
}


Measured memory_bytes: 1792
c11, c12, c13 = map(int, input().split())

for i in range(2):
    c1, c2, c3 = map(int, input().split())
    if (c1-c11) == (c2-c12) and (c2-c12) == (c3-c13):
        c11, c12, c13 = c1, c2, c3
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 9064
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 2000000000000000000 //2e18
 
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

char grid[1001][1001];
int dp[1001][1001]={0};

void solve()
{
    int n,m,t,i,k,r,l,u,v,w,j,s,pos,sum=0,flag=0,count=0;
    string S,T,U; 
    int h;
    cin>>h>>w;
    rep(i,0,h)
    {
        rep(j,0,w) 
        {
            cin>>grid[i][j];
        }
    }
    rep(i,0,h)
    {
        rep(j,0,w)
        {
            if(!i&&!j)
            {
                dp[i][j]=1;
            }
            else if(!i)
            {
                dp[i][j]=dp[i][j-1];
                dp[i][j]%=mod;
                if(grid[i][j]=='#') dp[i][j]=0;
            }
            else if(!j)
            {
                dp[i][j]=dp[i-1][j];
                dp[i][j]%=mod;
                if(grid[i][j]=='#') dp[i][j]=0;
            }
            else
            {
                dp[i][j]=dp[i-1][j]+dp[i][j-1];
                dp[i][j]%=mod;
                if(grid[i][j]=='#') dp[i][j]=0;
            }
        }
    }
    cout<<dp[h-1][w-1];
}

 

signed main()
{

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}


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

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

using namespace std;

const int IINF = INT_MAX;

int n,found,len;
vector<string> buf[30],seq;
string tmp,sequence,answer;
char transfer[26];

bool comp(const string& a,const string& b) {
  set<char> A,B;
  rep(i,a.size()) A.insert(a[i]);
  rep(i,b.size()) B.insert(b[i]);
  return A.size() > B.size();
}

void dfs(int cur){

  if( found >= 2 ) return;

  if( cur >= len ){
    ++found;
    rep(i,answer.size()) if( isupper(answer[i]) ) answer[i] = transfer[answer[i]-'A'];
    return;
  }

  int word_size = seq[cur].size();

  rep(i,(int)buf[word_size].size()){
    string word = buf[word_size][i];

    int *backtrack = new int[word_size+1];
    backtrack[0] = -1; // sentinel
    bool error = false;
    rep(j,word_size){
      if( transfer[word[j]-'A'] == '?' && transfer[seq[cur][j]-'A'] == '?' ) {
        backtrack[j] = 1, backtrack[j+1] = -1;
        transfer[word[j]-'A'] = seq[cur][j];
        transfer[seq[cur][j]-'A'] = word[j];
      } else if( transfer[word[j]-'A'] == seq[cur][j] && transfer[seq[cur][j]-'A'] == word[j] ) {
        backtrack[j] = 0;
      } else {
        backtrack[j] = -1;
        error = true;
        break;
      }
    }

    if( !error ) dfs( cur+1 );

    int j = 0;
    while( backtrack[j] != -1 && j < word_size) {
      if( backtrack[j] == 1 ) transfer[word[j]-'A'] = transfer[seq[cur][j]-'A'] = '?';
      ++j;
    }

  }

}

int main(){
  while( cin >> n, n ){
    seq.clear();
    rep(i,30) buf[i].clear();
    rep(i,n) {
      cin >> tmp;
      buf[(int)tmp.size()].push_back(tmp);
    }
    cin.ignore();
    getline(cin,sequence);
    stringstream ss(sequence.substr(0,(int)sequence.size()-1));
    while( !( ss >> tmp ).fail() ) seq.push_back(tmp);
    sort(seq.begin(),seq.end(),comp);

    answer = sequence;
    found = 0, len = (int)seq.size();
    rep(i,26) transfer[i] = '?';
    dfs(0);

    cout << ((found==1)?answer:"-.") << endl;

  }
  return 0;
}

Measured memory_bytes: 8100
import math
a,b,x=map(int,input().split())
A,B=a**2,b**2
print(math.degrees(math.asin((B/((2*x/(a*b))**2+B))**0.5) if 2*x<=a*a*b else math.acos((A/((2*(a*a*b-x)/A)**2+A))**0.5)))


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

int main(){
	char s[200001];
	int i,j;
	scanf("%s",s);
	for(i=0;i<strlen(s);i++){
		if(s[i]=='A') break;
	}
	for(j=strlen(s)-1;j>=0;j--){
		if(s[j]=='Z') break;
	}
	
	printf("%d\n",j-i+1);
	
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
#include <utility>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
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 * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*///map < string, ll> s;

/*i++ずつずらす
a[0] a[1] a[2]//a[1] a[2] a[3]
a[0] a[2] a[4]//a[1] a[3] a[5]
/*if (N % 2 != 0)a = N / 2;
else a = N / 2 - 1;
for (int i = 1;i <= a;i++) {
	for (int j = 0;j < N - (i * 2);j++) {
		if (S[j] != S[j + i] && S[j + i * 2] != S[j] && S[j + i] != S[j + i * 2]) sum--;
		if (sum == 0)break;
	}
}*/

//mapの使い方
/*map<int, int> mp;
for (int i = 0; i < N; i++)
	mp[a[i]]++;

int ans = 0;
for (auto p : mp) {
	int x = p.first;
	int n = p.second;
	if (n < x) ans += n;
	else ans += n - x;
}*/

int main() {
	ll A, B;cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
using namespace std;
int x[100010],y[100010],z[100010],b[3][100010];
signed main(){
	int a;
	cin>>a>>x[0]>>y[0]>>z[0];
	b[0][0]=x[0];
	b[1][0]=y[0];
	b[2][0]=z[0];
	f(i,a-1){
		cin>>x[i+1]>>y[i+1]>>z[i+1];
		b[0][i+1]=max(b[1][i]+x[i+1],b[2][i]+x[i+1]);
		b[1][i+1]=max(b[0][i]+y[i+1],b[2][i]+y[i+1]);
		b[2][i+1]=max(b[1][i]+z[i+1],b[0][i]+z[i+1]);
	}
	cout<<max({b[0][a-1],b[1][a-1],b[2][a-1]})<<endl;
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std;
 
int main() {
    int n, k;
    string s;

    cin >> n >> k >> s;

    s[k-1] += 0x20;

    cout << s << endl;
}


Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt()
	c := make([]int, n-1)
	s := make([]int, n-1)
	f := make([]int, n-1)
	for i := 0; i < n-1; i++ {
		c[i] = readInt()
		s[i] = readInt()
		f[i] = readInt()
	}

	for i := 0; i < n; i++ {
		now := 0
		for j := i; j < n-1; j++ {
			if now < s[j] {
				now = s[j]
			} else {
				if now%f[j] == 0 {
					now = (now / f[j]) * f[j]
				} else {
					now = (1 + now/f[j]) * f[j]
				}
			}
			now += c[j]
		}
		println(now)
	}
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
S = input()
n = len(S)
lis = [0] * (len(S)+1)
for i in range(n):
    if S[i] == '<':
        lis[i+1] = max(lis[i+1],lis[i] + 1)
for i in range(n-1,-1,-1):
    if S[i] == '>':
        lis[i] = max(lis[i], lis[i+1]+1)
print(sum(lis))


Measured memory_bytes: 30332
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
VI ps,al;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n,k;
  cin>>n>>k;
  ps=al=VI(n+1);
  forn(z,n){
    cin>>al[z+1];
    if(al[z+1]>=0)
      ps[z+1]=al[z+1];
    ps[z+1]+=ps[z];
    al[z+1]+=al[z];
  }
  in smps=ps[n];
  in bst=0;
  for(in s=0;s+k<=n;++s){
    bst=max(bst,smps-(ps[s+k]-ps[s])+max(0LL,al[s+k]-al[s]));
  }
  cout<<bst<<endl;
  return 0;
}


Measured memory_bytes: 1792
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define ushi int
#define tapu main
#define nichia (
#define kunn void
#define wara )

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

/*
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	ll ans = 0;
	if (a[0] != 0) {
		printf("-1\n");
		return 0;
	}
	rep(i, n - 1) {
		if (a[i + 1] - a[i] == 1)ans += a[i + 1] - a[i];
		else if (a[i + 1] - a[i] > 1) {
			printf("-1\n");
			return 0;
		}
		else ans += a[i + 1];
	}
	printf("%d\n", ans);
*/

ushi tapu nichia kunn wara{

	ushi x, a;
	scanf("%d%d", &x, &a);
	printf("%d\n", x < a ? 0 : 10);

	Please AC;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

const int INF = 1<<30;

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> lv(n), rv(n);
    for(int i = 0; i < n; i++){
        if (s[i] == 'W') {
            if (i == 0) lv[i] = 1;
            else lv[i] = lv[i-1]+1;
        }
        else lv[i] = lv[i-1];
    }
    reverse(all(s));
    for(int i = 0; i < n; i++){
        if (s[i] == 'E') {
            if (i == 0) rv[i] = 1;
            else rv[i] = rv[i-1]+1;
        }
        else rv[i] = rv[i-1];
    }
    reverse(all(rv));
    int ans = INF;
    for(int i = 0; i < n; i++){
        int cnt = 0;
        if (i-1 >= 0) cnt += lv[i-1];
        if (i+1 < n) cnt += rv[i+1];
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define queue QQQ
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RAnK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn = 2e5+233;
const int mod = 1e9+7;
int n;
int c1[maxn],c2[maxn],cnt[maxn],a[maxn],tot,D[maxn],invD[maxn];
int zero[maxn],S[maxn];
#define lowbit(x) ((x) & (-x))
inline int qpow(int a,int b){
	int ans = 1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1) ans=1ll*ans*a%mod;
	return ans;
}
void add(int c[],int x,int v){
	for(;x<=n;x+=lowbit(x))
		(c[x] += v) %= mod;
}
int query(int c[],int x){
	int ans = 0;
	for(;x;x-=lowbit(x))
		(ans += c[x]) %= mod;
	return ans;
}
int main(){
	n = rd();
	Rep(i,1,n) cnt[a[i]=rd()]++;
	Dep(i,n-1,1) cnt[i]+=cnt[i+1];
	tot = 1;
	Dep(i,n,1) cnt[i] -= n-i;
	Dep(i,n,1) tot = 1ll * tot * cnt[i] % mod; 
	if(!tot){puts("0");return 0;}
	S[0] = 1;D[0] = 1;
	Rep(i,1,n){
		if(cnt[i]==1) D[i] = D[i-1]; else  
					  D[i] = 1ll * (cnt[i]-1) * qpow(cnt[i],mod-2) % mod * D[i-1] % mod;
		if(cnt[i]==1){
			zero[i] = zero[i-1] + 1;
			S[zero[i]] = i;
		} else{
			zero[i] = zero[i-1];
		}
		invD[i] = qpow(D[i],mod-2);
	}
	mem(c1,0);mem(c2,0);
	ll ans = 0;
	Rep(i,1,n){
		ans = (ans + 1ll * tot * qpow(2,mod-2) %mod * (query(c1,a[i]) - query(c1,a[i]-1))) % mod;//same
		ans = (ans + 1ll * tot * qpow(2,mod-2) %mod * D[a[i]] %mod * (query(c2,a[i]-1) - query(c2,S[zero[a[i]]]-1) + mod) % mod) % mod;//small
		add(c1,a[i],1);
		add(c2,a[i],invD[a[i]]);
	}//相同的
//	writeln(ans);
	mem(c1,0);mem(c2,0);
	Dep(i,n,1){
		ans = (ans - 1ll * tot * qpow(2,mod-2) %mod * D[a[i]] %mod * (query(c2,a[i]-1) - query(c2,S[zero[a[i]]]-1) + mod)% mod + mod) % mod;
		ans = (ans + 1ll * query(c1,a[i]-1) * tot) % mod;
		add(c1,a[i],1);
		add(c2,a[i],invD[a[i]]);
	} 
	writeln(ans);
	return 0;
}
/*
考虑枚举出某个数

需要查询它右边的答案

1、右边和它相同的。 
	倒着做， 
2、右边比它小的。 

3、右边比它大的。 

sum * sum(D[i]) / (sum(D[])) 
*/

Measured memory_bytes: 6528
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	int n,i,j,k,x,y,ans,curr,temp,m;
	int tc;
    ll a,b,c;
    ll take;
    cin >> a >> b >> c >> take;
    ll chaeng = 0;
    chaeng += min(a, take);
    take -= min(a, take);
    take -= min(b, take);
    chaeng -= min(c, take);
    cout << chaeng << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
 
int main()
{
  int height[10];
   
  for(int i = 0 ; i < 10 ; i++)
    {
      cin >> height[i];
    }
 
  for(int i = 0 ; i < 10 ; i++)
    {
      for(int j = i + 1 ; j < 10 ; j++)
    {
      if(height[i] < height[j])
        {
          int dumy = height[i];
          height[i] = height[j];
          height[j] = dumy;
        }
    }
    }
  for(int i = 0 ; i < 3 ; i++)
    {
      cout << height[i] << endl;
    }
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    int a[5],b[5];
    int last = INF;
    int mem1,mem2,sum = 0;
    for (int i=0;i<5;i++) {
        cin >> a[i];
        b[i] = a[i]%10;
        if (b[i]!=0) {
            if (last >= b[i]) {
                last = b[i];
                mem1 = a[i];
                mem2 = i;
            }
            a[i] = (a[i]/10) + 1;
            a[i] = a[i] * 10;
        }
        sum += a[i];
    }
    if (last == INF) {
        cout << sum << endl;
        return 0;    
    }
    sum -= a[mem2];
    sum += mem1;
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int A, B;
void input() {
  cin >> A >> B;
  int x, y, z;

  ;
}
void solve() {
  bool alice;
  if (A == 13 && B == 1) {
    alice = false;
  } else if (A == 1 && B == 13) {
    alice = true;
  } else if (A == B) {
    cout << "Draw" << endl;
    return;
  } else {
    alice = A > B;
  }
  cout << (alice ? "Alice" : "Bob") << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int h, w;
	
	cin >> h >> w;
	
	char s[h][w];
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> s[i][j];
		}
	}
	
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (s[i][j] == '.')
			{
				char cnt = '0';
				
				if (i == 0)
				{
					if (j == 0)
					{
						if (w == 1)
						{
							if (s[i+1][j] == '#')  cnt++;	
						}
						else{
							if (s[i][j+1] == '#')  cnt++;
							if (s[i+1][j] == '#')  cnt++;
							if (s[i+1][j+1] == '#')  cnt++;
						}
					}
					else if (j == w - 1 && w != 1)
					{
						if (s[i][j-1] == '#')  cnt++;
						if (s[i+1][j] == '#')  cnt++;
						if (s[i+1][j-1] == '#')  cnt++;
					}
					else
					{
						if (s[i][j+1] == '#')  cnt++;
						if (s[i][j-1] == '#')  cnt++;
						if (s[i+1][j+1] == '#')  cnt++;
						if (s[i+1][j] == '#')  cnt++;
						if (s[i+1][j-1] == '#')  cnt++;
					}
				}
				else if (i == h - 1 && h != 1)
				{
					if (j == 0)
					{
						if (w == 1)
						{
							if (s[i-1][j] == '#')  cnt++;	
						}
						else{
							if (s[i][j+1] == '#')  cnt++;
							if (s[i-1][j] == '#')  cnt++;
							if (s[i-1][j+1] == '#')  cnt++;
						}
					}
					else if (j == w - 1 && w != 1)
					{
						if (s[i][j-1] == '#')  cnt++;
						if (s[i-1][j] == '#')  cnt++;
						if (s[i-1][j-1] == '#')  cnt++;
					}
					else
					{
						if (s[i][j+1] == '#')  cnt++;
						if (s[i][j-1] == '#')  cnt++;
						if (s[i-1][j+1] == '#')  cnt++;
						if (s[i-1][j] == '#')  cnt++;
						if (s[i-1][j-1] == '#')  cnt++;
					}
				}
				else
				{
					if (j == 0)
					{
						if (w == 1)
						{
							if (s[i+1][j] == '#')  cnt++;	
							if (s[i-1][j] == '#')  cnt++;
						}
						else{
							if (s[i][j+1] == '#')  cnt++;
							if (s[i-1][j] == '#')  cnt++;
							if (s[i-1][j+1] == '#')  cnt++;
							if (s[i+1][j] == '#')  cnt++;
							if (s[i+1][j+1] == '#')  cnt++;
						}
					}
					else if (j == w - 1 )
					{
						if (s[i][j-1] == '#')  cnt++;
						if (s[i-1][j] == '#')  cnt++;
						if (s[i-1][j-1] == '#')  cnt++;
						if (s[i+1][j] == '#')  cnt++;
						if (s[i+1][j-1] == '#')  cnt++;
					}
					else
					{
						if (s[i][j+1] == '#')  cnt++;
						if (s[i][j-1] == '#')  cnt++;
						if (s[i-1][j+1] == '#')  cnt++;
						if (s[i-1][j] == '#')  cnt++;
						if (s[i-1][j-1] == '#')  cnt++;
						if (s[i+1][j+1] == '#')  cnt++;
						if (s[i+1][j] == '#')  cnt++;
						if (s[i+1][j-1] == '#')  cnt++;
					}
				}
				s[i][j] = cnt;
			}
		}
	}
	
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cout << s[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d
#include <bits/stdc++.h>
using namespace std;

vector<long long> divisors(long long n){
  vector<long long> res;
  for(long long i = 1; i*i <= n; ++i) {
    if(n % i != 0) continue;
    res.push_back(i);
    if(n/i == i) continue;
    res.push_back(n/i);
  }
  return res;
}

int main(void){
  long long N;
  cin >> N;
  vector<long long> divs = divisors(N);

  long long sum = 0;
  for (int i = 0; i < divs.size(); i++){
    if (divs[i] > 1)
      if ((N / (divs[i] - 1)) == (N % (divs[i] - 1)))
        sum += divs[i] - 1;
  }

  cout << sum << endl;
}

Measured memory_bytes: 384
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 62;
const int inf = 1<<30;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        os << "\n";
    }
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << "(";
    os << P.first;
    os << " ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
//fixed<<setprecision(10)<<ans<<endl;

ll H,W;
bool is_inside(int h,int w){
    return (0<=h && h<H-2 && 0<=w && w<W-2);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> H >> W >> N;
    map<pair<int,int>,ll> cnt;
    int a,b;
    REP(i,N){
        cin >> a >> b;
        a--;b--;
        for(int dx=-2;dx<=0;dx++){
            for(int dy=-2;dy<=0;dy++){
                if(is_inside(a+dy,b+dx)){
                    cnt[mp(a+dy,b+dx)]++;
                }
            }
        }
    }

    vector<ll> ans(10,0);
    ans[0]=(H-2)*(W-2);
    pair<int,int> where;
    ll num=0;
    for(auto m:cnt){
        tie(where,num)=m;
        ans[num]++;
        ans[0]--;
    }



    cout << ans << endl;
}

Measured memory_bytes: 56576
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

signed main(){
    string S;
    cin >> S;
    ll sum = 0;
    REP(i, S.length()){
        sum += S[i] - '0';
    }
    if(sum % 9 == 0) PRINT("Yes");
    else PRINT("No");
    return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int a;
    cin >> a;
    if(a == 1) cout << "Hello World" << endl;
    else{
        int p, q;
        cin >> p >> q;
        cout << p+q << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        vector<ll> v(n);
        for(i = 0; i < n; i++){
            cin >> v[i];
        }
        ll flag = 0;
        for(i = 0; i < n ;i++){
            if(v[i] != i + 1){
                flag++;
            }
        }        
        if(flag <= 2){
            cout <<"YES";
        }
        else{
            cout << "NO";
        }
    }
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
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;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

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

    ll N;
    cin >> N;

    vector<char> memo(27);
    ll i = 1;
    for(char c = 'a'; c <= 'z'; c++) memo[i] = c, i++;

    string ans = "";
    while(N > 26) {
        if(N % 26 == 0) ans += 'z';
        else ans += memo[(N % 26)];
        N--;
        N /= 26;
    }
    if(N % 26 == 0) ans += 'z';
    else if(N > 0) ans += memo[(N % 26)];
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

int main() {
    int n;
    cin >> n;
    vector<int> a;
    int k=1;
    a.push_back(k);
    while(1) {
        k*=6;
        if (k<=n) a.push_back(k);
        else break;
    }
    k=1;
    while(1) {
        k*=9;
        if (k<=n) a.push_back(k);
        else break;
    }
    sort(a.begin(),a.end());
    int m=a.size();
    vector<int> dp(n+1);
    repr(i,1,n+1) {
        int tmp=n;
        rep(j,m) {
            if (i>=a[j]) tmp=min(tmp,dp[i-a[j]]+1);
        }
        dp[i]=tmp;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s1, s2, s3 string
	fmt.Scan(&s1, &s2, &s3)

	ans := strings.ToUpper(s1[0:1] + s2[0:1] + s3[0:1])

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;

const int inf = 1000000000;
typedef pair<int, int> pa;
typedef pair<pa, int> ppa;
int N, M;
vector<vector<int>> V;
vector<vector<int>> D;
vector<vector<vector<ppa>>> G;
map<pa, int> mp;
deque<pa> deq;

int main(){

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    V.resize(N, {0});
    D.resize(N, {inf});
    G.resize(N, {{}});

    auto addV = [&](int ver, int com){
        if(mp.find(pa(ver, com)) == mp.end()){
            int sz = (int)V[ver].size();
            mp[pa(ver, com)] = sz;
            V[ver].push_back(sz);
            D[ver].push_back(inf);
            G[ver][0].push_back(ppa(pa(ver, sz), 1));
            G[ver].push_back({ppa(pa(ver, 0), 0)});
        }
    };

    auto addE = [&](int from, int to, int com) {
        int fid = mp[pa(from, com)];
        int tid = mp[pa(to, com)];
        G[from][fid].push_back(ppa(pa(to, tid), 0));
        G[to][tid].push_back(ppa(pa(from, fid), 0));
    };

    rep(i, M){
        int p, q, c;
        cin >> p >> q >> c;
        p--; q--;
        addV(p, c);
        addV(q, c);
        addE(p, q, c);
    }

    D[0][0] = 0;
    deq.push_back(pa(0, 0));
    while((int)deq.size()){
        pa p = deq.front(); deq.pop_front();
        int ver = p.first, id = p.second;
        for(auto x : G[ver][id]){
            if(chmin(D[x.first.first][x.first.second], D[ver][id] + x.second)){
                if(x.second == 0)deq.push_front(pa(x.first.first, x.first.second));
                else deq.push_back(pa(x.first.first, x.first.second));
            }
        }
    }

    cout << (D[N - 1][0] == inf ? -1 : D[N - 1][0]) << endl;
    return 0;

}

Measured memory_bytes: 78336
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
    static const double pi = 3.141592653589793;
    int A, B;
    int H, M;
    cin >> A >> B >> H >> M;

    double thetah = pi * (H + M / 60.0) / 6.0;
    double thetam = pi * M / 30.0;
    double theta = thetam - thetah;
    double dist = A * A + B * B - 2.0 * A * B * cos(theta);
    dist = sqrt(dist);
    cout << setprecision(20) << dist;
}

Measured memory_bytes: 4164
using System;

class Program
{
    static void Main()
    {
        string s = Console.ReadLine();
        int count = 0;
        char prev = s[0];
        
        foreach (char c in s)
        {
            if (prev != c) {
                ++count;
                prev = c;
            }
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 11232
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

const ll MOD = 1000000007;

ll intpow(ll a, ll n) {
  if (n == 0) return 1;
  ll x = intpow(a, n/2);
  x = (x*x) % MOD;
  if (n&1) x = (x*a) % MOD;
  return x;
}

ll comb(ll n, ll a) {
  ll x = 1, y = 1;
  loop(i,1,a+1) {
    x = (x * (n-i+1)) % MOD;
    y = (y*i) % MOD;
  }
  
  return (x * intpow(y, MOD-2)) % MOD;
}

int main() {
  ll n, a, b; cin >> n >> a >> b;
  ll ans = intpow(2, n);
  ans -= 1;
  ans -= comb(n, a);
  if (ans < 0) ans += MOD;
  ans -= comb(n, b);
  if (ans < 0) ans += MOD;
  cout << ans << endl;
  return 0;
}


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

int d[111][111],dp[111][111],dd[1111111];
int main() {
  int s,n,u,m,o,t;
  cin >> s >> n >> u >> m >> o >> t;
  memset(d,-1,sizeof(d));
  d[0][0]=0;
  for(int i=0; i<n; i++) {
    int x,y;
    cin >> x >> y;
    for(int k=u-1; k>=0; k--) {
      for(int j=s-1; j>=0; j--) {
        if(j+x<=s&&d[j][k]!=-1) d[j+x][k+1]=max(d[j+x][k+1],d[j][k]+y);
      }
    }
  }
  fill(dd,dd+1111111,-(1<<29));
  dd[0]=0;
  for(int i=0; i<m; i++) {
    int x,y;
    cin >> x >> y;
    for(int j=0; j<1111111; j++) {
      if(j+x<1111111) dd[j+y]=max(dd[j+y],dd[j]+x);
    }
  }
  for(int i=1; i<1111111; i++) dd[i]=max(dd[i],dd[i-1]);
  memset(dp,-1,sizeof(dp));
  dp[0][s]=0;
  for(int i=0; i<t; i++) {
    for(int j=0; j<=s; j++) {
      if(dp[i][j]==-1) continue;
      int r=min(s,j+o);
      for(int k=0; k<=s; k++) {
        if(r-k<0) break;
        if(d[k][u]==-1) continue;
        dp[i+1][r-k]=max(dp[i+1][r-k],dp[i][j]+dd[d[k][u]]);
      }
    }
  }
  int ans=-1;
  for(int i=0; i<=s; i++) ans=max(ans,dp[t][i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_066_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, m, s;
            string[] word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            m = a;
            if (m < b)
                m = b;

            if (m < c)
                m = c;

            s = (a + b + c) - m;



            Console.WriteLine(s);

            //Console.ReadKey();


        }
    }
}

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

using namespace std;

int main()
{
    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
        string str;
        cin >> str;
        vector<string> vec;
        int l = str.size();
        for (int i = 0; i < l; i++) {
            string head = str.substr(0, i);
            string head_ = head;
            string tail = str.substr(i);
            vec.push_back(head + tail);
            vec.push_back(tail + head);
            reverse(head.begin(), head.end());
            vec.push_back(head + tail);
            vec.push_back(tail + head);
            reverse(tail.begin(), tail.end());
            vec.push_back(head_ + tail);
            vec.push_back(head + tail);
            vec.push_back(tail + head_);
            vec.push_back(tail + head);
        }
        sort(vec.begin(), vec.end());
        vec.erase(unique(vec.begin(), vec.end()), vec.end());
        cout << vec.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 3136
N=int(input())
XL=[list(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x:x[0]+x[1])
ans=1
left=XL[0][0]+XL[0][1]
for i in range(1,N):
  if XL[i][0]-XL[i][1] >= left:
    ans+=1
    left=XL[i][0]+XL[i][1]
  else:
    pass
print(ans)

Measured memory_bytes: 32296
package main

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

func main() {
	scanInit()

	s := nextStr()
	t := nextStr()

	if strings.Index(s, t) != -1 {
		fmt.Println(0)
		return
	}

	matchmax := 0
	for i := 0; i < len(s)-len(t)+1; i++ {
		nowmatch := 0
		for j := 0; j < len(t); j++ {
			if s[i+j] == t[j] {
				nowmatch++
			}

		}
		matchmax = max(matchmax, nowmatch)
	}

	fmt.Println(len(t) - matchmax)

}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1796
#include <iostream>
using namespace std;
typedef long long ll;

int N,M,K;
ll A[100010],dp[100010][310] = {{0}},D[100010] = {0};

int main(){
	cin >> N >> M >> K;
	for(int i=1;i<=N;i++){
		cin >> A[i];
		dp[i][1] = A[i];
	}
	int s = 0,t = 0;
	for(ll j=2;j<=K;j++){
		for(int i=1;i<N;i++){
			while(s<t && dp[D[t-1]][j-1]<=dp[i][j-1]) t--;
			D[t] = i;
			t++;
			if(j-1<=i){
				int m = D[s];
				dp[i+1][j] = dp[m][j-1] + j*A[i+1];
				if(i>=M && D[s]==i-M+1) s++;
			}
		}
		for(int i=0;i<=N;i++) D[i] = 0;
		s = 0; t = 0;
	}
	ll ans = 0;
	for(int i=K;i<=N;i++) ans = max(ans,dp[i][K]);
	cout << ans << endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;




signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  vll a(4);
  rep(i,4) a[i]=s[i]-'0';
  for(ll bit=0; bit<(1<<3); bit++){
    ll sum=a[0];
    rep(i,3){
      if(bit>>i&1) sum+=a[i+1];
      else sum-=a[i+1];
    }
    if(sum==7){
      cout<<a[0];
      rep(i,3){
        if(bit>>i&1) cout<<'+'<<a[i+1];
        else cout<<'-'<<a[i+1];
      }
      cout<<"=7"<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int pcnt(int n) {
	int ret = 0;
	for (int i = 0; i < 21; i++) {
		if (n & 1) ret++;
		n >>= 1;
	}
	return ret;
}

ll mod = 1000000007;
int dp[22][2100000];

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(n));
	rep(i, n) rep(j, n) cin >> a[i][j];
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < (1 << n); j++) {
			if (pcnt(j) != i) continue;
			for (int k = 0; k < n; k++) {
				if (a[i][k]) {
					dp[i + 1][j | (1 << k)] += dp[i][j];
					if (dp[i + 1][j | (1 << k)] > mod) dp[i + 1][j | (1 << k)] -= mod;
				}
			}
		}
	}
	cout << dp[n][(1 << n) - 1] << endl;
}

Measured memory_bytes: 323840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int,int>;

const int mx = 3e5+5;
const int md = 998244353;

int ten[mx], dig[10][mx];
int lazy[mx<<2], t[mx<<2];

void merge(int p, int l, int m, int r){
    int u = t[p<<1], v = t[p<<1|1];
    t[p] = (u * 1LL * ten[r-m] + v) % md;
}

void build(int p, int l, int r){
    if(l == r) t[p] = 1;
    else{
        int m = (l+r)/2;
        build(p<<1,   l,   m);
        build(p<<1|1, m+1, r);
        merge(p, l, m, r);
    }lazy[p] = -1;
}

void updateLazy(int p, int l, int r){
    t[p] = dig[lazy[p]][r-l+1];
    if(l != r){
        lazy[p<<1]   = lazy[p];
        lazy[p<<1|1] = lazy[p];
    }lazy[p] = -1;
}

void update(int p, int l, int r, int i, int j, int v){
    if(lazy[p] != -1) updateLazy(p, l, r);
    if(l>r || l>j || r<i) return;
    if(l>=i && r<=j) {
        lazy[p] = v;
        updateLazy(p, l, r);
        return;
    }
    int m = (l+r)/2;
    update(p<<1, l, m, i, j, v);
    update(p<<1|1, m+1, r, i, j, v);
    merge(p, l, m, r);
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);

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

    ten[0] = 1;
    for(int i=1; i<mx; i++)
        ten[i] = (ten[i-1] * 10LL) % md;

    for(int i=0; i<=9; i++){
        dig[i][0] = 0;
        for(int j=1; j<mx; j++)
            dig[i][j] = (dig[i][j-1] * 10LL + i)%md;
    }

    build(1, 1, n);
    int u, v, ans=0;
    for(int i=0; i<k; i++){
        int l, r, d;
        cin >> l >> r >> d;
        update(1, 1, n, l, r, d);
        cout << t[1] << "\n";
    }

    return 0;
}



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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int a_plan = N * A;
  
  if (a_plan < B){
    cout << a_plan << endl;
  } else {
    cout << B << endl;
  }
}


Measured memory_bytes: 256