akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String[] input = sc.nextLine().split(" ");
        long N = Integer.parseInt(input[0]);
        long M = Integer.parseInt(input[1]);
        long sum = 0;
        if( N == 1 || M == 1){
            sum = N * M - 2;
            if(sum < 0){
                sum *= -1;
            }
        }
        else{
            sum = (N-2) * (M-2);
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 21076
"""
author : halo2halo
date : 19,Oct,2019
"""

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
lis = list(map(int, readline().split()))
s = sum(lis)
ans = 0
for i in lis:
    s -= i
    ans += s * i

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int p,q,r;
  cin >> p >> q >> r;
  int a=p+q;
  int b=p+r;
  int c=q+r;
  int ans=min(a,b);
  ans=min(ans,c);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define N 100001
using namespace std;



int main()
{   IOS;
cout.precision(30);
    double n,k;
  cin>>n>>k;
  double ans=0;
  for(int64_t i=1;i<=n;i++){
    if(i>=k){
      ans+=1/n;
    }
    else{
      double t=1/n;
      int64_t z=i;
      int count=0;
      while(z<k){
        z*=2;
        count++;
      }
      t*=(1/pow(2,count));
      ans+=t;
    }
  }
  cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int N;
    string S;
    cin >> N >> S;
    cout << (unique(S.begin(), S.end()) - S.begin()) << '\n';
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, x;
  cin >>N >>x;
  long long ans=0;
  vector<int>X(N,0);
  for(int i=0; i<N; i++){
    int a;
    cin >>a;
    if(a>x){
      ans+=a-x;
      a=x;
    }
    X[i]=a;
  }
  for(int i=0; i<N-1; i++){
    if(X[i]+X[i+1]>x){
      ans+=X[i]+X[i+1]-x;
      X[i+1]-=X[i]+X[i+1]-x;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b)cout << c;else if (b == c) cout << a; else cout << b;
    return 0;
}

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

#define ll             long long
#define LL             long long
#define gcd(a,b)       __gcd(a, b)
#define lcm(a,b)       a * (b / gcd(a, b))
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof a)
#define smax(a, b)     a = max(a, b)
#define smin(a, b)     a = min(a, b)
#define sqr(x)         x * x
#define cube(x)        x * x * x
#define endl           '\n'

int in() {
	int n;
	scanf("%d", &n);
	return n;
}

ll Lin() {
	ll n;
	scanf("%lld", &n);
	return n;
}

double Din() {
	double n;
	scanf("%lf", &n);
	return n;
}

const ll inf = (ll)1e17;
const ll mod = (ll)1e9 + 7;
const int N = 1e5 + 5;

ll h[N];
ll dp[N];

ll call(int pos) {
	if (pos < 1) return 2e9;
	if (pos == 1) return 0;
	if (dp[pos] != -1) return dp[pos];
	return dp[pos] = min(call(pos - 1) + abs(h[pos] - h[pos - 1]), call(pos - 2) + abs(h[pos] - h[pos - 2]));
}


int solve() {
	int n = in();
	fill(dp, -1);
	for (int i = 1; i <= n; i++) {
		h[i] = Lin();
	}
	printf("%lld\n", call(n));
	return 0;
}

int main() {
	int test = 1, tc = 0;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>


using namespace std;
using ll = long long;

ll vx[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
ll vy[8] = { 1, 0, -1, 1, -1, 1, 0, -1 };

bool isOut(ll H, ll W, ll x, ll y) {
	if (x >= 0 && x < W && y >= 0 && y < H) return true;
	else return false;
}

int main() {
	ll H, W;
	cin >> H >> W;
	vector<string> str(H);
	vector<string> strans(H);
	for (ll i = 0; i < H; i++)
	{
		cin >> str[i];
		strans[i] = str[i];
	}
	for (ll i = 0; i < H; i++)
	{
		for (ll j = 0; j < W; j++)
		{
			if (str[i][j] == '.') {
				ll count = 0;
				for (ll k = 0; k < 8; k++)
				{
					if (isOut(H, W, j + vx[k], i + vy[k]) && str[i + vy[k]][j + vx[k]] == '#') count++;
				}
				strans[i].replace(j, 1, to_string(count));
			}
			else {
				strans[i][j] = '#';
			}
		}
	}
	for (ll i = 0; i < H; i++)
	{
		cout << strans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

vector<int> bfn(int spoint, int N, vector<int> *G);

int main(){
  int N;
  vector<int> *G;
  cin >> N;
  G = new vector<int>[N+1];
  int a, b;
  for(int i=1; i<N; i++){
    //cin >> a >> b;
    scanf("%d %d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  vector<int> dist1 = bfn(1,N,G);
  vector<int> dist2 = bfn(N,N,G);

  int l=0; int r=0;
  for(int i=1; i<=N; i++){
    if(dist1[i] <= dist2[i]) l++;
    else r++;
  }

  if(l>r) cout << "Fennec" << endl;
  else  cout << "Snuke" << endl;
}

vector<int> bfn(int spoint, int N, vector<int> *G){
  vector<int> dist(N+1,-1); 
  queue<int>  q; 
  q.push(spoint);
  dist[spoint] = 0;

  while(!q.empty()){
    int u = q.front();
    q.pop();
    for(int i : G[u]){
      if(dist[i]==-1){
	dist[i] = dist[u] + 1;
	q.push(i);
      }
    }
  }
  return dist;
};


Measured memory_bytes: 6528
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let mut ans: u64 = 0;
    let mut ac: u64 = 0;
    for c in sc.chars() {
        if c == 'B' {
            ac += 1;
        } else {
            ans += ac;
        }
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
lstA = list(input())
lstB = list(input())
lstC = list(input())

maxA = len(lstA)
maxB = len(lstB)
maxC = len(lstC)

numA = 0
numB = 0
numC = 0

res = ''
tmp = 'a'

while True:
	if tmp == 'a':
		if numA == maxA:
			res = 'A'
			break
		tmp = lstA[numA]
		numA += 1

	elif tmp == 'b':
		if numB == maxB:
			res = 'B'
			break
		tmp = lstB[numB]
		numB += 1

	else:
		if numC == maxC:
			res = 'C'
			break
		tmp = lstC[numC]
		numC += 1

print(res)


Measured memory_bytes: 42992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String str=scan.nextLine();

		if(str.equals("ABC")) {

			//S=ABC then the output is ARC
			System.out.println("ARC");

		}else if(str.equals("ARC")) {

			//S=ARC then the output is ABC
			System.out.println("ABC");

		}else{

			System.out.println("Incorrect input");

		}

		scan.close();

	}

}


Measured memory_bytes: 35716
#include <iostream> 
using namespace std;
 int main(){
     int K,S;
     cin >> K >> S;
     int cnt = 0;
     for(int x=0; x<=K; x++){
        
         for(int y=0; y<=K; y++){
             if(S-y-x<=K && x+y<=S)cnt += 1;
         }
     }
     cout << cnt << endl;
 }


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

int main() {
	int M;
	int D;

	cin >> M >> D;

	int count = 0;

	for (int m = 1; m < M + 1; m++)
	{
		for (int d = 22; d < D + 1; d++)
		{
			int d1 = d % 10;
			if (d1 > 1)
			{

				int d10 = (d - d1) / 10;
				int Flag = d1 * d10;
				if (Flag == m) {
					count++;
				}
			}
			}
	}
	cout << count << endl;
	cin >> M;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<max(a-2*b,0);
    return 0;
}

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

const int maxn=100000+5;
ll b[maxn];

vector<ll>ans;
int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; ++i)
    {
        scanf("%lld",b+i);
        b[i]*=2;
    }


    ll t=b[n];
    for(int i=1; i<n; ++i)
    {
        if(i&1)
            t-=b[i];
        else
            t+=b[i];
    }
    ans.push_back(t/2);
    for(int i=n-1; i>=1; --i)
        ans.push_back(b[i]-ans.back());
    for(int i=ans.size()-1; i>=0; --i)
    {

        printf("%lld",ans[i]);
        if(i)
            putchar(' ');
    }
    return 0;
}



Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int a, b, c, d;

	cin >> a >> b >> c >> d;

	cout << ((abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d)) ? "Yes" : "No") << endl;

	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)

bool init() {
}

string s;

#define INF 1000000000

pair<int, bool> dfs(int& pos) {
	if (pos == (int) s.length()) return make_pair(INF, false);
	if (s[pos] == '[') {
		vector<pair<int, bool>> t;
		while (pos < (int) s.length()) {
			if (s[pos] == ']') break;
			assert(s[pos] == '[');
			pos++;
			t.push_back(dfs(pos));
			assert(s[pos] == ']');
			pos++;
		}
		sort(t.begin(), t.end());
		int res = 0;
		rep(i, t.size() / 2 + 1) {
//			cout << "A " << t[i] << endl;
			if (t[i].second) res += t[i].first / 2 + 1;
			else res += t[i].first;
		}
		return make_pair(res, false);
	}
	int res = 0;
	assert('0' <= s[pos] && s[pos] <= '9');
	while ('0' <= s[pos] && s[pos] <= '9') {
		res = res * 10 + s[pos] - '0';
		pos++;
	}
	return make_pair(res, true);
}

void solve() {
	cin >> s;
	int p = 0;
	cout << dfs(p).first << endl;
}

int main() {
	int n;
	cin >> n;
	rep(i, n) {
		solve();
	}
}


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

int main()
{
 int r,d,x;
  cin>>r>>d>>x;
  int j=10;
  while(j--)
  {
    x = r*x - d;
    cout<<x<<"\n";
  }
  
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int cnt[100][26];
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	string s[n];
	for(int i=0;i<n;i++)cin>>s[i];
	
	for(int i=0;i<n;i++){
		
		for(int j=0;j<s[i].length();j++){
			cnt[i][s[i][j]-'a']++;
		}
	}
	
	for(int i=0;i<26;i++){
		int co=100;
		for(int j=0;j<n;j++){
			co=min(co,cnt[j][i]);
		}
		char p ='a'+i;
		for(int j=0;j<co;j++)cout<<p;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,a,b,ans=1,k;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		a=ans;
		if(a>k)a=k;
		ans+=a;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;
string s;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>s;
	int x=0,ans=0;
	for(int i=s.size()-1;i>=0;i--){
		int ch=s[i]-'0'+x;
		if(ch==10)x=1;
		else if(ch>5||i!=0&&ch==5&&s[i-1]-'0'>=5)ans+=10-ch,x=1;
		else ans+=ch,x=0;
	}
	ans+=x;
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 1948
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
a.sort()
parent = [a[-1]]
rest = a[:-1]

for _ in range(n):
    next_parent = []
    next_rest = []
    for i in parent[::-1]:
        while(rest):
            x = rest.pop()
            if x < i:
                next_parent.append(x)
                break
            else:
                next_rest.append(x)
                continue
    parent += next_parent
    parent.sort()
    next_rest.reverse()
    rest += next_rest

if len(parent) == 2**n:
    print("Yes")
else:
    print("No") 


Measured memory_bytes: 33968
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
int main(){
    int n;
    SCD(n);
    vector<int> v1;
    vector<int> v2;

    REP(i,n/2){
        int x,y;
        cin >> x >> y;
        v1.PB(x); v2.PB(y);
    }

    sort(ALL(v1));
    sort(ALL(v2));

    vector<PII> U1;	
    int count = 1;
    REP(i,v1.size()-1){
        if (v1[i] == v1[i+1]){
            count++;
        }else{
            U1.PB(MP(count,v1[i]));
            count = 1;
        }
    }
    U1.PB(MP(count,v1[v1.size()-1]));

    vector<PII> U2;	
    count = 1;
    REP(i,v2.size()-1){
        if (v2[i] == v2[i+1]){
            count++;
        }else{
            U2.PB(MP(count,v2[i]));
            count = 1;
        }
    }
    U2.PB(MP(count,v2[v2.size()-1]));

    sort(ALL(U1)); reverse(ALL(U1));
    sort(ALL(U2)); reverse(ALL(U2));
    int ans = 0;

    if (U1[0].snd != U2[0].snd){
        ans = n - U1[0].fst - U2[0].fst;
    }else{
        if ((U2.size() != 1) and (U1.size() != 1)){
            ans = min(n - U1[0].fst - U2[1].fst,n-U1[1].fst -U2[0].fst);
        }else if ((U2.size() == 1) and (U1.size() == 1)){
            ans = n/2;
        }else if (U1.size () == 1){
            ans = n/2 - U2[1].fst;
        }else if (U2.size () == 1){
             ans = n/2 - U1[1].fst;
        }else{
            
        }

    }   
    cout << ans << endl;   
}


Measured memory_bytes: 1784
#include<bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//ruogu_alter
const int N=105;
int n,m,s,t,a[N][N],dis[N<<1],iter[N<<1],px[N*N],py[N*N],res[N][N];
queue<int>qu;
vector<int>v[N][N];
struct edge{
	int to,val,rev;
};
vector<edge>g[N<<1];
//
inline void addedge(int x,int y,int val){
	g[x].push_back((edge){y,val,g[y].size()});
	g[y].push_back((edge){x,0,g[x].size()-1});
}
bool bfs(){
	memset(dis,-1,sizeof(dis));
	dis[s]=0;qu.push(s);
	while(!qu.empty()){
		int u=qu.front();qu.pop();
		rep(i,g[u].size()){
			edge &e=g[u][i];
			if(e.val&&dis[e.to]==-1){
				dis[e.to]=dis[u]+1;
				qu.push(e.to);
			}
		}
	}
	return dis[t]>=0;
}
int dfs(int x,int val){
	if(x==t)return val;
	while(iter[x]<g[x].size()){
		edge &e=g[x][iter[x]];
		if(dis[e.to]>dis[x]&&e.val){
			int ans=dfs(e.to,min(val,e.val));
			if(ans){
				e.val-=ans;
				g[e.to][e.rev].val+=ans;
				return ans;
			}
		}
		iter[x]++;
	}
	return 0;
}
int dinic(){
	int ans=0;
	while(bfs()){
		int f;
		memset(iter,0,sizeof(iter));
		while(f=dfs(s,INF))ans+=f;
	}
	return ans;
}
void P(){
	rep(i,n*m)res[px[i]][py[i]]=i;
	rep(i,n){
		rep(j,m)printf("%d ",res[i][j]+1);
		printf("\n");
	}
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=getint();m=getint();s=2*n;t=s+1;
	rep(i,n)rep(j,m){
		a[i][j]=getint()-1;
		v[i][a[i][j]/m].push_back(a[i][j]);
	}
	memset(px,-1,sizeof(px));
	memset(py,-1,sizeof(py));
	rep(x,m){
		rep(i,2*n+2)g[i].clear();
		rep(i,n)rep(j,n)if(v[i][j].size())addedge(i,j+n,1);
		rep(i,n)addedge(s,i,1),addedge(i+n,t,1);
		assert(dinic()==n);
		rep(i,n)rep(j,g[i].size())if(!g[i][j].val){
			int y=g[i][j].to-n,id=v[i][y].back();
			v[i][y].pop_back();
			px[id]=i;py[id]=x;
		}
	}
	P();
	rep(i,n*m)px[i]=i/m;
	P();
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n, K;
    scanf("%d%d", &n, &K);
    lint a[n];
    rep(i, n) scanf("%lld", &a[i]);
    sort(a, a+n, greater<>());
    lint ans=0;
    rep(i, n){
        if(K > 0) --K;
        else{
            ans+=a[i];
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 1792
N = int(input())
B = []
i = 0
if N == 0:
    print(0)
    exit()
while N != 0:
    if N % (2**(i+1)) != 0:
        B.insert(0,1)
        N -= (-2)**i
    else:
        B.insert(0,0)
    #print(B)
    #print(N)
    i += 1
print(''.join(map(str, B)))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	int resalt = 0;
      
        Scanner scan = new Scanner(System.in);

        int A = scan.nextInt();
        int B = scan.nextInt();

        B = B * 2;
        if ( 1 < A ) {
        	if ( A > B ) {
        		resalt = A - B;
        	}
        	else if(A < B){
        		resalt = 0;
        	}
        }
            System.out.println(resalt);
    }
}


Measured memory_bytes: 22608
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
A = readInts()
import math
print(1 if len(A) <= k else 1 + math.ceil((n-k)/(k-1)))


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

const int MAX = 3e5 + 5;
const int MOD = 1e9 + 7;
const int INV = 500000004;
int n, ans, pw[MAX], sz[MAX];
vector <int> g[MAX];

void dfs(int u, int p = -1) {
	int value = (1 - pw[n - 1] + MOD) % MOD;

	for(int v : g[u]) {
		if(v != p) {
			dfs(v, u);
			sz[u] += sz[v];

			int pk = (1 - pw[sz[v]] + MOD) % MOD;
			pk = 1LL * pk * pw[n - 1 - sz[v]] % MOD;
			value = (value - pk + MOD) % MOD;
		}
	}

	sz[u]++;

	int up = n - sz[u];
	
	int pk = (1 - pw[up] + MOD) % MOD;
	pk = 1LL * pk * pw[n - 1 - up] % MOD;
	value = (value - pk + MOD) % MOD;

	value = 1LL * value * INV % MOD;
	ans = (ans + value) % MOD;
}

int main() {
	scanf("%d", &n);

	pw[0] = 1;
	for(int i = 1; i <= n; i++)
		pw[i] = 1LL * pw[i - 1] * INV % MOD;

	for(int i = 1; i < n; i++) {
		int a, b; scanf("%d%d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}

	dfs(1);

	printf("%d\n", ans);
	return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit();
  int N, P;
  cin >> N >> P;
  vector<int> A(N);
  int cnt_odd = 0, cnt_even = 0;
  REP(i, N){
    cin >> A[i];
    if(A[i] % 2){
      cnt_odd++;
    }
    else{
      cnt_even++;
    }
  }
  ll even = 1, odd = 0;
  REP(i, cnt_even){
    even *=2;
  }
  if(cnt_odd == 0){
    if(P==0){
      cout << even << endl;
    }
    else{
      cout << 0 << endl;
    }
    return 0;
  }
  if(P == 0){
    for(int i = 0; i < cnt_odd+1; i+=2){
      odd += COM(cnt_odd, i);
    }
  }
  else{
    for(int i = 1; i < cnt_odd+1; i+=2){
      odd += COM(cnt_odd, i);
    }
  }
  cout << odd*even << endl;

  return 0; 
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define getMat(x, n, m, val) vector<vector<ll>> x(n, vector<ll> (m, val))
#define setp fixed<<setprecision // use it as cout<<setp(number of fractional digits in x)<<x;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll M=1000000000+7;
 
ll power(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

ll dp[1005][1005];
ll n;

string fun(string s,ll sub=0){
    if(s.length()==0)return "";
    // if(s.length()==1){
    //     for(ll i=0;i<s[0]-'0'-sub;i++)s="("+s;
    //     for(ll i=0;i<s[0]-'0'-sub;i++)s=s+")";
    //     return s;
    // }
    ll mn=INT_MAX,mnind=-1;
    vector<ll>indv;
    for(ll i=0;i<s.length();i++){
        if(s[i]<mn){
            mn=s[i];
            mnind=i;
        }
    }
    for(ll i=0;i<s.length();i++){
        if(s[i]==mn){
            indv.pb(i);
        }
    }
    string ts="";
    if(indv[0]>0)ts+=fun(s.substr(0,indv[0]),mn-'0');
    for(ll i=0;i<indv.size()-1;i++){
        ts+=(mn);
        ts+=fun(s.substr(indv[i]+1,indv[i+1]-1-indv[i]),mn-'0');
    }
    ts+=(mn);
    if(indv[indv.size()-1]<s.length()-1)ts+=fun(s.substr(indv[indv.size()-1]+1,s.length()-indv[indv.size()-1]-1),mn-'0');
    for(ll i=0;i<mn-'0'-sub;i++)ts="("+ts;
    for(ll i=0;i<mn-'0'-sub;i++)ts=ts+")";
    return ts;
}


int main(){
    fastio;
    ll t=1,cno=0;
    // ll mod=998244353 ;
    // cin>>t;
    while(t--){
        ll x,y,z;
        cin>>x>>y>>z;
        cout<<z<<" "<<x<<" "<<y<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	i64 c;
	cin >> n >> c;
	vector<i64> x(n), v(n);
	rep(i, 0, n) {
		cin >> x[i] >> v[i];
	}

	i64 ans = 0;
	{
		i64 sum = 0;
		rep(i, 0, n) {
			sum += v[i];
			ans = max(ans, sum - x[i]);
		}
	}
	{
		i64 sum = 0;
		for (int i = n - 1; i >= 0; i--) {
			sum += v[i];
			ans = max(ans, sum - (c - x[i]));
		}
	}
	
	{
		vector<i64> left(n), right(n);
		i64 sum = 0;
		rep(i, 0, n) {
			sum += v[i];
			left[i] = sum - x[i] * 2;
		}
		sum = 0;
		for (int i = n - 1; i >= 0; i--) {
			sum += v[i];
			right[i] = sum - (c - x[i]);
		}
		
		rep(i, 1, n) {
			left[i] = max(left[i - 1], left[i]);
		}
		for (int i = n - 2; i >= 0; i--) {
			right[i] = max(right[i + 1], right[i]);
		}
		rep(i, 0, n - 1) {
			ans = max(ans, left[i] + right[i + 1]);
		}
	}

	{
		vector<i64> left(n), right(n);
		i64 sum = 0;
		rep(i, 0, n) {
			sum += v[i];
			left[i] = sum - x[i];
		}
		sum = 0;
		for (int i = n - 1; i >= 0; i--) {
			sum += v[i];
			right[i] = sum - (c - x[i]) * 2;
		}

		rep(i, 1, n) {
			left[i] = max(left[i - 1], left[i]);
		}
		for (int i = n - 2; i >= 0; i--) {
			right[i] = max(right[i + 1], right[i]);
		}
		rep(i, 0, n - 1) {
			ans = max(ans, left[i] + right[i + 1]);
		}
	}

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

Measured memory_bytes: 3424
//#include "stdc++.h"
#include <bits/stdc++.h>
#include<iostream>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
//#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD =1000000007 ;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
#define pi 3.141592653589793238462
#define int  long long
int dp[200001];int C[200001],h[200001],m[200001];
ldb findinter(int m1,int c1,int m2,int c2)
{
    ldb xin;
    xin=c2-c1;
    xin=(ldb)(xin)/(m1-m2);
    return xin;
}
int32_t main()
{
    
    IOS;
    int n,c;map<ldb,int>s;
    map<ldb,int>::iterator it;
    cin>>n>>c;
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    dp[0]=0;
    C[0]=-h[0]*h[0];
    m[0]=2*h[0];
    s.insert(m1(-INF,0));int k;ldb xin;stack<pair<pair<int,int> ,ldb> >st;
    pair<pair<int,int>,ldb>pr;
    st.push(m1(m1(m[0],C[0]),-INF));
    for(int i=1;i<n;i++)
    {
        it=s.upper_bound((ldb)h[i]);
        it--;
        k=it->second;
        //cout<<k<<endl;
        dp[i]=dp[k]+h[i]*h[i]+c+h[k]*h[k]-2*h[i]*h[k];
        C[i]=-(dp[i]+h[i]*h[i]);
        m[i]=2*h[i];
        if(st.empty()||st.size()==1)
        {
            if(st.size()==1)
            {
                pr=st.top();
                
                xin=findinter(pr.first.first,pr.first.second,m[i],C[i]);
            }
            else
                xin=-INF;
            st.push(m1(m1(m[i],C[i]),xin));
                    s.insert(m1(xin,i));
        }
                    else
                    {
                        pr=st.top();
                        while(st.size()>=1&&(findinter(pr.first.first,pr.first.second,m[i],C[i])<=(pr.second)))
                        {
                            st.pop();
                            s.erase(s.find(pr.second));
                            pr=st.top();
                        }
                        pr=st.top();
                        xin=findinter(pr.first.first,pr.first.second,m[i],C[i]);
                        st.push(m1(m1(m[i],C[i]),xin));
                        s.insert(m1(xin,i));
                    
                    }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}




Measured memory_bytes: 28672
a,b = map(int,input().split())
c = 0
s = []
t = []
x = 0
y = 0

for _ in range(a):
    x,y = map(int,input().split())
    s.append(x)
    t.append(y)

d = max(s)
t.sort()
t.reverse()

for i in(t):
    if d < i:
        b -= i
        c += 1
        if b <= 0:
            print(c)
            exit()
    elif d >= i:
        c += b//d
        if b%d != 0:
            c += 1
        print(c)
        exit()
    
c += b//d
if b%d != 0:
    c += 1
print(c)

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

string s;

long long solve();

int main() {
  cin >> s;

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0, cnt = 0;
  for(int i = 1; i < s.size(); ++i) {
    if(s[i] == 'C' && s[i - 1] == 'B') {
      ans += cnt;
      ++i;
    }
    else if(s[i - 1] == 'A')
      ++cnt;
    else
      cnt = 0;
  }
  return ans;
}

Measured memory_bytes: 640
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int dist[1000][1000];
string s[1000];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

bool is_inside(int y, int x, int h, int w) { return 0 <= y && 0 <= x && y < h && x < w; }


int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int h, w;
  cin >> h >> w;
  for(int i = 0; i < h; i++) cin >> s[i];
  queue<pair<int, int>> q;
  for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) if(s[i][j] == '#') q.emplace(i, j);
  int ans = 0;
  while(q.size()) {
    int i, j;
    tie(i, j) = q.front();
    q.pop();
    for(int d = 0; d < 4; d++) {
      int ni = i + dx[d];
      int nj = j + dy[d];
      if(!is_inside(ni, nj, h, w)) continue;
      if(s[ni][nj] != '.') continue;
      s[ni][nj] = '#';
      dist[ni][nj] = ans = dist[i][j] + 1;
      q.emplace(ni, nj);
    }
  }

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


Measured memory_bytes: 10112
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    char str[5]={0};
    scanf("%s", str);

    if(str[0]==str[1]||str[1]==str[2]||str[2]==str[3]) {
        printf("Bad\n");
    }
    else {
        printf("Good\n");
    }


    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

struct data {
  int x, y;
  data(int x_, int y_) : x(x_), y(y_) {}
};

int main() {
  int N;
  cin >> N;
  vector<data> A, B;
  rep(i, 2*N) {
    int x, y;
    cin >> x >> y;
    if(i < N)
      A.push_back(data(x, y));
    else
      B.push_back(data(x, y));
  }
  sort(B.begin(), B.end(), [](data d1, data d2) {return d1.x < d2.x;});
  vector<bool> match(N);
  int cnt = 0;
  rep(i, N) {
    int tmp = -1;
    int tmpY = -1;
    rep(j, N) {
      if(!match[j] && A[j].x < B[i].x && A[j].y < B[i].y && tmpY < A[j].y)
        tmpY = A[j].y, tmp = j;
    }
    if(tmp != -1)
      match[tmp] = true, cnt++;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 256
l,r=map(int, input().split())
List=[]
for i in range(l, min(r+1, l+2019*2+1)):
    List.append(i%2019)
List=sorted(List)
if len(List)<2019:
    ans=2018
    for i in range(len(List)):
        for j in range(i, len(List)):
            if i==j:
                continue
            ans=min(ans, List[i]*List[j]%2019)
    print(ans)
else:
    print((List[0]*List[1])%2019)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=305,INF=1<<30;

int dis[MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A,B;cin>>A>>B;
    int N=16*16+1;
    int M=15*17+16*16;
    
    vector<pair<int,int>> ans;
    
    for(int i=0;i<256;i+=16){
        for(int j=0;j<15;j++){
            ans.push_back(mp(i+j,i+j+1));
        }
    }
    
    for(int i=0;i+16<256;i+=16) ans.push_back(mp(i,i+16));
    
    for(int i=0;i<256;i++) ans.push_back(mp(i,256));
    
    vector<vector<int>> S(A+1,vector<int>(B+1));
    
    for(int i=1;i<=A;i++){
        for(int j=1;j<=B;j++){
            cin>>S[i][j];
            
            for(int a=0;a<16;a++){
                for(int b=0;b<16;b++){
                    int sum=a*i+b*j;
                    chmax(dis[16*b+a][256],S[i][j]-sum);
                }
            }
        }
    }
    
    bool ok=true;
    
    for(int i=1;i<=A;i++){
        for(int j=1;j<=B;j++){
            int mini=INF;
            
            for(int a=0;a<16;a++){
                for(int b=0;b<16;b++){
                    chmin(mini,a*i+b*j+dis[16*b+a][256]);
                }
            }
            
            if(mini!=S[i][j]) ok=false;
        }
    }
    
    if(ok){
        cout<<"Possible\n";
        cout<<N<<" "<<M<<endl;
        for(int i=0;i<M;i++){
            cout<<ans[i].fi+1<<" "<<ans[i].se+1<<" ";
            if(ans[i].se==256) cout<<dis[ans[i].fi][256]<<"\n";
            else if(ans[i].se-ans[i].fi==1) cout<<"X\n";
            else if(ans[i].se-ans[i].fi==16) cout<<"Y\n";
        }
        cout<<1<<" "<<257<<endl;
    }else if(A==1){
        ok=true;
        for(int j=2;j<=B;j++){
            if(S[1][1]*j!=S[1][j]) ok=false;
        }
        if(ok){
            cout<<"Possible\n";
            cout<<S[1][1]+1<<" "<<S[1][1]<<endl;
            for(int i=1;i<=S[1][1];i++){
                cout<<i<<" "<<i+1<<" "<<"Y\n";
            }
            cout<<1<<" "<<S[1][1]+1<<"\n";
        }else{
            cout<<"Impossible\n";
        }
    }else if(B==1){
        ok=true;
        for(int j=2;j<=A;j++){
            if(S[1][1]*j!=S[j][1]) ok=false;
        }
        if(ok){
            cout<<"Possible\n";
            cout<<S[1][1]+1<<" "<<S[1][1]<<endl;
            for(int i=1;i<=S[1][1];i++){
                cout<<i<<" "<<i+1<<" "<<"X\n";
            }
            cout<<1<<" "<<S[1][1]+1<<"\n";
        }else{
            cout<<"Impossible\n";
        }
    }else{
        cout<<"Impossible\n";
    }
    
}


Measured memory_bytes: 640
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>


#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr,__VA_ARGS__)

using namespace std;

inline char nc(){ return getchar();static char buf[100000] , *p1,*p2; return p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,100000,stdin),p1 == p2) ? EOF: *p1++;}
template<class T>inline void rd(T & x){ x = 0;char ch = nc();for(;!isdigit(ch);ch = nc()); for(;isdigit(ch);ch = nc()) x = x * 10 - 48 + ch;}

typedef long long ll;

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

int a[maxn],  inv[maxn];
void getinv(){
	inv[0] = inv[1] = 1;
	for(int i = 2;i < maxn;i++){
		inv[i] = mod - (ll)inv[mod % i] * (mod / i) % mod;
	}
}
int main(){
	int n;
	rd(n);
	for(int i = 1;i <= n;i++){ rd(a[i]); }
	getinv();
	int sum = 0,ans = 0;
	for(int i = 1;i <= n;i++) sum = (sum + inv[i]) % mod;
	for(int i = 1;i <= n;i++){
		ans = (ans + (ll)a[i] * sum % mod) % mod;
		sum = ((ll)sum - inv[n - i + 1] + mod) % mod;
		sum = (sum + inv[i + 1]) % mod;
	}
	for(int i = 2;i <= n;i++){
		ans = 1ll * ans * i % mod;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main() {
	int n; cin >>n;
	vector<int> v(100007);
	rep(i,n){
		int a; cin >> a;
		v[a]++;
	}
	int M = 0;
	for(int i = 2; i < v.size(); i++){
		M = max(M,v[i]+v[i-1]+v[i-2]);
	}
	cout << M << endl;
}

Measured memory_bytes: 640
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
N, L = tuple(li())
total = N * (L + N + L - 1) // 2
delta = 1 - L
if delta < 1:
    print(total - L)
elif delta > N:
    print(total - (L - 1 + N))
else:
    print(total)


Measured memory_bytes: 3060
import sys
H=int(input())
numlist = []
i = 1
if H == 1:
    print('1')
    sys.exit()

while True:
    tmp = 2**i
    numlist.append(tmp)
    i += 1
    if tmp >= 1000000000000:
        break

for i in range(1,len(numlist)):
    if H < numlist[i]:
        print(numlist[i-1]*2-1)
        sys.exit()

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

int n;
int a[200100];
int b[200100];

int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d%d",&a[i],&b[i]);}
  qsort(a,n,sizeof(int),compare_int);
  qsort(b,n,sizeof(int),compare_int);
  if(n%2==0){
    printf("%d\n",b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1);}
  else{
    printf("%d\n",b[n/2]-a[n/2]+1);}
  
  
  return 0;
}


Measured memory_bytes: 4080
#define _GLIBCXX_DEBUG
#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++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)

int main(){
  string S;
  cin >> S;
  S.at(3) = '8';
  cout << S << endl;
}

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

int main(){

int n;
cin >> n;

vector<int> a(n);

  
for(int i=0; i<n;++i){    
    cin >> a.at(i);
}

int m=0;

for(int i=0; i<n;++i){    
    if(a[i]%2==1&&(i+1)%2==1){
        ++m;
    }
}


cout << m;



return 0;

    
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

struct uf {
private:
	vector<int> par, ran;
public:
	uf(int n) {
		par.resize(n, 0);
		ran.resize(n, 0);
		rep(i, n)par[i] = i;
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return;
		if (ran[x] < ran[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (ran[x] == ran[y])ran[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};
map<P, int> mp;
void solve() {
	int h, w; cin >> h >> w;
	int n; cin >> n;
	vector<P> v(n);
	rep(i, n) {
		cin >> v[i].first >> v[i].second;
		mp[v[i]] = i + 1;
	}
	uf u(n + 2);
	int le = n, ri = n + 1;
	rep(i, n) {
		if (v[i].first == h - 1 || v[i].second == 0) {
			u.unite(le, i);
		}
		if (v[i].first == 0 || v[i].second == w - 1) {
			u.unite(i, ri);
		}
		for (int j = -1; j <= 1; j++) {
			for (int k = -1; k <= 1; k++) {
				int nx = j + v[i].first, ny = k + v[i].second;
				int z = mp[{nx, ny}];
				if (z > 0) {
					z--;
					u.unite(i, z);
				}
			}
		}
	}
	if (u.same(le, ri)) {
		cout << 0 << endl; return;
	}
	rep(i, n) {
		if (u.same(le, i)) {
			if (v[i].first == 1 || v[i].second == w - 2) {
				cout << 1 << endl; return;
			}
			for (int j = -2; j <= 2; j++) {
				for (int k = -2; k <= 2; k++) {
					int nx = j + v[i].first, ny = k + v[i].second;
					int z = mp[{nx, ny}];
					if (z > 0) {
						z--;
						if (u.same(z, ri)) {
							cout << 1 << endl; return;
						}
					}
				}
			}
		}
		else if (u.same(i, ri)) {
			if (v[i].first == h - 2 || v[i].second == 1) {
				cout << 1 << endl; return;
			}
			for (int j = -2; j <= 2; j++) {
				for (int k = -2; k <= 2; k++) {
					int nx = j + v[i].first, ny = k + v[i].second;
					int z = mp[{nx, ny}];
					if (z > 0) {
						z--;
						if (u.same(z, le)) {
							cout << 1 << endl; return;
						}
					}
				}
			}
		}
	}
	cout << 2 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
		return 0;
}


Measured memory_bytes: 60556
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
const int UNIMAX = 200002;
int uni[UNIMAX] = {}; //parent -- size of member , kid -- leader name,def -1

int uniroot(int a){ //return a's leader
	if (uni[a] < 0) return a;
	return uni[a] = uniroot(uni[a]); //uni[a] => 0 , reconnect root directly
}

bool uniconnect(int a,int b){
	a = uniroot(a);
	b = uniroot(b);
	
	if(a==b) return false;
	
	if(uni[a] > uni[b]){
		a ^= b;
		b ^= a;
		a ^= b;
	}
	
	uni[a] = uni[a] + uni[b]; // membersize++
	uni[b] = a;
	return true;
}

bool uniisConnect(int a,int b){
	return (uniroot(a) == uniroot(b));
}

int unisize (int a){
	return (-uni[uniroot(a)]);
}
	
int main(){
	REP(i,UNIMAX){
		uni[i] = -1;
	}
	
	int N,K,L;
	SCD(N); SCD(K); SCD(L);
	static int a[UNIMAX];
	static int b[UNIMAX];
	
	REP(i,K){
	    int p,q;
	    SCD2(p,q);
	    uniconnect(p,q);
	}
	
	FORq(i,1,N){
	    if (uni[i] < 0) {
	        a[i] = i;
	    }else{
	        a[i] = uniroot(i);
	    }
	}
	
	REP(i,UNIMAX){
		uni[i] = -1;
	}
	
    REP(i,L){
        int p,q;
        SCD2(p,q);
        uniconnect(p,q);
    }

	FORq(i,1,N){
	    if (uni[i] < 0) {
	        b[i] = i;
	    }else{
	        b[i] = uniroot(i);
	    }
	}
	
	map< pair<int,int>,set<int> > f;
	
	FORq(i,1,N){
	    pair<int,int> P = make_pair(a[i],b[i]);
	    f[P].insert(i);
	}
    
    FORq(i,1,N){
        int x;
        pair<int,int> P = make_pair(a[i],b[i]);
        x = f[P].size();
        if (i != N) printf("%d ",x);
        else printf("%d\n",x);
    }



}



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

int main() {
  
  int n;
  scanf("%d", &n);

  vector<int> a(n + 1);
  a[0] = 0;

  for(int i = 1; i < n + 1; i++){
    scanf("%d", &a[i]);
  }

  int now;
  now = 1;

  int count;
  count = 1;

  while(a[now] != 2){
    now = a[now];
    count++;

    if(count > n){
      cout << -1 << endl;
      exit(0);
    }
  } 

  cout << count << endl;
}



Measured memory_bytes: 640
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N;cin>>N;
    vector<ll> a(N+1);
    REPS(i,N)cin>>a[i];
    vector<bool> pushed(N+1,false);

    ll idx=1;ll cnt=0;
    while(1){
        if(idx==2){
            cout<<cnt<<"\n";
            exit(0);
        }
        if(pushed[idx]){
            cout<<"-1\n";
            exit(0);
        }
        pushed[idx]=true;
        idx=a[idx];
        cnt++;
    }
}

Measured memory_bytes: 1024