akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 5100000;
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 Sieve {
  ll n;
  vector<ll> f, primes;
  Sieve(ll n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    //エラトステネスの篩
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        //最小素因数がかかれるようにしている
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(ll x) { return f[x] == x;}
  //素因数列挙
  vector<ll> factorList(ll x) {
    vector<ll> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  //頻度を集計したもの
  vector<P> factor(int x) {
    vector<ll> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (ll p : fl) {
      //小さい順に出てくるので前回と同じなら足す作業でmapが作れる
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main(){
  //前処理
  Sieve sieve(1e6);
  //入力
  ll N;cin>>N;
  vector<ll> a(N);
  rep(i,N) cin>>a[i];

  //最小公倍数を求める
  map<ll,ll> m;
  rep(i,N){
    auto f = sieve.factor(a[i]);
    for(auto p: f){
      m[p.first] = max(m[p.first], (ll)p.second);
    }
  }

  mint lcm = 1;
  for(auto p : m){
    rep(i,p.second){
      lcm *= p.first;
    }
  }

  mint ans = 0;

  rep(i,N){
    mint b = lcm/a[i];
    ans += b;
  }
  cout<<ans.x<<endl;

}


Measured memory_bytes: 9332
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

//#define P 1000000007
#define P 998244353

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint_fast32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }

inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}

int a[3001];
long d[3001];
int main(void){
	int n=nextpint();
	int s=nextpint();
	for(int i=1; i<=n; i++){
		a[i]=nextpint();
	}
	for(int i=1; i<=n; i++){
		for(int j=s; j>=1; j--){
			long D=0;
			if(a[i]==j){
				D=i;
			}else if(a[i]<j){
				D=d[j-a[i]];
			}
			if(j==s){
				D*=(n-i+1);
			}
			d[j]=(d[j]+D)%P;
		}
	}
	printf("%ld\n", d[s]);
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

void Main() {
    // input
    int R;
    cin >> R;

    cout << 2 * R * M_PI << endl;
    // translate


    // output

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3712
//use proconio::input;
use std::cmp::min;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

const N_MAX: usize = 100;
const VI_MAX: usize = 1000;
const V_MAX: usize = VI_MAX * N_MAX;

fn main() {
    input! {
        n: usize,
        w: u64,
        d: [(u64, usize); n],
    }
    let mut dp = vec![vec![w + 1; V_MAX + 1]; n];
    let mut vi = d[0].1;
    for j in 0..(vi + 1) {
        dp[0][j] = d[0].0;
    }
    for i in 1..n {
        vi += d[i].1;
        for j in 0..(vi + 1) {
            if j > d[i].1 {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - d[i].1] + d[i].0);
            } else {
                dp[i][j] = min(dp[i - 1][j], d[i].0);
            }
        }
    }
    let mut r = 0;
    for j in 0..(V_MAX + 1) {
        if dp[n - 1][j] <= w {
            r = j;
        }
    }

    println!("{}", r);
}


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

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

template<class T>
    bool chmin(T& a, T b) {
        if (a > b) {
            a = b;
            return true;
        }
        return false;
}
template<class T> 
    bool chmax(T& a, T b) {
        if (a < b) {
            a = b;
            return true;
        }
        return false;
}

const ll INF = 1e10;;

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

    vector<ll> c(n,INF);
    c[0] = 0;
    rep(i,n-2){
        chmin(c[i+1],c[i]+abs(h[i]-h[i+1]));
        chmin(c[i+2],c[i]+abs(h[i]-h[i+2]));
    }
    chmin(c[n-1], c[n-2]+abs(h[n-1]-h[n-2]));

    cout << c[n-1] << endl;

    return 0;
}

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

using namespace std;

int main(){
	int a,b,c; cin>>a>>b>>c;
  	if((a==5 && b==5)||(b==5 && c==5)||(c==5 && a==5)){
    	cout<<"YES\n";
    }
  	else{
    	cout<<"NO\n";
    }
}

Measured memory_bytes: 256
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()

ans = 0
for i in range(n):
    if (i+1) % 2 == 1 and a[i] % 2 == 1:
        ans += 1
print(ans)

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

using namespace std;

int main()
{
    int n,a;
    cin>>n;
    vector<int>v;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v.push_back(a);
        m[a]++;
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(m[v[i]]>v[i])
        {
            ans+=1;
            m[v[i]]--;
        }
        else if(m[v[i]]<v[i])
        {
            ans+=1;
            m[v[i]]--;
        }
    }
cout<<ans<<endl;
}


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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007

//container-use 

typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< ll,ll > pll;
typedef vector<pair<ll,ll > > vpl;
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,a,b) for (int i = a; i <= b; i++)

//main function here
ll inv[1000011];
void invfact()
{
    inv[0] = inv[1] =1;
    for (ll i = 2; i <= 1000010-5; i++)
        inv[i] = (inv[mod % i] * (mod - mod / i) )% mod;
}
// long long int gcdExtended(long long int a,long long int b,long long int *x,long long int *y)
// {
//     if (a == 0)
//     {
//         *x = 0, *y = 1;
//         return b;
//     }
//     long long int x1, y1;
//     long long int gcd = gcdExtended(b%a, a, &x1, &y1);
//     *x = y1 - (b/a) * x1;
//     *y = x1;

//     return gcd;
// }
// long long int modInverse(long long int b)
// {
//     long long int x, y,m =mod;
//     long long int g = gcdExtended(b, m, &x, &y);
//     if (g != 1)
//         return -1;
//     return (x%m + m) % m;
// }
ll prime[1000011]; 
unordered_map<ll, ll> max_map; 
ll power(ll a, ll n) 
{ 
    if (n == 0) 
        return 1; 
    ll p = power(a, n / 2) % mod; 
    p = (p * p) % mod; 
    if (n & 1) 
        p = (p * a) % mod; 
    return p; 
}
void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (int i = 2; i < 1000010; i++) { 
        if (prime[i] == 0) { 
            for (int j = i * 2; j < 1000010; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
} 
ll lcmModuloM(ll ar[],ll n) 
{ 
    for (int i = 0; i < n; i++) { 
        ll num = ar[i]; 
        unordered_map<ll, ll> temp; 
        while (num > 1) { 
            ll factor = prime[num]; 
            temp[factor]++;
            num /= factor;
        } 

        for (auto it : temp) { 
            max_map[it.first] = max(max_map[it.first], it.second); 
        } 
    } 
    ll ans = 1; 
    for (auto it : max_map) { 
        ans = (ans * power(it.ff, it.ss)) % mod; 
    } 
    return ans; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    ll n;
    cin>>n;
    ll a[n];
    invfact();
    sieve();
    for(int i=0;i<n;i++)
        cin>>a[i];
    ll lcm=1;
    ll sum=0;
    for(int i=0;i<n;i++)
    {   
        sum=(sum+inv[a[i]])%mod;
    }
    lcm=lcmModuloM(a,n);
    cout<<(sum*lcm)%mod;
  return 0;
 }

Measured memory_bytes: 16384
#include<iostream>
#include<queue>
using namespace std;
int main(){
    queue<int> qt;
    queue<string> qn;
    string name;
    int n, q, time, sum=0;
    cin>>n>>q;
    for(int i=0;i<n;i++){
        cin>>name>>time;
        qn.push(name);
        qt.push(time);
    }
    while(qn.size()){
        if(qt.front()>q){
            qt.front()-=q;
            qt.push(qt.front());
            qt.pop();
            sum+=q;
            qn.push(qn.front());
            qn.pop();
        }
        else{
            sum+=qt.front();
            cout<<qn.front()<<' '<<sum<<'\n';
            qt.pop();
            qn.pop();
        }
    }
    return 0;
}


Measured memory_bytes: 5868
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p==NIL) printf("root, ");
  else if(T[u].l==NIL) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
  if(T[u].r!=NIL) calcDepth(T[u].r,p);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 3300
R=[]
n,*a=`dd`.split.map &:to_i
n.times{R<<1;(1...n).map{|i|
a[i-1]>a[i]&&(R<<n-1;a[i-1],a[i]=a[i],a[i-1])
R<<1
}}
p R.size,*R

Measured memory_bytes: 4088
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
V<int> dx={1,0,-1,0},dy={0,-1,0,1};
map<P,P> mp;
int main(){
    ll n;
     cin>>n;
     if(n%2==1){
         cout<<0<<endl;
         return 0;
     }
     ll t=5;
     ll ans=0;
     while(t*2<=n){
         ans+=(n/(t*2));
         t*=5;
     }
     cout<<ans<<endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

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


int main(void) {
	int h, w;
	int white = 0;
	queue< pair<int, int>> que;
	int x, y;
	bool check = false;
	int dist;
	


	cin >> h >> w;
	vector<string> s(h);
	vector<vector<int> > deep(h, vector<int>(w, -1));

	FOR(i, 0, h-1) {
		cin >> s[i];
	}
	
	FOR(i, 0, h - 1) {
		FOR(j, 0, w - 1) {
			if (s[i][j] == '.') {
				white++;
			}
		}
	}

	que.push(make_pair(0, 0));
	deep[0][0] = 1;

	while (!que.empty()) {
		y = que.front().first;
		x = que.front().second;
		que.pop();
		if (y == h - 1 && x == w - 1) {
			check = true;
			dist = deep[y][x];
			break;
		}

		FOR(i, 0, 3) {
			if (y + dy[i] >= 0 && y + dy[i] <= h - 1 && x + dx[i] >= 0 && x + dx[i] <= w - 1) {
				if (deep[y + dy[i]][x + dx[i]] == -1&&s[y+dy[i]][x+dx[i]]=='.') {
					deep[y + dy[i]][x + dx[i]] = deep[y][x] + 1;
					que.push(make_pair(y + dy[i], x + dx[i]));
				}
			}
		}
	}

	if (check) {
		cout << white-dist << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
const int N=101101;
int T,n,k;
int main(){
	ll a,b,c,d;
	scanf("%lld%lld.%lld",&a,&b,&c);
	d=a*(b*100+c)/100;
	printf("%lld\n",d);
	return 0;
}

Measured memory_bytes: 1732
N=int(input())
w=[]
c=[]
r=0
for i in range(N):
    w.append(input())

for i in range(N-1):
    if w[i][len(w[i])-1]!=w[i+1][0]:
        r+=1
for v in w:
    if v not in c:
        c.append(v)
if len(c)==len(w):
    r+=0
else:
    r+=1
       
if r==0 :
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>


int main()
{
    int i,j,k,v;

    //??\???
    int n;
    scanf("%d", &n);
    int A[n];
    for( i = 0; i < n; ++i ){
        scanf("%d", &A[i]);
    }

    for(i = 0; i < n; i++){
        v = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > v){
        	A[j+1] = A[j];
        	j--;
        }
        A[j+1] = v;
        for(k = 0; k < n; k++){
        	printf("%d", A[k]);
        	if( k != n-1 ){
        		printf(" ");
        	}
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <algorithm>

int main(void){
    int N, L;
    std::cin >> N >> L;
    std::vector<std::string> S(N);
    for (int i=0; i<N; ++i){
        std::cin >> S.at(i);
    }
    
    std::sort(S.begin(), S.end());

    for (std::string s: S){
        std::cout << s;
    }

    std::cout << std::endl;

    return 0;
}


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

int main(void){
    int n; cin >> n;
    vector<ll>A(n),B(n),C(n-1);
    for (int i=0;i<n;i++) cin >> A[i], A[i]--;
    A.push_back(0);
    for(int i=0;i<n;i++) cin >> B[i];
    for(int i=0;i<n-1;i++) cin >> C[i];
    ll ans =0;
    for(int i=0;i<n;i++){
        ans += B[A[i]];
        if(A[i]+1 == A[i+1]) ans += C[A[i]];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int a, b;

	while(cin >> a >> b) {
		cout << toString(a+b).size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
import Control.Applicative
import Data.List
import Data.Char

getInt :: IO Int
getInt = (\a -> read a :: Int) <$> getLine

getIntArray :: IO [Int]
getIntArray = ((map (\a -> read a :: Int)) . words) <$> getLine

getStrArray :: Int -> IO [String]
getStrArray 0 = return [] :: IO [String]
getStrArray n = (:) <$> getLine <*> (getStrArray (n - 1))

canEat :: [Int] -> String
canEat [a, b]
    | mod a 3 == 0 = "Possible"
    | mod b 3 == 0 = "Possible"
    | mod (a + b) 3 == 0 = "Possible"
    | otherwise = "Impossible"

main = do
    putStrLn =<< (canEat <$> getIntArray)


Measured memory_bytes: 508
N=int(input())
AB=[list(map(int,input().split())) for _ in range(N)]
AB_=sorted(AB,key=lambda x:-x[0])
CD=[list(map(int,input().split())) for _ in range(N)]
CD_=sorted(CD,key=lambda x:-x[0])
ans=0
for i in range(N):
    target=[]
    for j in range(len(CD_)):
        if CD_[j][0]>AB_[i][0] and CD_[j][1]>AB_[i][1]:
            target.append(CD_[j])
    target=sorted(target,key=lambda x:x[1])
    if len(target)==0:
        continue
    else:
        ans+=1
        CD_.remove(target[0])
print(ans)

Measured memory_bytes: 3192
/*
* Welcome to my code!
*---------------------------------------------*
* author : lynmisakura(twitter : @andoreiji11)
*/

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size()) 
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using pl = pair<ll,ll>;
using vpl = vector<pl>;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){ int sz = a.size();
for(int i=0;i<a.size();i++)cout << a[i] << (i < sz-1 ? ' ' : '\n'); }
void ioboost(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}
///////////////////////////////////////////////////////////

int main(int argc, char const *argv[])
{
	ioboost();
	string s;cin >> s;
	if(s == "ARC")cout << "ABC" << '\n';
	else cout << "ARC" << '\n';
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main(){

  int n,a;
  cin>>n;
  long long int sum=0;
  int min=9999999999;
  int max=-9999999999;
  for(int i=0;i<n;i++){
   cin>>a;
   sum=sum+a;
   if(min>a)min=a;
   if(max<a)max=a;
 }
 cout<<min<<" "<<max<<" "<<sum<<endl;
 return 0;
}

Measured memory_bytes: 3068
#include<stdio.h>
#include<math.h>
int main(){
	double A1,A2,B1,B2,C1,C2;
	double x1,x2,x3,y1,y2,y3;
	double x,y,r;
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		A1=2*(x2-x1);
		B1=2*(y2-y1);
		C1=x1*x1-x2*x2+y1*y1-y2*y2;
		A2=2*(x3-x1);
		B2=2*(y3-y1);
		C2=x1*x1-x3*x3+y1*y1-y3*y3;
		x=(B1*C2-B2*C1)/(A1*B2-A2*B1);
		y=(C1*A2-C2*A1)/(A1*B2-A2*B1);
		r=sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));
		printf("%.3f %.3f %.3f\n",x,y,r);
	}
	return 0;
}

Measured memory_bytes: 664
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100001];
long long qs[100001];
main()
{
    int n, ans = 1;
    scanf("%d",&n);
    for(int i = 0;i < n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    qs[0] = a[0];
    for(int i = 1;i < n;i++)
        qs[i] = qs[i-1] + a[i];
    for(int i = n-2;i >= 0;i--)
    {
        if(a[i] == a[i+1]) ans++;
        else if(qs[i]*2 >= a[i+1]) ans++;
        else break;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 1280
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,M;
	int keiyu[200001]={0};
	scan(N);scan(M);
	rep(i,M){
		int x1,x2;
		scan(x1);scan(x2);
		if(x1==1) keiyu[x2]++;
		if(x2==N) keiyu[x1]++;
	}
	int flag=0;
	rep1(i,N){
		if(keiyu[i]>=2){
			flag=1;
			break;
		}
	}
	if(flag) prin("POSSIBLE");
	else prin("IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		int x;

		for (; i <= n; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}

			if (i % 10 == 3) {
				System.out.print(" " + i);
				continue;
			}

			x = i;

			while (x != 0) {
				x = x / 10;
				if (x % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
			}
		}
		System.out.println("");
	}
}

Measured memory_bytes: 28732
H = int(input())
S = []
for _ in range(H):
    S.append(input())  # S += [input()] とも書ける

print("AC x",S.count("AC"))
print("WA x",S.count("WA"))
print("TLE x",S.count("TLE"))
print("RE x",S.count("RE"))


Measured memory_bytes: 16152
# Painting Balls with AtCoDeer
N, K = map(int, input().split())
ans = 0
# i=0の色はK i<=1の色の選択肢はK-1
# K*(K-1)*(K-1)... N回積をとる

for i in range(1, N+1):
    if i == 1:
        ans = K
    else:
        ans = ans*(K-1)
print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, a[20][2], b[20], cnt[20]; 
P p[20];

ll cal(ll bit){
	zep(i, 0, n){
		p[i] = (bit & (1LL << i))? P(1, i) : P(0, i);
		b[i] = a[i][p[i].first];
	}
	sort(b, b+n);
	memset(cnt, 0, sizeof(cnt));
	
	ll res = 0;
	zep(i, 0, n){
		ll x = -1;
		zep(j, i, n){
			//cout << a[p[j].second][p[j].first] << b[i] << i << j << cnt[p[j].second] << p[j].first << endl;
			if(a[p[j].second][p[j].first] == b[i] && (j-i+cnt[p[j].second])%2 == p[j].first){
				x = j;
				break;
			}
		}
		if(x == -1){return INF;}
		
		rrep(j, x-1, i){
			cnt[p[j].second]++;
			cnt[p[j+1].second]++;
			
			P tmp = p[j];
			p[j] = p[j+1];
			p[j+1] = tmp;
			
			res++;
		}
	}
	return res;
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	zep(j, 0, 2){zep(i, 0, n){cin >> a[i][j];}}
	
	ll ans = INF;
	zep(bit, 0, (1LL << n)){
		ans = min(ans, cal(bit));
	}
	if(ans == INF){ans = -1;}
	//cal(2);
	print(ans)
	return 0;
}

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

int main(){
	string S, ans;
	cin >> S;
	if(S=="Sunny"){
		ans = "Cloudy";
	}
	else if(S=="Cloudy"){
		ans = "Rainy";
	}
	else{
		ans = "Sunny";
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

vector<ll> yakusu;

int main(void){
    ll N, M, Maxim=1;
    cin>>N>>M;
    rep1(i, sqrt(M)){
        if(M%i==0){
            if(i*N<=M) Maxim=max(Maxim, (ll)i);
            if((M/i)*N<=M) Maxim=max(Maxim, (ll)(M/i));
        }
    }
    cout<<Maxim<<endl;
    return 0;
}


Measured memory_bytes: 256
def ABC_85_B():
    N=int(input())
    d = [0 for _ in range(N)]
    c=1
    for i in range(N):
        d[i]=int(input())

    d.sort(reverse=True)

    for i in range(N-1):

        if d[i] > d[i+1]:
            c+=1
        elif d[i] == d[i+1]:
            c=c
        else:
            break

    print(c)



if __name__ == '__main__':

    ABC_85_B()

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

// 插入此處

void solve(int idx, int n, string str, int top, set<int> s) {
	if (idx == n) {
		cout << str << endl;
		return;
	};
	for (auto x : s) {
		solve(idx+1, n, str + (char)(x), top, s);
	}
	set<int> ss(s);
	ss.insert('a' + top);
	solve(idx+1, n, str + (char)('a' + top), top+1, ss);
}

int main() {
	int n; cin >> n;
	solve(0, n, "", 0, {});
	return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
pair<int, char> sCnt[26];
pair<int, char> tCnt[26];
 
vector<int> sNum;
vector<int> tNum;
 
 
bool dosth(vector<int> a, vector<int> b){
	if(a.size() != b.size()) return false;
	for(int i=0; i<a.size(); i++){
		if(a[i] != b[i]) return false;}
	return true;
}
 
 
int main() {
	string s,t;
	cin>>s>>t;
 
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
 
	for(int i=0; i<26; i++){
		sCnt[i] = {0,char(i+97)};
		tCnt[i] = {0,char(i+97)};
	}
 
	for(int i=0; i<s.length(); i++){
		int num = int(s[i]);
		sCnt[int(s[i]-'a')].first++;
		tCnt[int(t[i]-'a')].first++;
	}
 
	sort(sCnt, sCnt+26);
	sort(tCnt, tCnt+26);
 
	for(int i = 0; i<= 25;i++){
    if(sCnt[i].first) sNum.push_back(sCnt[i].first);
	} 
 
	for(int i = 0; i<= 25;i++){
    if(tCnt[i].first) tNum.push_back(tCnt[i].first);
	}
 
	sort(sNum.begin(), sNum.end());
	sort(tNum.begin(), tNum.end());
 
	bool ret = dosth(sNum, tNum);
	if(ret) cout<<"Yes";
	else cout<<"No";
 
	for(int i=0; i<sNum.size(); i++)
	return 0;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
int main(){
  int N,Q;cin>>N>>Q;
  vector<LL>A(N);
  for(int i=0;i<N;i++)scanf("%lld",&A[i]);
  if(N%2!=0){
    A.insert(A.begin(),0);
    N+=1;
  }
  A.push_back(100000000000L);
  
  vector<LL>s(N),k(N);
  s[0]=A[0];
  for(int i=1;i<N;i++)s[i]=s[i-1]+A[i];
  
  k[0]=A[0];
  for(int i=1;i<N;i++)k[i]=k[i-1]+ (i%2==0?A[i]:0);
  
  vector<LL>d(N/2);
  for(int i=0;i<N/2;i++){
    d[i]=(A[N-(N/2-i)]+A[i*2+1])/2;
  }
  
  for(int i=0;i<Q;i++){
    LL X;scanf("%lld",&X);
    vector<LL>::iterator it=lower_bound(d.begin(),d.end(),X);
    int o=(it-d.begin());
    printf("%lld\n",s[N-1]-((s[N-(N/2-o)-1]-(o*2-1<0?0:s[o*2-1])) + (o*2-1<0?0:k[o*2-1])));
  }
}


Measured memory_bytes: 4464
#include <stdio.h>
int N;
int a;
int main(){
  int i;
  int x=0;
  long long int ans=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a);
    ans=ans+(a+x)/2;
    if(a==0)x=0;
    else x=(a+x)%2;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline

def main():
    k, s = map(int, input().split())
    ans = 0
    for x in range(k+1):
        if x > s:
            break
        for y in range(k+1):
            if x + y > s:
                break
            if s - (x + y) <= k:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<stdio.h>
#include<math.h>
#define P(x) pow(double(x),2)



void c_xpypr(){


}


int main(){


	int i,j,k;
	int n;
	double x[3],y[3];
	double xp,yp,r;
	double a1,a2,b1,b2,c1,c2;
	
	while((scanf("%d",&n))!=EOF){
		for(i=0;i<3;i++){
			scanf("%lf",&x[i]);
			scanf("%lf",&y[i]);
		}
		a1=2*(x[1]-x[0]);
		a2=2*(x[2]-x[1]);
		b1=2*(y[1]-y[0]);
		b2=2*(y[2]-y[1]);
		c1=(P(x[0])-P(x[1])+P(y[0])-P(y[1]));
		c2=(P(x[1])-P(x[2])+P(y[1])-P(y[2]));
	
		xp=(b1*c2-b2*c1)/(a1*b2-a2*b1);
		yp=(c1*a2-c2*a1)/(a1*b2-a2*b1);
		r=(double)(sqrt((long double)(((xp-x[0])*(xp-x[0]))+((yp-y[0])*(yp-y[0])))));	


		printf("%.3f %.3f %.3f\n",xp,yp,r);

	}



}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

const int MAX_W = 501;
int h, w;
char C[MAX_W][MAX_W];
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};
bool memo[MAX_W][MAX_W];

struct P{
	int x, y;
	P(int x_, int y_){ x = x_; y = y_; }
};

bool search(int ax, int ay, int bx, int by){
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			memo[y][x] = false;
		}
	}
	for(int i=0 ; i < 4 ; i++ ){
		int mx = ax + dx[i];
		int my = ay + dy[i];
		while( true ){
			if( mx < 0 || my < 0 || w <= mx || h <= my ) break;
			if( C[my][mx] == '.' ){
				memo[my][mx] = true;
			}else{
				break;
			}
			mx += dx[i];
			my += dy[i];
		}
	}
	for(int i=0 ; i < 4 ; i++ ){
		int mx = bx + dx[i];
		int my = by + dy[i];
		while( true ){
			if( mx < 0 || my < 0 || w <= mx || h <= my ) break;
			if( memo[my][mx] ){
				return true;
			}else if( C[my][mx] != '.' ){
				break;
			}
			mx += dx[i];
			my += dy[i];
		}
	}
	return false;
}

int solve(){
	vector<P> v[26];
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			if( C[y][x] != '.' ){
				v[C[y][x]-'A'].push_back(P(x,y));
			}
		}
	}
	int res = 0;
	while( true ){
		bool change = false;
		for(int i=0 ; i < 26 ; i++ ){
			if( v[i].size() == 2 ){
				if( search(v[i][0].x, v[i][0].y, v[i][1].x, v[i][1].y) ){
					C[v[i][0].y][v[i][0].x] = '.';
					C[v[i][1].y][v[i][1].x] = '.';
					v[i].erase(v[i].begin(),v[i].end());
					change = true;
					res += 2;
				}
			}
		}
		if( !change ) break;
	}
	return res;
}

int main(){
	cin >> h >> w;
	for(int y=0 ; y < h ; y++ ){
		cin >> C[y];
	}
	cout << solve() << endl;
}

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

using ll = long long;

using str = string;
using ss = stringstream;

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

    str s;cin>>s;

    ll ans=0;

    for(int i=0;i<s.size();i++)
    {
        ans+=s[i]-'0';
    }

    puts(ans%9==0?"Yes":"No");

    return 0;
}


Measured memory_bytes: 3768
#include<stdio.h>
 
int main(){
    int dice[6],q,i;
    char c;
     
    for(i=0;i<6;i++){
        scanf("%d",&dice[i]);
    }
     
    scanf("%d",&q);
    for(i=0;i<q;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        if((x==dice[5] && y==dice[4])||(x==dice[4] && y==dice[0])||(x==dice[0] && y==dice[1])||(x==dice[1] && y==dice[5])){
            printf("%d\n",dice[2]);
        }else if((x==dice[0] && y==dice[2])||(x==dice[2] && y==dice[5])||(x==dice[5] && y==dice[3])||(x==dice[3] && y==dice[0])){
            printf("%d\n",dice[4]);
        }else if((x==dice[5] && y==dice[1])||(x==dice[1] && y==dice[0])||(x==dice[0] && y==dice[4])||(x==dice[4] && y==dice[5])){
            printf("%d\n",dice[3]);
        }else if((x==dice[0] && y==dice[3])||(x==dice[3] && y==dice[5])||(x==dice[5] && y==dice[2])||(x==dice[2] && y==dice[0])){
            printf("%d\n",dice[1]);
        }else if((x==dice[2] && y==dice[1])||(x==dice[1] && y==dice[3])||(x==dice[3] && y==dice[4])||(x==dice[4] && y==dice[2])){
            printf("%d\n",dice[5]);
        }else{
            printf("%d\n",dice[0]);
        }
    }
    return 0;
}

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

int main() {
	string O, E;
	cin >> O >> E;
	for (int i = 0;i < E.size();i ++) {
		cout << O[i];
		cout << E[i];
	}
	if (O.size() != E.size()) cout << O[E.size()];
}

Measured memory_bytes: 256
num = int(input())
arr = list(map(int, input().split()))

num_of_inversions = 0

def merge(arr, left, middle, right, count):
    global num_of_inversions

    L = arr[left:middle]
    L.append(float('inf'))
    R = arr[middle:right]
    R.append(float('inf'))

    offset = len(L) - 1 + left
    countL, countR = 0, 0

    iterL, iterR = iter(L), iter(R)
    l,r = next(iterL), next(iterR)

    for index in range(left, right):
        count += 1
        if l <= r:
            arr[index] = l
            l = next(iterL)
            countL += 1
        else:
            arr[index] = r
            r = next(iterR)
            num_of_inversions += countR - index + offset
            countR += 1
    return count

def merge_sort(arr, left, right, count):
    if left + 1 < right:
        pivot = (left + right) // 2
        count = merge_sort(arr, left,  pivot, count)
        count = merge_sort(arr, pivot, right, count)

        count = merge(arr, left, pivot, right, count)
    return count

_ = merge_sort(arr, 0, num, 0)
print(num_of_inversions)


Measured memory_bytes: 27480
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill((T*)array, (T*)(array+N), val);
}
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


template<typename T>
class Comb {
    ll mod = 1e9+7;
  public:
    vector<vector<T>> comb;
    vector<T> fact;
    vector<T> finv;
    vector<T> inv;
    Comb(int n){
        build(n);
    };

    void build(int n){
        inv.assign(n+1, 0);
        fact.assign(n+1, 0);
        finv.assign(n+1, 0);
        fact[0] = fact[1] = finv[0] = finv[1] = 1;
        inv[1] = 1;
        reps(i, 2, n){
            fact[i] = fact[i-1]*i % mod;
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
            finv[i] = finv[i-1]*inv[i]%mod;
        }
    }

    // return nCk
    T result(int n, int k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
    }
};

class EMaxMinSums {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n, k;
        in >> n >> k;
        vector<ll> a(n);
        rep(i, n){
            in >> a[i];
        }
        Comb<ll> comb(n);
        ll res = 0;
        sort(all(a));
        reps(i, 0, n-1){
            res += a[n-1-i] * comb.result(n-1-i, k-1);
            res -= a[i] * comb.result(n-1-i, k-1);
            res = (res + mod) % mod;
        }

        out << res << endl;
    }
};


int main() {
	EMaxMinSums solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REV(i,a,n) for(int i=a;i>=n;i--)
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin >> num_tests;
    while(num_tests-->0){
        string s,t; cin >> s >> t;
        int opera = 1e18;
        FOR(i,0,s.size() - t.size() + 1){
            int cnt = 0;
            FOR(j,i,i+t.size()){
                if(s[j] != t[j-i])
                    cnt++;
            }
            opera = min(opera,cnt);
        }
        cout << opera;
    }    
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
ll mod=1e9+7;
int main()
{
   ll n;
   cin>>n;
   vector<ll> a(n);
   for(int i=0;i<n;i++)
   cin>>a[i];
   ll ans=0;
   sort(begin(a),end(a));
   for(int i=0;i<n;i++)
   {
       for(int j=i+1;j<n;j++)
       {
           for(int k=j+1;k<n;k++)
           {
               if(a[i]!=a[j]&&a[j]!=a[k])
               {
                    if(a[i]+a[j]>a[k])
                     ans++;
               }
              
           }
       }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3632
import static java.util.Arrays.deepToString;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			char[] a = sc.next().toCharArray();
			char[] b = sc.next().toCharArray();
			if (a.length != 4) break;
			int hit = 0;
			int blow = 0;
			
			int[] aa = new int[10];
			int[] bb = new int[10];
			for (int i = 0; i < 4; i++) {
				if (a[i] == b[i]) {
					hit++;
				} else {
					aa[a[i]-'0']++;
					bb[b[i]-'0']++;
				}
			}
			for (int i = 0; i < 10; i++) blow += Math.min(aa[i], bb[i]);			
			System.out.println(hit + " " + blow);
		}
	}
}

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

using namespace std;

int main() {
  int x, y;
  cin >> x >> y;

  set<int> s1{1, 3, 5, 7, 8, 10, 12}, s2{4, 6, 9, 11}, s3{2};

  bool ok = false;
  if (s1.count(x) && s1.count(y)) {
    ok = true;
  } else if (s2.count(x) && s2.count(y)) {
    ok = true;
  } else if (s3.count(x) && s3.count(y)) {
    ok = true;
  }

  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main(){
    string S = "abcdefghijklmnopqrstuvwxyz";
    char N;
    cin >> N;

    for (int i = 0; i < 26; i++){
        if (S[i] == N){
            cout << S[i+1] << endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////

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

	pair<ll, ll> t[MAX];

	repn(i, N) cin >> t[i].first >> t[i].second;

	vector<ll> g[MAX];


	ll x[MAX] = {};
	ll y[MAX] = {};

	repn(i, N) {
		if (x[t[i].first] == 0) { x[t[i].first] = i; }
		else { 
			g[x[t[i].first]].push_back(i);
			g[i].push_back(x[t[i].first]);
		}

		if (y[t[i].second] == 0) { y[t[i].second] = i; }
		else {
			g[y[t[i].second]].push_back(i);
			g[i].push_back(y[t[i].second]);
		}
	}

	ll ans = 0;

	ll visit[MAX] = {};

	repn(v, N) {
		if (visit[v] == 1) { continue; }

		stack<ll> st;

		set<ll> xx;
		set<ll> yy;
		
		st.push(v);
		
		while (!st.empty()) {
			ll w = st.top();
			visit[w] = 1;
			st.pop();

			xx.insert(t[w].first);
			yy.insert(t[w].second);

			rep(i, g[w].size()) {
				ll u = g[w][i];
				if (visit[u] == 0) { st.push(u); }
			}
			

		}

		ans += xx.size()*yy.size();


	}

	ans -= N;

	cout << ans;


	
	system("PAUSE");
}

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

int main(){
  int n,m,i;
  int b[1000],d[1000];

  for(;;){
    cin >> n >> m;
    if(!n && !m)break;

    for(i=0;i<n;i++)cin >> b[i];
    for(i=0;i<m;i++)cin >> d[i];

    int pos = 0;
    for(i=0;i<m;i++){
      pos += d[i];
      pos += b[pos];
      if(pos>=n-1)break;
    }

    cout << i+1 << endl;
  }
}

Measured memory_bytes: 0
n = gets.chomp.to_i
d = gets.split(" ").map(&:to_i)

i = 0
j = i + 1

a = 0

while d[i]
    if d[j]
        a = a + d[i]*d[j]
        j += 1
    else
        i += 1
        j = i + 1
    end
end

puts a

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MAX = 1e6+10;
const int INF = 0x3fffffff;

int main(){
	int n,a,b;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF){
		int ans1=a*n;
		cout<<min(ans1,b)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define ITR(x, c) for(__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
int main() {
    cin>>n>>k>>x;
    rep(i,n){
        if(i<k)cout<<x;
        else if(x!=1000000000)cout<<x+1;
        else cout<<x-1;
        if(i!=n-1)cout<<" ";
        else cout<<endl;
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
int main(){
    long long n;
    long long transNum[5];

    cin >> n;
    long long min = 9223372036854775800;
    for(int i = 0; i < 5; ++i){
        cin >> transNum[i];
        if(transNum[i] < min){
            min = transNum[i];
        }
    } 

    if(n <= min){
        cout << 5;
    }else if(n%min == 0){
        cout << n/min + 4;
    }else{
        cout << n/min + 5;
    }
    cout << endl;

    
}

Measured memory_bytes: 256