akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

int main(void) {
    string s;
    cin >> s;
    vector<int> f(26);
    int n = s.size();
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 26; ++j) {
            if (s[i] - 'a' != j) {
                ++f[j];
            }
        }
        ans += f[s[i] - 'a'];
    }
    cout << ans + 1<< endl;
    return 0;
}


Measured memory_bytes: 640
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n:usize = read();
    let mut xn = read_vec::<i64>();
    let median_index = (n-2)/2;
    let yn = xn.clone();
    xn.sort();
    for j in 0..n{
        let ans = if yn[j] <= xn[median_index] {
            xn[median_index + 1]
        } else {
            xn[median_index]
        };
        println!("{}",ans );
    }
}

Measured memory_bytes: 10928
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 100 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int a[N][N], n, m, M[N];
int mark[N], MT[N];
vi G[N];

bool DFS(int v){
	mark[v] = 1;
	for (auto u:G[v]){
		if (mark[M[u]]) continue;
		if (M[u] == 0){
			M[u] = v;
			MT[v] = 1;
			return 1;
		}
		if (DFS(M[u])){
			M[u] = v;
			MT[v] = 1;
			return 1;
		}
	}
	return 0;
}

inline void Matching(){
	memset(M, 0, sizeof M);
	memset(MT, 0, sizeof MT);
	for (int i = 1; i <= n; i++){
		memset(mark, 0, sizeof mark);
		for (int j = 1; j <= n; j++){
			if (!mark[j] && !MT[j]){
				if (DFS(j)){
					break;
				}
			}
		}
	}
//	for (int i = 1; i <= n; i++) cout << M[i] << ' ';
//	cout << '\n';
}

inline void Solve(int x){
	for (int i = 1; i <= n; i++) G[i].clear();
//	cout << "Fuck\n";
	for( int i = 1; i <= n; i++) for (int j = x; j <= m; j++){
		G[a[i][j] / m + 1].pb(i);
//		cout << a[i][j] / m + 1 << ' ' << i << '\n';
	}
//	cout << "YES" << endl;
	Matching();
//	cout << "YES2" << endl;
	for (int i = 1; i <= n; i++){
		for (int j = x; j <= m; j++){
			if (a[i][j] / m + 1 == M[i]){
				swap(a[i][x], a[i][j]);
				break;
			}
		}
	}
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++){
		cin >> a[i][j];
		a[i][j] --;
	}
	for (int i = 1; i <= m; i++){
		Solve(i);		
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++) cout << a[i][j] + 1 << ' ';
		cout << '\n';
	}
	for (int i = 1; i <= m; i++){
		for (int j = 1; j <= n; j++){
			for (int k = j; k <= n; k++){
				if (a[k][i] / m + 1 == j){
					swap(a[j][i], a[k][i]);
					break;
				}
			}
		}
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++) cout << a[i][j] + 1 << ' ';
		cout << '\n';
	}







	return 0;
}


Measured memory_bytes: 3704
// <------------- Template -----------------------> //


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(2);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 
 
typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAX5]; ll visit[] = {};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, y, q, m;
string s, t, d;
ll sum = 0;
ll cou = 0;


// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> s;
	if(stoull(s.substr(5,2)) > 4) cout<<"TBD";
	else cout<<"Heisei";
}

int main() {
	fastio; randomINT;
	//cin>>T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 5996
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc144/tasks/abc144_f>
 問題文============================================================
 =================================================================
 解説=============================================================
 
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N,M; cin >> N >> M;
    vector<vector<int>> G(N);
    for(int i = 0; i < M;i++){
        int s,t; cin >> s >> t;
        s--; t--;
        G[s].emplace_back(t);
    }
    
    res = LINF;
    for(int i = 0; i < N-1;i++){
        vector<double> dp(N,LINF);
        dp[N-1] = 0;
        for(int j = N-2; j>= 0; j--){
            double sump = 0;
            double maxp = 0;
            for(auto v:G[j]){
                sump += dp[v];
                maxp = max(maxp,dp[v]);
            }
            
            if(j == i && G[j].size() > 1){
                dp[j] = (sump-maxp)/(G[j].size()-1) + 1;
            }else{
                dp[j] = sump/G[j].size() + 1;
            }
        }
        res = min(res,dp[0]);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<double>() << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	ll n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	string t;
	cin >> t;
	ll l = lcm(n,m);
	ll x = l / n;
	ll y = l / m;
	for (ll i = 0; i < m; i++) {
		if ((i * y) % x != 0) continue;
		if (t[i] != s[(i * y) / x]) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << l << endl;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
int INF = 10000000;
struct lazy_segment_tree{
  int N;
  vector<int> ST; //range_min
  vector<pair<int, int>> lazy;
  lazy_segment_tree(int n){
    N = 1;
    while (N < n){
      N *= 2;
    }
    ST = vector<int>(N * 2 - 1, INF);
    for (int i = 0; i < n; i++){
      ST[N - 1 + i] = 0;
    }
    for (int i = N - 2; i >= 0; i--){
      ST[i] = min(ST[i * 2 + 1], ST[i * 2 + 2]);
    }
    lazy = vector<pair<int, int>>(N * 2 - 1, make_pair(1, 0));
  }
  void eval(int i, int l){
    if (i < N - 1){
      if (lazy[i].first == 0){
        lazy[i * 2 + 1] = lazy[i];
        lazy[i * 2 + 2] = lazy[i];
      } else {
        lazy[i * 2 + 1].second += lazy[i].second;
        lazy[i * 2 + 2].second += lazy[i].second;
      }
    }
    if (lazy[i].first == 0){
      ST[i] = l + lazy[i].second;
    } else {
      ST[i] += lazy[i].second;
    }
    lazy[i] = make_pair(1, 0);
  }
  void range_update(int L, int R, int x, int i, int l, int r){
    eval(i, l);
    if (r <= L || R <= l){
      return;
    } else if (L <= l && r <= R){
      lazy[i] = make_pair(0, x);
      eval(i, l);
    } else {
      int m = (l + r) / 2;
      range_update(L, R, x, i * 2 + 1, l, m);
      range_update(L, R, x, i * 2 + 2, m, r);
      ST[i] = min(ST[i * 2 + 1], ST[i * 2 + 2]);
    }
  }
  void range_update(int L, int R, int x){
    range_update(L, R, x, 0, 0, N);
  }
  void range_add(int L, int R, int x, int i, int l, int r){
    eval(i, l);
    if (r <= L || R <= l){
      return;
    } else if (L <= l && r <= R){
      lazy[i] = make_pair(1, x);
      eval(i, l);
    } else {
      int m = (l + r) / 2;
      range_add(L, R, x, i * 2 + 1, l, m);
      range_add(L, R, x, i * 2 + 2, m, r);
      ST[i] = min(ST[i * 2 + 1], ST[i * 2 + 2]);
    }
  }
  void range_add(int L, int R, int x){
    range_add(L, R, x, 0, 0, N);
  }
  int range_min(int L, int R, int i, int l, int r){
    eval(i, l);
    if (r <= L || R <= l){
      return INF;
    } else if (L <= l && r <= R){
      return ST[i];
    } else {
      int m = (l + r) / 2;
      return min(range_min(L, R, i * 2 + 1, l, m), range_min(L, R, i * 2 + 2, m, r));
    }
  }
  int range_min(int L, int R){
    return range_min(L, R, 0, 0, N);
  }
};
int main(){
  int H, W;
  cin >> H >> W;
  vector<int> A(H), B(H);
  for (int i = 0; i < H; i++){
    cin >> A[i] >> B[i];
    A[i]--;
  }
  lazy_segment_tree ST(W);
  for (int i = 0; i < H; i++){
    ST.range_add(0, W, 1);
    if (A[i] == 0){
      ST.range_update(0, B[i], INF);
    } else {
      int x = ST.range_min(A[i] - 1, A[i]);
      ST.range_update(A[i], B[i], x - (A[i] - 1));
    }
    int ans = ST.range_min(0, W);
    if (ans >= INF){
      cout << -1 << endl;
    } else {
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 10816
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		int n = s.length();
		boolean fumiyasui = true;
		for(int i=0;i<n;i++) {
			char step = s.charAt(i);
			if(i%2 == 1) {
				if((step == 'L')||(step == 'U' || (step == 'D')));
				else fumiyasui = false;
			}else {
				if((step == 'R')||(step == 'U' || (step == 'D')));
				else fumiyasui = false;
			}
		}

		if(fumiyasui) System.out.println("Yes");
		else System.out.println("No");

	}
}


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

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int n;
	
	while (cin >> n, n) {
		bool f[101][101] = {false};
		rep(i, n) {
			int m = in();
			rep(j, m) {
				f[i][in()] = true;
			}
		}

		vi a, l;
		
		int k = in();
		rep(i, k) l.pb(in());

		rep(i, n) {
			bool beet = true;
			rep(j, l.size()) {
				if (!f[i][l[j]]) beet = false;
			}
			if (beet) a.pb(i + 1);
		}

		cout << (a.size() == 1 ? a[0] : -1) << endl;
	}
}

Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
#define ENDL "\n"
typedef long long int llint;
int intinput()
{
  int x;
  scanf("%d", &x);
  return x;
}

int checked[1000][1000];

int main()
{
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  for(int i=0;i<H;i++){
    cin >> A[i];
  }
  queue<pair<int, int>> q;
  //
  for(int h=0;h<H;h++){
    for(int w=0;w<W;w++){
      if(A[h][w]=='#'){
        checked[h][w]=1;
        q.push(make_pair(h, w));
      }
    }
  }
  //
  int ans=-1;
  while(!q.empty()){
    ans += 1;
    int size = q.size();
    for(int i=0;i<size;i++){
      pair<int, int> p = q.front();
      q.pop();
      int h = p.first;
      int w = p.second;
      int nh, nw;
      //
      nh = h-1;
      nw = w;
      if(0<=nh && nh<H && 0<=nw && nw<W && checked[nh][nw]==0 && A[nh][nw]=='.'){
        checked[nh][nw]=1;
        q.push(make_pair(nh, nw));
      }
      nh = h+1;
      nw = w;
      if(0<=nh && nh<H && 0<=nw && nw<W && checked[nh][nw]==0 && A[nh][nw]=='.'){
        checked[nh][nw]=1;
        q.push(make_pair(nh, nw));
      }
      nh = h;
      nw = w-1;
      if(0<=nh && nh<H && 0<=nw && nw<W && checked[nh][nw]==0 && A[nh][nw]=='.'){
        checked[nh][nw]=1;
        q.push(make_pair(nh, nw));
      }
      nh = h;
      nw = w+1;
      if(0<=nh && nh<H && 0<=nw && nw<W && checked[nh][nw]==0 && A[nh][nw]=='.'){
        checked[nh][nw]=1;
        q.push(make_pair(nh, nw));
      }
    }
  }
  cout << ans << ENDL;
}


Measured memory_bytes: 13328
#include <iostream>
#include <vector>
#include <limits>

using namespace std;

struct info_t {
  int start;
  int end;
  int channel;
};

int n, c;
vector<info_t> info;

bool comp(info_t a, info_t b) {
  return a.start < b.start;
}

void sort_by_start_time() {
  sort(info.begin(), info.end(), comp);
}

void delete_first_same_end_info(vector<info_t>& arr) {
  int size = arr.size();
  if(size == 0)
    return;
  int hd = arr[0].end;
  int i = 1;
  while(i < size && hd == arr[i].end) { i++; }
  arr.erase(arr.begin(), arr.begin() + i);
}

void insert_info(info_t x, vector<info_t>& arr) {
  int i = 0;
  for(; i < arr.size(); i++) {
    if(x.end <= arr[i].end)
      break;
  }
  arr.insert(arr.begin() + i, x);
}

int get_minimum_end(vector<info_t>& arr) {
  if(arr.size() == 0)
    return INT_MAX;
  return arr[0].end;
}

void delete_minimum_end(int channel, vector<info_t>& arr) {
  int size = arr.size();
  if(size == 0)
    return;

  int min = arr[0].end;
  for(int i = 0; i < size; i++) {
    if(min != arr[i].end)
      return;

    if(arr[i].channel == channel) {
      arr.erase(arr.begin() + i, arr.begin() + (i+1));
      return;
    }
  }
}

int calc() {
  sort_by_start_time();
  vector<info_t> showing; // sorted by end
  int maxsize = 0;
  for(int i = 0; i < n;) {
    info_t x = info[i];
    int start = x.start;
    int min = get_minimum_end(showing);

    if(min < start) {
      delete_first_same_end_info(showing);
    } else {
      bool joined = min == start;
      int j = 0;
      while(i + j < n) {
        if(start != info[i+j].start)
          break;
        insert_info(info[i+j], showing);
        if(joined)
          delete_minimum_end(info[i+j].channel, showing);
        j++;
      }
      i += j;
    }
    int sz = showing.size();
    maxsize = maxsize < sz ? sz : maxsize;
  }
  return maxsize;
}

int main() {
  cin >> n;
  cin >> c;
  info.resize(n);
  int start, end, channel;

  for(int i = 0; i < n; i++) {
    cin >> start;
    cin >> end;
    cin >> channel;
    info_t x = { start, end, channel };
    info[i] = x;
  }
  cout << calc() << "\n";
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int A, B;
  cin >> A >> B;
  int C, D;
  cin >> C >> D;
  
  int t=(C+B-1)/B;
  int a=(A+D-1)/D;

  if(t<=a)cout << "Yes\n";
  else cout << "No\n";
  
}

Measured memory_bytes: 3660
/*
  AOJ 0148
  Title:Candy and Class Flag
  @kankichi573
*/
#include <stdio.h>

main()
{
  int n,r;

  while(EOF!=scanf("%d",&n))
    {
      r=n%39;
      printf("3C%02d\n",(r==0)?39:r);
    }
  return(0);
}

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  if(N<=K)
    cout << 0 << endl;
  else{
    sort(H.begin(),H.end());
    long long sum=0;
    for(int i=0;i<N-K;i++){
      sum +=H[i];
    }
    cout << sum << endl;
  }
  
}

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

using namespace std;

int main(){

    int n, k;
    cin>>n>>k;
    vector<int> height(n);
    for(auto &x : height) cin>>x;
    vector<int> ans(n, 0);

    for(int i = n-2; i >= 0; i--){

        ans[i] = abs(height[i] - height[i+1]) + ans[i+1];
        for(int j = 2; j <= k; j++){
        if(i+j < n){
                    ans[i] = min(ans[i], abs(height[i] - height[i+j]) + ans[i+j]);

        }
        }
    }

    cout<<ans[0];


}



Measured memory_bytes: 1152
n,k = map(int, input().split())
a = list(map(int, input().split()))
right = [0]*n
whole = [0]*n
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            whole[i] += 1
            if i < j:
                right[i] += 1
ans = 0
for i in range(n):
    ans += right[i]*k + whole[i]*(k-1)*k//2
    ans %= 10**9+7
print(ans)

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

bool isPrime(int num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrtNum = sqrt(num);

  for (int i = 3; i <= (int)sqrtNum; i++)
  {
    if (num % i == 0)
      return false;
  }

  return true;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int Q;
  cin >> Q;
  vector<int> l(Q), r(Q);
  for (int i = 0; i < Q; i++)
    cin >> l[i] >> r[i];
  vector<int> cnt(100010);
  for (int i = 3; i <= 100000; i++)
  {
    cnt[i] = cnt[i - 1];
    if (i % 2 != 0 && isPrime(i) && isPrime((i + 1) / 2))
      cnt[i]++;
  }
  for (int i = 0; i < Q; i++)
  {
    int ans = cnt[r[i]] - cnt[l[i] - 1];
    cout << ans << endl;
  }
  return 0;
}

// 累積和的な解き方？0から10^5まで2017に似た数かを調べて数を累積していく


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string S;
    cin>>S;
    cout<<S.substr(0,4)<<" "<<S.substr(4,8)<<endl;
    return 0;
}


Measured memory_bytes: 256
N,Q = map(int,input().split())
par = [-1]*(N+1)
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
def size(x):
    return -par[find(x)]


for i in range(Q):
    a,b = map(int,input().split())
    a-=1
    b-=1
    unite(a,b)

M = 0 
for i in range(N):
    M = max(size(i),M)
print(M)

Measured memory_bytes: 14720
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long Sum = 0;
        
        for(int i=1; i<=N; i++){
            if(!(i%3==0||i%5==0||i%15==0)){
                Sum += i;
            }
        }
    
        System.out.println(Sum);
    }
}


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

// see: https://qiita.com/drken/items/4a7869c5e304883f539b
int main() {
  int n;
  cin >> n;

  vector<int> order;
  int P[n], Q[n];
  for (int i = 1; i <= n; i++) {
    order.push_back(i);
  }

  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    P[i] = tmp;
  }

  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    Q[i] = tmp;
  }

  int ordernum = 1;
  int pOrder = 0;
  int qOrder = 0;

  do {
    bool pMatched = true;
    bool qMatched = true;

    for (int i = 0; i < order.size(); i++) {
      int num = order[i];

      if (num != P[i]) pMatched = false;
      if (num != Q[i]) qMatched = false;
    }

    if (pMatched) pOrder = ordernum;
    if (qMatched) qOrder = ordernum;
    ordernum++;
  } while (next_permutation(order.begin(), order.end()));

  cout << (abs(pOrder - qOrder)) << endl;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
int a[3][3];
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
signed main(){
  REP(i,3)REP(j,3)cin>>a[i][j];
  int n;cin>>n;
  while(n--){
    int s;cin>>s;
    REP(i,3)REP(j,3)if(a[i][j]==s)a[i][j]=0;
  }
  REP(i,3){
    int c=0;
    REP(j,3)c+=a[i][j];
    if(!c)fin("Yes");
  }
  REP(i,3){
    int c=0;
    REP(j,3)c+=a[j][i];
    if(!c)fin("Yes");
  }
  REP(i,3){
    int c=0;
    REP(j,3)c+=a[j][j];
    if(!c)fin("Yes");
  }
  REP(i,3){
    int c=0;
    REP(j,3)c+=a[2-j][j];
    if(!c)fin("Yes");
  }
  fin("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    cout << max(a*b,c*d) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 1145141919810000
#define ll long long
#define mem(x,y) memset(x,y,sizeof x)
using namespace std;
struct edge{
	int t,next;
	ll cst;
	int rev;
};
vector<edge>G[110000];
void add(int f,int t,int next,ll cst){
	G[f].push_back((edge){t,next,cst,(int)G[t].size()});
	G[t].push_back((edge){f,0,-cst,(int)G[f].size()-1});
}
bool used[110000];
ll dis[110000];
int prv[110000],pre[110000],S,T;
bool SPFA(){
	for(int i=0;i<=T;i++)dis[i]=-inf;
	queue<int>q;
	q.push(0);
	dis[0]=0;
	used[0]=true;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		used[x]=false;
		for(int i=0;i<(int)G[x].size();i++){
			edge &e=G[x][i];
			if(e.next && dis[x]+e.cst>dis[e.t]){
				dis[e.t]=dis[x]+e.cst;
				prv[e.t]=x;
				pre[e.t]=i;
				if(!used[e.t]) used[e.t]=1,q.push(e.t);
			}
		}
	}
	return (dis[T]!=-inf);
}
int n,m,lx[210],rx[210],ly[210],ry[210],x[210],y[210];
ll v[210],ans;
ll MCMF(){
	ll nowans=0;
	while(SPFA()){
		int nowp=T;
		while(nowp){
			edge &e=G[prv[nowp]][pre[nowp]];
			e.next--;
			G[e.t][e.rev].next++;
			nowp=prv[nowp];
		}
		nowans+=dis[T];
	}
	return nowans;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d%lld",&x[i],&y[i],&v[i]);
	scanf("%d",&m);
	for(int i=1;i<=n;i++) rx[i]=ry[i]=110;
	for(int i=1;i<=m;i++){
		int a,b;char cc;
		scanf("%s%d%d",&cc,&a,&b);
		if(cc=='L')lx[b+1]=max(lx[b+1],a);
		if(cc=='R')rx[b+1]=min(rx[b+1],a);
		if(cc=='D')ly[b+1]=max(ly[b+1],a);
		if(cc=='U')ry[b+1]=min(ry[b+1],a);
	}
	for(int i=2;i<=n;i++) lx[i]=max(lx[i],lx[i-1]),rx[i]=min(rx[i],rx[i-1]),ly[i]=max(ly[i],ly[i-1]),ry[i]=min(ry[i],ry[i-1]);
	for(int i=1;i<=n;i++){
		T=n+n+i+i+1;mem(G,0);
		for(int j=1;j<=i;j++) add(0,n+n+j,1,0),add(n+n+i+j,T,1,0);
		for(int j=1;j<=i;j++){
			for(int k=1;k<=n;k++){
				if(lx[j]<x[k]&&x[k]<rx[i+1-j]) add(n+n+j,k,1,0);
				if(ly[j]<y[k]&&y[k]<ry[i+1-j]) add(n+k,n+n+i+j,1,0);
			}
		}
		for(int j=1;j<=n;j++) add(j,n+j,1,v[j]);
		ans=max(ans,MCMF());
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 30976
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[6];
    rep(i,3){
        cin >> A[i];
    }
    sort(A,A+3);
    cout << (A[0]==A[1] ? (A[1]==A[2] ? 1 : 2 ) :(A[1]==A[2] ? 2 : 3 )  ) << endl;
}

Measured memory_bytes: 256
// be name khoda
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const ll maxn=100009;
vector <ll> adj[maxn];
ll p[maxn]; ll s=0;
int main()
{
	ios_base::sync_with_stdio(false);
	ll n;	cin >> n; 
	for (ll i=0;i<n;i++)
	{
		ll x; cin>>x; s+=x;
	}
	if (s%2==0) cout<<"YES";
	else cout<<"NO";
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t,u;
    int a,b,d,e;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s)
    {
        d=a-1;
        cout<<d<<" "<< b<<endl;
    }
    else if(u==t)
    {
        e=b-1;
        cout<<a<<" "<< e<<endl;
    }
    return 0;
}


Measured memory_bytes: 3584
import math
# import numpy as np


def D1(x,y):
    d1 = 0
    for i in range(len(x)):
        d1 +=  abs(x[i] - y[i])
    return d1

def D2(x,y):
    d2 = 0
    for i in range(len(x)):
        d2 +=  abs(x[i] - y[i]) ** 2
    return d2 ** (1/2)

def D3(x,y):
    d3 = 0
    for i in range(len(x)):
        d3 +=  abs(x[i] - y[i]) ** 3
    return d3 ** (1/3)

def Dmax(x,y):
    dmax = 0
    for i in range(len(x)):
        if dmax <= abs(x[i] - y[i]):
            dmax = abs(x[i] - y[i])
    return dmax

n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

print(D1(x,y))
print(D2(x,y))
print(D3(x,y))
print(Dmax(x,y))



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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

inline int addmod(lli x,lli y)
{
    return (x%mod + y%mod)%mod;
}
inline int submod(lli x,lli y)
{
    return (x%mod - y%mod + mod)%mod;
}
inline int mulmod(lli x,lli y)
{
    return (x%mod * y%mod)%mod;
}


inline int nextSubMask(int i, int mask)
{
    return (i-1)&mask;   /// returns next  submask
}

template<typename T>
void we_r_done(T mssg)
{
    cout<<mssg;
    exit(0);
}


int main()
{
    ///freopen("output.txt","w",stdout);
   // freopen("input.txt","r",stdin);
    FastIO;
    
    int n;
    while(cin>>n){
        lli a[n+1];
        int idx = 1;
        for(int i=1; i<=n; i++){
            cin>>a[i];
            if(abs(a[idx])<abs(a[i])) idx = i;
        }
        lli mx = a[idx];
        cout<<(2*n - 1)<<endl;
        
        for(int i=1; i<=n; i++) cout<<idx<<" "<<i<<endl;
        
        if(mx>0){
            for(int i=1; i<n; i++){
                cout<<i<<" "<<(i+1)<<endl;
            }
        }
        else{
            for(int i=n; i>1; i--){
                cout<<i<<" "<<i-1<<endl;
            }
        }
    }

    return 0;
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?
///sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b : x.a<y.a);});


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 

int gcd (int x, int y){
    if(x % y == 0){
        return y ;
    }
    int k = x % y ; 
    return gcd(y, k) ;
}
int main(){
    int k ; 
    cin >> k ;
    ll ans = 0 ;
    for(int i = 1 ; i <= k ; i++){
        for(int j = 1 ; j <= k ; j++){
            for(int s = 1 ; s <= k ; s++){
                int f = gcd (i, j) ;
                int t = gcd (s, f) ;
                ans += t ;
            }
        }
    }
    cout << ans << endl ;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
const double EPS=1e-10;
const double INF=1e8;
typedef complex<double> P;
typedef pair<P,P> L;
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}
typedef vector<P> G;
double D(P a, P b) {
  return sqrt((a.real()-b.real())*(a.real()-b.real())+(a.imag()-b.imag())*(a.imag()-b.imag()));
}
int ccw(P a, P b, P c) {
  b-=a;c-=a;
  if(cross(b,c)>EPS)return +1;
  if(cross(b,c)<-EPS)return -1;
  if(dot(b,c)<-EPS)return +2;
  if(norm(b)<norm(c))return -2;
  return 0;
}
P projection(const L &l, const P &p) {
  double t=dot(p-l.F,l.F-l.S)/norm(l.F-l.S);
  return l.F+t*(l.F-l.S);
}
bool intersectLL(const L &l, const L &m) {
  return abs(cross(l.S-l.F,m.S-m.F))>EPS||
         abs(cross(l.S-l.F,m.F-l.F))<EPS;
}
double distanceLP(const L &l, const P &p){return abs(p-projection(l,p));}
double distanceLL(const L &l, const L &m){return intersectLL(l,m)?0:distanceLP(l, m.F);}
P crosspointLL(const L &a,const L &b){
    P va=a.S-a.F,vb=b.S-b.F;
    double d = cross(vb,va);
    if(abs(d)<EPS) return b.F;
    return a.F+va*cross(vb,b.S-a.F)*(1.0/d);
}
G convex_cut(const G &pg,const L &l){
  G res;
  for(int i=0; i<pg.size(); i++){
    P cp=pg[i],np=pg[(i+1)%pg.size()];
    if(ccw(l.F,l.S,cp)!=-1) res.push_back(cp);
    if(ccw(l.F,l.S,cp)*ccw(l.F,l.S,np)<0){
	    res.push_back(crosspointLL(L(cp,np),l));
    }
  }
  return res;
}

double area(G p) {
  double area=0;
  for(int i=0; i<p.size(); i++) area+=cross(p[i],p[(i+1)%p.size()]);
  return abs(area)/2;
}

int main() {
  int n;
  double d,v;
  while(cin >> n >> d >> v && n) {
    v/=d;
    P a[n];
    G g;
    for(int i=0; i<n; i++) {
      double x,y;
      cin >> x >> y;
      a[i]=P(x,y);
      g.push_back(a[i]);
    }
    double ans=0;
    for(int i=0; i<n; i++) {
      L e=L(a[i],a[(i+1)%n]);
      for(int k=0;k<2;k++){
        for(int kk=0;kk<2;kk++) {
          double l=0,r=INF;
          L w;
          for(int tt=0;tt<100;tt++) {
            double m=(l+r)/2;
            double m2=kk?m:-m;
            w=L(P(a[i].real()+(k?0:m2),a[i].imag()+(k?m2:0)),P(a[(i+1)%n].real()+(k?0:m2),a[(i+1)%n].imag()+(k?m2:0)));
            swap(w.F,w.S);
            G p=convex_cut(g,w);
            double s=area(p);
            if(s<v) l=m;
            else r=m;
          }
          if(EPS<l&&l<INF) {
            double x=distanceLL(e,w);
            ans=max(ans,x);
          }
        }
      }
    }
    printf("%.10f\n",ans);
  }
  return 0;
}


Measured memory_bytes: 1272
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

fn main() {
    input!{
      n: usize,
      aa: [i64; n],
    }

    let mut minus = 0;
    for i in 0..n {
        if aa[i] < 0 {
            minus += 1;
        }
    }

    let mut aa: Vec<i64> = aa.iter().map(|&v| v.abs()).collect();
    let mut min_a = *aa.iter().min().unwrap();
    let mut ans: i64 = aa.iter().sum::<i64>();

    if minus%2==1 {
        ans -= min_a*2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a>=b && c>=d){
        cout<<b+d<<endl;    
    }
    else if(a>=b && c<=d){
        cout<<b+c<<endl;    
    }
    else if(a<=b && c>=d){
        cout<<a+d<<endl;    
    }
    else if(a<=b && c<=d){
        cout<<a+c<<endl;    
    }// Your code here!
    
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	ll ans = 0;
	if (K == 0){
		ans = N*N;
	} else {
		for (ll b = K+1; b <= N; ++b){
			ll num = N / b;
			ans += (b - K) * num;
			ll rem = N % b;
			if (rem >= K){
				ans += rem - K + 1;
			}
		}		
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  char s[100][100];
  int ans[100][100];
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      cin >> s[i][j];
      if(s[i][j]=='#'){
        ans[i-1][j-1]++;
        ans[i-1][j]++;
        ans[i-1][j+1]++;
        ans[i][j-1]++;
        ans[i][j+1]++;
        ans[i+1][j-1]++;
        ans[i+1][j]++;
        ans[i+1][j+1]++;
      }
    }
  }
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      if(s[i][j]=='#'){
        cout << '#';
      }else{
        cout << ans[i][j];
      }
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
    if((A+B)>(C+D)){
    cout<<"Left"<<endl;
   }else if((A+B)<(C+D)){
    cout<<"Right"<<endl;
   }else{
    cout<<"Balanced"<<endl;
   }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            Dictionary<int, int> players = new Dictionary<int, int>();
            bool[] points = new bool[31];

            while (true)
            {
                string[] input1 = Console.ReadLine().Split(',');
                int p = int.Parse(input1[0]);
                int s = int.Parse(input1[1]);

                if (p == 0 && s == 0) break;

                players.Add(p, s);

                if (!points[s]) points[s] = true;
            }

            int[] ranks = new int[31];
            int rank = 0;

            for (int i = 30; i >= 0; i--)
            {
                if (points[i]) rank++;
                ranks[i] = rank;
            }

            string input2;

            while (!string.IsNullOrEmpty(input2 = Console.ReadLine()))
            {
                int q = int.Parse(input2);

                sb.AppendLine(ranks[players[q]].ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9688
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

typedef vector<vector<ll>> vvll;

int main() {
//	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	vll a(n);
	rep(i, n) cin >> a[i];

	vector<vvll> dp(n+1, vvll(3, vll(2, -INFL)));
	dp[0][0][0] = dp[0][0][1] = 0;
	rep(i, n) {
		rep(j, 3) {
			dp[i+1][j][0] = dp[i][j][1];
			dp[i+1][j][1] = dp[i][j][0] + a[i];
		}
		rep(j, 2) chmax(dp[i+1][j+1][0], dp[i][j][0]);
	}
	if(n % 2) cout << max(dp[n][1][0], dp[n][2][1]) << endl;
	else cout << max(dp[n][0][0], dp[n][1][1]) << endl;
}


Measured memory_bytes: 43908
#!/usr/bin/env python3
import sys


def solve(N: int, T: int, c: "List[int]", t: "List[int]"):
    cand = [c[i] for i in range(N) if t[i] <= T]
    if len(cand) == 0:
        print("TLE")
    else:
        print(min(cand))
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    c = [int()] * (N)  # type: "List[int]"
    t = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        c[i] = int(next(tokens))
        t[i] = int(next(tokens))
    solve(N, T, c, t)


if __name__ == '__main__':
    main()


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

int main() {
    string ring, s;
    cin >> ring;
    cin >> s;
    ring = ring + ring;
    bool result = false;
    for(int i = 0; i < ring.length()/2; i++) {
        if(ring.substr(i,s.length()).compare(s) == 0){
            result = true;
        }
        
    }
    if(result){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdint>

int main()
{
	std::uint16_t weight_of_obj;
	while (std::cin >> weight_of_obj) {
		std::vector<std::uint16_t> weights;
		std::uint16_t weight = 1;
		while (weight_of_obj != 0) {
			if ((weight_of_obj & 1) == 1) {
				weights.push_back(weight);
			}
			weight_of_obj >>= 1;
			weight *= 2;
		}
		std::copy(weights.begin(), weights.end() - 1,
				std::ostream_iterator<std::uint16_t>(std::cout, " "));
		std::cout << weights.back() << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=5005;
int n,mo,a[N];
int f[N][N];
int main(){
	scanf("%d%d",&n,&mo);
	int T=(n-1)/2;
	For(i,1,T+1) a[i]=1;
	For(i,n-T+1,n) a[i]=-1;
	Rep(i,n,1) a[i]+=a[i+1];
	For(i,2,n) a[i]*=-1;
	sort(a+2,a+n+1);
	reverse(a+2,a+n+1);
	f[0][0]=1;
	For(i,2,n) For(j,0,n/max(a[i],1)) For(k,0,n-a[i])
		f[j+1][k+a[i]]=(f[j+1][k+a[i]]+f[j][k])%mo;
	int ans=0;
	For(i,0,n) For(j,0,n){
		int tms=max(0,n-j-i);
		ans=(ans+1ll*tms*f[i][j])%mo;
	}
	printf("%d\n",ans); 
}
/*
5000 998244353
*/


Measured memory_bytes: 98048
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
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)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
vector<long long> A;

int main() {
    while (cin >> N) {
        A.resize(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        sort(A.begin(), A.end());

        long long res = A[N-1] - A[0];
        for (int i = 0, j = N-2; i + 1 < j; ++i, --j) res += A[j] - A[i];
        for (int i = 1, j = N-1; i + 1 < j; ++i, --j) res += A[j] - A[i];
        if (N & 1) res += max(A[N/2 + 1] - A[N/2], A[N/2] - A[N/2-1]);
        cout << res << endl;
    }
}












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

int main(){
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  for(int i = 0; i <= N/R ; ++i){
    for(int j = 0; j <= N/G; ++j){
      if(i*R+j*G > N) break;
      int d = (N - i*R - j*G);
      if(d%B) continue;
      ++ans;
      //cerr << i << " " << j << " " << k << endl;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256