akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

LL gcd(LL a, LL b) {
	return b != 0 ? gcd(b, a % b) : a;
}

int main() {
	int n; cin >> n;
	vector<LL> a(n);

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

	vector<LL> l(n+1);
	vector<LL> r(n+1);

	for (int i = 0; i < n; i++) {
		l[i + 1] = gcd(l[i], a[i]);
	}

	for (int i = n-2; i >=0; i--) {
		r[i] = gcd(r[i + 1], a[i+1]);
	}

	LL ans = 1;
	for (int i = 0; i < n; i++) {
		ans = max(ans, gcd(l[i], r[i]));
	}

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

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int ar[105];
int32_t main(){
	int n;cin>>n;for(int i=1;i<=n;i++)cin>>ar[i];sort(ar+1,ar+n+1);
	int a=0,b=0;
	for(int i=n;i>=1;i--){
		if((n-i)&1) b+=ar[i];
		else a+=ar[i];
	}
	cout<<a-b;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll M=1000000000000000000LL;
  ll a,b,c,n;
  cin >> a >> b >> c >> n;
  if(a==b) {
    pr(0);
    return;
  }
  if(n%2) pr(b-a);
  else pr(a-b);
  /*else if(n>60) {
    pr("Unfair");
    return;
  }
  */
  /*
  ll x=1,y=0;
  rep(i,n) {
    pr(i,x,y);
    ll xx=y*2,yy;
    if(i%2) yy=xx-1;
    else yy=xx+1;
    x=xx,y=yy;
    ll s=x*a+y*b,t=y*a+x*b;
    if(abs(s-t)>M) {
      pr("Unfair");
      return;
    }
  }
  ll s=x*a+y*b,t=y*a+x*b;
  pr(s-t);
  */
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
    return xx*ff;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	fastio;

	int n; cin>>n;
	ll a[n]; forn(i,n) cin>>a[i];

	ll ans = 1000;

	forn(i,n-1){
		if(a[i+1] < a[i]) continue;
		ll stock = ans / a[i];
		ans += stock * (a[i+1] - a[i]);
	}
	cout<<ans<<ln;


	return 0;
}

Measured memory_bytes: 3664
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
A = [abs(753 - int(x+y+z)) for x, y, z in zip(S[:], S[1:], S[2:])]
answer = min(A)
print(answer)


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

public class Main {


    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public void execute(CustomReader in) throws IOException {
        int N = Integer.parseInt(in.readLine());
        long[] A = in.readLineAsLongArray();
        long total = 0L;
        boolean containsZero = false;
        long minAbs = Long.MAX_VALUE;
        int negativeCnt = 0;
        for (int i = 0; i < N; i++) {
            total += Math.abs(A[i]);
            minAbs = Math.min(minAbs, Math.abs(A[i]));
            if (A[i] == 0) {
                containsZero = true;
            }
            if (A[i] < 0) {
                negativeCnt++;
            }
        }
        if (!containsZero && negativeCnt % 2 == 1) {
            total -= 2 * minAbs;
        }
        System.out.println(total);
    }


    static class CustomReader extends BufferedReader {
        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }


        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public long[] readLineAsLongArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            long[] longArray = new long[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                longArray[i] = Long.parseLong(strArray[i]);
            }
            return longArray;
        }


        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }
    }

}

Measured memory_bytes: 51276
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
   string s;
   cin>>s;
   int len = s.size(), cnt = 0;
   for(int i = 0; i < len ; i++){
      if(s[i] == '1')
         cnt++;
   }
   printf("%d\n", cnt);
   return 0;
}


Measured memory_bytes: 3692
import java.util.*

fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val hh = readLine()!!.split(" ").map { it.toInt() }
    val ff = IntArray(n){0}

    val stack = Stack<Pair<Int, Int>>()
    stack.push(Pair(0, n-1))

    var cnt = 0L

    while (stack.isNotEmpty()) {
        cnt++
        val seg = stack.pop()
        var sIdx = seg.first
        var eIdx = seg.first

        for (i in seg.first..seg.second) {
            if (ff[i] < hh[i]) {
                ff[i]++
                eIdx = i
            } else {
                if (i == sIdx) {
                    sIdx++
                } else {
                    stack.push(Pair(sIdx, eIdx))
                    sIdx = i+1
                }
            }
        }

        if (sIdx <= seg.second) {
            stack.push(Pair(sIdx, eIdx))
        }
    }

    println(cnt-1)
}

Measured memory_bytes: 38080
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
using namespace std;

#define ll long long

int main(){
    int A,B,C,ans;
    cin >> A >> B >> C;
    if(A>=B && A>= C)ans = A*10 + B + C;
    else if(B>A && B>=C)ans = B*10 + C + A;
    else ans = C*10 + A + B;
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int N, H[100], flag, count = 1;
	
	cin >> N;
	
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	
	for (int i = 1; i < N; i++) {
		flag = 1;
		
		for (int j = 0; j < i; j++) {
			if (H[j] > H[i]) {
				//海を眺められない
				flag = 0;
				break;
			}
		}
		
		if (flag) {
			//海を眺められる
			count++;
		}
	}
	
	cout << count << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
 
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
 
def lcm(a, b):
    return (a * b)//gcd(a,b)
 
lcm_a = 1
 
for i in range(N):
    lcm_a = lcm(lcm_a,A[i])
 
ans = 0
for i in range(N):
    ans += lcm_a//A[i]
 
mod = int(1e9+7)
 
print(ans%mod)

Measured memory_bytes: 75188
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}

fn main() {
    let q: Vec<usize> = read_vec();
    let (n, m) = (q[0], q[1]);

    let mut xs: Vec<i32> = read_vec();
    xs.sort();
    let mut intervals: Vec<i32> = (0..(m - 1)).map(|i| xs[i + 1] - xs[i]).collect();
    intervals.sort();

    let ans = if n < m {
        intervals[0..(m - n)].iter().sum()
    } else {
        0
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;

using ll = long long;

ll n, k;

unsigned char a[123];
ll memo[123][123][300];
ll dp(ll p, ll q, ll r)
{
	if (p < 0 || q < 0)return 0;
	if (memo[p][q][r] >= 0)return memo[p][q][r];
	ll ans = dp(p - 1, q, r);
	if (p - 1 >= 0)ans += dp(p - 1, q - 1, r ^ a[p - 1]);
	ans %= 1000000007;
	return memo[p][q][r] = ans;
}

ll fact[123] = { 1 };

int main(void)
{
	scanf("%lld %lld", &n, &k);
	for (int i = 0; i < n; ++i)
	{
		int tmp; scanf("%d", &tmp);
		a[i] = (unsigned char)tmp;
	}
	memset(memo, 0xFF, sizeof(memo));
	memo[0][0][0] = 1;
	for (ll i = 1; i < 111; ++i)
	{
		fact[i] = fact[i - 1] * i;
		fact[i] %= 1000000007;
	}
	ll ans = 0;
	for (ll q = 0; q <= n; ++q)
	{
		ans += dp(n, q, k) * fact[q];
		ans %= 1000000007;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 35712
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  set<ll> a;
  rep(i,n){
    ll k;
    cin>>k;
    a.insert(k);
  }
  if(sz(a)==n){
    COUT("YES");
  }
  else{
    COUT("NO");
  }
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<int> b(n + 1);
  rep(i, n - 1) cin >> b[i + 1];
  b[0] = b[1];
  b[n] = b[n - 1];
  int ans = 0;
  rep(i, n) ans += min(b[i], b[i + 1]);
  out(ans);
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappush, heappop
from collections import defaultdict

N,Q = map(int,readline().split())
data = list(map(int,read().split()))
S = data[:3*N:3]
T = data[1:3*N:3]
X = data[2:3*N:3]
D = data[3*N:]

event = []
event += [(s-x,1,x) for x,s in zip(X,S)] # xに通行止めを1つ追加
event += [(t-x,2,x) for x,t in zip(X,T)] # xの通行止めを1つ削除
event += [(x,3,i) for i,x in enumerate(D)] # 最小の通行止めを答える

event.sort()

INF = 10**10
q = [INF]
counter = defaultdict(int)
counter[INF] = 1

answer = [None] * Q
for a,b,c in event:
    if b == 1:
        heappush(q,c)
        counter[c] += 1
    elif b == 2:
        counter[c] -= 1
    else:
        while counter[q[0]] == 0:
            heappop(q)
        x = q[0]
        if x == INF:
            x = -1
        answer[c] = x

print('\n'.join(map(str,answer)))

Measured memory_bytes: 146344
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;


int main() {
    string s;
    cin >> s;

    int nen, tuki, hi;
    nen = (s.at(0) - '0') * 1000 + (s.at(1) - '0') * 100 + (s.at(2) - '0') * 10 + (s.at(3) - '0');
    tuki = (s.at(5) - '0') * 10 + (s.at(6) - '0');
    hi = (s.at(8)) * 10 + (s.at(9));


    if (nen > 2019) {
        std::cout << "TBD";
    } else if (nen == 2019) {
        if (tuki <= 4) {
            std::cout << "Heisei";
        }else if(tuki>4){
            std::cout<<"TBD";
        }
    } else {
        std::cout << "Heisei";
    }
    return 0;
}



Measured memory_bytes: 256
N = int(input())
INF = float('inf')
dp = [INF for _ in range(N+1)]
dp[0] = 0

for n in range(N + 1):
    power = 0
    while pow(6, power) <= n:
        dp[n] = min(dp[n], dp[n - pow(6, power)] + 1)
        power += 1

    power = 0
    while pow(9, power) <= n:
        dp[n] = min(dp[n], dp[n - pow(9, power)] + 1)
        power += 1

print(dp[N])


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

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

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int n;
int m[110][2], dp[110][110];

int rec(int l, int r) {
    if (dp[l][r] != -1) {
        return dp[l][r];
    }

    if (abs(l - r) <= 1) {
        return dp[l][r] = 0;
    }

    int res = iINF;

    if (abs(l - r) == 2) {
        return dp[l][r] = m[l][0] * m[l][1] * m[r - 1][1];
    }

    for (int mid = l + 1; mid < r; mid++) {
        res = min(
            res, rec(l, mid) + rec(mid, r) + m[l][0] * m[mid - 1][1] * m[r - 1][1]);
    }

    return dp[l][r] = res;
}

int main() {
    cin >> n;
    REP(i, n) {
        int r, c;
        cin >> r >> c;
        m[i][0] = r;
        m[i][1] = c;
    }

    memset(dp, -1, sizeof(dp));

    cout << rec(0, n) << endl;
    return 0;
}


Measured memory_bytes: 3140
import java.util.*;

class Main{
  public static void main(String[] s){
  	Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if(a%2==1 && b%2==1)
      System.out.println("Odd");
    else
      System.out.println("Even");
  }
}


Measured memory_bytes: 21716
f=lambda:map(int,input().split())
h,w=f()
ch,cw=f()
dh,dw=f()
g=[[*input()] for _ in range(h)]
from collections import *
q=deque([(0,ch-1,cw-1)])
while q:
  d,x,y=q.popleft()
  if g[x][y]!='.': continue
  g[x][y]=d
  for dx in range(-2,3):
    for dy in range(-2,3):
      j=abs(dx)+abs(dy)
      nx,ny=x+dx,y+dy
      if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and j:
        if j>1: q.append((d+1,nx,ny))
        else: q.appendleft((d,nx,ny))
a=g[dh-1][dw-1]
print([a,-1][a=='.'])

Measured memory_bytes: 247248
#include<stdio.h>
#include<string.h>
int main()
{
	char s[200005], t[200005];
	scanf("%s%s", s, t);
	int i, j, n = strlen(s);
	int p[30];
	for (i = 0; i < 30; i++)
		p[i] = -1;
	for (i = 0; i < n; i++)
	{
		if (p[s[i] - 'a'] < 0)
			p[s[i] - 'a'] = t[i] - 'a';
		else if (p[s[i] - 'a'] != t[i] - 'a')
		{
			printf("No\n");
			return 0;
		}
	}
	for (i = 0; i < 27; i++)
	{
		for (j = i + 1; j < 30; j++)
		{
			if (p[i] == p[j] && p[i] >= 0)
			{
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 512
function Main(input) {
  input=input.split("\n");
　const N=input[0].split(" ")[0]-0;
　const K=input[0].split(" ")[1]-0;
  
  
  console.log(K*((K-1)**(N-1)));
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


Measured memory_bytes: 29396
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int l;
	while(1){
		cin>>l;
		if(l==0) break;
		vi a(l);
		rep(i,0,l) cin>>a[i];
		int n=31;
		o(n);
		rep(i,0,10){
			int tmp=n-a[i%l];
			if(tmp<=0){
				o(0); break;
			}
			o(tmp);
			n-=5;
			o(n);
		}
	}
}

Measured memory_bytes: 1196
N = int(input())
if N<=10:
  print('Yes')
elif N ==12 or N == 14 or N == 15 or N == 16 or N == 18 or N ==21 or N == 24 or N == 27:
  print('Yes')
elif N ==20 or N == 32 or N == 36 or N == 35 or N ==40 or N == 45 or N == 25:
  print('Yes')
elif N ==42 or N == 48 or N == 54 or N == 49 or N ==56 or N == 63 or N == 64:
  print('Yes')
elif N == 72 or N == 81:
  print('Yes')
else:
  print('No')

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

int main()
{
	string s, t;
	cin >> s >> t;
	map<string, int> m;
	cin >> m[s] >> m[t];
	string u;
	cin >> u;
	m.at(u)--;

	cout << m.at(s) << " " << m.at(t) << endl;
}

Measured memory_bytes: 256
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();      
        int[] a = r.ii();
        int N = a[0],
            T = a[1],
            min = 1001;

        for(int i = 0; i < N; i++){
            a = r.ii();
            if(a[1] <= T){
                if(a[0] < min){
                    min = a[0];
                }
            }
        }        
        print(1000 < min ? "TLE" : String.valueOf(min));
    }
    static void print(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int Int(String s){
            return Integer.parseInt(s);
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}

Measured memory_bytes: 24660
N=int(input())
A=[int(i) for i in input().split()]
ans=10**9
def f(x,A):
    s=0
    for a in A:
        s+=pow(abs(x-a),2)
    return s
for i in range(201):
    x=-100+i
    t=f(x,A)
    if ans>t:
        ans=t
print(ans)

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

int main(void) {
	int n;
	cin >> n;
	vector<int> a(n);
	
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	vector<int> b = a;
	sort(b.rbegin(), b.rend());
	for (int i = 0; i < n; i++){
		int ans = b[0];
		if (a[i] == b[0]) ans = b[1]; 
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
const long long mod = 1000000007;
//const long long mod = 998244353;
class Combination {
	int MAX;
	int mod;
	long long *rev;
	long long modpow(long long a, long long n, long long mod) {
		long long res = 1;
		while (n > 0) {
			if (n & 1) res = res * a % mod;
			a = a * a % mod;
			n >>= 1;
		}
		return res;
	}

public:
	void rInit() {
		for (int i = 0; i < MAX; i++) {
			rev[i] = modpow(i, mod - 2, mod);
		}
	}
	Combination(int max, int mod) :mod(mod), MAX(max) {
		rev = new long long[max];
	}
	~Combination() {
		delete[] rev;
	}
	long long operator()(int n, int k) {
		if (n < 0 || k < 0)return 0;
		long long res = 1;
		int s = 1;
		for (int i = n; i > n - k; i--) {
			res *= i;
			res %= mod;
			res *= rev[s];
			res %= mod;
			s++;
		}
		return res;
	}
};

int main() {
	int X, Y;
	scanf("%d %d", &X, &Y);
	if ((X + Y) % 3 != 0) {
		printf("0");
	}
	else {
		Combination nck(1000001, mod);
		nck.rInit();
		printf("%d", nck((X + Y) / 3, X - (X + Y) / 3));
	}
	return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MX=3e5+10;
int n,m;
ll a[MX],b[MX],k;
int main()
{
    //freopen("input.txt","r",stdin);
    scanf("%d %d %lld",&n,&m,&k);
    a[0]=b[0]=0;
    for( int i=1 ; i<=n ; i++ ){
        scanf("%lld",&a[i]);
        a[i]=a[i]+a[i-1];
    }
    a[n+1]=a[n]+1;
    int ans=upper_bound(a+1,a+2+n,k)-a-1;
    for( int i=1 ; i<=m ; i++ ){
        scanf("%lld",&b[i]);
        b[i]=b[i]+b[i-1];
        ll rem=k-b[i];
        if( rem>0 ){
            int num=upper_bound(a+1,a+2+n,rem)-a;
            num--;
            ans=max(ans,i+num);
        }
    }
    b[m+1]=b[m]+1;
    int ans1=upper_bound(b+1,b+2+m,k)-b-1;
    ans=max(ans,ans1);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 6924
#include <iostream>
#include <vector>
#include <climits>
#include <list>
using namespace std;

bool visited[100001];
long long dist[100001];
vector<pair<int, int>> vv[100001];

int bfs(int n)
{
    for (auto &it : visited) it = false;
    for (auto &it : dist) it = 0;

    list<int> q;

    visited[n] = true;
    dist[n] = 0;

    q.push_back(n);

    while (!q.empty())
    {
        n = q.front();

        q.pop_front();

        for (auto it : vv[n])
            if (!visited[it.first])
            {
                visited[it.first] = true;

                dist[it.first] = dist[n] + it.second;

                q.push_back(it.first);
            }
    }
    return -1;
}

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

    int n, a, b, c, q, k, x, y;

    cin >> n;

    for (int i = 1; i < n; ++i)
    {
        cin >> a >> b >> c;
        vv[a].push_back(make_pair(b, c));
        vv[b].push_back(make_pair(a, c));
    }

    cin >> q >> k;

    bfs(k);

    for (int i = 0; i < q; ++i)
    {
        cin >> x >> y;
        cout << dist[x] + dist[y] << '\n';
    }
}

Measured memory_bytes: 11636
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

const int MOD = 1e9+7;
class mint {
    ll x;
public:
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    
    mint operator -() const {
        return mint(-x);
    }
    
    mint &operator +=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator -=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator *=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator +(const mint &a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator *(const mint &a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(MOD - 2);
    }

    mint &operator /=(const mint &a) {
        return (*this) *= a.inv();
    }

    mint operator /(const mint &a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream &operator<<(ostream& os, const mint &m) {
        os << m.x;
        return os;
    }
};

const int MAX = 510000;
mint fac[MAX], finv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * mint(i);
        finv[i] = finv[i-1] * mint(i).inv();
    }
}

mint COM (int n, int k) {
    if (n < k) return mint(0);
    if (n < 0 || k < 0) return mint(0);
    // o(k)
    // if (k < MAX) {
    //     mint ret(1);
    //     Rep (i, k) {
    //         ret *= mint(n-i);
    //         ret /= mint(k-i);
    //     }
    //     return ret;
    // }

    return fac[n] * finv[k] * finv[n-k];
}


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

    ll N, K;
    cin >> N >> K;

    mint ans(0);
    COMinit();

    for (ll i = K; i <= N+1; i++) {
        ll a = (i-1) * i / 2;
        ll b = (N+N-i+1) * i / 2;
        ans += b-a+1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 11608
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K, S;
    cin >> K >> S;
    int cnt = 0;
    rep(i, K+1) {
        rep(j, K+1) {
            int tmp = S - (i + j);
            if (0 <= tmp && tmp <= K) cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}


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

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

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: usize = read();
    let mut a: Vec<i32> = read_vec();
    a.sort();

    if a[0] >= 0 {
        let m = a.iter().fold(0, |sum, x| sum + x) - 2 * a[0];
        println!("{}", m);
        let mut tmp = a[0];
        for i in 1..n - 1 {
            println!("{} {}", tmp, a[i]);
            tmp -= a[i];
        }
        println!("{} {}", a[n - 1], tmp);
    } else if a[n - 1] <= 0 {
        let m = 2 * a[n - 1] - a.iter().fold(0, |sum, x| sum + x);
        println!("{}", m);
        let mut tmp = a[n - 1];
        for i in (0..n - 1).rev() {
            println!("{} {}", tmp, a[i]);
            tmp -= a[i];
        }
    } else {
        let m = a.iter().fold(0, |sum, x| sum + x.abs());
        println!("{}", m);
        let mut k = 0;
        for i in 1..n {
            if a[i] > 0 {
                k = i - 1;
                break;
            }
        }
        let mut tmp1 = a[0];
        for i in k + 1..n - 1 {
            println!("{} {}", tmp1, a[i]);
            tmp1 -= a[i];
        }
        let mut tmp2 = a[n - 1];
        for i in 1..k + 1 {
            println!("{} {}", tmp2, a[i]);
            tmp2 -= a[i];
        }
        println!("{} {}", tmp2, tmp1);
    }
}


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

int main() {
  int N,T; cin >> N >> T;
  ll t[N]; rep(i,0,N) cin >> t[i];
  
  ll ans = T;
  rep(i,1,N) {
    if (t[i-1] + T > t[i]) ans -= T + t[i-1] - t[i];
    ans += T;
  }

  cout << ans << endl;
}  

Measured memory_bytes: 5176
#include "bits/stdc++.h"
using namespace std;

typedef pair<int, int> P;

int main() {
	int H, W, INF = 1000000000, wall = 0;
	string S[50];
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') wall++;
		}
	}
	queue<P> Q;
	int dx[4] = { 1, -1, 0, 0 }, dy[4] = { 0, 0, 1, -1 };
	int Dis[50][50];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			Dis[i][j] = INF;
		}
	}
	Dis[0][0] = 0;
	Q.push(P(0, 0));
	while (Q.size()) {
		P p = Q.front();
		Q.pop();
		if (p.first == H - 1 && p.second == W - 1) break;
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (nx != -1 && nx != H && ny != -1 && ny != W) {
				if (S[nx][ny] == '.' && Dis[nx][ny] == INF) {
					Q.push(P(nx, ny));
					Dis[nx][ny] = Dis[p.first][p.second] + 1;
				}
			}
		}
	}
	if (Dis[H - 1][W - 1] == INF) cout << -1;
	else cout << H * W - wall - Dis[H - 1][W - 1] - 1;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<map>
#include<vector>
#include<cmath>
#include<set>
#include<unordered_set>
#include<algorithm>
#define int long long int
#define mod 1000000007
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int j,arr[n];
	for(j=0;j<n;j++)
	    cin>>arr[j];
	vector<int> vec;
	if(n==1)
	{
		cout<<1000<<endl;
		exit(0);
	}
	int stocks=0,money=1000;
	for(j=0;j<n;j++)
	{
		if(j==n-1)
		{
			vec.push_back(arr[j]);
			break;
		}
		else
		{
			if(arr[j+1]>=arr[j])
			{
				vec.push_back(arr[j]);
				int i;
				for(i=j+1;i<n&&arr[i]>=arr[i-1];i++);
				if(i==n)
				{
					vec.push_back(arr[n-1]);
					break;
				}
				else
				{
					j=i-2;
				}
			}
			else
			{
				vec.push_back(arr[j]);
				int i;
				for(i=j+1;i<n&&arr[i]<arr[i-1];i++);
				if(i==n)
				{
					vec.push_back(arr[n-1]);
					break;
				}
				else
				{
					j=i-2;
				}
			}
		}
	}
	n=vec.size();
	if(n==1)
	{
		cout<<1000<<endl;
		exit(0);
	}
	for(j=0;j<n;j++)
	{
		if(j==n-1)
		{
			if(stocks!=0)
			{
				money+=stocks*vec[j];
				break;
			}
		}
		else
		{
			if(vec[j+1]<=vec[j])
			{
				money+=stocks*vec[j];
				stocks=0;
			}
			else
			{
				stocks+=(money/vec[j]);
				money%=vec[j];
			}
		}
	}
	cout<<money<<endl;
}


Measured memory_bytes: 3656
using System;
using System.Linq;
using System.Collections.Generic;

public class AtCoderC
{
    static void Main()
    {
        int n;
        int m;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            m = int.Parse(words[1]);
        }

        int[] nums = new int[n];

        for (int i = 0; i < m; i++)
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            int s = int.Parse(words[0]);
            int c = int.Parse(words[1]);
            if (nums[s - 1] != 0 && nums[s - 1] != c)
            {
                Console.WriteLine("-1");
                return;
            }
            if (n != 1 && s == 1 && c == 0)
            {
                Console.WriteLine("-1");
                return;
            }
            nums[s - 1] = c;
        }

        string answer = "";
        for (int i = 0; i < n; i++)
        {
            if (i == 0 && nums[0] == 0)
            {
                if (n == 1)
                {
                    answer += 0;
                }
                else
                {
                    answer += 1;
                }
            }
            else
            {
                answer += nums[i];
            }
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e5+10;
int a[N],num[N];
bool vis[N];
int main()
{
    int n,m,x,y;
    scanf("%d%d",&n,&m);
    memset(vis,false,sizeof(vis));
    for(int i=1;i<=n;i++) num[i]=1;
    vis[1]=true;
    while(m--)
    {
        scanf("%d%d",&x,&y);
        if(!num[x]) continue;
        if(vis[x])
        {
            if(num[x]==1)
                vis[x]=false;
            vis[y]=true;
        }
        num[y]++;
        num[x]--;
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        if(vis[i]) ans++;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 768
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  int scan; // scanf result
  int x; // to input 
  int y; // to input 
  int z; // to input 
  int temp;

  scan = scanf("%d", &x);
  scan = scanf("%d", &y);
  scan = scanf("%d", &z);

  temp = 0;
  temp = x;
  x = y;
  y = temp;
  
  temp = 0;
  temp = x;
  x = z;
  z = temp;

  printf("%d", x);
  printf(" ");
  printf("%d", y);
  printf(" ");
  printf("%d", z);
  return (0);
}


Measured memory_bytes: 128
using System;

namespace AtCoder.ABC098
{
    class d
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            var N = int.Parse(line);
            line = Console.ReadLine().Trim();
            var spl = line.Split(' ');
            var A = Array.ConvertAll<string, int>(spl, new Converter<string, int>(s => int.Parse(s)));
            long cnt = N;
            var start = 0;
            var end = 0;
            var tmp = A[0];
            for (var i = 1; i < N; ++i)
            {
                if((tmp ^ A[i]) == tmp + A[i])
                {
                    end = i;
                    tmp += A[i];
                }
                else
                {
                    if(start == end)
                    {
                        start = i;
                        end = i;
                        tmp = A[i];
                    }
                    else
                    {
                        var c = Count(start, end);
                        for (var j = start; j <= end; ++j)
                        {
                            tmp ^= A[j];
                            if ((tmp ^ A[i]) == tmp + A[i])
                            {
                                cnt -= Count(j + 1, i - 1);
                                start = j + 1;
                                end = i;
                                tmp += A[i];
                                break;
                            }
                        }
                        cnt += c;
                    }
                }
            }
            cnt += Count(start, end);
            Console.WriteLine(cnt);
        }

        private static long Count(int start, int end)
        {
            long div = end - start + 1;
            return (div % 2 == 0 ? div / 2 : div) * ((div + 1) % 2 == 0 ? (div + 1) / 2 : div + 1) - div;
        }
    }
}


Measured memory_bytes: 29020
n, m = [int(i) for i in input().split(" ")]

a =[ [int(i) for i in input().split(" ")] for _ in range(n) ]
b =[]
for i in range(m):
    b.append( int(input()) )


for x in range(n):
    result = 0
    for y in range(m):
        result += a[x][y] * b[y]
    print(result)
    

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

int main(void) {
    ll x; cin >> x;
    ll ans;
    ll money = 100;
    for(ll i=1; i<1e25; i++) {
        money += money/100;
        if(money>=x) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;

int main() {
    char B;
    cin >> B;

    if (B == 'A') {
        cout << "T" << endl;
    }
    else if (B == 'T') {
        cout << "A" << endl;
    }
    else if (B == 'G') {
        cout << "C" << endl;
    }
    else {
        cout << "G" << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);


int main(){
    std::ios::sync_with_stdio(false);
    ll x;
    cin>>x;
    if(x<=6) cout<<1<<endl;
    else{
        if(x%11==0) cout<<x/11*2<<endl;
        else{
            ll before = x/11*2;
            x-=before/2*11;
            if(x<=6) before++;
            else before+=2;
            cout<<before<<endl;
        }
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1000000007;

struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  ll n, k;
  cin >> n >> k;

  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());

  combination c(n);

  mint ans = 0;
  rep(ri, 2) {
    rep(i, n) {
      mint now = c(i, k - 1);
      if (ri == 1) now = -now;
      ans += now * a[i];
    }
    reverse(a.begin(), a.end());
  }
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <vector>



int main(void)
{
    int a,b,c;

    std::cin >> a >> b;

    int check = 0;

    for ( int i = 1; i <4 ; i ++)
    {
        int mul = a * b * i;
        if(mul % 2 == 1)
        {
            check = 1;
        }
    }

    if(check == 1)
    {
        std::cout<<"Yes"<<std::endl;
    }
    else
    {
        std::cout<<"No"<<std::endl;
    }



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int X,A;
	cin>>X>>A;
	if(X<A)
	{
		cout<<"0"<<endl;
	}
	else
	{
		cout<<"10"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
using LL = long long;
using ULL = unsigned long long;
#define NUM 1000000007

using namespace std;

int main()
{
    int n, t;
    ULL count = 0;
    cin >> n >> t;
    vector<int> v(n);
    for (auto& i : v)
    {
        cin >> i;
    }

    for (size_t i = 0; i < n - 1; i++)
    {
        int tmp = v[i + 1] - v[i];
        if (tmp >= t)
        {
            count += t;
        }
        else
        {
            count += tmp;
        }
    }
    count += t;
    cout << count << endl;

}

Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
  int a , b;
  scanf("%d %d\n",&a , &b);
  if(a < b)
  printf("a < b\n");

  if(a > b)
  printf("a > b\n");

  if(a == b)
  printf("a == b\n");

  return 0;
}


Measured memory_bytes: 2048
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stdio.h>

using namespace std;

int main(){
  int L;
  cin >> L;
  
  double ans;
  ans = pow((double)L, 3.0) / 27.0;
  
  printf("%.12f\n",ans);
  //cout << ans << endl;
}

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

using namespace std;

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int n, e, ans = 0;

signed main()
{
	IOS;
	cin >> n;
	int pre = 100009;
	for (int i = 1; i < n; i++) {
		cin >> e;
		ans += min(pre, e);
		pre = e;
	}
	cout << ans + pre << endl;
	return 0;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


const ll mod = 1e9+7;
ll kaizyou(int x){
  int res = 1;
  FOR(i,1,x+1){
    res *= i;
    res %= mod;
  }
  return res;
}

void testFunc(VI & a, VI& b){
  VLL vec;
  rep(i,b.size()) vec.push_back(i);
  map<ll,ll> mp;
  ll minMul = 1e15;
  do {
    ll sum = 0;
    rep(i,a.size()) sum += abs(a[i]-b[vec[i]]);
    mp[sum]++;
    minMul = min(minMul,sum);
  } while (next_permutation(all(vec)));
  cout << minMul << endl;
  cout << mp[minMul] << endl;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI a(n);
  rep(i,n) cin >> a[i];
  VI b(n);
  rep(i,n) cin >> b[i];

  // debug
  // testFunc(a,b);

  vector<PII> vec;
  rep(i,n) vec.push_back({a[i], -1});
  rep(i,n) vec.push_back({b[i], 1});

  sort(all(vec));
  int sum = 0;

  ll ans = 1;
  rep(i,vec.size()){
    if(sum < 0 && vec[i].second > 0) ans *= abs(sum);
    if(sum > 0 && vec[i].second < 0) ans *= abs(sum);
    ans %= mod;
    sum += vec[i].second;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3188