akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

signed main(){
	int q;
	map<string,int>m;
	cin>>q;
	while(q--){
		int t,y;
		string x;
		cin>>t;
		if(t==0){
			cin>>x>>y;
			m[x]=y;
		}
		if(t==1){
			cin>>x;
			cout<<m[x]<<endl;
		}
	}
}


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

using namespace std;
long long a[100005];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int k;
    cin >> k;
    for (int i = 1; i <= k; i++)
        cin >> a[i];
    long long l = 2, r = 2;

    for (int i = k; i > 0; i--)
    {
        long long t = ((l - 1) / a[i] + 1) * a[i];
        if (t > r) cout << -1, exit(0);
        l = t;
        r = r / a[i] * a[i] + a[i] - 1;
    }
    cout << l << ' ' << r;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define sc1(n) scanf("%lld",&n)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define MX 100000
using namespace std;

typedef long long int ll;
typedef unsigned long long ul;

ll arr[100005];
ll dp[100005];
ll n,k;

int main()
{
    for(ll i=1;i<=100000;i++)
    {
        dp[i]=INT_MAX;
    }
    sc2(n,k);
    for(ll i=1;i<=n;i++)
    {
        sc1(arr[i]);
    }
    dp[1]=0;
    for(ll i=1;i<n;i++)
    {
        for(ll j=1;j<=k;j++)
        {
            if(i+j>n)
                continue;
            dp[i+j]=min(dp[i+j],abs(arr[i]-arr[i+j])+dp[i]);
        }
    }
    printf("%lld\n",dp[n]);
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>

long long dp[51][2];

int main()
{
  long long n, p;
  scanf("%lld%lld", &n, &p);
  long long a[50];
  dp[0][0] = 1;
  for (long long i = 0; i < n; ++i)
  {
    scanf("%lld", a + i);
  }
  for (long long i = 0; i < n; ++i)
  {
    dp[i + 1][0] = (a[i] & 1) ? dp[i][0] + dp[i][1] : 2 * dp[i][0];
    dp[i + 1][1] = (a[i] & 1) ? dp[i][0] + dp[i][1] : 2 * dp[i][1];
  }
  printf("%lld\n", dp[n][p]);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

#define MAX 30
#define NIL -1

typedef struct node{
  int parent;
  int left;
  int right;
}Node;

Node T[MAX];

void preorder(int);
void inorder(int);
void postorder(int);

int main(){
  int i, j, n;
  int id, left, right;
  int root = NIL;
  
  scanf("%d",&n);
  for(i=0; i<n; i++){
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }

  for(i=0; i<n; i++){
    scanf("%d%d%d",&id,&left,&right);
    T[id].left = left;
    T[id].right = right;
    if(left != NIL) T[left].parent = id;
    if(right != NIL) T[right].parent = id;
  }
  for(i=0; i<n; i++){
    if(T[i].parent == -1) root = i;
  }

  printf("Preorder\n");
  preorder(root);
  printf("\n");

  printf("Inorder\n");
  inorder(root);
  printf("\n");

  printf("Postorder\n");
  postorder(root);
  printf("\n");
  return 0;
}

void preorder(int u){
  if(u != NIL){
    printf(" %d",u);
    preorder(T[u].left);
    preorder(T[u].right);
  }
}

void inorder(int u){
  if(u != NIL){
    inorder(T[u].left);
    printf(" %d",u);
    inorder(T[u].right);
  }
}

void postorder(int u){
  if(u != NIL){
    postorder(T[u].left);
    postorder(T[u].right);  
    printf(" %d",u);
  }
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int h, w; cin >> h >> w;
  REP(i, h) {
    REP(j, w) {
      string s; cin >> s;
      if(s == "snuke") {
        cout << (char)('A'+j) << i+1 << endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
pair<int,int> c[110000];
int main(){
	int a;
	long long b;
	scanf("%d%lld",&a,&b);
	for(int i=0;i<a;i++){
		int p,q;scanf("%d%d",&p,&q);
		c[i]=make_pair(p,q);
	}
	std::sort(c,c+a);
	for(int i=0;i<a;i++){
		if(b<=c[i].second){
			printf("%d\n",c[i].first);
			return 0;
		}
		b-=c[i].second;
	}
}

Measured memory_bytes: 896
io = STDIN
h,w=io.gets.split.map(&:to_i)
maze=[]


h.times do |i|
  maze << io.gets.chomp.split(//)
end
maze.select!{|row|row.any?{|c|c=="#"}}
tran=maze.transpose.select{|row|row.any?{|c|c=="#"}}
puts tran.transpose.map{|ar|"#{ar.join}\n"}.join


Measured memory_bytes: 2684
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

int main(){
    int N,M; cin >> N >> M;
    vector<ll> X(M);
    for(int i=0;i<M;i++) cin >> X[i];
    if(N>=M){
        cout << 0 << endl;
        return 0;
    }
    sort(X.begin(),X.end());
    vector<ll> L;
    for(int i=1;i<M;i++){
        L.push_back(X[i]-X[i-1]);
    }
    sort(L.begin(),L.end(),greater<ll>());

    ll cnt=0;
    for(int i=0;i<N-1;i++){
        cnt += L[i];
    }
    cerr << "\t" << cnt << "\n";
    cout << X[M-1]-X[0]-cnt << endl;
    return 0;
}


Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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() {
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        a.at(x-1)=i+1;
    }
    for(int i=0;i<n;i++){
        cout<<a.at(i)<<" ";
    }
    cout<<endl;





    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      // cout << i << " " << a[i] << endl;
      cnt++;
    }  
    ans += cnt;
  }
  cout << ans << endl;
}

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

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;
const int N = 200000;
int n;
ll a[N], c[N+1];

int main() {
  fscanf(stdin, "%d ", &n);
  memset(c, 0, n*sizeof(ll));
  REP(i,n) {
    fscanf(stdin, "%lld ", a+i);
    c[a[i]]++;
  }
  ll sum = 0;
  REP(i,N+1) sum += c[i]*(c[i]-1)/2;
  REP(i,n) fprintf(stdout, "%lld\n", sum-max<ll>(c[a[i]]-1, 0));
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  double x[n];
  string u[n];
  for ( int i = 0; i < n; i++ ) {
    cin >> x[i] >> u[i];
  }

  double ans = 0;
  for ( int i = 0; i < n; i++ ) {
    ans += ( u[i] == "JPY" ) ? x[i] : x[i]*380000.0;
  }

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


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll cn=b/c-(a-1)/c;
  ll dn=b/d-(a-1)/d;
  ll g=c/__gcd(c,d)*d;
  ll cdn=b/g-(a-1)/g;
  //cout<<cn<<" "<<dn<<" "<<cdn<<endl;
  cout<<b-a+1-(cn+dn-cdn)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<long> vl;
typedef vector<vector<long> > vvl;
typedef vector<string> vs;

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

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    int N;
    cin >> N;
    vl heights = input<long>(N);

    int prevHeight = heights[0];
    int maxSteps = 0;
    int steps = 0;

    for (int i = 1; i < N; ++i) {
        if (heights[i] <= prevHeight) {
            steps++;
        } else {
            steps = 0;
        }
        if (maxSteps < steps) {
            maxSteps = steps;
        }
        prevHeight = heights[i];
    }

    cout << maxSteps << endl;

    return 0;
}


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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define int long long

using namespace std;

const int N = 25, MASK = 1 << 18, mod = 1e9 + 7;

int n, m, ar[N], dp[N][MASK], fc[MASK], in[MASK], nn, ans;

int binpow (int a, int b)
{
    if (b == 0)
        return 1ll;

    if (b & 1)
        return (a * 1ll * binpow(a, b - 1) % mod);

    int res = binpow(a, b >> 1);

    return (res * 1ll * res % mod);
}
int Calc (int n, int k)
{
    if (n < k)
        return 0ll;

    return fc[n] * 1ll * in[k] % mod * in[n - k] % mod;
}
main()
{
    cin >> n >> m;

    nn = (1 << n);

    fc[0] = in[0] = 1;

    for (int i = 1; i <= nn; i++)
    {
        fc[i] = fc[i - 1] * 1ll * i % mod;
        in[i] = binpow(fc[i], mod - 2);
    }
    for (int i = 1; i <= m; i++)
        cin >> ar[i];

    sort( ar + 1, ar + m + 1, greater <int>() );

    dp[0][0] = 1;

    for (int i = 1; i <= m; i++)
    {

        for (int mask = 0; mask < (1 << n ); mask++)
        {
            int sum = 0;

            for (int j = 0; j < n; j++)
            {
                if (mask & (1 << j))
                    sum += (1 << j);
            }
            dp[i][mask] += dp[i - 1][mask];
            dp[i][mask] %= mod;
            for (int j = 0; j < n; j++)
            {
                if (!(mask & (1 << j)) ) continue;

                dp[i][mask] += ( (dp[i - 1][mask ^ (1 << j) ] * 1ll * fc[ (1 << j) ] ) % mod * 1LL * Calc( nn - ar[i] - sum + (1 << j), (1 << j) - 1 ) ) % mod;
                dp[i][mask] %= mod;
            }
        }
    }
    for (int mask = 0; mask < (1 << n); mask++)
    {
        int res = dp[m][mask], sum = 0;

        if (__builtin_popcount(mask) & 1)
            res = -res + mod;

        for (int i = 0; i < n; i++)
        {
            if (mask & (1 << i)) continue;
            sum += (1 << i);
        }

        ans = ans + res * fc[sum] % mod;

        ans %= mod;
    }
    cout << ans * (1 << n) % mod << endl;
}


Measured memory_bytes: 37632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		while (n > 0) {
			int max = 0;
			int min = Integer.MAX_VALUE;
			int sum = 0;
			for (int i = 0; i < n; i++) {
				int v = scanner.nextInt();
				sum += v;
				if (max < v) max = v;
				if (min > v) min = v;
			}
			sum -= (max + min);
			int av = sum / (n-2);
			System.out.println(av);
			n = scanner.nextInt();
		}
	}
}



Measured memory_bytes: 28484
use std::cmp;
use std::collections::VecDeque;
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let p: Vec<_> = (0..(n * n)).map(|_| sc.read::<usize>() - 1).collect();
    let mut dist = vec![0; n * n];
    for x in 0..(n * n) {
        let (i, j) = (x / n, x % n);
        let h = cmp::min(i, n - 1 - i);
        let w = cmp::min(j, n - 1 - j);
        dist[x] = cmp::min(h, w);
    }

    let mut next = vec![vec![vec![]; n]; n];
    for i in 0..n {
        for j in 0..n {
            if i > 0 {
                next[i][j].push((i - 1, j));
            }
            if j > 0 {
                next[i][j].push((i, j - 1));
            }
            if i + 1 < n {
                next[i][j].push((i + 1, j));
            }
            if j + 1 < n {
                next[i][j].push((i, j + 1));
            }
        }
    }

    let mut empty = vec![false; n * n];
    let mut sum = 0;
    for p in p.into_iter() {
        empty[p] = true;
        let (i, j) = (p / n, p % n);
        sum += dist[p];
        let mut q = VecDeque::new();
        for &(ni, nj) in next[i][j].iter() {
            let np = ni * n + nj;
            if dist[np] > dist[p] {
                dist[np] = dist[p];
                q.push_back((ni, nj));
            }
        }

        while let Some((i, j)) = q.pop_front() {
            let p = i * n + j;
            let cost = if empty[p] { 0 } else { 1 };
            for &(ni, nj) in next[i][j].iter() {
                let np = ni * n + nj;
                if dist[np] > dist[p] + cost {
                    dist[np] = dist[p] + cost;
                    q.push_back((ni, nj));
                }
            }
        }
    }
    println!("{}", sum);
}
pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 31572
def resolve():
    n = int(input())

    count = {
        'AC': 0,
        'WA': 0,
        'TLE': 0,
        'RE': 0
    }

    for _ in range(n):
        s = input()
        count[s] += 1

    for k, v in count.items():
        print(k, 'x', v)


if 'unittest' not in globals():
    resolve()

Measured memory_bytes: 69844
#https://atcoder.jp/contests/abc048/tasks/abc048_b

#import math

a,b,x=map(int,input().split())
#max_num=math.floor(b/x)
#min_num=math.ceil(a/x)
#print(max_num-min_num+1)

if a==0:
    print((b//x)+1)
else:
    print((b//x)+1-(((a-1)//x)+1))
    

Measured memory_bytes: 2940
n, k = map(int, input().split())
arr = list(map(int, input().split()))
dp = [float("inf")] * len(arr)
dp[0] = 0
for j in range(1, len(arr)):
    for i in range(1, k + 1):
        if j >= i:
            dp[j] = min(dp[j], dp[j - i] + abs(arr[j] - arr[j - i]))
        else:
            break
print(dp[-1])


Measured memory_bytes: 54880
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,p;
  cin>>n;
  p=n%10;
  if(p==3) cout<<"bon"<<endl;
  else if(p==0||p==1||p==6||p==8) cout<<"pon"<<endl;
  else cout<<"hon"<<endl;;
}


Measured memory_bytes: 3656
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
for _ in range(N) :
  l = list(map(int, input().split()))
  A.append(l)
#print (A)

cnt = 0
for i in range(N) :
  sum = C
  for j in range(M) :
    sum += A[i][j] * B[j] 
  if sum > 0 :
    cnt += 1
    
print (cnt)




Measured memory_bytes: 38256
#ifdef LOCAL
#  define _GLIBCXX_DEBUG
#  define _GLIBCXX_DEBUG_PEDANTIC
#endif

#include "bits/stdc++.h"
#define ff first
#define ss second
#define szof(_x) ((int) (_x).size())
#define TASK_NAME ""

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const ll INFL = 1e18 + 123;
const double PI = atan2(0, -1);
mt19937 tw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(tw) % (y - x + 1) + x; }

const int MOD = 1000000007;

void add(int& a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

int sum(int a, int b) {
	add(a, b);
	return a;
}

int mult(int a, int b) {
	return (ll) a * b % MOD;
}

int mpow(int a, int b) {
	int ret = 1;
	while (b) {
		if (b & 1) {
			ret = mult(ret, a);
		}
		a = mult(a, a);
		b >>= 1;
	}
	return ret;
}

void solve() {
	int n;
	cin >> n;
	vector<int> inp;
	vector<int> pref = {0};
	vector<int> sum_of_len(n + 1);
	for (int i = 0; i < n; ++i) {
		int num;
		cin >> num;
		inp.push_back(num);
		pref.push_back(sum(pref.back(), num));
		add(sum_of_len[n], num);
	}

	function<ll(int, int)> get_sum = [&](int l, int r) {
		return sum(pref[r], MOD - pref[l]);
	};

	for (int i = n - 1; i >= 1; --i) {
		if (i * 2 >= n) {
			sum_of_len[i] = sum(sum_of_len[i + 1], get_sum(n - i, i));
		} else {
			sum_of_len[i] = sum(sum_of_len[i + 1], MOD - get_sum(i, n - i));
		}
	}

	// for (int i = 1; i <= n; ++i) {
	// 	ll tmp = 0;
	// 	for (int j = 0; j + i <= n; ++j) {
	// 		for (int k = 0; k < i; ++k) {
	// 			tmp += inp[j + k];
	// 		}
	// 	}

	// 	assert(tmp == sum_of_len[i]);
	// }

	vector<int> factorial = {1};

	for (int i = 1; i <= n + 5; ++i) {
		factorial.push_back(mult(factorial.back(), i));
	}

	vector<int> inv_factorial = {mpow(factorial.back(), MOD - 2)};

	for (int i = n + 5; i >= 1; --i) {
		inv_factorial.push_back(mult(inv_factorial.back(), i));
	}

	reverse(inv_factorial.begin(), inv_factorial.end());

	function<ll(int, int)> cnk = [&](int n, int k) {
		return mult(factorial[n], mult(inv_factorial[k], inv_factorial[n - k]));
	};

	int ans = 0;
	for (int i = 1; i <= n - 2; ++i) {
		int s = sum(sum(sum_of_len[i], MOD - get_sum(0, i)), MOD - get_sum(n - i, n));
		add(ans, mult(mult(mult(mult(factorial[n - i - 2], factorial[i]), 2), cnk(n, i + 2)), s));
	}
	for (int i = 1; i <= n - 1; ++i) {
		int s = sum(get_sum(0, i), get_sum(n - i, n));
		add(ans, mult(mult(mult(factorial[n - i - 1], factorial[i]), cnk(n, i + 1)), s));
	}

	add(ans, mult(factorial[n], get_sum(0, n)));

	cout << ans << "\n";
}


int main() {
	//freopen(TASK_NAME ".in", "r", stdin);
	//freopen(TASK_NAME ".out", "w", stdout);
	cerr << fixed << setprecision(15);
	cout << fixed << setprecision(15);
	ios::sync_with_stdio(false);

	int tests = 1;
	// cin >> tests;
	for (int it = 1; it <= tests; ++it) {
		solve();
	}
	
	#ifdef LOCAL
		cerr << "time: " << clock() << " ms\n";
	#endif
	return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  
  vector<vector<char>> data1(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> data1.at(i).at(j);
    }
  }
  
  vector<vector<char>> data2;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (data1.at(i).at(j) == '#') {
        data2.push_back(data1.at(i));
        break;
      }
    }
  }
  
  vector<vector<char>> data3(w, vector<char>(data2.size()));
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < data2.size(); j++) {
      data3.at(i).at(j) = data2.at(j).at(i);
    }
  }
  
  
  vector<vector<char>> data4;
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < data2.size(); j++) {
      if (data3.at(i).at(j) == '#') {
        data4.push_back(data3.at(i));
        break;
      }
    }
  }
    
  vector<vector<char>> data5(data2.size(), vector<char>(data4.size()));
  for (int i = 0; i < data2.size(); i++) {
    for (int j = 0; j < data4.size(); j++) {
      data5.at(i).at(j) = data4.at(j).at(i);
    }
  }
  for (int i = 0; i < data2.size(); i++) {
    for (int j = 0; j < data4.size(); j++) {
      cout << data5.at(i).at(j);
      if (j == data4.size() - 1)
        cout << endl;
    }
  }
  
}

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

AC=0
WA=0
TLE=0
RE=0

for i in range(N):
  TEST = input()
  if TEST == "AC":
    AC += 1
  elif TEST == "WA":
    WA += 1
  elif TEST == "TLE":
    TLE += 1
  else:
    RE += 1

print("AC x "+str(AC))
print("WA x "+str(WA))
print("TLE x "+str(TLE))
print("RE x "+str(RE))

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
char s[105] = {};
int main() {
	scanf("%s", s + 1);
	int n = 1, ans = 0;
	while(s[n] != 0) {
		n++;
	}
	n--;
	int x = n / 2;
	for(int i = 1; i <= x; i++) {
		if(s[i] != s[n - i + 1]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
F = []
P = []
for i in range(N):
    F += [list(map(int, input().split()))]
for i in range(N):
    P += [list(map(int, input().split()))]
ans = float('-inf')

for b in range(2**10):
    tmp = 0
    sumc = 0
    for i in range(N):
        c = 0
        for j in range(10):
            if (b >> j) & 1 and F[i][j]:
                c += 1
        tmp += P[i][c]
        sumc += c
    if sumc:
        ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 3064
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = list(input())
# = [tuple(map(int, input().split())) for _ in range(n)]

n, k = map(int, input().split())
h = list(map(int, input().split()))

h.sort(reverse=True)

if k >= n:
    print(0)
else:
    print(sum(h[k:]))

Measured memory_bytes: 26180
#include <bits/stdc++.h>
using namespace std;
#define int long long

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

  set <int> st = {1, 2, 3};
  int x, y;
  cin >> x >> y;
  st.erase(x);
  st.erase(y);
  cout << *st.begin();
  return 0;
}


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

typedef long long ll;

int n, k;
int a[105];
int game[100005];
int main()
{
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a, a+n);

    for(int i = a[0]; i <= k; i++) {
        bool willwin = 0;
        for(int j = 0; j < n && i >= a[j]; j++) {
            if(game[i-a[j]] == 0) {
                willwin = 1;
                break;
            }
        }
        game[i] = willwin;
    }

    if(game[k] == 1) {
        printf("First\n");
    } else {
        printf("Second\n");
    }

    return 0;
}


Measured memory_bytes: 640
while True:
    n=int(input())
    k=int(input())
    if n==0:
        break
    c=[input() for _ in [0]*n]
    
    s=set()
    
    from itertools import permutations
    
    cnt=0
    for i in permutations(range(n),k):
        s.add(int("".join([c[j] for j in i])))
    print(len(s))


Measured memory_bytes: 5848
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
const ll inf = 1LL<<60;

int main()
{
  int n; cin >> n;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  int ans = 1001001001;
  for (int p=1; p<=100; p++) {
    int tmp = 0;
    for (int i=0; i<n; i++) {
      tmp += (x[i]-p)*(x[i]-p);
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


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

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

    int ans = 1e7;
    for (int i = 1; i < n; ++i) {
      ans = min(ans, a[i] - a[i - 1]);
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3132
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int V,E;
int d[20][20];
int dp[1<<16][16];
int main(){
	cin>>V>>E;
	//memset(d, INF, sizeof(d));
	for(int S =0;S <(1<<V);S++){
		fill(dp[S], dp[S]+V, INF);
	}
	for(int i =0;i <V;i++){
		for(int j =0;j <V;j++){
			d[i][j]=INF;
		}
	}
	for(int i =0;i <E;i++){
		int x,y,c;
		cin>>x>>y>>c;
		d[x][y]=c;
	}
	dp[(1<<V)-1][0]=0;
	for(int S =(1<<V)-2;S >=0;S--){
		for(int v = 0; v <V;v++){
			for(int u = 0;u < V;u++){
				if(!(S>>u&1)){
					dp[S][v]=min(dp[S][v],dp[S|1<<u][u]+d[v][u]);
					//cout <<dp[S][v]<<endl;
				}
			}
		}
	}
	if(dp[0][0]>=INF){
		cout <<-1<<endl;
	}else{
		cout <<dp[0][0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 5252
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define INF 1e9
#define vint vector<int>

using namespace std;
typedef long long  ll;

const long long M = 1e9+7;

int main()
{
    int s, w;
    cin >> s >> w;
    if(w >= s){
        p("unsafe");

    } else {
        p("safe");
    }
}

Measured memory_bytes: 3136
package main

import (
	"fmt"
	"sort"
)

type RuneSlice []rune
func (p RuneSlice) Len() int           {return len(p)}
func (p RuneSlice) Less(i, j int) bool {return p[i] < p[j]}
func (p RuneSlice) Swap(i, j int)      { p[i], p[j] = p[j], p[i]}

func main() {
	var s string
	fmt.Scan(&s)
	rs := []rune(s)
	sort.Sort(RuneSlice(rs))
	
	if rs[0] == rs[1] && rs[1] != rs[2] && rs[2] == rs[3] {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}


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

template<typename T, T M>
struct modint {
  T n;
  constexpr modint(const T n = 0) : n((n % M + M) % M) {}
  constexpr modint pow(T r) const {
    modint ans(1), a(n);
    while(r) { if (r & 1) ans *= a; a *= a; r >>= 1; }
    return ans;
  }
  
  constexpr modint& operator+= (const modint r) {
    n += r.n; if (n >= M) n -= M; return *this;
  }
  constexpr modint& operator-= (const modint r) {
    n -= r.n; if (n < 0) n += M; return *this;
  }
  constexpr modint& operator*= (const modint r) {
    n = n * r.n % M; return *this;
  }
  constexpr modint operator+ (const modint r) const { return modint(n) += r; }
  constexpr modint operator- (const modint r) const { return modint(n) -= r; }
  constexpr modint operator* (const modint r) const { return modint(n) *= r; }
  
  /* Divisions only work for prime modules */
  constexpr modint& operator/= (const modint r) { return (*this) *= r.pow(M-2); }
  constexpr modint operator/ (const modint r) const { return modint(n) /= r; }
};

template<typename T>
struct modfact {
  vector<T> fact, invfact;
  
  constexpr modfact(int n): fact(n + 1), invfact(n + 1) {
    fact[0] = T(1);
    for(int i = 1; i <= n; i++)
      fact[i] = fact[i - 1] * T(i);
    invfact[n] = T(1) / fact[n];
    for(int i = n - 1; i >= 0; --i)
      invfact[i] = invfact[i + 1] * T(i + 1);
  }
  
  constexpr T p(int n, int k) const {
    // permutations: n! / k!
    if (k < 0 || k > n) return T(0);
    return fact[n] * invfact[k];
  }
  
  constexpr T c(int n, int k) const {
    // combinations(binomial coefficient): n! / (k! * (n - k)!)
    if (k < 0 || k > n) return T(0);
    return p(n, k) * invfact[n - k];
  }
};

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

typedef modint<long, 1000000007L> mint;

int main() {
  int k, n(0);
  char c;
  cin >> k;
  while (cin >> c) n++;
  
  mint ans(0);
  modfact<mint> mf(n + k);
  
  for (int i = 0; i <= k; ++i)
    ans += mint(26).pow(k - i) * mint(25).pow(i) * mf.c(i + n - 1, n - 1);
  
  cout << ans.n << '\n';
  return 0;
}

Measured memory_bytes: 34332
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

string S, T;

bool solve(string U) {
	if (U.size() < T.size()) return false;
	for (int i = 0; i <= U.size() - T.size(); i++) {
		bool flag = false;
		for (int j = 0; j < T.size(); j++) {
			if (U[i + j] != '?' && U[i + j] != T[j]) flag = true;
		}
		if (flag == false) return true;
	}
	return false;
}

int main() {
	cin >> S >> T;
	if (solve(S) == false) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != '?') continue;
		for (int j = 0; j < 26; j++) {
			S[i] = ('a' + j);
			if (solve(S) == true) break;
		}
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 3596
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

l = [int(input()) for _ in range(5)]

idx = -1
mi = 10

for i in range(5):
    remain = l[i] % 10
    if remain != 0:
        if mi > remain:
            mi = remain
            idx = i
ans = 0
for i in range(5):
    remain = l[i] % 10
    if (remain == 0):
        ans += l[i]
    else:
        if (i == idx):
            ans += l[i]
        else:
            ans += (l[i] // 10 + 1)*10
print(ans)




Measured memory_bytes: 9140
Scanf.scanf "%d" (fun n ->
    let d = ref 1 in
    for i = 1 to (int_of_float @@ sqrt @@ float_of_int @@ n) do
        if n mod i == 0 then d := i
    done;
    Printf.printf "%d\n" ( !d - 1 + n / !d - 1 )
)


Measured memory_bytes: 3844
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e3+5,mod=1e9+7;
int n,k;
long long ans=0,f[maxn][maxn],dp[maxn][maxn];
long long qpow(long long x,int i){
	long long res=1;
	while(i){
		if(i&1){res=res*x%mod;}
		x=x*x%mod;i/=2;
	}
	return res;
}
int main(){
	scanf("%d%d",&n,&k);
	memset(f,0,sizeof(f));
	memset(dp,0,sizeof(dp));
	dp[0][2]=1;
	for(int i=n;i>=2;i--){f[1][i]=1;dp[1][i]=(f[1][i]+dp[1][i+1])%mod;}
	for(int i=2;i<k;i++){
		for(int j=n-i+1;j>=2;j--){
		    f[i][j]=(f[i-1][j]+dp[i-1][j+1])%mod;
			dp[i][j]=(f[i][j]+dp[i][j+1])%mod;
		}
	}
	ans=dp[k-1][2];
	ans=ans*qpow(2,max(n-k-1,0))%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 63104
#include<iostream>

using namespace std;

int main()
{
  int n,x,count;
  cin >> n >> x;
  while(n||x){
    count=0;
    for(int i=1; i<n-1; i++){
      for(int j=i+1; j<n; j++){
        for(int k=j+1; k<n+1; k++){
          if(i+j+k==x)count++;
        }
      }
    }
    cout << count << endl;
    cin >> n >> x;
  }
  return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



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

  if(a<=b&&b<=a+W){
    cout<<0;
    return 0;
  }
  if(b<=a&&a<=b+W){
    cout<<0;
    return 0;
  }
  if(a+W<b){
    cout<<b-a-W;
    return 0;
  }
  if(b+W<a){
    cout<<a-b-W;
  }
  return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class UnionFind{
	vector<ll> rank;
	vector<ll> diff_weight;
	vector<ll> num;
public:
	vector<ll> par;

	UnionFind(ll N):par(N),num(N),rank(N),diff_weight(N){
		for(ll i=0;i<N;i++){
			par[i]=i;
			num[i]=1;
			rank[i]=0;
			diff_weight[i]=0;
		}
	}

	ll root(ll x){
		if(par[x]==x){
			return x;
		}
		ll r = root(par[x]);
		diff_weight[x]+=diff_weight[par[x]];
		return par[x]=r;
	}

	void unite(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		if(rank[rx]<rank[ry]) swap(rx,ry);
		if(rank[rx]==rank[ry]) ++rank[rx];
		par[ry] = rx;
		num[rx] += num[ry];
	}

	void relate(ll x,ll y,ll w){
		w+=weight(x),w-=weight(y);
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		if(rank[rx]<rank[ry]){
			swap(rx,ry);
			w = -w;
		}
		if(rank[rx]==rank[ry]) ++rank[rx];
		par[ry] = rx;
		diff_weight[ry] = w;
		num[rx] += num[ry];
	}

	bool same(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		return rx == ry;
	}

	ll getsize(ll x){
		return num[root(x)];
	}

	ll weight(ll x){
		root(x);
		return diff_weight[x];
	}

	ll diff(ll x,ll y){
		return weight(y)-weight(x);
	}
};

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

	int N=in(),M=in();
	UnionFind uf(N);
	REP(i,M){
		int x=in()-1,y=in()-1,z=in();
		uf.unite(x,y);
	}
	unordered_set<int> S;
	REP(i,N){
		S.emplace(uf.root(i));
	}

	out(S.size());
	return 0;
}


Measured memory_bytes: 7460
#include<stdio.h>
#include<string.h>
#define p_x 100
#define p_y 100
int high[200][200];
int deme[200][200];
char* dtable[7][7]={{"none","none","none","none","none","none","none"},
					{"none","none","2354","3542","4235","5423","none"},
					{"none","1463","none","3146","4631","none","6314"},
					{"none","1265","2651","none","none","5126","6512"},
					{"none","1562","2156","none","none","5621","6215"},
					{"none","1364","none","3641","4136","none","6413"},
					{"none","none","2453","3245","4532","5324","none"}};
int vector[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
					
int judgefunc(char* a,char* b){
	return (*b)-(*a);
}
char selectway(int top,int front,int num){//num番目に大きな数の位置を返す
	char* i;
	char buf[5];
	strcpy(buf,dtable[top][front]);
	qsort(buf,4,sizeof(char),judgefunc);
//	puts(dtable[top][front]);
	i=strchr(dtable[top][front],buf[num-1]);
	return i-dtable[top][front];
}
int checkroll(int nx,int ny,int way){//nx,nyの位置からway方向へ落とせるかいなか
	return (high[nx][ny]>high[nx+vector[way][0]][ny+vector[way][1]]);
}

int diceroll(int top,int front,int px,int py){

	int i;
	int flag=0;
	for(i=1;i<5;i++){//i番目に大きな面へ転がせるかチェック]
		int way=selectway(top,front,i);
		if(dtable[top][front][way]>='4'&&checkroll(px,py,way)){
			//転がせる時
			flag=1;
		//	printf("%d to turn\n",way);
			//次のtopとfrontを決める
			int ntop=7-(dtable[top][front][way]-'0');
			int nfront;
			if(way==0){
				nfront=top;
			}
			else if(way==2){
				nfront=7-top;
			}
			else {
				nfront=front;
			}			
			diceroll(ntop,nfront,px+vector[way][0],py+vector[way][1]);
			break;
		}
	}
	//もうころがれない
	
	if(flag==0){
		//puts("high++");
		high[px][py]++;
		deme[px][py]=top;
	}
	return 0;
}
int main(){
	int n;
	int i,j,k;
	int top,front;
	int ans[6];
	while(1){
		scanf("%d",&n);
		if(n==0)
			break;
		for(i=0;i<6;i++){//初期化
			ans[i]=0;
		}
		for(i=0;i<200;i++){
			for(j=0;j<200;j++){
				high[i][j]=0;
				deme[i][j]=0;
			}
		}
		for(i=0;i<n;i++){//入力
			scanf("%d %d",&top,&front);
			diceroll(top,front,p_x,p_y);
		}
		for(i=0;i<200;i++){
			for(j=0;j<200;j++){//答えを算出
				if(1<=deme[i][j]&&deme[i][j]<=6){
					ans[deme[i][j]-1]++;
				}
			}
		}
		printf("%d %d %d %d %d %d\n",ans[0],ans[1],ans[2],ans[3],ans[4],ans[5]);
	}

	return 0;
}

Measured memory_bytes: 0
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize, k: usize,
        r: usize, s: usize, p: usize,
        t: Chars
    };

    let mut res = 0_usize;
    for i in 0..k {
        let mut prev = 'x';
        let mut i = i;
        let mut sum = 0;
        while i < n {
            let ch = t[i];
            match ch {
                'r' => {
                    if prev != 'p' {
                        sum += p;
                        prev = 'p';
                    } else {
                        prev = 'x';
                    }
                }
                's' => {
                    if prev != 'r' {
                        sum += r;
                        prev = 'r';
                    } else {
                        prev = 'x';
                    }
                }
                'p' => {
                    if prev != 's' {
                        sum += s;
                        prev = 's';
                    } else {
                        prev = 'x';
                    }
                }
                _ => unreachable!(),
            }
            i += k;
        }
        res += sum;
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2448
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    int N,S=0;
    string ans;
    cin >> N;

    int temp=N;
    while(temp>0){
        S+=temp%10;
        temp/=10;
    }
    ans = (N%S) ? "No" : "Yes";
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 256
import java.math.BigInteger;//n進数に治すメソッド
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			BigInteger b = sc.nextBigInteger();
			if(b.intValue()==-1)break;
			System.out.println(b.toString(4));//4進数
		}
	}
}

Measured memory_bytes: 21732
#include <bits/stdc++.h>
#define rep(i, e, n) for (int i = e; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int inf=1000000007;


int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  ll mx=0;
  rep(i,0,n){
    cin >> a[i];
    mx = max(mx,a[i]);
  }
//  cout << mx << endl;
  vector<P> val(mx+1);
  sort(a.begin(), a.end());
  rep(i,0,n){
    val[a[i]].first++;
    for(int j=a[i];j<=mx+1;j+=a[i]){
      if(val[j].second==2) continue;
      val[j].second++;
    }
  }
  ll ans =0;
  rep(i,1,mx+1){
    if(val[i].first==1&&val[i].second==1){
      ans+=1;
//      cout << i << endl;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12760
#include <bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int n;
    cin >> n;
    set<string> ans;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        ans.emplace(s);
    }
    
    cout << ans.size() << '\n';
    
}

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

int main(){
    string str;
    cin >> str;
    int i;
    if (str.substr(2,1) == str.substr(3,1) 
        && str.substr(4,1) == str.substr(5,1)){
            cout << "Yes" << endl;
        }else {
            cout << "No" << endl;
        }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)

using namespace std;

const long long MOD = 2;

void solve(long long N, std::vector<long long> a){
    a.insert(a.begin(), -1);
    vector<int> tab(N+1, -1);
    for(LL i=N/2+1; i<=N; i++)tab[i]=a[i];
    for(LL i=N/2; i>=1; i--){
        LL j=2, total=0;
        while(i*j <= N){
            total += tab[i*j];
            j++;
        }
        if(total%2 != a[i]){
            tab[i] = 1;
        }else{
            tab[i] = 0;
        }
    }
    LL cnt=0;
    for(LL i=1; i<=N; i++){
        if(tab[i]>0)cnt++;
    }
    cout << cnt << endl;
    for(LL i=1; i<=N; i++){
        if(tab[i]>0)cout << i << " ";
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	int n;
	cin >> n;
	vector <int> x(n),y(n),h(n);
	for(int i = 0;i < n;++i){
		cin >> x[i] >> y[i] >> h[i];
	}
	for(int i = 0;i <= 100;++i){
		for(int j = 0;j <= 100;++j){
			vector <pair <int,bool>> t(n);
			for(int k = 0;k < n;++k){
				if(h[k] == 0){
					t[k] = {abs(x[k] - i) + abs(y[k] - j),0};
				}
				else{
					t[k] = {h[k] + abs(x[k] - i) + abs(y[k] - j),1};
				}
			}
			int minn = 2e9;
			for(int k = 0;k < n;++k){
				if(t[k].second == 0) minn = min(minn,t[k].first);
			}
			int l = -1;
			bool flag = 1;
			for(int k = 0;k < n;++k){
				if(t[k].second == 1 and l == -1) l = t[k].first;
				else if(t[k].second == 1 and t[k].first != l){
					flag = 0;
					break;
				}
			}
			if(flag == 0) continue;
			else{
				if(l <= minn){
					cout << i << " " << j << " " << l << newl;
				}
			}
		}
	}

	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 3600
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i])
	}
	a := 1000000000
	for i := 0; i < n-k+1; i++ {
		p, q := x[i], x[i+k-1]
		if p*q < 0 {
			a = min(a, max(abs(p), abs(q))+min(abs(p), abs(q))*2)
		} else {
			a = min(a, max(abs(p), abs(q)))
		}
	}
	fmt.Println(a)
}
func min(a, b int) int {
	if a >= b {
		return b
	} else {
		return a
	}
}
func max(a, b int) int {
	if a <= b {
		return b
	} else {
		return a
	}
}
func abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}


Measured memory_bytes: 5504
/*
sonu_verma1
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(a) push_back(a)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
	ll k,n;
	cin>>k>>n;
	ll a[n],i,j;
	for(i=0;i<n;i++)
		cin>>a[i];
	ll mx=k-a[n-1]+a[0];
	// mx=max(mx,a[0]);
	for(i=1;i<n;i++)
		mx=max(mx,a[i]-a[i-1]);
	cout<<k-mx;


	return 0;
}

Measured memory_bytes: 1792