akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 140010;
const int mod = 1e9+7;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n;

int l[maxn],r[maxn],v[maxn];

vector<PLL> s[maxn],tmp;

int Ans;

ll lim;

void dfs(int u){
	if(!Ans)return;
	if(!l[u]){
		s[u].push_back(MP(0,0));
		return;
	}
	int L=l[u],R=r[u];
	dfs(L);dfs(R);
	if(sz(s[L])>sz(s[R]))swap(L,R);
	if(!sz(s[L]))return;
	int now=sz(s[R])-1;
	RREP(i,sz(s[L])-1,0){
		while(~now&&s[R][now].fi+s[L][i].se+v[L]+v[R]>lim)now--;
		if(~now)s[u].PB(MP(s[L][i].fi+v[L],s[R][now].se+v[R]));
	}
	now=0;
	REP(i,0,sz(s[L])-1){
		while(now<sz(s[R])&&s[R][now].se+s[L][i].fi+v[L]+v[R]>lim)now++;
		if(now<sz(s[R]))s[u].PB(MP(s[R][now].fi+v[R],s[L][i].se+v[L]));
	}
	if(!sz(s[u])){Ans=0;return;}
	sort(s[u].begin(),s[u].end());
	tmp.clear();
	ll mx=1e18;
	for(auto x:s[u])if(x.se<mx)tmp.PB(x),mx=min(mx,x.se);
	s[u]=tmp;
}

bool check(ll M){
	REP(i,1,n)s[i].clear();
	lim=M;
	Ans=1;
	dfs(1);
	return Ans;
}

void Work(){
	check(2);
	ll l=0,r=1LL*maxn*maxn;
	while(l<r){
		int M=l+r>>1;
		if(!check(M))l=M+1;else r=M;
	}
	cout<<l<<endl;
}

void Init(){
	read(n);
	REP(i,2,n){
		int fa;
		read(fa,v[i]);
		if(l[fa])r[fa]=i;else l[fa]=i;
	}
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 28140
#include<stdio.h>

int main(){
  int H,W,i,j;
  for(;;){
    scanf("%d %d", &H,&W);
    if(H==0 && W==0) break ;
    for(j=0;j<H;j++){
      for(i=0;i<W;i++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0 ;
}



Measured memory_bytes: 2048
#include <stdio.h>

int main(){

  int n,i,j,a=0;
  int b[100],minj,x;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&b[i]);
  }
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(b[j]<b[minj]){
	minj=j;
      }
    }

    if(b[i]>b[minj]){
      a++;
    }
    x = b[minj];
    b[minj] = b[i];
    b[i] = x;
  }
  
    for(i=0;i<n-1;i++){
      printf("%d ",b[i]);
    }
    printf("%d\n",b[n-1]);
    printf("%d\n",a);

    return 0;
  }
  



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
using ll = long long;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) cin >> a[i];
    ll minus = 0;
    for (ll i = 0; i < n;i++){
        if (a[i] < 0) minus++;
    }
    ll ans = 0;
    if (minus % 2 == 0) {
        for (ll i = 0; i < n; i++) ans += abs(a[i]);
    }
    else{
        ll minn = INF;
        for (ll i = 0; i < n;i++){
            chmin(minn, abs(a[i]));
        }
        for (ll i = 0; i < n; i++) ans += abs(a[i]);
        ans -= 2 * minn;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 55+10;

int a[maxn],b[maxn],c[maxn],d[maxn],ans[maxn];

int main(){
	int n,m;
	cin >> n >> m;
	for(int i=0; i<n; i++)
		cin >> a[i] >> b[i];
	for(int i=0; i<m; i++)
		cin >> c[i] >> d[i];

	for(int i=0; i<n; i++){
		int mi=INF;
		for(int j=0; j<m; j++){
			if(abs(a[i]-c[j])+abs(b[i]-d[j]) < mi){
				mi = abs(a[i]-c[j])+abs(b[i]-d[j]);
				ans[i] = j;
			}
		}
	}
	for(int i=0; i<n; i++)
		cout << ans[i]+1 << endl;

    return 0;
}

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

using ll = long long;
const int N = 1e5L + 11;

int a[N];

int main() {
	ios :: sync_with_stdio(0);
	int n, k; cin >> n >> k;
	int g = 0, ma = 0;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
		ma = max(ma, a[i]);
		g = __gcd(g, a[i]);
	}
	if(k <= ma && k % g == 0)
		cout << "POSSIBLE\n";
	else
		cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 640
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict


S = input()

bCnt = 0
ret = 0
for s in S:
    if s == "B":
        bCnt +=1
    if s == "W":
       ret += bCnt



print(ret)


Measured memory_bytes: 4140
/*
=============================================================

------------------Welcome To My Code-------------------------

---------Ankit Kumar || IIITBH || CSE || 2018-2022-----------

=============================================================
*/

#include <bits/stdc++.h>
using namespace std;

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007
map<ll, ll>::iterator itr;
vector<ll>::iterator it, it1;
const double PI = 3.141592653589793238;

int main()
{
	FASTIO;


        ll i,j,k,x,y,z,m,n,a=1,b=1,c,c1=0,c2=0,flag=0,sum=0;

        cin>>n>>k;
        ll arr[n];
        FOR(i,n)
            cin>>arr[i];




         for(i=0;i<n;i++)
         {


             if((arr[i]<arr[i+k]))
                cout<<"Yes";

             else
                cout<<"No";

                if((i+k)==(n-1))
                break;



             nl;
         }





}


Measured memory_bytes: 5156
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll d, t, s;
    cin >> d >> t >> s;
    if(1.0*d/s <= t) Yes();
    else No();
}

Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define timer_start()                          \
  chrono::system_clock::time_point start, end; \
  start = chrono::system_clock::now();
#define timer_wrap()                                                     \
  end = chrono::system_clock::now();                                     \
  double time = static_cast<double>(                                     \
      chrono::duration_cast<chrono::microseconds>(end - start).count() / \
      1000.0);                                                           \
  printf("time %lf[ms]\n", time);                                        \
  start = end;
#define optimize_cin() \
  cin.tie(0);          \
  ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
#define INF 1000000000  // 10^9
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
// ########## template end ##########

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  vector<ll> dp(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
    dp.at(i) = pow(10, 15);
  }
#ifdef DEBUG_ON
  timer_start();
#endif
  dp.at(0) = 0;
  dp.at(1) = abs(h.at(1) - h.at(0));
  for (int i = 2; i < N; i++) {
    ll minA = pow(10, 15);
    int times = i + 1;
    if (K + 1 < times) {
      times = K + 1;
    }
    for (int j = 1; j < times; j++) {
      chmin(minA, dp.at(i - j) + abs(h.at(i) - h.at(i - j)));
    }
    dp.at(i) = minA;
  }
  cout << dp.at(N - 1) << endl;

#ifdef DEBUG_ON
  timer_wrap();
#endif
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
using namespace std;
int main()
{
	bool odev[26] = {0};
	string s;
	cin >> s;
	for(unsigned int i = 0; i < s.size(); i++){
		int n  = int(s[i] - 'a');
		odev[n] = !odev[n];
	}
	for(int i = 0; i < 26; i++){
		if(odev[i] == 1){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <bitset>
using namespace std;
long long gcd(long long a, long long b) {
	if (a < b) return gcd(b, a);
	if (b == 0) return a;
	return gcd(b, a % b);
}
bitset<1000001> bs;
vector<long long> primes;
void sieve() {
	bs.set();
	bs[0] = bs[1] = 0;
	for (long long i = 2; i <= 1000000; ++i) {
		if (bs[i]) {
			primes.push_back(i);
			for (long long j = i * i; j <= 1000000; j += i) bs[j] = 0;
		}
	}
}
int main() {
	sieve();
	long long A, B, ans = 1;
	scanf("%lld %lld", &A, &B);
	A = gcd(A, B);
	for (long long i: primes) {
		if (A % i == 0) ++ans;
		while (A % i == 0) A /= i;
	}
	if (A != 1) ++ans;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1656
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl

int main() {
  int N, K;  cin >> N >> K;
  string S; cin >> S;

  rep(i, N) {
    if (i == K-1) cout << char(S[i] + 0x20);
    else cout << S[i];
  }
}

Measured memory_bytes: 256
#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
#define int long long int
 
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A, B;
    cin >> N >> A >> B;
 
    if( A > B) {
        cout << '0' << endl;
    }
    else if( A != B && N == 1) {
        cout << '0' << endl; 
    } else {
        cout << (N-2)*(B-A) + 1 << endl;
    }
    return 0;
 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int H[100005];
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> H[i];
  }
  int ret = 0;
  int d = 0;
  for (int i=1; i<N; i++) {
    if (H[i] <= H[i-1]) {
      d++;
      ret = max(ret, d);
    } else {
      d = 0;
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
#define kd int
#define fors(i,a,b) for(int i=(a);i<=(b);++i)
inline kd read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
	return x*=f;
}
inline void write(kd x){
	if(x<0) {putchar('-');x=-x;}
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
const int maxn=1<<29;
int main(){
	register int n,m,a[61],b[61],x[61],y[61];
	n=read(),m=read();
	fors(i,1,n)
		a[i]=read(),b[i]=read();
	fors(i,1,m)
		x[i]=read(),y[i]=read();
	fors(i,1,n){
	int ans=maxn,t;
	fors(j,1,m){
		int tmp=abs(b[i]-y[j])+abs(a[i]-x[j]);
		if(ans > tmp){
			ans = tmp;
			t=j;
		}
	}
	cout<<t<<endl;
}
    return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split(' '))
ls = [0] * h
result = 0

for i in range(h):
    ls[i] = input()

for i in range(1<<h):
    for j in range(1<<w):
        cnt = 0
        for s in range(h):
            for t in range(w):
                if ((i>>s) & 1) & ((j>>t) & 1): 
                    if ls[s][t] == '#':
                        cnt += 1
        if cnt == k:
            result += 1
print(result)

Measured memory_bytes: 9008
def max2(x,y):
    return x if x > y else y

H, W = map(int, input().split())
A = []
B = []
ofs = 80*H*W
for _ in range(H):
    A.append(list(map(int, input().split())))
for _ in range(H):
    B.append(list(map(int, input().split())))
d = [[0]*W for _ in range(H)]
for h in range(H):
    for w in range(W):
        d[h][w] = abs(A[h][w]-B[h][w])

dp = [[0 for _ in range(W)] for _ in range(H)]
dp[0][0] = 1<<ofs
dp[0][0] = (dp[0][0]<<d[0][0])|(dp[0][0]>>d[0][0])
for h in range(H):
    for w in range(W):
        if h < H-1:
            dp[h+1][w] |= (dp[h][w]<<d[h+1][w])|(dp[h][w]>>d[h+1][w])
        if w < W-1:
            dp[h][w+1] |= (dp[h][w]<<d[h][w+1])|(dp[h][w]>>d[h][w+1])
res = dp[-1][-1]>>ofs
print((-res&res).bit_length()-1)

Measured memory_bytes: 598380
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        try  (Scanner scanner = new Scanner(System.in);) {
            String s = scanner.nextLine();
            int count = 0;
            boolean flag = true;
            for (int i=0; i < 4; i++) {
                String s1 = s.substring(i,i+1);
                for (int k=0; k < 4; k++) {
                    String s2 = s.substring(k,k+1);
                    if (s1.equals(s2)) {
                        count++;
                    }
                }
                if (count == 2) {
                    count = 0;
                } else {
                    System.out.println("No");
                    flag = false;
                    break;
                }
            }
            if (flag) {
                System.out.println("Yes");
            }
        }
    }

}


Measured memory_bytes: 23764
#include <iostream>
 
using namespace std;
 
#define N 500
 
int adj[N][N], use[N];
 
int main(void){
    while(1){
        int n, m;
        cin >> n >> m;
        if(n == 0 && m == 0) break;
 
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                adj[i][j] = 0;
            }
        }
        for(int i = 0; i < n; i++) use[i] = 0;

        for(int i = 0; i < m; i++){
            int a, b; cin >> a >> b;
            a--, b--;
 
            adj[a][b] = adj[b][a] = 1;
        }
 
        for(int i = 0; i < n; i++){
            if(adj[0][i] == 0) continue;

            // 0 -- i
            use[i] = 1;

            for(int j = 0; j < n; j++){

                // 0 -- i -- j
                if(adj[i][j] == 1){
                    use[j] = 1;
                }
            }
        }
 
        int res = 0;
        for(int i = 1; i < n; i++){
            if(use[i] == 1) res++;
        }
 
        cout << res << endl;
    }
 
    return 0;
}

Measured memory_bytes: 2136
N=int(input())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]

xyp=[]
xym=[]
for i in range(N):
    xyp.append(x[i]+y[i])
    xym.append(x[i]-y[i])
    
print(max(max(xyp)-min(xyp),-min(xym)+max(xym),max(xym)-min(xym),-min(xym)+max(xym)))

Measured memory_bytes: 130360
#include <iostream>

using namespace std;

int main()
{
	int M, D;
	cin >> M >> D;

	int count = 0;
	for (int m = 1; m <= M; m++) {
		for (int d = 1; d <= D; d++) {
			int d1 = d % 10;
			int d2 = d / 10;
			if (m == d1 * d2 && (d1 >= 2 && d2 >= 2)) {
				//cout << m << "/" << d << endl;
				count++;
			}
		}
	}
	cout << count << endl;
}




Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int M,N;
    int sum=0;
    cin>>M>>N;
    if(M>1)
        sum+=M*(M-1)/2;
    if(N>1)
        sum+=N*(N-1)/2;
        cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "3", "7 6 8" ].parse.expand.solve == 2 );
	assert( [ "3", "12 15 18" ].parse.expand.solve == 6 );
	assert( [ "2", "1000000000 1000000000" ].parse.expand.solve == 1000000000 );
}



import std.algorithm;
import std.conv;
import std.numeric : gcd;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	// 左からのgcd累積表を作成
	auto ls = new long[]( as.length );
	ls[ 0 ] = as[ 0 ];
	foreach( i, a; as[ 1 .. $ ] )
	{
		ls[ i + 1 ] = ls[ i ].gcd( a );
	}
	
	// 右からのgcd累積表を作成
	auto rs = new long[]( as.length );
	rs[ $ - 1 ] = as[ $ - 1 ];
	foreach_reverse( i, a; as[ 0 .. $ - 1 ] )
	{
		rs[ i ] = rs[ i + 1 ].gcd( a );
	}
	
	// aiを抜いたgcdを計算して一番大きいやつを答えにする
	auto ans = max( ls[ $ - 2 ], rs[ 1 ] );		// 端っこを抜いたやつは先にやっておく
	for( auto i = 1L; i + 1 < as.length; i++ )
	{
		ans = max( ans, ls[ i - 1 ].gcd( rs[ i + 1 ] ) );
	}
	return ans;
}


Measured memory_bytes: 7240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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

int n, f[105][15], p[105][15], cnt, ans=-(1<<30), c;


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

    cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++)cin>>f[i][j];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<11;j++)cin>>p[i][j];
	}
	for(int i=1;i<(1<<10);i++){
	    cnt=0;
		for(int j=0;j<n;j++){
		    c=0;
			for(int k=0;k<10;k++){
				if((i>>k&1)&&f[j][k])c++;
			}
			cnt+=p[j][c];
		}
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const double INF = 1e16;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    

    while(1){
    int n; cin >> n;
    if(!n) break;
    vector<double> x(n);
    vector<double> y(n);
    map<int, int> mp;
    map<int, int> inv;
    for(int i = 0; i < n; i++){
        int b;
        cin >> b >> x[i] >> y[i];
        b--;
        mp[i] = b;
        inv[b] = i;
    }
    vector<vector<double> > g(n, vector<double> (n, INF));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            double dist = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
            if(dist <= 50.0 + 1e-4) g[i][j] = dist;
        }
    }

    vector<vector<double> > org(n, vector<double> (n));
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) org[i][j] = g[i][j];
    
    /*
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cout << g[i][j] << " ";
        }
        cout << endl;
    }*/

    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                g[i][j] = min(g[i][j], g[i][k] + g[j][k]);
            }
        }
    }

    int m; cin >> m;

    for(int i = 0; i < m; i++){
        int s, t; cin >> s >> t;
        s--;
        t--;
        s = inv[s];
        t = inv[t];

        int cur = s;
        vector<int> ans;
        ans.push_back(s);
        double D = g[s][t];
        vector<int> used(n, false);
        used[s] = true;
        
        if(g[s][t] == INF){
            cout << "NA" << endl;
            continue;
        }

        while(cur != t){
            
            for(int j = 0; j < n; j++){
                if(used[j]) continue;
                
                double val = org[cur][j] + g[s][cur] + g[j][t];
                if(D - 1e-4 <= val && val <= D + 1e-4){
                    ans.push_back(j);
                    cur = j;
                    used[cur] = true;
                    break;
                }
            }

        }

        for(int i = 0; i < (int)ans.size(); i++){
            if(i + 1 == ans.size()) cout << mp[ans[i]] + 1 << endl;
            else cout << mp[ans[i]] + 1 << " ";
        }
    }

    }   

    return 0;
}



Measured memory_bytes: 3360
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  int M = N * (N - 1) / 2 - N / 2;
  cout << M << endl;
  if(N%2==0){
    for(int i=1;i<=N;i++){
      for(int j=i+1;j<=N;j++){
        if(i + j != N + 1) cout << i << " " << j <<endl;
      }
    }
  }
  if(N%2==1){
    for(int i=1;i<=N;i++){
      for(int j=i+1;j<=N;j++){
        if(i + j != N) cout << i << " " << j <<endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
void intstr(int n,char* s){
  int i,j=0;
  for(i=n?n:1;i  ;i/=10)s[++j]=0;
  for(i=n;j--;i/=10)s[j]=i%10+'0';
}
int strint(char* a){
  int n,i;
  for(i=n=0;a[i];i++)n=n*10+a[i]-'0';
  return n;
}
int main(){
  int i,n,t,max,m;
  char s[1010];
  scanf("%d",&m);
  while(m--){
    scanf("%s",s);//printf("%d\n",n);
    for(t=0;t<100000;t++){
      if(s[1]==0)break;
      for(i=n=max=0;s[i+1];i++){
	n=n*10+s[i]-'0';//printf("%d %d:",n,strint(s+i+1));
	max=MAX(max,n*strint(s+i+1));
      }//printf(":%d  ",max);
      intstr(max,s);//printf("%s\n",s);
    }
    printf("%d\n",t-100000?t:-1);
  } 
  return 0;
}

Measured memory_bytes: 596
#include "stdio.h"
#include "climits"

long long int box[3];
long long int min=LLONG_MAX;

int main() {
	scanf("%lld %lld %lld", &box[0], &box[1], &box[2]);
	if (box[0] % 2 == 0 || box[1] % 2 == 0 || box[2] % 2 == 0)	printf("0\n");
	else {
		if (min > box[0] * box[1])min = box[0] * box[1];
		if (min > box[0] * box[2])min = box[0] * box[2];
		if (min > box[2] * box[1])min = box[2] * box[1];
		printf("%lld\n",min);
	}
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	ll n;
	cin >> n;

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


	if (t.size() == 1) {
		cout << t[0] << endl;
		return 0;
	}

	ll res = t[0];
	for (int i = 0; i < n - 1; i++) {
		res = lcm(res, t[i + 1]);
	}

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

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;


int main(){
    int n;
    int b[101];
    scanf("%d", &n);
    for(int i=0; i < n - 1; i++){
        scanf("%d", b + i);
    }
    int res = 0;
    res += b[0];
    for(int i=1; i < n - 1; i++){
        res += min(b[i - 1], b[i]);
    }
    res += b[n-2];
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 128
N,M=map(int,input().split())
to=[]
fr=[]
for _ in range(M):
  A,B=map(int,input().split())
  if A==1:
    to.append(B)
  if B==N:
    fr.append(A)
print('POSSIBLE' if len(set(to) & set(fr)) else 'IMPOSSIBLE')



Measured memory_bytes: 21852
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    ll sum = 0;
    for(int i=1; i<=N; i++){
        if(i%3 and i%5) sum += i;
    }
    cout << sum << endl;
    return 0;
}


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

int main() {
    string s; cin >> s;
    string tar = "AKIHABARA";
    int i = 0, j = 0;
    while (i < (int) s.size() || j < (int) tar.size()) {
        if (i < (int) s.size() && j < (int) tar.size() && s[i] == tar[j]) {
            ++i;
            ++j;
        } else if (j < (int) tar.size() && tar[j] == 'A') {
            tar.erase(j, 1);
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << (tar == s ? "YES" : "NO");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<ll> vp;
    for (int i = 2; i <= n; i++) {
        bool ok = true;
        for (int j = 2; j < i; j++) {
            if (i % j == 0) ok = false;
        }
        if (ok) vp.push_back(i);
    }

    vector<ll> vc;
    for (auto p : vp) {
        ll cnt = 0;
        rep(i, 1, n+1) {
            ll m = i;
            while (m > 0 && m % p == 0) {
                cnt++;
                m /= p;
            }
        }
        vc.emplace_back(cnt);
    }

    ll ans = 1;
    for (auto cnt : vc) {
        ans *= (cnt + 1) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
alph = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
s = list(input())
ans = 100
for i in range(26):
    c = 0
    for j in s:
        if alph[i] == j:
            c = 1
            break
    if c == 0:
        ans = i
        break
if ans == 100:
    print("None")
else:
    print(alph[ans])

Measured memory_bytes: 3956
from collections import Counter
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(i) for i in stdin.readline().rstrip().split()]

even = []
odd = []
for i in range(n):
    if i % 2 == 0:
        even.append(a[i])
    else:
        odd.append(a[i])

even_conter = Counter(even)
odd_conter = Counter(odd)

even_sorted = even_conter.most_common()
odd_sorted = odd_conter.most_common()

even_key1 = even_sorted[0][0]
even_val1 = even_sorted[0][1]
odd_key1 = odd_sorted[0][0]
odd_val1 = odd_sorted[0][1]

ans = n
if even_key1 == odd_key1:
    if len(even_sorted) >= 2:
        even_val2 = even_sorted[1][1]
        odd_val2 = odd_sorted[1][1]
        ans -= max((even_val1 + odd_val2), (odd_val1 + even_val2))
    else:
        ans -= max(even_val1, odd_val1)
else:
    ans -= (even_val1 + odd_val1)

print(ans)


Measured memory_bytes: 23776
fun main(args: Array<String>) {

    val (n,k) = readLine()!!.split(" ").map{it.toInt()}

    var h = readLine()!!.split(" ").map{it.toInt()}
    var dp =  IntArray(n+1){1000000000}



    dp[0] = 0
    for(i in 0 until n){
        for(j in 1..Math.min(k,n-i-1)){
//                print("i $i j $j ")
//                print(dp[i+j])
//                print(" ")
//                println(dp[i] + Math.abs(h[i]-h[i+j]))
                dp[i + j] = Math.min(dp[i+j],dp[i] + Math.abs(h[i]-h[i+j]))

        }

    }
    println(dp[n-1])

}

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

int p[999999] = {-1};

int main(void)
{
	int a, d, n;

	for (int i = 2; i < 1000000; ++i)
	{
		if (p[i-1] != 0) continue;
		p[i-1] = 1;
		for (int j = i+i; j < 1000000; j += i) p[j-1] = -1;
	}

	while (cin >> a >> d >> n && a && d && n)
	{
		int m = 0, i;
		for (i = a; i < 1000000; i += d)
		{
			if (p[i-1] == 1)
			{
				++m;
				if (m == n) break;
			}
		}
		cout << i << endl;
	}
}

Measured memory_bytes: 0
from collections import deque

n, m = map(int, input().split())
eg = [[] for _ in range(n + 1)]

for _ in range(m):
    a, b = map(int, input().split())
    eg[a].append(b)
    eg[b].append(a)

xs = [0] * (n + 1)
q = deque()
q.append(1)
seen = {1}
while len(q) > 0:
    v = q.popleft()
    for t in eg[v]:
        if t in seen:
            continue
        q.append(t)
        seen.add(t)
        xs[t] = v
print("Yes")
print(*xs[2:], sep="\n")


Measured memory_bytes: 111108
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var ans = n-1;
  for(var i = 2; i*i <= n; i++){
    if(n%i === 0)ans = i+n/i-2;
  }
  return ans;
}

Measured memory_bytes: 21320
#include <bits/stdc++.h>
using namespace std;
#define N 100005
bool cmp(int k1,int k2) {
	return k1 < k2;
}
int A[N];
int main() {
	int n;
	cin >> n;
	for(int i=1; i<=n; i++) scanf("%d",&A[i]);
	sort(A+1,A+n+1,cmp);
	double Ans;
	for(int i=1; i<n; i++) {
		if(i == 1) Ans = (A[1]+A[2])/2.0;
		else Ans = (Ans+A[i+1])/2.0;
	}
	cout<<Ans;
	return 0;
}

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

#define pi acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define ps(s) printf("%s",s.c_str())
#define	inf (ll)1e15
#define mod 1000000007
#define mem(x,val) memset(x,val,sizeof x)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

using namespace __gnu_pbds;
using namespace std;

inline string str_inp(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string line_inp(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;


const int S=100100;

ll F(ll n)
{
	ll cnt=0;
	while(n>0)
	{
		ll d=__builtin_popcountll(n);
		n%=d;
		cnt++;
	}
	return cnt;
}

ll bigmod(ll b, ll p, ll m)
{
    ll ret = 1, cur = b % m;
    while( p )
    {
        if(p & 1) ret = ( ret * cur ) % m;
        cur = ( cur * cur ) % m;
        p = p >> 1;
    }
    return ret;
}


int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //#endif
	ll n;
	while(~sf("%lld",&n))
	{
		string s=str_inp(n+5);

		ll one=0;
		for(int i=0;i<n;i++)if(s[i]=='1')one++;

		ll sml=one-1;
		ll big=one+1;
		
		ll ms=0,mb=0;
		for(int i=0;i<n;i++)
		{
			if(s[i]=='1')
			{
				if(sml>=1)
				{
					ll p=bigmod(2,n-i-1,sml);
					ms=(ms+p)%sml;
				}
				ll p=bigmod(2,n-i-1,big);
				mb=(mb+p)%big;
			}
		}

		for(int i=0;i<n;i++)
		{
			ll cur=0;
			if(s[i]=='1')
			{
				if(sml==0)puts("0");
				else
				{

					ll p=bigmod(2,n-i-1,sml);
					cur=(ms-p+sml)%sml;
					pf("%lld\n",F(cur)+1);
				}
			}
			else if(s[i]=='0')
			{
				ll p=bigmod(2,n-i-1,big);
				cur=(mb+p)%big;
				pf("%lld\n",F(cur)+1);
			}
		}
	}
    return 0;
}
 






































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

int main(){
  int a;
  cin >> a;
  cout << a + a*a + a*a*a << endl;
}

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


int main(){
  int n;
  cin>>n;
  bool flag=false;
  for(int i=1;i<10;++i){
    for(int j=1;j<10;++j){
      if(n==(i*j))flag =true;

    }

  }
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

#define min(a,b) (a<b?a:b)

int main() {
	int q1, b, c1, c2, q2;
	int amax, A, B;
	while(1) {
		cin >> q1;
		if(!q1) break;
		cin >> b >> c1 >> c2 >> q2;
		amax = min(b/c1, q2);
		for(A=amax; A>0; --A) {
			B = (b-A*c1)/c2;
			if(A+B>=q1) break;
		}
		if(!A) cout << "NA" << endl;
		else cout << A << " " << B << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
using namespace std;

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;

int main()
{
	// 入力
	ll A, B, T;
	cin >> A >> B >> T;

	cout << B*(ll)( T / A) << endl;

	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, z, w; cin >> n >> z >> w;
  vi a(n);
  REP(i, n) cin >> a[i];
  if(n == 1) cout << abs(a[0] - w) << endl;
  else cout << max(abs(a[n-2] - a[n-1]), abs(a[n-1] - w)) << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()
res = 0
MOD = 10**9+7
nCk_2 = dict()
fac, finv, inv = [0]*(N+1), [0]*(N+1), [0]*(N+1)
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,N+1):
    fac[i] = fac[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD
def comb(n, k):
    return (fac[n]*((finv[k]*finv[n-k])%MOD))%MOD
s = [1,-1]
for m in range(2):
    for i in range(K-1,N):
        res = (res + s[m]*int((A[i])*comb(i,K-1)))%MOD
    A = sorted(A, reverse=True)
print(res)


Measured memory_bytes: 20304
#include<bits/stdc++.h>
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
const long long lim = 2e5+100;
typedef long long int lld;
typedef long long ll;

#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define mset(a, v) memset(a, v, sizeof(a))
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
 
 
#define popcount __builtin_popcountll
 
ll powP(ll x, ll y) {
    ll ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}


vector<ll> Ans, Adj[lim];
ll Array[lim], C[lim],dp[600][600];
pair<ll,ll> P[lim];

ll f(ll a,ll b) {
    // Error(a,b);
    ll x=min(a,b), y = max(a,b);
    if(y==x) return x;
    if(y%x==0) return 2*y-x;
    return 2*x*(y/x) + f(x,y%x);
}

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    
    lld T,i,p,j,l,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum=0,val,countA=0,indicator=0,pos,h,minA,maxA,type,n,ans=0,left,right;
    string A,B;
    cin>>n>>x;
    cout<<n+f(x,n-x)<<endl;
    // Error(f(2,3),f(2,1));
    return 0;
}
    


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

int main() {
    string s, p; cin >> s >> p;
    int loop = s.size() - 1;
    s += s;
    string ans = "No";
    
    for (int i = 0; i <= loop; ++i) if (s.substr(i, p.size()) == p) ans = "Yes"; 
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3224
from collections import deque

N=int(input())
d=deque()
S=list(map(int,input().split()))

revflag=False

for i in range(N):
    if revflag==False:
        d.append(S[i])
        revflag=True
    else:
        d.appendleft(S[i])
        revflag=False
    
if revflag==True:
    d.reverse()

Z=list(d)
Z=[str(a) for a in Z]
Z=" ".join(Z)
print(Z)


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{
    lint n, m;
    cin >> n >> m;

    lint ans;

    ans = n * m;
    if(n>9||m>9){
        ans = -1;
    }

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long ans = 0L;
        int count = 0;

        while(true){
            long und = (long)Math.pow(2,count);
            ans += und;

            if(h/und <= 1L)
                break;

            count++;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n;
    cin>>n;
    if(n==1){
        cout<<0;
        return 0;
    }
    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    ll tam=a[0],rs=0;
    for(ll i=1;i<n;i++ ){
        if(a[i]<tam) rs+=(tam-a[i]);
        else tam=a[i];
    }
    cout<<rs;
    return 0;
}


Measured memory_bytes: 5192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int n,m,q;
int a[60],b[60],c[60],d[60];
ll ans=0;

void dfs(vector<int> &A){
    if(A.size()==n){
        ll tmp=0;
        rep(i,q){
            if(A[b[i]]-A[a[i]]==c[i]) tmp+=d[i];
        }
        ans=max(ans,tmp);
        return;
    }

    int x=(A.empty() ? 1 : A.back());
    for(int i=x;i<=m;i++){
        A.push_back(i);
        dfs(A);
        A.pop_back();
    }

}

int main(){
    cin>>n>>m>>q;
    rep(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--,b[i]--;
    }

    vector<int> A;
    dfs(A);

    cout<<ans<<endl;

}




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

class Program {
    static Scanner sc = new Scanner();

    internal static void Main(string[] args) {
        var N = sc.nextInt();
        var lst = new List<int>();
        for (int i = 0; i < N; i++) {
            lst.Add(sc.nextInt());
        }
        lst = lst.OrderBy(i => i).ToList();

        while (lst.Count > 0 && lst.Sum() % 10 == 0) {
            var min = lst.Min();
            for (int i = 0; i < lst.Count; i++) {
                if (lst[i] % 10 != 0) { 
                    min = lst[i];
                    break;
                }
            }
            lst.Remove(min);
        }

        WriteLine(lst.Sum());
    }
}




class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13396
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n,m,x=map(int,input().split())
    L=[list(map(int,input().split())) for i in range(n)]
    val=10**10

    # bit全探索    
    # https://qiita.com/gogotealove/items/11f9e83218926211083a#%E4%BE%8B%E9%A1%8C-1
    for i in range(2 ** n):
        ans=[0]*m
        cnt=0
        for j in range(n):  # このループが一番のポイント
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                cnt+=L[j][0]
                for k in range(1,m+1):
                    ans[k-1]+=L[j][k]
        flag=True
        for l in range(m):
            if ans[l]<x:
                flag=False
                break
        if flag==True:
            val=min(val,cnt)
        
    if val==10**10:
        print(-1)
    else:
        print(val)
    

    
resolve()

Measured memory_bytes: 68812
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int n,m;
cin >> n >> m;
vector<bool>che(n,false);
vector<int>wan(n,0);
int ac=0,wa=0;
for(int i=0;i<m;i++){
	int z;
	string t;
	cin >> z >> t;
	z--;
	if(!che.at(z)&&t=="WA"){
		wan.at(z)++;
	}
	if(!che.at(z)&&t=="AC"){
		ac++;
		che.at(z)=true;
		wa+=wan.at(z);
	}
}
cout << ac <<" "<<wa<<endl;
}





Measured memory_bytes: 640
h1,m1,h2,m2,k = map(int,input().split())

H = h2-h1

if(m2-m1<0):
    M = 60 + m2 -m1
    H -=1
else:
    M = m2-m1

time = 60*H+M

if time <= k:
    print(0)
else:
    print(time-k)

Measured memory_bytes: 9176