akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>

#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[1005];

void solve()
{
    scanf("%s", str);
    int n = strlen(str);
    if (str[n - 1] == 's') {
        printf("%ses\n", str);
    }
    else {
        printf("%ss\n", str);
    }

    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define MAXN 1000002
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod=1e9+7;

void solve()
{
  double pi=3.141592653589;
  double n;
  cin>>n;
  double a=2.000000000000;
  double ans=a*pi*n;
  cout<<setprecision(12)<<fixed<<ans;
}

int main()
{
  fastio
  solve();
}


Measured memory_bytes: 3800
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 998244353;
const long long int INF = 1e18;

long long int N,M;
string t;
int main()
{
    cout << fixed << setprecision(18);
    cin>>N;
    long long int res=N/500*1000;
    N%=500;
    res+=N/5*5;
    cout<<res<<endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = 1000000;
		int[] count = new int[N];
		boolean[] prime = new boolean[N];
		Arrays.fill(prime, true);
		for (int i = 2; i < N; i++) {
			count[i] = count[i - 1];
			if (prime[i]) {
				count[i]++;
				for (int j = i; j < N; j += i) {
					prime[j] = false;
				}
			}
		}
		while (scanner.hasNext())  {
			int n = scanner.nextInt();
			System.out.println(count[n]);
		}
	}
}

Measured memory_bytes: 31424
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      long h = sc.nextInt();
      long w = sc.nextInt();
      long ans;
      if(h==1 || w==1){
        ans=1;
      }else{
        ans=(h*w+1)/2;
      }
      System.out.println(ans);
    }
}

Measured memory_bytes: 35712
from collections import Counter
N,K,L = map(int,input().split())
P = [tuple(map(int,input().split())) for i in range(K)]
R = [tuple(map(int,input().split())) for i in range(L)]

class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1

uf1 = UnionFind(N)
for p,q in P:
    p,q = p-1,q-1
    if uf1.is_same(p,q): continue
    uf1.unite(p,q)

uf2 = UnionFind(N)
for r,s in R:
    r,s = r-1,s-1
    if uf2.is_same(r,s): continue
    uf2.unite(r,s)

pairs = Counter()
for i in range(N):
    a = uf1.root(i)
    b = uf2.root(i)
    pairs[(a,b)] += 1

ans = []
for i in range(N):
    a = uf1.root(i)
    b = uf2.root(i)
    ans.append(pairs[(a,b)])
print(*ans)

Measured memory_bytes: 80492
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

const ll MAXN = 200005;

// fac: n!のmod
// finv: 1/n!のmod
// inv: 1/nのmod
vll fac(MAXN), finv(MAXN), inv(MAXN);

void COMinit() {
  fac.at(0) = fac.at(1) = 1;
  finv.at(0) = finv.at(1) = 1;
  inv.at(1) = 1;
  rep(i, 2, MAXN) {
    fac.at(i) = fac.at(i-1) * i % MOD;
    inv.at(i) = MOD - inv.at(MOD%i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i-1) * inv.at(i) % MOD;
  }
}

ll COM(ll n, ll k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac.at(n) * (finv.at(k) * finv.at(n-k) % MOD) % MOD;
}

int main() {
  ll h, w, a, b; cin >> h >> w >> a >> b;
  COMinit();
  ll ans = 0;
  rep(i, b+1, w+1) {
    ans += ((((fac.at(i+h-a-2) * finv.at(i-1) % MOD) * finv.at(h-a-1) % MOD) * fac.at(w-i+a-1) % MOD)
      * finv.at(w-i) % MOD) * finv.at(a-1) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


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

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

    int h, n;
    cin >> h >> n;
    vector<int> v;
    for(int i = 0; i < n; i++) {
        int input;
        cin >> input;
        v.push_back(input);
    }
    int s = accumulate(v.begin(), v.end(), 0);
    if(s >= h)
        cout << "Yes";
    else
        cout << "No";
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3900
#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>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
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;



int main() {
    int n,x,y;
    cin>>n>>x>>y;
    vector<int>ans(n,0);
    vector<vector<int>>d(n, vector<int>(n));
    for(int i=0;i<n-1;i++){
        d.at(i).at(i+1)=1;
        d.at(i+1).at(i)=1;
    }

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            d.at(i).at(j)=min(j-i, abs(i-x+1)+1+abs(j-y+1));
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            ans.at(d.at(i).at(j))++;
        }
    }
    for(int i=1;i<n;i++){
        cout<<ans.at(i)<<endl;
    }


    return 0;
}


Measured memory_bytes: 16000
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	// スペース区切りの整数の入力
	int a = sc.nextInt();
	int b = sc.nextInt();
    int max = b + (a - 1);
    int min = b - (a - 1);
    for(int i = min; i < max; i++){
    	System.out.print(i + " ");
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 21844
def main():
  N = int(input())
  B = []
  B.append(N)
  i = 1
  while True:
    if B[i - 1] % 2 == 0:
      B.append(B[i - 1] / 2)
    else:
      B.append(B[i - 1] * 3 + 1)
    i += 1
    A = sorted(B)
    for j in range(len(A) - 1):
      if A[j] == A[j + 1]:
        print(i)
        return
main()

Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
#include<stack>
int main(){
    using namespace std;
    stack <int>S;
    int a;
    while(~scanf("%d",&a)){
        if(a==0){
            printf("%d\n",S.top());
            S.pop();
        }
        else{
            S.push(a);
        }
    }
}

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


int main() {

    char a, b;
    cin >> a >> b;
    if (a == 'H' && b == 'H' || a == 'D' && b == 'D') cout << 'H' << endl;
    else cout << 'D' << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a: char
    }
    // annotate for rust-analyzer
    let a: char = a;

    println!("{}", if a.is_ascii_uppercase() { 'A' } else { 'a' });
}


Measured memory_bytes: 2124
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <random>
using namespace std;
typedef long long ll;
const int MAX_N = 3e5 + 2;
vector<int>width[MAX_N];
int sum[MAX_N] = { 0, };
int N, M, K;
vector<pair<int, int>>input;
vector<pair<int, int>>order;

int f(pair<int, int>target)
{
	int maxN = 0;
	for (int i = 1; i <= M; i++)
	{
		int cnt = 0;
		for (auto j : width[i])if (j != target.second)cnt++;
		maxN = max(maxN, cnt);
	}
	return target.first + maxN;
}

int f2(pair<int, int>target)
{
	int maxN = 0;
	for (int i = 1; i <= N; i++)
	{
		int cnt = 0;
		for (auto j : width[i])if (j != target.second)cnt++;
		maxN = max(maxN, cnt);
	}
	return target.first + maxN;
}

int solution1()
{
	for (auto i : input)
	{
		sum[i.first]++;
		width[i.second].push_back(i.first);
	}

	int ret = 0;
	for (int i = 1; i <= N; i++)order.push_back({ sum[i],i });
	sort(order.rbegin(), order.rend());
	for (int i = 0; i < min(5, N); i++)
	{
		ret = max(ret, f(order[i]));
		//cout << order[i].first << " " << order[i].second << " " << f(order[i]) << endl;
	}
	return ret;
}

int solution2()
{
	for (int i = 0; i < MAX_N; i++)width[i].clear();
	memset(sum, 0, sizeof(sum));
	order.clear();

	for (auto i : input)
	{
		sum[i.second]++;
		width[i.first].push_back(i.second);
	}

	int ret = 0;
	for (int i = 1; i <= M; i++)order.push_back({ sum[i],i });
	sort(order.rbegin(), order.rend());
	for (int i = 0; i < min(5, M); i++)
	{
		ret = max(ret, f2(order[i]));
	}
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> M >> K;
	while (K--)
	{
		int y, x;
		cin >> y >> x;
		input.push_back({ y,x });
	}
	int ret1 = solution1(), ret2 = solution2();
	//cout<<ret1<<" "<<ret2<<endl;
	cout << max(ret1, ret2);
}


Measured memory_bytes: 29108
from math import factorial
import itertools


def combination(n, r):  # n個からr個選ぶ場合の数
    if n < r:
        return 0
    else:
        return factorial(n)//(factorial(r) * factorial(n-r))


N = int(input())
l = ["M", "A", "R", "C", "H"]
S = [input()[0] for i in range(N)]
ans = 0
anagram = list(itertools.combinations([0, 1, 2, 3, 4], 3))

for ana in anagram:
    ans += S.count(l[ana[0]])*S.count(l[ana[1]])*S.count(l[ana[2]])

print(ans)


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

int main(void) {
  int k, n;
  cin >> k >> n;
  vector<int> as(n);
  for (int &a : as) cin >> a;

  int mx = 0;
  mx = k - as[n - 1] + as[0];
  for (int i = 1; i < n; i++) {
    mx = max(mx, as[i] - as[i - 1]);
  }

  cout << k - mx << endl;
  return 0;
}

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

using namespace std;

int main() {

  //  freopen ("in.txt", "r", stdin);

    int n;
    cin >> n;

    map < long, long > cnt;

    long a[n];
    vector < long > lst;

    for (int i=0; i<n; i++) {

        cin >> a[i];
        if(cnt[a[i]]==0) lst.push_back(a[i]);
        cnt[a[i]]++;
    }
    long lagbe = 0;
    for (int i=0; i<(int)lst.size(); i++) {
        int v = lst[i];
        if(v!=cnt[v]) {
            if(cnt[v]>v) {
                lagbe += cnt[v]-v;
            }
            else lagbe += cnt[v];
        }
    }

    cout << lagbe << endl;


    return 0;
}


Measured memory_bytes: 7796
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let S: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };
    let T: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };

    let ans = (0..3).filter(|&i| S[i] == T[i]).count();

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>

int main()
{
    char cards[200+1];
    char tmp[200+1];
    int m;
    int h;
    int len;
    int i;
    while(1) {
        scanf("%s", cards);
        if(strcmp(cards, "-") == 0) {
            break;
        }
        len = strlen(cards);
        scanf("%d", &m);
        for(i = 0; i < m; i++) {
            scanf("%d", &h);
            strncpy(tmp, cards+h, len-h);
            strncpy(tmp+len-h, cards, h);
            strcpy(cards, tmp);
        }
        cards[len] = '\0';
        printf("%s\n", cards);
    }
    return 0;
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    string s;
    ll a=0;
    ll b=0;
    cin>>s;
    if(s=="AAA"||s=="BBB")
    {
        cout<<"No\n";
    }
    else 
    {
        cout<<"Yes\n";
    }
    return 0;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let mut ab = [0usize; 26usize];
    let mut line = String::new();
    io::stdin().read_line(&mut line);
    let mut line = line.trim();

    for c in line.bytes() {
        ab[(c - 97u8) as usize] += 1;
    }

    for i in 0..26 {
        if 1 < ab[i] {
            println!("no");
            return;
        }
    }

    println!("yes");
    return;
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 60;

struct edge{
    ll to;
    ll cost;
    edge(ll t, ll c){
        to = t;
        cost = c;
    }
};

struct fulledge{ //* u->v with cost
    ll u, v, cost;
    fulledge(){}
    fulledge(ll _u, ll _v, ll _c){
        u = _u; v = _v; cost = _c;
    }

    bool operator< ( fulledge const &e) const {
        return cost < e.cost;
    }
};

void bfs(vector<vector<ll> > &G, vll &checked, ll s){
    queue<ll> que;
    checked[s] = 1;
    que.push(s);
    while(!que.empty()){
        ll u = que.front(); que.pop();
        for(auto v: G[u]){
            if(checked[v])
                continue;
            checked[v] = 1;
            que.push(v);
        }
    }
}

//* simplest bellman-ford shortest path calculator
bool BellmanFord(vector<fulledge> &es, vector<ll> &dist, ll s){
    ll N = dist.size();
    ll M = es.size();
    fill(dist.begin(), dist.end(), INF);
    dist[s] = 0;
    bool update;
    rep(k, N){
        update = false;
        rep(i, M){
            fulledge e = es[i];
            if(dist[e.u]!=INF && dist[e.v] > dist[e.u]+e.cost) {
                dist[e.v] = dist[e.u] + e.cost;
                update = true;
            }
        }
        if(!update) 
            break;
    }
    return update;
}


void solve(long long N, long long M, long long P, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    vll checkedfrom(N, 0), checkedto(N, 0);
    vector<vll> Gfrom(N), Gto(N);
    rep(i, M){
        Gfrom[A[i]].push_back(B[i]);
        Gto[B[i]].push_back(A[i]);
    }
    bfs(Gfrom, checkedfrom, 0);
    bfs(Gto, checkedto, N-1);

    vector<fulledge> es;
    rep(i, M){
        if(checkedfrom[A[i]]&&checkedfrom[B[i]]&&checkedto[A[i]]&&checkedto[B[i]]){
                es.push_back(fulledge(A[i], B[i], C[i]));
        }
    }
    vll dist(N);
    vector<bool> neg(N);
    bool isBad = BellmanFord(es, dist, 0);
    if(!isBad)
        cout << max(-dist[N-1], 0LL) << endl;
    else
        cout << -1 << endl;

}

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


Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>
#include <iterator>
#include <fstream>

#define SIZE 100005
#define MOD 1000000007

using namespace std;

class CColon {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double m_degree = 360 * m / 60.0;
    double m_radian = m_degree * M_PI / 180;
    double h_degree = 360 * h / 12.0;
    h_degree += 30 * m / 60.0;
    double h_radian = h_degree * M_PI / 180;
    double m_x = sin(m_radian) * b;
    double m_y = cos(m_radian) * b;
    double h_x = sin(h_radian) * a;
    double h_y = cos(h_radian) * a;
    double ans = sqrt(pow(abs(m_x - h_x), 2) + pow(abs(m_y - h_y), 2));
    printf("%.10f\n", ans);
  }
};


int main() {
    CColon solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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


bool isPalindrome(string s) {
	string t(s.rbegin(), s.rend());
	return s == t;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	int n = s.length();
	string s1 = s.substr(0, (n - 1) / 2);
	string s2 = s.substr((n + 1) / 2);
	if (isPalindrome(s) && isPalindrome(s1) && isPalindrome(s2)) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}
	
	return 0;
}


Measured memory_bytes: 256
s = input()
k = int(input())
c = len(s)
d = 0
a = []
if c < 5:
  d = c
else:
  d = 5
for i in range(d):
  b = [s[j:i+j+1] for j in range(c-i)]
  b = list(set(b))
  a = a + b
a.sort()
print(a[k-1])


Measured memory_bytes: 4164
#include <cmath>
#include <chrono>
#include <random>
#include <ctime>
#include <algorithm>
#include <iosfwd>
#include <iostream>
#include <list>
#include <ostream>
#include <streambuf>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fori(i, n) for(ll i = 0; i < (n); ++i)
#define forI(i, n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define ff first
#define ss second

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#define pt pair<ll, ll>
#define x first
#define y second

pll operator+ (pll a, pll b){ return {a.x + b.x, a.y + b.y}; }

ll rand0m() {
    return (ull(rand()) << 15ull | ull(rand()));
}                   //[0 ... n)
ll rand0m(ll x) {
    return rand0m() % x;
}               //[0 ... n)
ll rand0m(ll minn, ll maxx) {
    return rand0m(maxx - minn + 1) + minn;
}   //[minn ... maxx]

const ll MAXN = 1e5 + 1;
const ll mod = 1e9 + 7;
const ll INF = 2e9 + 1000;

ll n, m;
ll dp[101][MAXN];
ll sum[101][MAXN];
ll a[3010];

void solve(){
    cin >> n >> m;
    forI(i, n) cin >> a[i];
    dp[0][0] = 1;
    fori(i, m + 1) sum[0][i] = 1;
    forI(i, n){
        fori(j, m + 1){
            ll minus = (j - a[i] - 1 < 0 ? 0 : sum[i - 1][j - a[i] - 1]);
            dp[i][j] = (sum[i - 1][j] - minus + mod) % mod;
            sum[i][j] = ((j ? sum[i][j - 1] : 0) + dp[i][j]) % mod;
        }
    }
    cout << dp[n][m];
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //stress();
    solve();
}

Measured memory_bytes: 157312
#include <iostream>
#include <algorithm>
#include <vector>

using namespace::std;

int main()
{
	int num;
	int N;
	int sum = 0;

	cin >> num;
	cin >> N;

	
	vector<int> X(N);
	vector<int> Y(N-1);


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

	if (num >= N) {
		cout << sum << endl;
		return 0;
	}

	sort(X.begin(), X.end()); // vector

	
	for (int i = 0; i < N - 1; i++) {
		Y[i] = X[i + 1] - X[i];
	}

	
	sort(Y.begin(), Y.end()); // vector

	for (int i = 0; i < N - num; i++) {
		sum += Y[i];
	}

	cout << sum << endl;

    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    ll ans = min(n+m, min(n+l, m+l));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int N, M;
	scanf("%d %d", &N, &M);
	
	int r;

	int jud[N];
	int seitou = 0;
	int batsu[N];
	for(r=0; r<N; r++){
		jud[r] = 0;
		batsu[r] = 0;
	}

	int p[M];
	char S[M];
	char T[M];

	for(r=0; r<M; r++){
		scanf("%d %c%c", &p[r], &S[r], &T[r]);
		if(jud[p[r]-1] == 0 && S[r] == 'A'){
			jud[p[r]-1]++;
			seitou++;
		}
		
		if(jud[p[r]-1] == 0 && S[r] == 'W') batsu[p[r]-1]++;
		
	}
	
	int dame = 0;
	
		for(r=0; r<N; r++){
			if(jud[r]==0) batsu[r] = 0;
			dame = dame + batsu[r];
		}
	
	
	printf("%d %d", seitou, dame);
		
		return 0;
}

Measured memory_bytes: 1536
import math
a,b=map(int, input().split())
gcd=math.gcd(a,b)
m = gcd
pf = {}
for i in range(2, int(m**0.5)+1):
    while m % i == 0:
        pf[i] = pf.get(i, 0)+1
        m //= i
if m > 1:
    pf[m] = 1
print(len(pf)+1)


Measured memory_bytes: 9208
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <tuple>
#include <cmath>
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
int64_t N,A,B;
vector<int64_t> H;

bool bomb(int64_t T){
    int64_t sum = B*T;
    int64_t cnt = 0;
    for(int i=0;i<N;i++){
        cnt += (max(int64_t(0),H[i]-sum)+(A-B)-1)/(A-B);
    }
    return cnt<=T;
}

int main(){
    cin>>N>>A>>B;
    for(int i=0;i<N;i++){
        int h;
        cin>>h;
        H.push_back(h);
    }

    int64_t lo = 0, up = 1000000000;
    while(up-lo>1){
        int64_t mid = (lo+up)/2;
        if(bomb(mid)){
            up=mid;
        }else{
            lo=mid;
        }
    }
    if(bomb(lo)){
        cout<<lo<<endl;
    }else{
        cout<<up<<endl;
    }
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
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; }
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-12;
const double PI = acos(-1.0);

int dp[110][5][2];

int main() {
	string n;
	int K;
	cin >> n >> K;
	dp[0][0][0] = 1;
	for(int i = 0; i < n.size(); i++){
		int x = n[i]-'0';
		for(int j = 0; j <= K; j++){
			for(int k = 0; k <= 1; k++){
				for(int l = 0; l <= 9; l++){
					if(k==0 && l>x) continue;
					dp[i+1][j+(l!=0)][k||(l<x)] += dp[i][j][k];
				}
			}
		}
	}
	cout << dp[n.size()][K][0]+dp[n.size()][K][1] << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [0] * N

ans = 0
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a + b
    ans -= b
A = sorted(A, reverse=True)
for i in range(N):
    if i % 2 == 0:
        ans += A[i]
print(ans)


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

using namespace std;

int main(void) {
    int N, M, cnt[100010] = {}, a, b;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
    }

    bool flag = true;
    for (int i = 1; i <= N; i++)
        if (cnt[i] % 2) flag = false;
    
    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define  __  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

int n,first_b,last_a,both,ab;

string s;

int main()
{
    __;

        cin >> n;

        for(int i=0;i<n;i++)
        {
            cin >> s;

            if(s[0]=='B' && s[s.size()-1]=='A') both++;

            if(s[0]=='B' && s[s.size()-1]!='A') first_b++;

            if(s[0]!='B' && s[s.size()-1]=='A') last_a++;

            for(int j=1;j<s.size();j++)
            {
                if(s[j-1]=='A' && s[j] == 'B') ab++;
            }

        }

        if(both==0) ab+=min(first_b,last_a);

        else if( both!=0 && first_b+last_a>0 ) ab+=both+min(first_b,last_a);

        else ab+=both-1;

        cout << ab ;

    return 0;
}


Measured memory_bytes: 256
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 998244353;
const ll maxn = 100005;
const ll mm = 1e+18;
void solve()
{
    int n,q;
    cin>>n>>q;
    int mix=n;
    int miy=n;
    int tot=(n-2)*(n-2);
    int ans=0;
    vector<int>row(n+1,0),col(n+1,0);
    while(q--){
        int type,x;
        cin>>type>>x;
        if(type==1){
            if(x>miy){
                ans+=col[x];
            }
            else{
                for(int i=x;i<miy;i++){
                    col[i]=(mix-2);
                }
                ans+=col[x];
                miy=x;
            }
        }
        else{
            if(x>mix){
                ans+=row[x];
            }
            else{
                for(int i=x;i<mix;i++){
                    row[i]=(miy-2);
                }
                ans+=row[x];
                mix=x;
            }
        }
        //deb(ans);
    }
    cout<<tot-ans;
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 6264
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for(int i=a;i<b;i++)
#define repds(i,a,b) for(int i=a+1;i<=b;i++)
#define rep(i,N) repd(i,0,N)
#define reps(i,N) repds(i,0,N)
#define debug(x) cout<<#x<<"="<<x<<endl
#define debugarr(arr,N,M){rep(i,N){rep(j,M){if(arr[i][j]==INF)printf(" INF");\
	else printf(" %3d",arr[i][j]);} cout<<endl;}}
#define pb push_back
#define pob pop_back
#define cint(a) int a;cin>>a
#define cint2(a,b) int a,b;cin>>a>>b
#define cint3(a,b,c) int a,b,c;cin>>a>>b>>c
typedef long long ll;
typedef pair<int,int> P;
const int INF=100000000;
const int dx[4]={ 0, 1, 0,-1};
const int dy[4]={ 1, 0,-1, 0};
//--------------------------------------//
int n;

int main(){
	cin>>n;
	int ans=0;
	rep(i,n){
		int a;
		cin>>a;
		while(a%2==0){
			ans++;
			a/=2;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=2e5+5;

int vt[MX];

int main(){
     int i, j, k;
     int n;
     cin >> n;
     for(i=0; i<n; ++i) cin >> vt[i];
     int sm=0;
     for(i=0; i<n; ++i) sm^=vt[i];
     for(i=0; i<n; ++i){
          cout << (sm^vt[i]) << " ";
     }
     cout << endl;
}


Measured memory_bytes: 4304
#include<stdio.h>
#include<string.h>


int main(){
    int n,i,j;
    char mozia[100],mozib[100];
    int numa[100],numb[100];
    int flag=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf(" %c%d",&mozia[i],&numa[i]);
        strcpy(&mozib[i],&mozia[i]);
        numb[i]=numa[i];
    }
    //Bubble
    char tempa;
    int tempb;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(numa[j-1]>numa[j]){
                tempa=mozia[j];
                mozia[j]=mozia[j-1];
                mozia[j-1]=tempa;
                tempb=numa[j];
                numa[j]=numa[j-1];
                numa[j-1]=tempb;
            }
        }
    }
    for(i=0;i<n;i++){
        if(i!=0)printf(" ");
        printf("%c%d",mozia[i],numa[i]);
    }
    printf("\nStable\n");
    
    //Select
    int minj;
    for(i=0;i<n;i++){
        minj=i;
        for(j=i;j<n;j++){
            if(numb[j]<numb[minj])minj=j;
        }
        tempa=mozib[i];
        mozib[i]=mozib[minj];
        mozib[minj]=tempa;
        tempb=numb[i];
        numb[i]=numb[minj];
        numb[minj]=tempb;
    }
    for(i=0;i<n;i++){
        if(i!=0)printf(" ");
        printf("%c%d",mozib[i],numb[i]);
    }
    printf("\n");
    for(i=0;i<n;i++){
        if(mozia[i]!=mozib[i])flag=1;
    }
    if(flag==1)printf("Not stable\n");
    else printf("Stable\n");
    
    return 0;
}




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

Money = 1000
Stock = 0
for i in range(N-1):
	if A[i] < A[i+1]:
		Stock = Stock + (Money//A[i])
		Money = Money % A[i]
	elif A[i] > A[i+1]:
		Money = Money + Stock * A[i]
		Stock = 0

ans = Money + Stock * A[i+1]
print(ans)

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define REP(i,n) for(int i=0; i < (n); ++i)
#define SIZE(c) (int) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
#define FWD(i,a,b) for (int i=(a); i<(b); ++i)
#define BCK(i,a,b) for (int i=(a); i>(b); --i)
#define PI 3.14159265358979311600
#define pb push_back
#define mp make_pair
#define st first
#define nd second

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

typedef vector < int > VI;
typedef vector<ll> VL;

typedef long double K;

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

	int n;
	cin >> n;
	vector<int> a(n);
	for (auto& item : a) {
		cin >> item;
	}
	int result = 0;
	for (int i = 0; i < n; ++i) {
		int j = i;
		int dir = 0;
		int prv = a[i];
		while (j < n) {
			int ndir;
			if (a[j] - prv > 0) {
				ndir = +1;
			} else 
			if (a[j] - prv < 0) {
				ndir = -1;
			} else {
				ndir = 0;
			}
			if (dir * ndir == -1) {
				break;
			}
			if (ndir) dir = ndir;
			prv = a[j];
			++j;
		}
		i = j - 1;
		++result;
	}

	cout << result << endl;

	return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, k;
    cin>>a>>b>>k;
    if(k>a){
        k = k-a;
        a = 0;
        if(k>b){
            cout<<a<<" "<<0<<"\n";
        }else{
            cout<<a<<" "<<b-k<<"\n";
        }
    }else{
        cout<<a-k<<" "<<b<<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define  N 666666
int a[N];

signed main(){
	string s;cin>>s;int f=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='7') f=1;
	}if(f) cout<<"Yes";else cout<<"No";
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string> 
#include <cstdlib>

int main(int argc, char *argv[]) 
{
	std::string N;
	int sn = 0;
	std::cin >> N;
	
	for (int i = 0; i < N.length(); i++) {
		char tmp = N[i];
		sn += std::atoi(&tmp);
	}
	if (std::atoi(N.c_str()) % sn == 0) 
		printf("Yes\n");
	else
		printf("No\n");
	
	return 0;
}
	

Measured memory_bytes: 256
import numpy as np
i8 = np.int64
i4 = np.int32


def solve(A, F, K):
    min_ = 0
    max_ = 10 ** 12
    while min_ < max_:
        mid = (min_ + max_) // 2
        count = A - mid // F
        sum_ = count[count > 0].sum()
        if sum_ <= K:
            max_ = mid
        else:
            min_ = mid + 1
    return min_

def main():
    stdin = open('/dev/stdin', 'rb')
    pin = np.fromstring(stdin.read(), i8, sep=' ')
    N, K = pin[:2]
    A = pin[2: N + 2]
    F = pin[N + 2: 2 * N + 2]
    A = np.sort(A)[::-1]
    F.sort()
    ans = solve(A, F, K)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 21840
void main() {
    int[] tmp = readln.split.to!(int[]);
    int a = tmp[0], b = tmp[1], c = tmp[2];
    writeln(c % gcd(a, b) == 0 ? "YES" : "NO");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<cstdio>
        #include<cstring>
        using namespace std;
         
        int main()
        {
            int MAX = 11;
            char a[MAX], b[MAX], c[MAX];
            scanf("%s", a);
            scanf("%s", b);
            scanf("%s", c);
            if(a[strlen(a)-1] != b[0] || b[strlen(b)-1] != c[0]) {
                printf("NO");
            }
            else {
                printf("YES");
            }
    }

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

char s[105];

int main(){
	scanf("%s",s);
	int len = strlen(s) - 1,flag1 = 0;
	for(int i = 0; i <= len; i++){
		if(s[i] == 'C')
			flag1 = 1;
		if(s[i] == 'F' && flag1 == 1){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
} 

Measured memory_bytes: 256
n = int(input())
s = input()

dp = [[0]*10 for _ in range(10)]

count = [0]*10

result = []

for i in range(n-2):
    if count[int(s[i])]==0:
        for j in range(i+1,n-1):
            if dp[int(s[i])][int(s[j])]==0:
                tem = "".join(set(s[j+1:]))
                for k in range(len(tem)):
                    result.append(s[i]+s[j]+tem[k])
                dp[int(s[i])][int(s[j])]=1
        count[int(s[i])]=1

ans = set(result)
print(len(ans))

Measured memory_bytes: 66648
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << -1 << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    int B[114514];
    int Ans=0;
    cin >> N;
    REP(i,N-1){
        cin >> B[i];
    }
    REP(i,N){
        if(i==0){
            Ans+=B[0];
        }else if(i==N-1){
            Ans+=B[N-2];
        }else{
            Ans+=min(B[i],B[i-1]);
        }
    }
    cout << Ans << endl;
  return 0;
}



Measured memory_bytes: 256
n=int(input())
arr=list(map(int,input().split()))
brr=[]
if n%2==0:
    for i in range(n-1,0,-2):
        brr.append(arr[i])
    for i in range(0,n-1,2):
        brr.append(arr[i])
else:
    for i in range(n-1,-1,-2):
        brr.append(arr[i])
    for i in range(1,n,2):
        brr.append(arr[i])
print(' '.join(list(map(str,brr))))


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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

const ll mod = 1000000007;
//const ll mod = 998244353;

const int MAX_N = 100010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void create_table(int n) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= n;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[n] = pow_mod(fact[n],mod-2);
    for (int i = n;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= n;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    create_table(n);
    ll ans = 0;
    vector<ll> sums(n+1,0);
    for (int i = 1;i < n+1;++i) sums[i] = (sums[i-1]+inv[i])%mod;
    for (int i = 0;i < n;++i) {
        ans += (sums[i+1]+sums[n-i]-1)*a[i];
        ans %= mod;
    }
    cout << ans*fact[n]%mod << endl;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <map>

using std::cout;
using std::endl;
using std::cin;
using std::vector;
using std::pair;
using pii = std::pair<int, int>;
using std::make_pair;
using std::queue;
using std::map;

int bfs(vector<vector<char>> table, pii start, pii goal);

int main() {
	// Input
	int H, W;
	cin >> H >> W;
	pii start = make_pair(0, 0);
	pii goal = make_pair(W-1, H-1);
	int pathCount = 0;
	vector<vector<char>> table(W, vector<char>(H, 0));
	for(int y = 0; y < H; ++y) {
	for(int x = 0; x < W; ++x) {
		char c;
		cin >> c;
		table[x][y] = c;
		if(c == '.') ++pathCount;
	}
	}
	// Calculation
	int pathLength = bfs(table, start, goal);
	if(pathLength < 0) {
		cout << -1 << endl;
	} else {
		cout << (pathCount - pathLength) << endl;
	}
	// Output
	return 0;
}

int bfs(vector<vector<char>> table, pii start, pii goal) {
	queue<pii> que;
	// map<destination, source>
	map<pii,pii> dejaVu;
	pii dummy = make_pair(-1, -1);
	que.push(start); dejaVu.insert(make_pair(start, dummy));
	while(!que.empty()) {
		pii cur = que.front(); que.pop();
		if(cur.first > 0) {
			pii left = make_pair(cur.first - 1, cur.second);
			if(table[left.first][left.second] == '.') {
				auto inserted = dejaVu.insert(make_pair(left, cur));
				if(inserted.second) {
					que.push(left);
				}
			}
		}
		if(cur.first < goal.first) {
			pii right = make_pair(cur.first + 1, cur.second);
			if(table[right.first][right.second] == '.') {
				auto inserted = dejaVu.insert(make_pair(right, cur));
				if(inserted.second) {
					if(right == goal) break;
					que.push(right);
				}
			}
		}
		if(cur.second > 0) {
			pii up = make_pair(cur.first, cur.second - 1);
			if(table[up.first][up.second] == '.') {
				auto inserted = dejaVu.insert(make_pair(up, cur));
				if(inserted.second) {
					que.push(up);
				}
			}
		}
		if(cur.second < goal.second) {
			pii down = make_pair(cur.first, cur.second + 1);
			if(table[down.first][down.second] == '.') {
				auto inserted = dejaVu.insert(make_pair(down, cur));
				if(inserted.second) {
					if(down == goal) break;
					que.push(down);
				}
			}
		}
	}
	// Track back.
	if(dejaVu.find(goal) == dejaVu.end()) return -1;
	int pathLength = 0;
	pii cur = goal;
	while(cur != dummy) {
		++pathLength;
		cur = dejaVu.at(cur);
	}
	return pathLength;
}

Measured memory_bytes: 384
$M = 1000000007
def pow(x, n)
  ret = 1
  while n > 0
    ret = (ret * x) % $M if n % 2 == 1
    x *= x
    n >>= 1
  end
  return ret
end

n = gets.to_i
puts (pow(10, n) - 2*pow(9, n) + pow(8, n) + $M) % $M

Measured memory_bytes: 20708
from itertools import product
data = [list(map(int, input().split())) for i in range(3)]
n = int(input())
bl = [int(input()) for _ in range(n)]
ok = [[0]*3 for _ in range(3)]

for b in bl:
    for i in range(3):
        for j in range(3):
            if data[i][j] == b:
                ok[i][j] = 1

# print(data)
# print(ok)
if sum(ok[0][:]) == 3 or sum(ok[1][:]) == 3 or sum(ok[2][:]) == 3 or (ok[0][0]+ok[1][0]+ok[2][0]) == 3 or (ok[0][1]+ok[1][1]+ok[2][1]) == 3 or (ok[0][2]+ok[1][2]+ok[2][2]) == 3 or (ok[0][0]+ok[1][1]+ok[2][2]) == 3 or (ok[0][2]+ok[1][1]+ok[2][0]) == 3:
    print('Yes')
else:
    print('No')


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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end() //昇順
#define enb(a) a.rbegin(),a.rend() //降順
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)
int main(){
	int n;
	string s;
	cin >> n >> s;
	if(!(n % 2)){
		if(s.substr(0,n / 2) == s.substr(n / 2,n - 1)){
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

ll MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  string S;
  cin >> S;
  vector<ll> sumW(N + 1);
  vector<ll> sumE(N + 1, 0);
  sumW[0] = 0;
  for (ll i = 0; i < N; i++) {
    if (S[i] == 'W') {
      sumW[i+1] = sumW[i] + 1;
      sumE[i+1] = sumE[i];
    } else {
      sumW[i+1] = sumW[i];
      sumE[i+1] = sumE[i] + 1;
    }
  }

  // for (ll i = 0; i < N; i++) {
  //   cout << "w: " << sumW[i] << endl;
  //   cout << "e: " << sumE[i] << endl;
  //   cout << "-----" << endl;
  // }

  //i番目の人をリーダーにする
  ll ans = 10000000000;
  for (ll i = 0; i < N; i++) {
    ll cost = sumW[i] + sumE[N] - sumE[i+1];
    ans = min(ans, cost);
  }
  cout << ans << endl;
}

Measured memory_bytes: 5380
n = int(input())
F = [list(map(int,input().split())) for _ in range(n)]
P = [list(map(int,input().split())) for _ in range(n)]
res = -10**10

for bit in range(1, 1 << 10):
    a = [0 for _ in range(n)]
    for j in range(10):
        for i in range(n):
            if bit%2==1 and F[i][j]:
                a[i] += 1
        bit //= 2
    tmp = 0
    for i in range(n):
        tmp += P[i][a[i]]
    res = max(res, tmp)
print(res)


Measured memory_bytes: 3188
import sys
class Bit:
  def __init__(self,n):
    self.size = n
    self.tree = [0]*(n+1)
 
  def sum(self,i):
    s = 0
    while i > 0:
      s += self.tree[i]
      i -= i & -i
    return s

  def add(self,i,x):
    while i <= self.size:
      self.tree[i] += x
      i += i & -i
input = sys.stdin.readline
from collections import defaultdict
mod = 998244353
n = int(input())
p2t = [1]
for i in range(n):
  p2t.append(p2t[-1]*2%mod)
dcy = defaultdict(int)
xy = [list(map(int,input().split())) for i in range(n)]
xy.sort()
yls = list(zip(*xy))[1]
yls = list(yls)
for i in range(n):
  dcy[yls[i]] = i
yls.sort()
yind = [0 for i in range(n)]
for i in range(n):
  ind = dcy[yls[i]]
  yind[ind] = i
xyd = []
for i in range(n):
  xyd.append((i,yind[i]))
ans = 0
bit = Bit(n+1)
for i in range(n):
  x,y = xyd[i]
  upper = n-y-1
  right = n-x-1
  ld = bit.sum(y+1)
  ru = upper+right+ld-n+1
  rd = right-ru
  lu = upper-ru
  p2lu = p2t[lu]
  p2rd = p2t[rd]
  p2ru = p2t[ru]
  p2ld = p2t[ld]
  ans += ((p2lu-1)*(p2rd-1)*(p2t[ld+ru])%mod+(p2ld-1)*(p2ru-1)*(p2t[lu+rd])%mod+
  p2t[n-1]-(p2lu-1)*(p2rd-1)*(p2ld-1)*(p2ru-1)%mod)
  ans %= mod
  bit.add(y+1,1)
print(ans)

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

using namespace std;

int main(){
    int n[4];
    char c[3][3];
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> c[i][j];
        }
    }

    cout << c[0][0] << c[1][1] << c[2][2] << endl;

}

Measured memory_bytes: 256