akhauriyash/Code-Regression huggingface dataset:
from itertools import permutations
 
N = int(input())
Nlist = [i for i in range(1, N+1)] 
Nlist = list(permutations(Nlist)) 
 
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
 
print(abs(Nlist.index(P) - Nlist.index(Q)))

Measured memory_bytes: 13916
MIN_H = 3
MIN_W = 3

h, w, n = gets.split(" ").map(&:to_i)

count_map = {}
# 黒マスを起点として、影響範囲を数える
(0...n).each{
  black_y, black_x = gets.split(" ").map(&:to_i)
  (0...MIN_H).each{ |y|
    (0...MIN_W).each{ |x|
      # 各影響範囲の左上のマス
      sub_y = black_y - y
      sub_x = black_x - x
      in_y = (1 <= sub_y && sub_y <= (h-2))
      in_x = (1 <= sub_x && sub_x <= (w-2))
      if in_x && in_y
        # 左上のマスごとにマッピング
        if !count_map.key?(sub_y)
          count_map[sub_y] = {}
        end
        if !count_map[sub_y].key?(sub_x)
          count_map[sub_y][sub_x] = 0
        end
        count_map[sub_y][sub_x] += 1
      end
    }
  }
}

# 0～9までの件数
counts = Array.new(MIN_W * MIN_H + 1, 0)
count_map.each{ |k, in_count_map|
  in_count_map.each { |k2, v|
    counts[v] += 1
  }
}
counts[0] = (w - 2) * (h - 2) - counts.inject(0, &:+)

puts counts


Measured memory_bytes: 108156
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define Whole(xs) xs.begin(), xs.end()

template<class T>
ostream& operator<<(ostream& os, const vector<T>& vs) {
    if (vs.empty()) return os << "[]";
    os << "[" << vs[0];
    for (int i = 0; i < vs.size(); i++) os << " " << vs[i];
    return os << "]";
}
ostream& operator<<(ostream& os, const vector<int>& vs) {
    if (vs.empty()) return os << "[]";
    bool flag = false;
    os << "[";
    for (int i = 0; i < vs.size(); i++) {
        if (flag) {
            os << " ";
        } else {
            flag = true;
        }
        for (int j = 0; j < 5; j++) {
            os << ( (vs[i] & (1 << j)) > 0 );
        }
    }
    return os << "]";
}

const int IINF = 1<<28;
const Long LINF = 1LL<<56;
#define INF IINF

int N;
vector<int> F;
bool Input() {
    cin >> N;
    if (N == 0 || cin.eof()) return false;
    F.clear();
    return true;
}

void WSet(int Q, int P) {
    int R = 0;
    for (int i = Q; i < Q + P; i++) {
        R ^= (1 << i);
    }
    if (F.empty()) {
        F.push_back(R);
    } else{
        if ((F.back() & R) == 0) {
            for (int i = F.size() - 1; i >= -1; i--) {
                if ( i < 0 || (F[i] & R) > 0 ) {
                    F[i + 1] ^= R;
                    break;
                }
            }
        } else {
            F.push_back(R);
        }
    }
}

void HSet(int Q, int P) {   
    if (F.empty()) {
        for (int i = 0; i < P; i++) {
            F.push_back(1 << Q);
        }
        return;
    }
    int Rem = P;
    for (int i = F.size() - 1; i >= -1; i--) {
        if (i < 0 || F[i] & (1 << Q)) {
            for (int j = i + 1; Rem > 0 && j < F.size(); j++) {
                Rem--;
                F[j] ^= (1 << Q);
            }
            break;
        }
    }
    for (int i = 0; i < Rem; i++) {
        F.push_back(1 << Q);
    }
}

void Fall() {
    vector<int> nF;
    for (int i = 0; i < F.size(); i++) {
        if (F[i] != (1 << 5) - 1) {
            nF.push_back(F[i]);
        }
    }
    F = nF;
}

void Solve() {
    for (int n = 0; n < N; n++) {
        int D, P, Q; cin >> D >> P >> Q;
        Q--;
        if (D == 1) {
            WSet(Q, P);
        } else {
            HSet(Q, P);
        }
        Fall();
    }
    int Ans = 0;
    for (int i = 0; i < F.size(); i++) {
        for (int j = 0; j < 5; j++) {
            if (F[i] & (1 << j)) {
                Ans++;
            }
        }
    }
    cout << Ans << endl;
}

int main() {
    while (Input()) {
        Solve();
    }
    return 0;
}

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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (auto &(e) : (x))
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define lc(i) 2*i
#define rc(i) 2*i+1
#define int long long
using namespace std;
using ii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vii = vector<ii>;

const int N = 1e5 + 5, MOD = 1e9 + 7, INF = 1e9 + 5;
vi g[N];
int dp[N][2];

int mul(int x, int y) { return (x * y) % MOD; }

void dfs(int u = 0, int p = -1) {
    trav(v, g[u]) {
        if (v == p) continue;
        dfs(v, u);
        dp[u][0] = mul(dp[u][0], dp[v][0] + dp[v][1]);
        dp[u][1] = mul(dp[u][1], dp[v][0]);
    }
}

signed main() {
    FAST_IO;
//    setIO("input.txt", "output.txt");

    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    for (int i = 0; i <= n; i++) dp[i][0] = dp[i][1] = 1;
    dfs();
    cout << (dp[0][0] + dp[0][1]) % MOD;
}

Measured memory_bytes: 17480
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{

    string S;
    cin >> S;
    int x,y;
    cin >> x >> y;
    
    ve<int> vx,vy;
    int xy = 0;
    vx.push_back(0);
    rep(i,int(S.length())){
        if(xy == 0){
            if(S[i] == 'F') vx.back()++;
            else {
                xy = 1;
                vy.push_back(0);
            }
        }else{
            if(S[i] == 'F') vy.back()++;
            else {
                xy = 0;
                vx.push_back(0);
            }
        }
    }
    
    
    int xs = vx[0],ys = 0;
    vx.erase(vx.begin()+0);
    
    sor(vx);rev(vx);sor(vy);rev(vy);
    
    rep(i,int(vx.size())){
        if(xs <= x) xs += vx[i];
        else xs -= vx[i];
    }
    rep(i,int(vy.size())){
        if(ys <= y) ys += vy[i];
        else ys -= vy[i];
    }
    
    if(xs == x && ys == y) out("Yes");
    else out("No");
    //cout << xs << " " << ys << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] Xz = new int[N];
        for (int i = 0; i < N; i++) {
            Xz[i] = sc.nextInt();
        }
        int sum = 0;
        int minSum = 1000000000;
        for (int i = 1; i < 100; i++) {
            sum = 0;
            for (int j = 0; j < N; j++) {
                sum += Math.pow((Xz[j] - i), 2);
            }
            if (sum < minSum) {
                minSum = sum;
            }
        }
        System.out.println(minSum);
    }
}



Measured memory_bytes: 36084
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int k=0;
	cin>>s;
	string ss;
	for(int i=0;i<s.length();i++){
		if(i==0){
			ss=s.substr(i,1);
			k++;
		}else{
			for(int j=1;j<=s.length()-i;j++){
				string sss=s.substr(i,j);
				if(j>1){
					i++;
				}
				if(sss!=ss){
					k++;
					//cout<<sss<<endl;
					ss=sss;
					break;
				}
			}
		}
	}
	printf("%d",k);
}
/*
a aa c ca c a b a ab a b c
*/

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

/*
 BBBWWW
 BBBWWW
 BBBWWW
 WWWBBB
 WWWBBB
 WWWBBB
*/

int main(){
    int N, K;
    cin >> N >> K;
    bool if_hope_ok[N];
    int now_hope_ok = 0;
    vector<int> x_axis_count[K * 2];
    vector<int> y_axis_count[K * 2];
    for(int i = 0; i < N; i++){
        int x, y;
        string color;
        cin >> x >> y >> color;
        x_axis_count[y % K].push_back(i);
        y_axis_count[x % K].push_back(i);
        if((x % (K * 2) >= K) ^ (y % (K * 2) >= K) ^ color == "W"){
            if_hope_ok[i] = true;
            now_hope_ok++;
        }else{
            if_hope_ok[i] = false;
        }
    }
    int min_hope_ok = now_hope_ok, max_hope_ok = now_hope_ok;
    for(int x = 0; x < K; x++){
        for(int y = 0; y < K; y++){
            min_hope_ok = min(min_hope_ok, now_hope_ok);
            max_hope_ok = max(max_hope_ok, now_hope_ok);
            for(int i = 0; i < x_axis_count[K - y - 1].size(); i++){
                if(if_hope_ok[x_axis_count[K - y - 1][i]]){
                    now_hope_ok--;
                }else{
                    now_hope_ok++;
                }
                if_hope_ok[x_axis_count[K - y - 1][i]] ^= 1;
            }
        }
        now_hope_ok = N - now_hope_ok;
        for(int i = 0; i < N; i++){
            if_hope_ok[i] ^= 1;
        }
        for(int i = 0; i < y_axis_count[K - x - 1].size(); i++){
            if(if_hope_ok[y_axis_count[K - x - 1][i]]){
                now_hope_ok--;
            }else{
                now_hope_ok++;
            }
            if_hope_ok[y_axis_count[K - x - 1][i]] ^= 1;
        }
        min_hope_ok = min(min_hope_ok, now_hope_ok);
        max_hope_ok = max(max_hope_ok, now_hope_ok);
    }
    cout << max(max_hope_ok, N - min_hope_ok) << endl;
}


Measured memory_bytes: 1664
//#include<bits/stdc++.h> using namespace std;
#include<iostream>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<queue> //priority_queue inside queue
#include<deque>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl '\n'
typedef long long ll;
typedef unsigned long long ull;
#define f(i,start,end) for(i=start;i<=end;i++)
#define min_heap priority_queue<int, vector<int>, greater<int> >
#define max_heap priority_queue<int>

bool isPrime(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        if(n%i==0) return false;
    }
    return true;
} //returns true if prime!


int main()
{
    fast;
//int t=0,tc=0; cin >> tc; f(t,1,tc) //testcases
    {
       int n; cin >> n;
       ll tmp = 1, tmp2=2;
       while(true)
       {
          if(  (tmp2*tmp2*tmp2*tmp2*tmp2)-(tmp*tmp*tmp*tmp*tmp)<=n ){ tmp2+=1; tmp+=1; }
          else break;
       }
       
        int i=0, j=0;
        f(i, -tmp+1, tmp)
        f(j, -tmp, i-1)
        {
            if((i*i*i*i*i)-(j*j*j*j*j)==n)
            { cout << i << ' ' << j << nl; return 0; }
        }  
    }
    return 0;
}
    

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int n; cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  int ans = 0;
  vector<int> res(3);
  for (int i = 0; i < n; ++i){
    if (i + 2 >= n || i + 1 >= n) continue;
    res[0] = p[i]; res[1] = p[i + 1]; res[2] = p[i + 2];
    sort(res.begin(), res.end());
    if (res[1] == p[i + 1]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int map[21][21],n,a,b,c,d,x,y,n2;
	char h;
	while(cin>>n){
		if(n==0)break;
		for(int i=0;i<21;i++)for(int j=0;j<21;j++)map[i][j]=0;
		for(int i=0;i<n;i++){cin>>a>>b;map[b][a]++;}
		cin>>n2;c=0;x=y=10;
		for(int i=0;i<n2;i++){
			cin>>h;
			cin>>d;
			if(h=='N')for(int j=0;j<d;j++){y++;if(map[y][x]!=0){map[y][x]=0;c++;}}
			else if(h=='S')for(int j=0;j<d;j++){y--;if(map[y][x]==1){map[y][x]=0;c++;}}
			else if(h=='E')for(int j=0;j<d;j++){x++;if(map[y][x]==1){map[y][x]=0;c++;}}
			else if(h=='W')for(int j=0;j<d;j++){x--;if(map[y][x]==1){map[y][x]=0;c++;}}
		}
		if(c==n)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
N, K = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)

C = Hash.new{|h, k| h[k] = 0}
A.each{|a| C[a] += 1}
cnt = C.keys.size - K
ans = 0
C.sort_by{|k, v| v}.each{|k, v|
  break if cnt <= 0
  ans += v
  cnt -= 1
}

puts ans


Measured memory_bytes: 42220
#include <iostream>
#define ll long long
using namespace std;

const int INF = (1<<31)-1, MAX_N = 1<<17;

int N, dat[2*MAX_N -1];

void init( int n_ )
{
    // make 2^n over n_
    N = 1;
    while( N < n_ )
        N <<= 1;
 
    for(int i=0; i < 2*N-1; i++)
        dat[i] = INF;
 
    return;
}
 

void update(int k, int a){
    k += N - 1;
    dat[k] = a;
    while(k > 0){
        k = ( k - 1 ) / 2;
        dat[k] = min(dat[ k * 2 + 1 ], dat[ k * 2 + 2 ]);
    }
    return;
}

// get minimum value of [a, b)
int query(int a, int b, int k, int l, int r){
    // if [a, b) and [l, r) are not crossed
    if( r <= a || b <= l ){
        return INF;
    }
    // if [a, b) includes [l, r)
    if( a <= l && r <= b ){
        return dat[k];
    }else{
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
}

int main(){
    int n, q;
    
    cin >> n >> q;
    init(n);
    
    for(int i=0; i<q; i++){
        ll com, x, y;
        cin >> com >> x >> y;
        
        if(com == 0){
            update(x, y);
        }else{
            cout << query(x, y+1, 0, 0, N) << endl;
        }
    }
}


Measured memory_bytes: 4104
using namespace std;

#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <numeric>
#include <map>
using namespace std;

void strReplace (std::string& str, const std::string& from, const std::string& to) {
    std::string::size_type pos = 0;
    while(pos = str.find(from, pos), pos != std::string::npos) {
        str.replace(pos, from.length(), to);
        pos += to.length();
    }
}
int main(void){
		string s;

		cin >> s;
		strReplace(s, "BC", "D");
  s += "_";
	long long int r = 0, As = 0, Ds = 0;
  for (auto it = s.begin(); it != s.end(); ++it) {
    switch (*it) {
      case 'A':
        r += Ds * As;
        Ds = 0;
        As++;
        break;
      case 'D':
        Ds++;
        break;
      default:
        r += Ds * As;
        As = Ds = 0;
    }
  }
  
  cout << r << endl;
	return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;
int N;
struct Node {
  Node(int X = 0, int D = 0) : X(X), D(X) {}
  int X, D;
  void input() {
    cin >> X >> D;
  }

  bool operator < (const Node& node) const {
    return X < node.X;
  }

  vector<int> nextNodeIndexList;
};

Node nodes[MAX_N];

bool buildTree(int pos, int& nodesIndex)
{
  if(N <= nodesIndex) {
    return true;
  }

  int nextNodeIndex = nodesIndex;
  // 範囲内なら追加
  if(nodes[pos].X <= nodes[nodesIndex].X && nodes[nodesIndex].X < nodes[pos].X + nodes[pos].D) {
    nodes[pos].nextNodeIndexList.push_back(nodesIndex);
    nodesIndex++;
    while(!buildTree(nextNodeIndex, nodesIndex)) {
      if (nodes[pos].X <= nodes[nodesIndex].X && nodes[nodesIndex].X < nodes[pos].X + nodes[pos].D) {
        nextNodeIndex = nodesIndex;
        nodes[pos].nextNodeIndexList.push_back(nodesIndex);
        nodesIndex++;
      } else {
        return false;
      }
    }
    return true;
  } else { // 範囲外なら先祖に追加してもらう
    return false;
  }
}

int solve(int pos = 0)
{
  int ret = 1;
  for(int next : nodes[pos].nextNodeIndexList) {
    ret *= solve(next);
    ret %= MOD9;
  }
  return (ret + 1) % MOD9;
}

signed main()
{
  nodes[0].X = -INF_LL; nodes[0].D = 2*INF_LL;
  cin >> N;
  FOR(n,1,N+1) {
    nodes[n].input();
  }
  N++;

  sort(nodes, nodes+N);

  int nodesIndex = 1;
  buildTree(0, nodesIndex);

  cout << (solve() + MOD9 - 1) % MOD9 << endl;

  return 0;
}


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

using namespace std;

int main(){
    int n, t, ci, ti, r=1001;

    cin>>n>>t;

    while(n--){
        cin>>ci>>ti;
        if(ti<=t && ci<r){
            r=ci;
        }
    }

    r<1001?cout<<r:cout<<"TLE";

    return 0;
}

Measured memory_bytes: 256
//ABC142C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int n;
	cin >> n;
	int x;
	vector<pair<int,int>> a;
	for(int i=0;i<n;i++){
		cin >> x;
		a.push_back(make_pair(x,i));
	}
	sort(a.begin(),a.end());
	for(pair<int, int> t : a){
		int x, y;
		tie(x,y) = t;
		cout << y+1 << " ";
	}
	return 0;
}

Measured memory_bytes: 1780
//use std::convert::TryInto;
#![allow(dead_code)]

const MD: u64 = 1_000_000_007;

fn main(){
    let k: u64 = input();
    let s: String = input();
    // end input

    
    let s_len = s.len() as u64;
    let mut fact: Vec<u64> = Vec::new();
    fact.push(1);
    for i in 1..(k+s_len+1) {
        let t: u64 = fact[(i-1) as usize]*i%MD;
        fact.push(t as u64);
    }
    
    let mut ans: u64 = 0;
    for i in (0..=k).rev() {
        let t = comb(s_len+i-1, i, &fact)*pow(25, i)%MD *pow(26,k-i)%MD;
        ans = (ans+t)%MD;
    }
    println!("{}", ans);
}

fn comb(n: u64, r: u64, fact: &Vec<u64>) -> u64{
    fact[n as usize]*inv(fact[r as usize])%MD *inv(fact[(n-r) as usize])%MD
}

fn inv(n: u64) -> u64{
    pow(n, MD-2)
}

fn pow(mut x: u64, mut y: u64) -> u64{
    let mut res = 1;
    while y>0 {
        if y&1==1 { res = res*x%MD; }
        x = x*x%MD;
        y >>= 1;
    }
    res
}


/*
 * input function
 */
fn input<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


fn input_vec<T: std::str::FromStr>() -> Vec<T> {
    input::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 19104
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,l;
	cin>>n>>l;
	vector<string>s(n);
	rep(i,n)cin>>s[i];
	sort(all(s));
	rep(i,n)cout<<s[i];
	cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int N, X; cin >> N >> X; int pos = 0, ans = 0;
    F0R(i, N) {
    	if (pos <= X) ans++;
    	int cur; cin >> cur; pos += cur;
    }
    if (pos <= X) ans++;
    cout << ans << endl;
    
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	long long A, B, N;
	cin >> A >> B >> N;

	if (B <= N) {
		double val = (double)A * (double)(B - 1) / (double)B;
		long long ans = (long long)val;

		cout << ans << endl;
	}
	else {
		double val = (double)A * (double)N / (double)B;
		long long ans = (long long)val;

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main() {
    double n;
    cin >> n;
    for(int i = floor(n / 1.08);i <= ceil(n / 1.08);i++) {
        if(floor(i * 1.08) == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

k,x = get_nums_l()

print(" ".join(map(str, range(x-k+1, x+k))))

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

int A[200005];

int main() {
  int N;
  int K;
  cin >> N >> K;
  rep(i, N) {
    scanf("%d", &A[i]);
  }
  double L = 0;
  double max_L = *max_element(A, A+N) + 1;
  rep(i, 1000) {
    int sum = 0;
    double mid = (L + max_L) / 2;
    rep(i, N) {
      sum += ceil(A[i] / mid) - 1;
      /* cout << ceil(A[i] / mid) - 1 << endl; */
    }
    if(sum <= K) {
      max_L = mid;
    } else {
      L = mid;
    }
  }
  cout << (int)(ceil(L)) << endl;
  return 0;
}




Measured memory_bytes: 4536
import statistics
N = int(input())
X = list(map(int,input().split()))
y = statistics.median(X)
yl = statistics.median_low(X)
yh = statistics.median_high(X)
for x in X:
  if x>y:
    print(yl)
  if x<=y:
    print(yh)
    


Measured memory_bytes: 27180
///In the name of Almighty Allah(swt).

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,m,cunt=0;
    cin>>n;
    m = n;
    while(m!=0)
    {
        m=m/10;
        cunt++;
    }

    if(cunt <= 3)
        cout<<1000-n<<endl;
    else if(cunt == 4)
    {
        int x,p;
        if(n%1000==0)
            cout<<0<<endl;
        else{
        x = n/1000;
        p = (x+1)*1000;
        cout<<p-n<<endl; }
    }
    else if(cunt == 5)
    {
        cout<<0<<endl;
    }


    return 0;
}



Measured memory_bytes: 3588
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define cin_desync()                                                           \
    do {                                                                       \
        ios_base::sync_with_stdio(false);                                      \
        cin.tie(0);                                                            \
    } while (0)

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

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

const int max_N = 1e5 + 10;
const int mod = 1e9 + 7;

ll one_dir[max_N];
ll A[max_N];

ll modexp(ll a, ll b);

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

    ll f = 1;
    for (int i = 2; i <= N; ++i) {
        f *= i; f %= mod;
    }

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

    one_dir[0] = 0;
    for (int i = 1; i < N; ++i) {
        one_dir[i] = one_dir[i - 1] + f * modexp(i + 1, mod - 2);
        one_dir[i] %= mod;
    }

    ll ans = 0;
    for (int i = 1; i <= N; ++i) {
        ll res = one_dir[i - 1] + one_dir[N - i] + f;
        res %= mod;
        ans += res * A[i];
        ans %= mod;
    }

    cout << ans << endl;
}

ll modexp(ll a, ll b)
{
    ll ans = 1, res = a;
    while(b) {
        if (b % 2) {
            ans *= res;
            ans %= mod;
        }

        res *= res;
        res %= mod;
        b /= 2;
    }

    return ans;
}


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

int main()
{
    ll t,a,b;
    ll mab=1e9+10000;
    cin>>t;
    int flag=1;
    ll tot=0;
    while(t--)
    {
        cin>>a>>b;
        if(a>b&&mab>b)
            mab=b;
        tot+=b;
        if(a!=b) flag=0;
    }
    if(flag)
        cout<<0<<endl;
    else
        cout<<tot-mab<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
 
int main(void){
    int N;
    cin >> N;
    lint A[N];
    rep(i,N) cin >> A[i];
    lint ans=0;
    for(int i=1;i<N;i++){
        if(A[i]<A[i-1]){
            ans+=A[i-1]-A[i];
            A[i]=A[i-1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5216
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    
    vector<int> cnt(4);
    rep(i, 6) {
        int x;
        cin >> x;
        x--;
        cnt[x]++;
    }

    int flag = 0;
    rep(i, 4) {
        if(cnt[i] == 3) {
            flag = 1;
        }
    }

    if(flag) {
        cout << "NO";
    }
    else {
        cout << "YES";
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	uint64_t N;
	int64_t A, B;
	uint64_t i;
	if (scanf("%" SCNu64, &N) != 1) return 1;
	if (scanf("%" SCNd64 "%" SCNd64, &A, &B) != 2) return 1;
	N %= 12;
	for (i = 0; i < N; i++) {
		if (i % 2 == 0) A = A - B; else B = A + B;
	}
	printf("%" PRId64 " %" PRId64 "\n", A, B);
	return 0;
}

/*

A B

A-B B
A-B A

-B A
-B A-B

-A A-B
-A -B

-A+B -B
-A+B -A

B -A
B -A+B

A -A+B
A B

*/



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

int main(){
    long long H;cin>>H;
    int count=1;
    long long ans=0;
    while(true){
        if(H==1){
            break;
        }
        else{
            H/=2;
            count++;
        }
    }
    for(int i=0;i<count;i++){
        ans+=pow(2,(double)i);
    }
    cout<<ans<<endl;
}

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

using namespace std;

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

    string s;
    cin>>s;
    long long ans = 1;
    int n = s.size();
    map<int, int> al;
    al[s[0] - 'a'] = 1;
    for (int i = 1; i < n; i++){
        int c = s[i] - 'a';
        for(auto p : al){
            if(p.first != c) ans += p.second;
        }
        al[c] ++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 720
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = ni();
        }
        long[] s_mon = new long[N+1];
        long[] s_sto = new long[N+1];
        long[] b_mon = new long[N+1];
        long[] b_sto = new long[N+1];
        
        s_mon[0] = 1000;
        s_sto[0] = 0;
        b_mon[0] = 0;
        b_sto[0] = 0;
        for (int i = 1; i <=N; i++) {
            s_mon[i] = Math.max(b_sto[i-1] * A[i-1] + b_mon[i-1], s_mon[i-1]);
            s_sto[i] = 0;
            if(b_mon[i-1] + b_sto[i-1]*A[i-1] >= s_mon[i-1] + s_sto[i-1]*A[i-1]){
                b_mon[i] = b_mon[i-1];
                b_sto[i] = b_sto[i-1];
            }else{
                b_mon[i] = s_mon[i-1] - (s_mon[i-1]/A[i-1]) * A[i-1];
                b_sto[i] = s_sto[i-1] + s_mon[i-1]/A[i-1];
            }
            // System.out.println(s_mon[i]);
            // System.out.println(s_sto[i]);
            // System.out.println(b_mon[i]);
            // System.out.println(b_sto[i]);
        }
        long ans = s_mon[N];
        out.println(ans);
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);
    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 33272
#include <bits/stdc++.h>
 
#define ll long long
#define ld long double
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forr(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define foriter(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define endl '\n'
#define INF (ll)(1e9)
#define EPS 1e-9
#define MOD (ll)(1e9+7)
#define PI 3.1415926535897932384626433832795
#define set set
#define mset multiset
#define uset unordered_set
#define umset unordered_multiset
#define map map
#define mmap multimap
#define umap unordered_map
#define ummap unordered_multimap

using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vll;
typedef vector<vll> vvll;
typedef pair<i64, i64> pll;

int inp(){
  int x; 
  cin>>x;
  return x;
}

//=============================================================================//

void solve() {
    ll n; cin>>n;
    vll v(n); for0(i, n) cin>>v[i];
    vll sums(n+1, 0);
    for(int i=n-1; i>=1; i--){
      sums[i] = (v[i]+sums[i+1])%MOD;
    }
    ll ans = 0; 
    for(int i=0; i<n-1; i++){
      ans+=v[i]*sums[i+1];
      ans%=MOD;
    }
    cout<<ans;
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);

    int T=1;
    //cin >> T;
    while (T--) {
        solve();
        cout<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 6340
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
#define pr pair<pair<int,int>,int>
#define fr first.first
#define se first.second
#define tr second
#define mp make_pair
#define N 100050
set<pr > q[2];
int l[N],r[N],x,n,i,ll,rr;
long long ans[2];
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d%d",&l[i],&r[i]);
	for (i=1;i<=n;i++) q[0].insert(mp(mp(-l[i],-r[i]),i)),q[1].insert(mp(mp(r[i],l[i]),i));
	int zw=0;x=0;
	for (i=1;i<=n;i++){
		pr psz=*q[zw].begin();q[zw].erase(psz);q[zw^1].erase(mp(mp(-psz.se,-psz.fr),psz.tr));
		if (zw==0) ll=-psz.fr,rr=-psz.se;else ll=psz.se,rr=psz.fr;
		if (x<ll) ans[0]+=ll-x,x=ll;else if (x>rr) ans[0]+=x-rr,x=rr;
		zw^=1;
	}if (x>0) ans[0]+=x;else ans[0]+=-x;
	for (i=1;i<=n;i++) q[0].insert(mp(mp(-l[i],-r[i]),i)),q[1].insert(mp(mp(r[i],l[i]),i));
	zw=1;x=0;
	for (i=1;i<=n;i++){
		pr psz=*q[zw].begin();q[zw].erase(psz);q[zw^1].erase(mp(mp(-psz.se,-psz.fr),psz.tr));
		if (zw==0) ll=-psz.fr,rr=-psz.se;else ll=psz.se,rr=psz.fr;
		if (x<ll) ans[1]+=ll-x,x=ll;else if (x>rr) ans[1]+=x-rr,x=rr;
		zw^=1;
	}if (x>0) ans[1]+=x;else ans[1]+=-x;
	printf("%lld\n",max(ans[0],ans[1]));
	return 0;
}

Measured memory_bytes: 13568
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define ll long long

std::set<int> S;
std::set<int>::iterator it;

int now;
int n, Q;
int p[111111];

struct Qry{
	int x, num;
	bool operator <(const Qry &a)const{
		return x > a.x;
	}
}q[111111];

bool vis[111111];
int work(int X){
	if(X <= p[1]) return n / 2 + 1;
	if(X >= p[n]) return n;
	int sm = 0, l, r, rr = n;
	for(int i = 1; i <= n; i++)
		if(p[i] >= X) {r = i; break;}
	l = r - 1;
	p[0] = -1000000007;
	while(1){
		if(vis[rr]) return rr + 1;
		vis[rr] = true, rr--;
		if(vis[rr]) return rr + 1;
		if(p[r] - X < X - p[l]){
			if(vis[r]) return r;
			vis[r] = 1, r++;
		}
		else vis[l] = 1, l--;
	}
}

ll pre[111111];
ll suf[111111];
ll ans[111111];

int main(){
	scanf("%d %d", &n, &Q);
	for(int i = 1; i <= n; i++) scanf("%d", &p[i]);
	pre[1] = p[1];
	for(int i = 1; i <= n; i++)
		pre[i] = pre[i - 2] + p[i];
	for(int i = n; i; i--) suf[i] = suf[i + 1] + p[i];
	for(int i = 1; i <= Q; i++) scanf("%d", &q[i].x), q[i].num = i;
	std::sort(q + 1, q + Q + 1);
	
	int now = work(q[1].x);
	ans[q[1].num] = suf[now] + ((2 * now - n - 2 >= 0) ? (pre[2 * now - n - 2]) : 0);
	
	for(int i = 2; i <= Q; i++){
		if(q[i].x <= p[1]) now = n / 2 + 1;
		if(now <= n / 2 + 1) ans[q[i].num] = suf[now];
		else{
			int bg = 2 * now - n - 2;
			while(bg && q[i].x - p[bg] <= p[now - 1] - q[i].x)
				now--, bg = 2 * now - n - 2;
			ans[q[i].num] = suf[now] + pre[bg];
		}
	}
	
	for(int i = 1; i <= Q; i++) printf("%lld\n", ans[i]);
	return 0;
}

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

int main() {

    // 1. input.
    int n, m;
    cin >> n >> m;
    
    // 2. input check.
    long long a[n][m], b[m];
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> a[i][j];
    for(int i = 0; i < m; i++) cin >> b[i];
    
    // 3. calculate product of matrices.
    long long c[n];
    for(int i = 0; i < n; i++) c[i] = 0;
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) c[i] += (a[i][j] * b[j]);
    
    // 3. output answer.
    for(int i = 0; i < n; i++) cout << c[i] << endl;
    return 0;
    
}


Measured memory_bytes: 3184
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, m, *x = map(int, read().split())
    if n >= m:
        print(0)
        sys.exit()
    x.sort()
    sa = []
    pre = x[-1]
    for xe in x:
        sa.append(abs(xe - pre))
        pre = xe
    sa.sort()
    num = m - n
    r = sum(sa[:num])
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 20664
#include <iostream>
#include <vector>
using namespace std;
class Field {
  public:
  vector<vector<bool> > field;
  int nx, ny;
  bool def;
  Field(int nnx, int nny, bool firs, bool ddef) {
    def = ddef;
    nx = nnx;
    ny = nny;
    vector<vector<bool> > buff(nnx, vector<bool>(nny, firs));
    field = buff;
  }
  void set(int x, int y, bool flag) {
    field[x][y] = flag;
  }
  bool get(int x, int y) {
    if(x >= nx || y >= ny || x < 0 || y < 0) return def;
    return field[x][y];
  }
  void print() {
    for(int i = 0; i < ny; ++i) {
      for(int j = 0; j < nx; ++j) {
        cout << field[j][i];
      }
      cout << endl;
    }
    cout << endl;
  }
};
int mark(Field&, Field&, int x, int y);

int main() {
  while(1) {
    int nx, ny;
    cin >> nx >> ny;
    if(!nx && !ny) break;
    Field field(nx, ny, false, false);
    int startx, starty;
    for(int i = 0; i < ny; ++i) {
      for(int j = 0; j < nx; ++j) {
        char c;
        cin >> c;
        field.set(j, i, ((c == '#') ? false : true));
        if(c == '@') {
          startx = j;
          starty = i;
        }
      }
    }
    //for(auto i = field.begin(); i != field.end(); ++i) {
    //  for(auto j = field[i].begin(); j != field[j].end(); ++j) {
    //    cout << field[i][j];
    //  }
    //  cout << endl;
    //}
    Field result(nx, ny, false, true);
    cout << mark(field, result, startx, starty) << endl;
  }
  return 0;
}

int mark(Field &field, Field &result, int x, int y) {
  int count;
  if(field.get(x, y) && !result.get(x, y)) {
    result.set(x, y, true);
    count = mark(field, result, x + 1, y);
    count += mark(field, result, x, y + 1);
    count += mark(field, result, x - 1, y);
    count += mark(field, result, x, y - 1);
    ++count;
    return count;
  } else {
    return 0;
  }
}

Measured memory_bytes: 1240
def calc(n, k):
	a = [int(input()) for _ in range(n)]
	s = [0] * (n + 1)
	for i in range(n):
		s[i + 1] = s[i] + a[i]
	ans = float('-inf')
	for i in range(n-k+1):
		ans = max(ans, s[k+i] - s[i])
	print(ans)

def resolve():
	while True:
		n, k = map(int, input().split())
		if n == 0 and k == 0:
			return
		calc(n, k)
resolve()


Measured memory_bytes: 13428
#!/usr/bin/env python

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")

def main():
    N = int(input())

    F = [0]*(N+1)
    for x in range(1, int(N**.5)+1):
        for y in range(1, int(N**.5)+1):
            for z in range(1, int(N**.5)+1):
                a = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if a <= N:
                    F[a] += 1
    
    for i in range(1,N+1):
        print(F[i])

if __name__ == "__main__":
    main()

Measured memory_bytes: 9716
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod = 1e9 + 7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
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; }
#define INF 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 1000
#define PI 3.141592653589793
#define vecP vector<P>
// cout << setprecision(15) << std::fixed;


int main() {
	int n,k,s;
	cin >> n>>k>>s;
	vec ans;
	int kc = 0;
	for (int i = 0;i < n;i++) {
		if (kc < k) {
			ans.push_back(s);
			kc++;
		}
		else {
			if (s != pow(10,9)) {
				ans.push_back(pow(10,9));
			}
			else {
				ans.push_back(1);
			}
		}
	}
	for (int i = 0;i < n;i++) {
		if (i < n - 1) {
			cout << ans[i] << " ";
		}
		else {
			cout << ans[i];
		}
	}
	ent;
}

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

int main() {
	
	int n, d, x;
	cin >> n >> d >> x;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int ans = x;
	rep(i, n){
		ans += (d - 1) / a[i] + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int label(int num){
    if(num == 1 || num== 3 || num== 5 || num==7 || num==8 || num==10 || num==12){
        return 1;
    }else if(num == 4 || num== 6 || num== 9 || num== 11){
        return 2;
    }else{
        return 3;
    }
}

int main(int argc, const char * argv[]) {
    int x,y;
    cin >> x >> y;
    map<int,int> number;
    if(label(x) == label(y)){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	while ( stdin.hasNextLine() ) {
	    final String[] input = stdin.nextLine().split( "," );
	    final double[] p1 = { Double.parseDouble( input[0] ), Double.parseDouble( input[1] ) };
	    final double[] p2 = { Double.parseDouble( input[2] ), Double.parseDouble( input[3] ) };
	    final double[] pq = { Double.parseDouble( input[4] ), Double.parseDouble( input[5] ) };

	    final double[] a = sub( p1, pq );
	    final double[] b = sub( p2, pq );

	    final double alpha = - ip( b, sub( a, b ) ) / norm( sub( a, b ) );
	    double[] ans = add( pq, times( add( times( a, alpha ), times( b, 1 - alpha ) ), 2 ) );
	    System.out.printf( "%f %f\n", ans[0], ans[1] );
	}	
    }

    static double[] times( double[] v, double val ) {
	final double[] vc = Arrays.copyOf( v, v.length );
	for ( int i = 0; i < v.length; i++ ) {
	    vc[i] *= val;
	}
	return vc;
    }

    static double ip( double[] v1, double[] v2 ) {
	double sum = 0.0;
	for( int i = 0; i < v1.length; i++ ) {
	    sum += v1[i] * v2[i];
	}
	return sum;
    }

    static double norm( double[] v ) {
	return ip( v, v );
    }

    static double[] add( double[] v1, double[] v2 ) {
	final double[] v1c = Arrays.copyOf( v1, v1.length );
	for ( int i = 0; i < v1c.length; i++ ) {
	    v1c[i] += v2[i];
	}
	return v1c;
    }

    static double[] sub( double[] v1, double[] v2 ) {
	final double[] v1c = Arrays.copyOf( v1, v1.length );
	for ( int i = 0; i < v1c.length; i++ ) {
	    v1c[i] -= v2[i];
	}
	return v1c;
    }
    
}

Measured memory_bytes: 17368
#import sys

#input = sys.stdin.readline

import heapq

def main():
#    h,w,a,b = map(int, input().split())
    n=int(input())
    a = list(map(int,input().split()))
    b=[]
    for i in range(n):
        b.append([a[i],i+1])
#    print(b)
#    heapq.heapify(b)
#    print(heapq.heappop(b))
#    print(b)
    b=sorted(b,key=lambda x: x[0])
    for i in range(n):
        print(b[i][1], end=" ")


#    for i in range(h):
#            print(aaa)

if __name__ == "__main__":
    main()

Measured memory_bytes: 23164
#include<stdio.h>

int main(void)
{
	int a,b;
	char op;
	scanf("%d %c %d",&a,&op,&b);
	while(1)
	{
	 if(op == '+')
		{
			printf("%d\n",a+b);
		}
		else if(op == '-')
		{
			printf("%d\n",a-b);
		}
		else if(op == '/')
		{
			printf("%d\n",a/b);
		}
		else if(op == '*')
		{
			printf("%d\n",a*b);
		}
		else
		{
			break;
		}
		scanf("%d %c %d",&a,&op,&b);
	}
	return 0;
}

Measured memory_bytes: 600
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program{
  static void Main(){
	var order = ReadLine().Split(' ').Select(int.Parse).ToArray();
    var dice = ReadLine().Split(' ').Select(long.Parse).ToArray();
    decimal num = 0;
    decimal total = 0;
    decimal evalue = 0;
    var dice1 = dice.Select(i => i+1).ToArray();
    var dices = dice1.Select(i => decimal.Divide(i,2)).ToArray();
    
    for(var i = 0;i < order[1];i++){
      num += dices[i];
    }
    total = num;
    
    for(var i = 0;i < order[0]-order[1];i++){
      num = num-dices[i]+dices[order[1]+i];
      if(num>total){
        total = num;
      }
    }
    //evalue = decimal.Divide(total + order[1],2);
    Write(total);
  }
}



Measured memory_bytes: 47964