akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.ArrayList;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
      	int N = sc.nextInt();
      
      List <Integer> a = new ArrayList <Integer>();//リストでaを格納する
      
      for(int i=0; i<N; i++){
          a.add(sc.nextInt());//リストにaを入力していく,aはXに含まれない整数
      }
      
      for(int i=0; i<100; i++){//N(0~100)をまわす
      if(!a.contains(X-i)){//aに含まれないX-iの整数
         System.out.println(X-i);//Xに近い前の整数
         break;
      }
      else if(!a.contains(X+i)){
              System.out.println(X+i);//Xに近い後ろの整数
              break;
      }
      }
    }
}

Measured memory_bytes: 36176
use std::cmp::*;
use std::io::Read;
use std::iter::Scan;

fn cost(a: &[i64], bits: u32) -> Option<i64> {
    let mut cur_height = 0;
    let mut cost = 0;
    for (i, &height) in a.iter().enumerate() {
        if (bits >> i) & 1 != 0 {
            let expected_height = max(cur_height + 1, height);
            cur_height = expected_height;
            cost += expected_height - height;
        } else if height > cur_height {
            return None;
        }
    }
    Some(cost)
}

fn solve(n: usize, k: usize, a: Vec<i64>) -> i64 {
    (0u32..(1 << n))
        .filter(|&bits| bits.count_ones() >= (k as u32))
        .filter_map(|bits| cost(&a, bits))
        .min()
        .unwrap()
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();
    let a = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect();
    let r = solve(n, k, a);
    println!("{}", r);
}


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

using namespace std;

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

    vector<double> v(n);
    for(int i=0; i<n; i++){
        cin >> v[i];
    }

    while(v.size()!=1){
        sort(v.begin(),v.end());
        v.push_back((v[0] + v[1])/2.0);
        v.erase(v.begin()+0);
        v.erase(v.begin()+0);
        n--;
    }


    cout << setprecision(16) << v[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// for (int i = 0, i < N, i++) {
// strint'', char'
// エスケープシークエンス改行になる\n　cout << "こんにちは\nAtCoder";
// 行全て取り出す　getline(cin, 文字列変数);
// int型 data[要素数]; // Cの配列
// 逆順に並び替え　reverse(配列変数.begin(), 配列変数.end());
// 小さい順に並び替え　sort(配列変数.begin(), 配列変数.end());
// 関数定義　返り値の型 関数名(引数1の型 引数1の名前, 引数2の型 引数2の名前, ...) {
// 関数定義はmain関数の前で行うこと, 返り値はreturn
// 範囲for文_配列(stringもおk)の要素を全て取り出す　for (配列の要素の型 変数名 : 配列変数) {
// =========配列===========
// 配列　vector<型> vec(要素数, 初期値);　　vec.at(i)　　vec.size()
// 2次元配列　vector<vector<要素の型>> 変数名(要素数1(行数), vector<要素の型>(要素数2(列数), 初期値));
// 2次元配列　変数名.at(添字1_行).at(添字2_列)
// ジャグ配列(行ごとに要素数が異なる)も可能
// 3次元配列　vector<vector<vector<要素の型>>> 変数名(要素数1, vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));
// 配列の末尾に追加　配列名.push_back(要素)
// 参照はむずい2-4をよく読むこと　参照先の型 &参照の名前 = 参照先;
// 参照渡しは高速化に重要
// 後再帰もむずい
// int64_t 末尾にLLをつけるとint64_tとして扱われる
// double型の出力　cout << fixed << setprecision(桁数);
// キャスト(型変換)　(double)a　aをdouble型に
// ========printfでの出力========
// printf("x = %d, pi = %lf\n", x, pi);
// 出力 x = 12345, pi = 3.141593
// フォーマット指定子 int %d　int64_t %ld　double %lf　char %c
// string型出力　printf("%s\n", s.c_str());
// ========scanfでの入力=======
// scanf("x = %d, pi = %lf", &x, &pi);
// 入力 x = 12345, pi = 3.141593
// 数値から文字列 to_string(変数名)
// 文字列から, int stoi(変数名)　int64_t stoll(変数名)　double stod(変数名)
// ========pair===============
// 宣言と初期化 pair<型1, 型2> 変数名(値1, 値2);
// アクセス 変数名.first   // 1つ目の値　変数名.second  // 2つ目の値
// pairの生成 make_pair(値1, 値2)
// pairの分解(以下3行)
// 型1 変数1;
// 型2 変数2;
// tie(変数1, 変数2) = pair型の値;
// =========tuple==============
// pairは値が2つに対して, tupleは値が3つ以上
// アクセス get<K>(tuple型の変数)  // K(定数)番目にアクセス
// 他はpairと同様
// pairとtupleの比較はまず一番目が最優先され, 等しい場合は2番目以降となる. sortなども同様
// autoとignoreは省略
// =========型エイリアス========
// using pii = pair<int, int>;
// これ以降 pii という型名はpair<int, int> と同じ意味で使える
// using vi = vector<int>; // intの1次元の型に vi という別名をつける
// using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
// int N = 10, M = 20;
// vvi data(N, vi(M));  // N * M の2次元配列
// typedefも同様に使える







int main() {
  int n;
  cin >> n;
  vector<tuple<string, int, int>> vec(n);
  for (int i = 0; i < n; i++) {
    string s;
    int p;
    cin >> s >> p;
    vec.at(i) = make_tuple(s, 100-p, i+1);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < n; i++) {
    cout << get<2>(vec.at(i)) << endl;
  }
    
}



Measured memory_bytes: 3620
import java.util.*;

class Main {

	static boolean touched[][] = new boolean[55][55];
	static char board[][] = new char[55][55];
	static int owner[][] = new int[55][55];
	static int w, h;
	static int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		for(;;){
			w = in.nextInt();
			h = in.nextInt();
			if(w==0 && h==0) break;
			for(int i=0; i<55; i++)for(int j=0; j<55; j++){
				board[i][j] = '@';
				owner[i][j] = 0;
			}
			for(int i=0; i<h; i++){
				String str = in.next();
				for(int j=0; j<w; j++){
					board[i][j] = str.charAt(j);
				}
			}
			for(int i=0; i<h; i++){
				for(int j=0; j<w; j++){
					if(board[i][j] != '.'){
						for(int ii=0; ii<h; ii++)for(int jj=0;jj<w;jj++) touched[ii][jj] = false;
						for(int k=0; k<4; k++)dfs(j+dx[k], i+dy[k], board[i][j]);
					}
				}
			}
			int black = 0, white = 0;
			for(int i=0; i<h; i++)
				for(int j=0; j<w; j++)
					if(owner[i][j]==1) black++;
					else if(owner[i][j]==2) white++;
			
			System.out.println(black + " " + white);
		}
	}
	
	static void dfs(int x, int y, char c){
		if(x<0 || w<=x || y<0 || h<=y) return ;
		touched[y][x] = true;
		if(board[y][x]=='.'){
			owner[y][x] |= (c=='B')?1:2;
			for(int i=0; i<4; i++){
				if(!(x+dx[i]<0 || w<=x+dx[i] || y+dy[i]<0 || h<=y+dy[i]) && !touched[y+dy[i]][x+dx[i]]){
					dfs(x+dx[i], y+dy[i], c);
				}
			}
		}
		return ;
	}

}

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

int main(){
    int h, w; cin >> h >> w;
    vector<string> lis(h);
    REP(i, 0, h){cin >> lis[i];}
    REP(i, 0, h){
        int f = 1;
        REP(l, 0, w){
            if(lis[i][l] != '.'){
                //cout << i << l << endl;
                f = 0;
                break;
            }
        }
        if(f == 1){
            REP(l, 0, w){
                lis[i][l] = 'A';
            }
        }
    }
    REP(i, 0, w){
        int f = 1;
        REP(l, 0, h){
            if(lis[l][i] == '#'){
                //cout << i << l << endl;
                f = 0;
                break;
            }
        }
        if(f == 1){
            REP(l, 0, h){
                lis[l][i] = 'A';
            }
        }
    }
    REP(i, 0, h){
        int f = 0;
        REP(l, 0, w){
            if(lis[i][l] == 'A'){
                continue;
            }else{
                f = 1;
                cout << lis[i][l];
            }
        }
        if(f == 1)
            cout << endl;
    }
}

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

using namespace std;

typedef long long LL;

#define fin "\n"


#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

template <typename T>
inline void chmin(T &l,T r){l=min(l,r);}

template <typename T>
inline void chmax(T &l,T r){l=max(l,r);}

template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef vector<int> V;
typedef vector<V> VV;

int main(){
    int K,S;
    cin>>K>>S;
    int res=0;
    REP(X,K+1)
        REP(Y,K+1){
        int Z=S-X-Y;
        if(0<=Z&&Z<=K)res++;

    }
    cout<<res<<endl;
    return 0;
}


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

#define ll long long
#define ld long double
#define pi 3.14159265359

int main(){
    int N; cin >> N;
    vector<int> A(N);
    int M = 0, MM = 0;
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        if (A.at(i) >= M) {
            MM = M;
            M = A.at(i);
        }
        else if (A.at(i) >= MM) {
            MM = A.at(i);
        }
    }
    for (int i = 0; i < N; i++) {
        if (A.at(i) == M) {
            cout << MM << endl;
        }
        else {
            cout << M << endl;
        }
    }
}

Measured memory_bytes: 2432
#include <algorithm>
#include <climits>
#include <complex>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>

#include <stdio.h>

using ll = long long;
using namespace std;

ll to5(ll a) { return a * a * a * a * a; }

int main() {
    ios::sync_with_stdio(false);
    int k, s;
    ll ans = 0;
    cin >> k >> s;

    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            if (x + y <= s && x + y + k >= s)
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3072
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int a[10],b[10],x,y,i;
	for(i=0;i<10;i++) scanf("%d",&a[i]);
	sort(a,a+10,greater<int>());
	for(i=0;i<10;i++) scanf("%d",&b[i]);
	sort(b,b+10,greater<int>());
	x=a[0]+a[1]+a[2]; y=b[0]+b[1]+b[2];
	printf("%d %d\n",x,y);
	return 0;
}

Measured memory_bytes: 2724
while True:
    H,W=map(int,input().split())
    array='#.'
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            print(array*(int(W/2)) + array[0]*(W%2))
            array=array[1]+array[0]
    print('') 

Measured memory_bytes: 7648
#include <iostream>

using namespace std;
int n,m,b[30],a[30][30],c;
int main(){
	int i,j,ans = 0;
	cin >> n >> m >> c;
	for(i=0;i<m;i++){
		cin >> b[i];
	}
	for(i=0;i<n;i++){
		int k = c;
		for(j=0;j<m;j++){
			cin >> a[i][j];
			k += a[i][j]*b[j];
		}
		if(k>0) ans++;
	}
	cout << ans << endl;
}
	

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

int main() {
  int N; cin >> N;
  vector<int> a(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    for (int j = 1; j <= 13; j++) if (a[i] >= max(400 * (j - 1), 1) && a[i] < 400 * j) a[i] = j;
  }

  sort(a.begin(), a.end() - 1);

  int min_ans = 0, max_ans = 0;
  for (int i = 1; i <= N; i++) {
    if (a[i] != a[i - 1] && a[i] <= 8) min_ans++, max_ans++;
    else if (a[i] >= 9) max_ans++;
  }

  cout << min_ans << " " << max_ans << endl;

  return 0;
}

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

const int N = 1000009;
int n, a[N], prime[N], cnt[N], Exit;

void solve() {
	for (int i = 1; i <= n; ++ i) {
		if (!prime[a[i]]) {
			 if (a[i] != 1) ++ cnt[a[i]];
			if (cnt[a[i]] > 1) {
				Exit = 1;
				return ;
			}
		}
		else {
			for (int j = 1; j <= sqrt(a[i]); ++ j) {
				if (a[i] % j == 0) {
					if (j != 1) ++ cnt[j];
					if (cnt[j] > 1) {
						Exit = 1;
						return ;
					}
					if (j * j != a[i]) {
						if (a[i] / j != 1) ++ cnt[a[i] / j];
						if (cnt[a[i] / j] > 1) {
							Exit = 1;
							return ;
						}
					}
				}
			}
		}
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
	prime[1] = 1;
	for (int i = 2; i <= 1000000; ++ i) 
		if (!prime[i]) 
			for (int j = i + i; j <= 1000000; j += i) prime[j] = 1;
	solve();
	if (Exit == 0) {
		puts("pairwise coprime");
		return 0;
	}
	int x = __gcd(a[1], a[2]);
	if (x == 1) {
		puts("setwise coprime");
		return 0;
	}
	for (int i = 1; i < n - 1; ++ i) {
		x = __gcd(x, a[i + 2]);
		if (x == 1) {
			puts("setwise coprime");
			return 0;
		}
	}
	puts("not coprime");
	return 0;
}

Measured memory_bytes: 11712
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, m, a[100010];
int cum[100010];
int mi = 0, ma = INF;
int ans;
int cnt2;

signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cum[a[i]]++;
	}
	for (int i = 2; i <= 100000; i++)cum[i] += cum[i - 1];
	while (ma - mi > 1) {
		int md = (mi + ma) / 2;
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			cnt += cum[100000] - cum[min((int)100000, max((int)0, md - a[i] - 1))];
		}
		if (m <= cnt)mi = md;
		else ma = md;
	}
	for (int i = 0; i < n; i++) {
		int x = cum[100000] - cum[min((int)100000, max((int)0, mi - a[i] - 1))];
		ans += a[i] * x * 2;
		cnt2 += x;
	}
	ans -= mi * (cnt2 - m);
	cout << ans << endl;
}


Measured memory_bytes: 1792
#67 A - Multiple Array
N = int(input())
A, B = [],[]
for _ in range(N):
    a,b= map(int,input().split())
    A.append(a); B.append(b)
A = list(reversed(A))
B = list(reversed(B))

c = 0
for a,b in zip(A,B):
    # 前に押されたボタンの回数分足される
    a += c
    # ボタンを押さなくてもいい時
    if a%b == 0:
        continue
    # c 回ボタンを押せば Ai は Bi の倍数になる
    c += b-(a%b)
print(c)

Measured memory_bytes: 17676
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define For(I,N) for(int I=0;I<N;I++)
#define cinone(N) int N;cin>>N;
#define scanfone(N) int N;cin>>N;
#define cinng(N,M) int N[M];for(int yiuytvnm=0;yiuytvnm<M;yiuytvnm++) cin>>N[yiuytvnm];
#define scanfng(N,M) int N[M];for(int qrwuoiq=0;qrwuoiq<M;qrwuoiq++) scanf("%d",&N[qrwuoiq]);
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
int n;
int a[100005];
vector <int> even;
vector <int> odd;
int e[100005];
int o[100005];
vector <pii> c,d;

int main()
{	
//	freopen("input.txt","r",stdin);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
		if(i&1)
		{
//			cout<<i<<' '<<a[i]<<' ';
			odd.push_back(a[i]);
		}
		else
		{
			even.push_back(a[i]);
		}
	}
	for(int i=0;i<odd.size();i++)
	{
		o[odd[i]]++;
	}
	for(int i=0;i<even.size();i++)
	{
		e[even[i]]++;
	}
//	cout<<o[3]<<' '<<e[3]<<endl;
	for(int i=1;i<=100000;i++)
	{
		c.push_back(mp(o[i],i));
		d.push_back(mp(e[i],i));
	}
	sort(all(c));
	sort(all(d));
	reverse(all(c));
	reverse(all(d));
	if(c.size()==1 && d.size()==1)
	{
		cout<<(c[0].second==d[0].second);
	}
	else if(c.size()==1)
	{
		if(c[0].second==d[0].second)
		{
			cout<<n-c[0].first-d[1].first<<endl;
		}
		else
		{
			cout<<n-c[0].first-d[0].first;
		}
	}
	else if(d.size()==1)
	{
		if(c[0].second==d[0].second)
		{
			cout<<n-c[1].first-d[0].first<<endl;
		}
		else
		{
			cout<<n-c[0].first-d[0].first;
		}
	}
	else
	{
//		cout<<c[0].first<<'-'<<c[0].second<<' '<<d[0].first<<'-'<<d[0].second<<endl;
		if(c[0].second==d[0].second)
		{
			cout<<n-max(c[1].first+d[0].first,c[0].first+d[1].first)<<endl;
		}
		else
		{
			cout<<n-c[0].first-d[0].first;
		}
	}
	return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>

int n,a[20];

int solve(int i,int key){
  if(key==0){
    return 1;
  }
  if(i>=n){
  return 0;
  }
  int res=solve(i+1,key)||solve(i+1,key-a[i]);
  return res;
}

int main(void)
{
  int i,q,key;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(solve(0,key)){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }
  }
  return 0;

}

Measured memory_bytes: 1784
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int r, d, x2k;
    cin >> r >> d >> x2k;

    int x = x2k;
    for(int i = 0; i < 10; i++){
        x = r * x - d;
        cout << x << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int h, w;
  cin >> h >> w;
  int a[h][w], b[h][w];
  rep(i, h) {
    rep(j, w) {
      cin >> a[i][j];
    }
  }
  rep(i, h) {
    rep(j, w) {
      cin >> b[i][j];
    }
  }

  int d[h][w];
  rep(i, h) {
    rep(j, w) {
      d[i][j] = abs(a[i][j] - b[i][j]);
    }
  }

  int maxd = (h + w) * 82;
  bool dp[h][w][maxd];
  memset(dp, false, sizeof(dp));
  dp[0][0][d[0][0]] = true;

  rep(i, h) {
    rep(j, w) {
      rep(k, maxd) {
        if (i && dp[i - 1][j][k]) {
          dp[i][j][k + d[i][j]] = true;
          dp[i][j][abs(k - d[i][j])] = true;
        }
        if (j && dp[i][j - 1][k]) {
          dp[i][j][k + d[i][j]] = true;
          dp[i][j][abs(k - d[i][j])] = true;
        }
      }
    }
  }

  rep(k, maxd) {
    if (dp[h - 1][w - 1][k]) {
      cout << k << endl;
      return 0;
    }
  }


  
  return 0;
}

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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n+2];
  for(int i=1; i<=n; i++){
    cin >> a[i];
  }
  a[0] = a[n+1] = 0;
  long long dis = 0;
  for(int i=1; i<=n+1; i++){
    dis += abs(a[i] - a[i-1]);
  }
  for(int i=1; i<=n; i++){
    cout << dis - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]) << endl;;
  }
  return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
int main(){
  int i,j,k;
  int d;	//365
  int c[26];
  int score[9490];
  int t[365] = {0};
  int day1[26] = {0};
  double x = 0.36787944117;
  int tmp1=-999999,tmp2=-999999;
  int tmpi = 0;
  
  scanf("%d",&d);
  for(i=0;i<26;i++){
      scanf("%d ",&c[i]);
  }
  for(i=0;i<d*26;i++){
      scanf("%d ",&score[i]);
  }
  //st
  
  for(i=0;i<26;i++){
    if(c[i]>tmp1){
     tmp1 = c[i];
    }
    tmpi = i;
  }
  tmp1 = -999999;/*
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      if(score[i*26+j]-c[j]*(1+day1[j])>tmp1){
       	t[i] = j;
      }
    }
  }
  */
  //en
  for(i=0;i<d;i++){
      printf("%d\n",tmpi+1);
  }
 return 0; 
}




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

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(int x){	
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(int x){
	write(x);puts("");
}

int n,m,ans;

int main(){
	n=read();m=read();
	ans=max(0,n-1);
	if(m>=n)ans++;
	writeln(ans);
}

Measured memory_bytes: 256
def main():
    S = input()
    we = ("W" in S and "E" in S) or ("W" not in S and "E" not in S)
    ns = ("N" in S and "S" in S) or ("N" not in S and "S" not in S)
    if we and ns:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
main(){
  char str[100],str1[100];
  int cnt=0,i,l,j;
 
  while(scanf("%s",str)!=EOF){
    l=strlen(str);
    for(i=0,j=l-1;j>=0;i++,j--) str1[i]=str[j];
    str1[l]='\0';
    if(strcmp(str,str1)==0)cnt++;
  }
 
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 548
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#include <numeric>
#define lint unsigned long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define VCIN(ar) for(auto &vcin: (ar)) cin >> vcin
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;
// lint:64ビット 10^19

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

    int n;
    cin >> n;
    cout << n / 2 + (n % 2) << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200000)

nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, K = nl()

from collections import defaultdict
edges = defaultdict(set)
for i in range(N-1):
    a, b = nl()
    edges[a].add(b)
    edges[b].add(a)


done = [False] * (N+1)
done[1] = True

def find(i, cands, prev):
    res = cands

    count = 0
    if prev:
        count += 1
    for edge in edges[i]:
        if done[edge]:
            continue
        count += 1
        done[edge] = True
        res *= find(edge, K - count, True)
        res %= 1000000007
    return res


print(find(1, K, False))



Measured memory_bytes: 106208
# https://atcoder.jp/contests/abc086/tasks/arc089_a

n = int(input().split()[0])

txy_list = []

for i in range(0, n):
    work_list = list(map(int, input().split()))
    txy_list.append(work_list)

pre_txy = [0, 0, 0]
answer = False

for txy in txy_list:
    t, x, y = txy[0], txy[1], txy[2]
    pre_t, pre_x, pre_y = pre_txy[0], pre_txy[1], pre_txy[2]

    t_w, x_w, y_w = t - pre_t, abs(x - pre_x), abs(y - pre_y)
    work = t_w - (x_w + y_w)

    if (work % 2 == 0) and (work >= 0):
        pre_txy = txy
        continue
    else:
        break
else:
    answer = True

a = 'Yes' if answer else 'No'
print(a)

Measured memory_bytes: 27300
function char(s, n)
  return string.sub(s, n, n)
end

s=io.read(3)
io.read()
t=io.read(3)

ans=0

for i=1, 3 do
  if char(s, i) == char(t, i) then
    ans=ans+1
  end
end

print(ans)

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

using ll = long long;

const ll mod = 1000000007;
const int INF = 1000000000;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << (N + 1) / 2 << endl;
}


Measured memory_bytes: 892
#include <iostream>
#include <stdio.h>
#include<string>
using namespace std;

int main()
{
 int a, b, i;
std:: string c,d,e;

 cin >> c >> d;

 cin >> a >> b;

 cin >> e;

 if (c == e) {
	 a = a - 1;
 }
 else {
	 b = b - 1;
 }


 cout << a << " " << b;

}


Measured memory_bytes: 256
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll N=11,M=1001;
ll n,m,k;
vvi mat(N,vi (M,0));
ll ans_mn;

ll fun(ll mask)
{
	vi pos1;
	ll f=0;
	rep(i,0,10) if(((mask>>i)&1)==1)
	{
		pos1.pb(i);
		if(i==n-1) f=1;
	} 

	ll temp_ans=sz(pos1);
	if(f==0) pos1.pb(n-1);
	ll last=0;

	vvi no1s;
	rep(ii,0,sz(pos1))
	{
		vvi mat1;
		rep(j,last,pos1[ii]+1)
		{
			vi temp(m);
			rep(kk,0,m) temp[kk]=mat[j][kk];
			mat1.pb(temp);
		}

		vi no1(m,0);
		rep(j,0,m) rep(i,0,sz(mat1)) no1[j]+=mat1[i][j];

		no1s.pb(no1);
		last = pos1[ii]+1;
	}

	vi cnt(sz(no1s),0);

	// if(mask==7)
	// {
	// 	rep(i,0,sz(no1s))
	// 	{
	// 		rep(j,0,m) cout<<no1s[i][j]<<" ";
	// 		cout<<"\n";
	// 	}
	// }

	rep(j,0,m)
	{	
		f=0;
		rep(i,0,sz(no1s)) if(cnt[i]+no1s[i][j]>k) f=1;
		if(f==0) rep(i,0,sz(no1s)) cnt[i]+=no1s[i][j];
		else
		{
			temp_ans++;
			rep(i,0,sz(no1s)) cnt[i]=no1s[i][j];
			rep(i,0,sz(no1s)) if(cnt[i]>k) return inf;

		}
		// 	if(mask==7)
		// 	{
		// 		whatis(j);
		// 		rep(i,0,sz(no1s)) cout<<cnt[i]<<" ";
		// 	}
		// cout<<"\n";
	}
	// whatis(sz(no1s));
	// whatis(sz(no1s[0]));



	// whatis(mask);
	// whatis(temp_ans);
	return temp_ans;

}

int solve()
{
	cin>>n>>m>>k;
	rep(i,0,n)
	{
		string s;cin>>s;
		rep(j,0,m) mat[i][j] = s[j]-'0';
	} 

	ans_mn = (n-1) + (m-1);
	for(ll i=0;i<(1<<(n-1));i++) ans_mn = min(ans_mn,fun(i));
	cout<<ans_mn<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

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

int main()
{
  int n,k;
  cin >> n >> k;
  
  int x[n];
  rep(i,n) cin >> x[i];
  
  int ans = 0;
  rep(i,n){
    if(x[i] < k - x[i]){
      ans += x[i] * 2;
    }else{
      ans += (k -x[i]) * 2;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3560
N, K = [int(_) for _ in input().split()]
t_and_d = [[int(_) for _ in input().split()] for _ in range(N)]
t_and_d.sort(key=lambda x: x[1], reverse=True)

over_stock = []
type_set = set()

for t_i, d_i in t_and_d[:K]:
    if t_i in type_set:
        over_stock += [d_i]
    else:
        type_set.add(t_i)

x = len(type_set)
point = sum([d for t, d in t_and_d[:K]]) + x ** 2
point_max = point

for t_i, d_i in t_and_d[K:]:
    if over_stock:
        if t_i in type_set:
            continue
        else:
            diff = (x + 1) ** 2 - x ** 2 + d_i - over_stock.pop()
            type_set.add(t_i)
            x += 1
            point += diff
            point_max = max(point_max, point)

print(point_max)

Measured memory_bytes: 24896
import java.util.*;

class Main {
        public static int H;
        public static long[] A;
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        H = sc.nextInt();
                        A = new long[H];
                        for (int i = 0; i < H; i++) {
                                A[i] = sc.nextLong();
                        }
                        for (int i = H / 2;  i >= 0; i--) {
                                maxHeapify(i);
                        }
                        for (int i = 0; i < H; i++) {
                                System.out.print(" "+A[i]);
                        }
                        System.out.println("");
                }
        }
        public static void maxHeapify(int i) {
                int left = i * 2 + 1, right = i * 2 + 2, largest;
                if (left < H && A[left] > A[i]) {
                        largest = left;
                } else {
                        largest = i;
                }
                if (right < H && A[right] > A[largest]) {
                        largest = right;
                }

                if (largest != i) {
                        long tmp = A[i];
                        A[i] = A[largest];
                        A[largest] = tmp;
                        maxHeapify(largest);
                }
        }
}

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

using namespace std;

int main()
{
  int N, M, A[1000];


  while(cin >> N >> M, N) {
    for(int i = 0; i < N; i++) cin >> A[i];

    int ret = -1;
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < i; j++) {
        if(A[i] + A[j] <= M) ret = max(ret, A[i] + A[j]);
      }
    }
    if(ret == -1) cout << "NONE" << endl;
    else cout << ret << endl;
  }
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int n;
vector<vi> tree;
ll hs[111111];
ll r = 456789065ll;

ll get_hash(int v)
{
	ll tmp = 0;
	for (auto u : tree[v])
	{
		tmp += get_hash(u) * r;
	}
	tmp += tree[v].size() * r;
	return hs[v] = tmp;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	cin >> n;
	tree.resize(n);
	REP(i, n - 1)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		tree[a].push_back(b);
	}
	get_hash(0);
	map<ll, ll> mp;
	REP(i, n)
	{
		mp[hs[i]]++;
	}
	ll ans = 0;
	for (auto i : mp)
	{
		ans += i.second * (i.second - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 19956
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++){
  	bool a = false;
	int x = i;
	if (x % 3 == 0)
		a = true;
	while(x != 0){
		if (x % 10 == 3)
    		a = true;
    	x /= 10;
	} 
	if (a)
		cout << " " << i;
    }
	cout << endl;
}


Measured memory_bytes: 3112
def main():
    n = int(input())
    m = 1
    k = int(n ** 0.5)

    ans = len(str(n))
    for i in range(k + 1, 0, -1):
        if n % i == 0:
            n = n // i
            m *= i
            tmp = max(len(str(m)), len(str(n)))
            ans = min(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9420
import itertools
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
p = tuple(LS())
q = tuple(LS())

num = [str(i) for i in range(1, n + 1)]
perm = list(itertools.permutations(num, n))
ans = abs(perm.index(p) - perm.index(q))
print(ans)


Measured memory_bytes: 8052
beki = [0] * 1010
beki[1] = 1
for i in range(2, 1001):
        t = i*i
        while t<1001:
                beki[t] = 1
                t *= i
ans = 1
for i in range(int(input())+1):
        if beki[i]: ans = i
print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<string, P>> v(n);
    rep(i,n){
        string s;
        int p;
        cin >> s >> p;
        v[i].first = s;
        v[i].second.first = p;
        v[i].second.second = i;
    }
    sort(v.begin(), v.end());
    vector<P> v2;
    string t = v[0].first;
    rep(i,n){
        if(v[i].first != t){
            sort(v2.rbegin(), v2.rend());
            for(auto q : v2){
                cout << q.second + 1 << endl;
            }
            v2 = vector<P>();
        }
        v2.emplace_back(v[i].second.first, v[i].second.second);
        t = v[i].first;
    }
    if(!v2.empty()){
        sort(v2.rbegin(), v2.rend());
        for(auto q : v2){
            cout << q.second + 1 << endl;
        }
    }
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int a = 0;
  for(int i = 0; i < S.size(); i++) {
    if(S.at(i) == '+') {
      a++;
    }
  }
  cout << 2*a - 4 << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split())) 
ans = 0
count = 1 # 頂点数
bo = 1 #作れるか判定
lena = len(a)
asum = -1       # 葉の数-1回2分する
for i in range(lena):
    asum += a[i]
    bo -= a[i]
    if bo == 0 and i != lena-1:
        print(-1)
        exit()
    if bo < 0:
        print(-1)
        exit()
    bo*=2
count2 = 0 #2分した回数
ans = 1
for i in range(lena):
    count -= a[i]
    tmp = min(count,asum-count2)
    count += tmp
    count2 += tmp
    ans += count
    #print(ans,count)
print(ans)

Measured memory_bytes: 20144
def resolve():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    import collections
    pointcands = collections.deque([A[-1]])
    ans = 0
    A = collections.deque(A[:-1])
    while A:
        point = pointcands.pop()
        ans += point
        arrived = A.pop()
        pointcands.appendleft(arrived)
        pointcands.appendleft(arrived)
    print(ans)



    

if '__main__' == __name__:
    resolve()

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

int main() {
    int h, n;
    cin >> h >> n;

    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];

    int sum_a = accumulate(a.begin(), a.end(), 0);
    
    if (h <= sum_a) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 640
n, k = map(int,input().split())
a = [0] + list(map(int,input().split()))

s = []
ord = [-1] *(n+1)
c = 0

v = 1
while ord[v] == -1:
    ord[v] = len(s)
    s.append(v)
    v = a[v]

c = len(s) - ord[v]
l = ord[v]

if k < l:
    print(s[k])
else:
    k -= l
    k %= c
    print(s[l+k])


Measured memory_bytes: 32280
n = int(input())
f = input()
s = sorted(list(set(f)))
l = len(s)
c = [0]*l
for j in range(l):
  c[j] = f.count(s[j])
for i in range(n-1):
  temp = input()
  for j in range(l):
    c[j] = min(c[j], temp.count(s[j]))
    
ans = ""
for j in range(l):
  ans += s[j]*c[j]
  
print(ans)

Measured memory_bytes: 3064
#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()
 
int main() {
  int N;
  cin >>N;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  map<string,int>kazu;
  string shurui[N];
  int shuruinum=0;
  int ikutu=0;
  for(string a:S){
    if(kazu.count(a)){
      kazu.at(a)++;
      ikutu=max(ikutu,kazu.at(a));
    }else{
      shurui[shuruinum]=a;
      //cout<<shurui[shuruinum]<<endl;
      shuruinum++;
      kazu[a]=1;
    }
  }
  //cout<<shuruinum<<endl;
  if(shuruinum==N){
    sort(all(S));
    rep(i,N){
      cout<<S.at(i)<<endl;
    }
    return 0;
  }
  string shurui2[shuruinum];
  for(int i=0;i<shuruinum;i++){
    shurui2[i]=shurui[i];
  }
  int count=0;
  for(string b:shurui2){
    if(kazu.at(b)==ikutu){
      count++;
    }
  }  
  vector<string> kotae(count);
  int b=0;
  for(string a:shurui2){
    if(kazu.at(a)==ikutu){
      kotae.at(b)=a;
      b++;
    }
  }
  sort(kotae.begin(), kotae.end());
  for(int i=0;i<count;i++){
    cout<<kotae.at(i)<<endl;
  }
  return 0;
}

Measured memory_bytes: 29568
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

/* 先行順巡回 */
void preParse(int u)
{
    if (u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

/* 中間順巡回 */
void inParse(int u)
{
    if (u == NIL) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

/* 後行順巡回 */
void postParse(int u)
{
    if (u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main()
{
    int i, v, l, r, root;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        T[i].p = NIL;
    }

    for (i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if (l != NIL) T[l].p = v;
        if (r != NIL) T[r].p = v;
    }

    for (i = 0; i < n; i++) if (T[i].p == NIL) root = i;

    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");

    return 0;
}


Measured memory_bytes: 2744
from math import factorial

N, K = map(int, input().split())
MOD = 10 ** 9 + 7
for i in range(1, K + 1):
    if N-K+1 < i or K-1 < i-1:
        ans = 0
    else:
        ans = factorial(N - K + 1) // (factorial(i) * factorial(N - K + 1 - i)) * factorial(K - 1) // (
                factorial(i - 1) * factorial(K - 1 - i + 1))
    print(ans % MOD)


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

int main(void){
    int N,M; cin >> N >> M;
    long long ans=1;
    long long mod=pow(10,9)+7;

    if(abs(N-M)>1){
        cout << 0 << endl;
        return 0;
    }

    for(int i=1; i<=N; i++) ans=(ans*i)%mod;
    for(int i=1; i<=M; i++) ans=(ans*i)%mod;

    if(N==M) cout << (2*ans)%mod << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

int n;
int a[105];
int main()
{
	while(scanf("%d", &n) != EOF)
	{
		for(int i = 1; i <= n; i++)
			scanf("%d", &a[i]);
		sort(a + 1, a + n + 1);
		printf("%d\n", a[n] - a[1]);
		memset(a, 0, sizeof(a));
	}
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int a, b;
    cin >> a >> b;
    set<int> ret = {1, 2, 3};
    ret.erase(a);
    ret.erase(b);
    cout << *ret.begin() << "\n";

    return 0;
}

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
#define chmax(x,y) (x = max(x, y))
//  cout.precision(15); cout << fixed;

int main() {
  int h, w; cin >> h >> w;
  vector<string> S(h);
  loop(i,0,h) cin >> S[i];
  loop(i,0,h) {
    loop(j,0,2) cout << S[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <stdlib.h>
#include <cmath>
using namespace std;
typedef long long ll;
ll mod=1000000007;

vector<int> d[100001];
ll var[100001];
ll rnk[100001];
int N,K;

ll dfs(int x){
    if(var[x]!=-1) return var[x];
    vector<int> p;
    for(int i=0;i<d[x].size();i++) {
        int a=d[x].at(i);
        if(rnk[a]>rnk[x]) p.push_back(a);
    }
    int kid=p.size();
    ll ans=1;
    int ab=K-2; if(x==1) ab++;
    if(kid==0) return var[x]=ans;

    for(int i=0;i<kid;i++) {
        ans*=ab; ab--; ans=(ans%mod); 
        ans*=dfs(p.at(i)); ans=(ans%mod); 
    }
    return var[x]=ans;
}

int main(){
    
    cin>>N>>K;
    //d[0].push_back(1);

    for(int i=0;i<N-1;i++){
        int a,b;
        cin>>a>>b;
        d[a].push_back(b);
        d[b].push_back(a);
    }

    for(int i=0;i<=N; i++) var[i]=-1;
    queue<int> Q;
    rnk[1]=1;
    Q.push(1);
    while(!Q.empty()){
        int x=Q.front();
        //cout<<'x'<<x<<endl;
        for(int i=0;i<d[x].size();i++) {
            int p=d[x].at(i);
            if(rnk[p]==0) {
                //cout<<x<<':'<<rnk[x]<<endl;
                rnk[p]=rnk[x]+1;
                Q.push(p);
            }
        }
        Q.pop();
    }

    //ll ans=dfs(1);
    cout<<(dfs(1)*K)%mod<<endl;
}

Measured memory_bytes: 17792
#include<cstdio>
using namespace std;

char d[110];

int main() {
  while (1) {
    scanf("%110[^\n]", d);
    if (d[0] == '.') break;
    getchar();
    int stack[100], sNum = 0;
    bool flag = true;
    for (int i = 0; d[i] != '.'; i++) {
      if (d[i] == '(') stack[sNum++] = 0;
      if (d[i] == '[') stack[sNum++] = 1;
      if (d[i] == ')') {
        if (sNum > 0 && stack[sNum - 1] == 0) sNum--;
        else { flag = false; break; }
      }
      if (d[i] == ']') {
        if (sNum > 0 && stack[sNum - 1] == 1) sNum--;
        else { flag = false; break; }
      }
    }
    if (flag && sNum == 0) printf("yes\n");
    else printf("no\n");
  }
}



Measured memory_bytes: 2612
class priorityQueue {
  constructor() {
    this.keys = [];
    Number.prototype.parentIdx = function() { return Math.ceil(this/2 - 1); };
    Number.prototype.leftIdx = function() { return this * 2 + 1; };
    Number.prototype.rightIdx = function() { return this * 2 + 2; };
  }

  insert(key) { this.heapIncrease(this.keys.push(key) - 1); }

  heapIncrease(idx) {
    const keys = this.keys;
    for (let i=idx, p=idx.parentIdx(); i > 0 && keys[i] > keys[p]; i=p, p=i.parentIdx()) {
      keys[p] = [keys[i], keys[i] = keys[p]][0];
    }
  }

  extract() {
    const keys = this.keys;
    const res = keys[0];
    keys[0] = keys.pop();
    this.maxHeapify(0);
    return res;
  }

  maxHeapify(idx) {
    const keys = this.keys;
    const n = keys.length;
    const innerMaxHeapify = (i) => {
      let left, right, largest = i;
      left = i.leftIdx();
      right = i.rightIdx();
      if (left < n && Number(keys[left]) > Number(keys[largest])) largest = left;
      if (right < n && Number(keys[right]) > Number(keys[largest])) largest = right;
      if (largest != i) {
        keys[largest] = [keys[i], keys[i] = keys[largest]][0];
        innerMaxHeapify(largest);
      }
    };
    innerMaxHeapify(idx);
  }
}

(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  lines.pop();
  const queue = new priorityQueue();
  let str = '';
  lines.forEach(function(cmd) {
    switch(cmd.charAt(0)) {
      case 'i': queue.insert(Number(cmd.split(' ')[1])); break;
      case 'e': str += `${queue.extract()|0}\n`; break;
    }
  });
  process.stdout.write(str);
})();




Measured memory_bytes: 203996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
bool used[1000100];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int k;
	cin>>k;
	set<int>rests;
	int cur=0;
	int add=0;
	while(true){
		cur=(cur*10+7)%k;
		add++;
		if(cur==0){
			cout<<add<<" ";
			return 0;
		}
		if(used[cur]){
			cout<<"-1";
			return 0;
		}
		used[cur]=true;
	}
}



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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

int main(void) {
    string ss;
    cin >> ss;

    int n = ss.size();
    bool flg;
    int ans=0;
    for(int i=2;i<n;i+=2) {
        flg = true;
        for(int j=0;j<i/2;j++) {
            if(ss.at(j)!=ss.at(j+i/2)) { 
                flg = false;
                break;
            }
        }
        if(flg) ans = max(ans, i);
    }

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


Measured memory_bytes: 256
// ---------- BEG ../defs.hpp BEG ----------
#ifndef atcoder_defs_hpp
#define atcoder_defs_hpp
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;
using i8t = std::int64_t;
using u8t = std::uint64_t;
using vi8t = std::vector<i8t>;
using vvi8t = std::vector<std::vector<i8t>>;
using vu8t = std::vector<u8t>;
#include <limits>
static const i8t i8t_max=numeric_limits<i8t>::max();
static const i8t i8t_min=numeric_limits<i8t>::min();
#include <unordered_map>
#include <unordered_set>
template<typename Key,typename Value> using map_t=std::unordered_map<Key, Value>;
template<typename Key> using set_t=std::unordered_set<Key>;
#define F3(i,i0,iN,step) for(i8t i=i0,i##_N=iN;i<i##_N;i+=step)
#define F2(i,i0,iN) F3(i,i0,iN,1)
#define F(i,N) F3(i,0,N,1)
#define FR(i,N) for(i8t i=N;i--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;
template<typename T> T umax(T& ans,T const& value) {if(value>ans)ans=value;return ans;}
template<typename T> T umin(T& ans,T const& value) {if(value<ans)ans=value;return ans;}
template<typename T> struct identity { using type = T; };
#endif
// ---------- END ../defs.hpp END ----------

int main() {
  R(A)R(B)
  P((A*(A-1)+B*(B-1))/2);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
class DisjointSet
{
public:
	vector<int> rank, p;

	DisjointSet() {}
	DisjointSet(int size) {
		rank.resize(size,0);
		p.resize(size,0);
		for (int i = 0; i < size; ++i)
		{
			makeSet(i);
		}
	}
	void makeSet(int x) {
		p[x] = x;
		rank[x] = 0;
	}
	bool same(int x, int y) {
		return findSet(x)==findSet(y);
	}
	void unite(int x, int y) {
		link(findSet(x), findSet(y));
	}
	void link(int x, int y) {
		if (rank[x] > rank[y]) {
			p[y] = x;
		} else {
			p[x] = y;
			if (rank[x] == rank[y]) {
				rank[y]++;
			}
		}
	}
	int findSet(int x) {
		if (x != p[x]) {
			p[x] = findSet(p[x]);
		}
		return p[x];
	}
};

int main()
{
	int n,a,b,q;
	int t;
	cin>>n>>q;
	DisjointSet ds = DisjointSet(n);
	for (int i = 0; i < q; ++i)
	{
		cin>>t>>a>>b;
		if (t == 0) ds.unite(a,b);
		else if (t == 1) {
			if (ds.same(a,b)) cout<<1<<endl;
			else cout<<0<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3192
#include <stdio.h>

int main(void)
{
	int D, T, S;//D:距離,T:時間S:分速

	scanf("%d %d %d", &D, &T, &S);

	if (T * S >= D)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	putchar('\n');

	return 0;
}

Measured memory_bytes: 1708