akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N; cin >> N;
  vector<int> a(N);
  map<string, int> score;
  for(int i = 0; i < N; i++) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  for(int i = 0; i < N; i++) {
    if(i % 2 == 0) score["Alice"] += a[i];
    else score["Bob"] += a[i];
  }
  cout << (score.at("Alice") - score.at("Bob")) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char w[100];int len;int n[33];
int main()
{
	scanf("%s",w);
	len=strlen(w);
	int value;
	for(int i=0;i<len;i++)
	{
		value=w[i]-'a';
		if(value>=0)n[value]++;
	}
	int ans=1;
	for(int i=0;i<26;i++)
	{
		if(n[i]%2==1)ans=0;
	}
	if(ans==1)printf("Yes");
	else printf("No");
}

Measured memory_bytes: 128
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var N = parseInt(input[0]);
  var output = 0;
  for(var i = 1; i <= N; i++){
    var l = input[i].split(" ")[0];
    var r = input[i].split(" ")[1];
    output += (r - l) + 1;
  }
  myout(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    if (n <= k) {
        cout << 0 << endl;
        return 0;
    }
    vector<ll> h(n);
    rep (i, n) cin >> h[i];
    sort(h.rbegin(), h.rend());
    ll sum = 0;
    FOR (i, k, n) sum += h[i];
    cout << sum << endl;
    
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

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

int goods[1010];

int main(){
	while(1){
		int n,m;
		cin >> n >> m;
		if(n + m == 0) break;
		for(int i = 0;i < n;i++){
			cin >> goods[i];
		}
		int ans = -1;
		for(int i = 0;i < n;i++){
			for(int j = i + 1;j < n;j++){
				if(goods[i] + goods[j] <= m){
					ans = max(ans,goods[i] + goods[j]);
				}
			}
		}
		if(ans == -1){
			cout << "NONE" << endl;
		}else{
			cout << ans << endl;
		}
	}

}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int a,b,c,res=3;
    cin >> a >> b >> c;
    if(a==b||b==c||a==c)res=2;
    if(a==b&&b==c)res=1;
    cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>

int main() {
    long l[100];
  	int n;
    scanf("%d",&n);
    for (int i=0;i<n;i++) {
        scanf("%ld",&l[i]);
    }
    int result=0;
    for (int i=0;i<n;i++) {
        for (int j=i+1;j<n;j++) {
            for (int k=j+1;k<n;k++) {
                if (l[i]==l[j]||l[j]==l[k]||l[i]==l[k]) continue;
                else {
                    long longest=l[i];
                    long other1=l[j];
                    long other2=l[k];
                    if(l[i]>l[j]&&l[i]>l[k]) {
                        ;
                    }
                    else if(l[j]>l[i]&&l[j]>l[k]) {
                        longest=l[j];
                        other1=l[i];
                    }
                    else if(l[k]>l[j]&&l[k]>l[i]) {
                        longest=l[k];
                        other2=l[i];
                    }
                  	
                    if (longest<other1+other2) result++;
                }
            }
        }
    }
  	printf("%d",result);
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  ll x = 0;
  cin >> x;
  ll now = 0;
  for(int i = 0;i < n;i++){
    ll in = 0;
    cin >> in;
    now += in;
    if(now > x){
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << n + 1 << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N>>K;
    ll last, ans = 0;
    cin>>last;
    rep(i,N-1){
        cin>>A;
        ans += min(A - last, K);
        last = A;
    }
    ans += K;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(n**0.5)+2):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(i)
 
    if temp!=1:
        arr.append(temp)
 
    if arr==[] and n != 1:
        arr.append(n)
 
    return arr
 
a, b = map(int, input().split())
 
an = set(factorization(a))
bn = set(factorization(b))
print(len(an&bn) + 1)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <utility>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <cctype>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
//#define pq priority_queue
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
#define init(x) memset(x,0,sizeof(x))
int n,k;
int a[100005];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for (int i=1;i<=n;++i){
		cin>>a[i];
	}
	cout<<ceil((n-1)/(float)(k-1));
	return 0;
}

Measured memory_bytes: 640
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int a, b;
    scan(a, b);
    writeln((a-1)*(b-1));
}


























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> s = a;
    sort(s.rbegin(), s.rend());
    rep(i, n)
    {
        int ans = s[0];
        if (s[0] == a[i])
            ans = s[1];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include<iostream>
using namespace std;
int main(){
  string s;
  cin>>s;
  int k=s.size()-1,z=-1,a=-1;
  bool flag1=true;
  bool flag2=true;
  for(int i=0;i<s.size();){
    if(s[i]=='A'){
      a=i;
      flag1=false;
    }
    if(s[k]=='Z'){
      z=k;
      flag2=false;
    }
    if(flag1) i++;
    if(flag2) k--;
    if(flag1==false && flag2==false) break;
  }
  cout<<z-a+1;

}


Measured memory_bytes: 640
while True:
    a = list(map(int,input().split()))
    if a[0] == 0 and a[1] == 0 :
        break
    else:
        if a[0] < a[1]:
            print("%d %d"%(a[0],a[1]))
        else:
            print("%d %d" % (a[1], a[0]))



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

int main(){
    int a, b;
    cin >> a >> b ;

    // string ans;
    if(a <= 8 && b <= 8){
        // ans = "Yey!";
        cout << "Yay!" << endl;
    }else{
        // ans = ":(";
        cout << ":(" << endl;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin >> S; 

    int mlong=0;
    for(int i=0; i<S.size(); i++){
        int count=0;
        for(int j=0; i+j<S.size(); j++){
            if(S.at(i+j) == 'A' || S.at(i+j) == 'T' || S.at(i+j) == 'G' || S.at(i+j) == 'C'){count++;}
            else{
                break;
            }
        }
        mlong = max(mlong, count);
    }
    cout << mlong << endl;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())

for i in range(Y // 10000 + 1):
    for j in range((Y - 10000 * i) // 5000 + 1):
        k = N - i - j
        if 10000 * i + 5000 * j + 1000 * k == Y:
            print(i, j, k)
            exit()
else:
    print(-1, -1, -1)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)1e5 + 100;
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

string s;
bool was[maxn];
void solve(){
	cin >> s;
	if(sz(s) == 26){
		string nxt = s;
		if(!next_permutation(all(nxt))){
			cout << -1;
			return;
		}
		//next_permutation(all(nxt));
		forn(i, 0, sz(nxt) - 1){
			if(nxt[i] > s[i]){
				forn(j, 0, i) cout << nxt[j];
				return;
			}
		}
		cout << -1;
	}else{
		for(auto x : s) was[x - 'a'] = 1;
		cout << s;
		forn(i, 0, 25) 
			if(!was[i]){
				putchar(i + 'a');
				return;
			}
	}
}

int main () {
  solve();
}





Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const long long mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define rep2(i,x,n) for(int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vvl = vector<vl>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k; 
ll INF = 10000000000000000;



int main(){
    vector<string> hon={"pon","pon","hon","bon","hon","hon","pon","hon","pon","hon"};
    int N;
    cin >>N;
    cout <<hon[N%10]<<endl;
}

Measured memory_bytes: 3632
def make_divisors(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors


n=int(input())
A=make_divisors(n)

ans=0
for m in A[1:]:
    m -=1
    if int(n/m)==n%m:
        ans +=m
print(ans)


Measured memory_bytes: 39408
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    ll n,k;
    ll a[100010];
    std::cin >> n>>k;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    ll index = distance(a,lower_bound(a,a+n,0));
    if(index == n){
        std::cout << abs(a[n-k]) << std::endl;
        return 0;
    }
    ll l = 0;
    ll r = 0;
    if(a[index] == 0){
        l = index;
        r = n - index-1;
        index++;
        k--;
    }else{
        l = index;
        r = n - index;
    }
    ll rs[100010];
    ll ls[100010];
    rs[0] = 0;
    for (int i = 0; i < r; i++) {
        rs[i+1] = a[index+i];
    }
    ls[0] = 0;
    for (int i = 0; i < l; i++) {
        ls[i+1] = abs(a[l-i-1]);
    }
    ll result = 1e9;
    for (int i = 0; i <= k; i++) {
        ll tl = i;
        ll tr = k-i;
        
        if(tl <= l && tr <= r){
            result = min(result,2*min(rs[tr],ls[tl])+max(rs[tr],ls[tl]));
        }
    }
    std::cout << result << std::endl;
}

Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll n;
	cin>>n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	vector<ll> b(n); //b[i] = a[i]-a[i+1]
	for(int i = 0; i < n; i++){
		if(i==n-1)b[i] = a[n-1]-a[0];
		else b[i] = a[i]-a[i+1];
	}

	ll sum=accumulate(all(a),(ll)0);
	if(2*sum % (n*(n+1)) != 0){
		cout << "NO" << endl;
		return 0;
	}

	ll cnt = 2*sum / (n*(n+1));

	vector<ll> c(n,-cnt);
	ll res = 0;
	for(int i = 0; i < n; i++){
		if(c[i]-b[i]<0 && (c[i]-b[i]) % n == 0) res += abs((c[i]-b[i])/n);
	}

	cout << (res==cnt?"YES":"NO")<<endl;

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <map>
int main(){
	int n;
	std::cin >> n;
	std::string s;
	while(n--){
		std::cin >> s;

		if(s.size() == 1){
			std::cout << s << std::endl;
			continue;
		}

		int pos = 0;
		while(pos = s.find("-", pos), pos != std::string::npos){
			s.replace(pos, 1, "");
		}

		std::map<char, char> m, rm;
		for(int i=1;i<s.size();i+=2){
			if(s[i] == '>')
				m[s[i+1]] = s[i-1], rm[s[i-1]] = s[i+1];
			else
				m[s[i-1]] = s[i+1], rm[s[i+1]] = s[i-1];
		}

		char end = (*m.begin()).first;
		while(m[end] != '\0'){
			end = m[end];
		}
		//whileI¹_ÅendÍstartÆÈé

		while(rm[end] != '\0'){
			std::cout << end;
			end = rm[end];
		}
		std::cout << end << '\n';
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define pb push_back
#define Int int64_t
using namespace std;

Int N,K;

int main()
{
    cin>>K;
    string S;cin>>S;
    for(int i=0;i<S.length();++i){
        cout<<char(((S[i]-'A')+K)%26+'A');
    }
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> v(n), c(n), d(n);
	for (int i = 0; i < n; i++)
		cin >> v.at(i);
	for (int i = 0; i < n; i++)
		cin >> c.at(i);
	int ans = 0;
	for (int i = 0; i < n; i++)
		if (v.at(i) - c.at(i) > 0)
			ans += v.at(i) - c.at(i);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-10;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


//ここから編集

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int H, W, K; cin >> H >> W >> K;

  vector<string> f(H);
  REP(i,H){
    cin >> f[i];
  }

  int ans = 0;
  for(int h=0; h<(1<<H); h++){

    auto a = f;

    for(int i=0; i<H; i++){
      if(h >> i & 1){
        for(int j=0; j<W; j++){
          a[i][j] = '?';
        }
      }
    }
    for(int w=0; w<(1<<W); w++){
      auto b = a;
      for(int i=0; i<W; i++){
        if(w >> i & 1){
          for(int j=0; j<H; j++){
            b[j][i] = '?';
          }
        }
      }
      int cnt = 0;
      for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
          if(b[i][j] == '#') cnt++;
        }
      }
      if(cnt == K) ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <map>

using namespace std;

int n, b, c, d;
map <int, int> M;

int main()
{
	cin >> n;
	
	for(int i=1; i <= n; i++)
		cin >> c, M[c]++;
	
	for(auto i: M) {
		int a = i.second;
		while(a > 2)
			a -= 2;
		
		if(a == 2) {
			if(d%2 == 0)
				b++;
			else
				b--;
			d++;
		}
	}
	
	cout << M.size()-b;
}
/*
15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1
*/

Measured memory_bytes: 4864
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=s-1; i>=s; i--)

int main(){

    int x, y, z, k;
    cin >> x >> y >> z >> k;

    ll a[x], b[y], c[z];
    priority_queue<ll> pq;
    rep(i, x){
        cin >> a[i];
    }
    rep(i, y){
        cin >> b[i];
    }
    rep(i, z){
        cin >> c[i];
    }

    sort(a, a+x, greater<ll>());
    sort(b, b+y, greater<ll>());
    sort(c, c+z, greater<ll>());
    
    vector<ll> vab;
    rep(ia, x){
        rep(ib, y){
            vab.push_back(a[ia]+b[ib]);
        }
    }

    sort(vab.begin(), vab.end(), greater<ll>());

    rep(iab, min(k, (int)vab.size())){
        rep(ic, z){
            pq.push(vab[iab]+c[ic]);
        }
    }
    

    rep(i, k){
        cout << pq.top() << endl;
        pq.pop();
    }

    return 0;
}

Measured memory_bytes: 43108
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, m, l, r, u, v, cnt;
bool used[100005], b[200005];
P p[100005];
vector<P> G[100005];
int dfs(int u){
	int ret = p[u].second != (u ? p[u-1].second : 0);
	used[u] = true;
	for(P nx: G[u]) if(!used[nx.first]){
		int tmp = dfs(nx.first);
		if(tmp % 2){
			cnt++;
			b[nx.second] = true;
		}
		ret += tmp;
	}
	return ret;
}
int main(){
	scanf("%d%d", &n, &m);
	rep(i,n) scanf("%d%d", &p[i].first, &p[i].second);
	sort(p,p+n);
	rep(i,m){
		scanf("%d%d", &l, &r);
		u = lower_bound(p,p+n,P{l,0}) - p;
		v = upper_bound(p,p+n,P{r,2}) - p;
		G[u].push_back({v,i+1});
		G[v].push_back({u,i+1});
	}
	rep(i,n) if(!used[i] && dfs(i) % 2) return puts("-1")*0;
	printf("%d\n",cnt);
	rep(i,m+1) if(b[i]) printf("%d ", i);
}

Measured memory_bytes: 13568
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
ll S;
ll inf=1e+9;
void solve(){
  ll X1=0,Y1=0;
  ll X2=inf,Y2=1;
  ll Y3=(S+inf-1)/inf,X3=inf*Y3-S;
  cout<<X1<<" "<<Y1<<" "<<X2<<" "<<Y2<<" "<<X3<<" "<<Y3<<"\n";
}
int main(){
  cin>>S;
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        LOOP: while(true) {
            int a = scanner.nextInt();
            String op = scanner.next();
            int b = scanner.nextInt();
            int result;
            switch (op) {
                case "+":
                    result = a + b;
                    break;
                case "-":
                    result = a - b;
                    break;
                case "*":
                    result = a * b;
                    break;
                case "/":
                    result = a / b;
                    break;
                default:
                    break LOOP;
            }
            System.out.println(result);
        }
        scanner.close();
    }
}



Measured memory_bytes: 26420
MOD = 1000000007
def fib(n)
	#return n+1>>1 if n<4
	return ((0.5+Math.sqrt(5)*0.5)**n/Math.sqrt(5)).round % MOD if n<70
	nb = n.bit_length-6;a=((0.5+Math.sqrt(5)*0.5)**(n>>nb)/Math.sqrt(5)).round;b=(a+a*Math.sqrt(5)).round>>1
	(nb-1).downto(0){|m|a,b=a*(2*b-a)%MOD,(b*b+a*a)%MOD;a,b=b,a+b if (n>>m).odd?}
	return a
end

def mypow(a,m)
	return a**m%MOD if m<4;c,res=a,1;while(m>0);res=res*c%MOD if m.odd?;c,m=c*c%MOD,m>>1;end;return res
end

N, M = gets.split.map(&:to_i)
exit p(0) if M*2 > N
res = 1
$<.map(&:to_i).unshift(-1).push(N+1).each_cons(2).map{|x,y|y-x}.group_by(&:pred).each{|x,y|res=res*mypow(fib(x),y.size)%MOD}
p res


Measured memory_bytes: 3196
N, M = map(int, input().split())
H = [int(i) for i in input().split()]
HP = [0] * N
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    if H[A] > H[B]:
        HP[B] += 1
    elif H[A] < H[B]:
        HP[A] += 1
    else:
        HP[A] += 1
        HP[B] += 1

print(HP.count(0))

Measured memory_bytes: 85136
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n = iter.next().unwrap();
    let a = iter.next().unwrap();
    let b = iter.next().unwrap();
    let s = a
        .chars()
        .zip(b.chars())
        .map(|(x, y)| x.to_string() + &y.to_string())
        .collect::<String>();
    println!("{}", s);
}


Measured memory_bytes: 4352
package main

import "fmt"

const MOD = 1e9+7

type Vertex struct {
  label int
  white, black int64
  adj []*Vertex
}

func (v *Vertex) add(u *Vertex) {
  v.adj = append(v.adj, u)
}

func main() {
  var n int
  fmt.Scanf("%d", &n)
  vertexs := make([]*Vertex, n)
  for i := 0; i < n; i++ {
    vertexs[i] = &Vertex{i, 0, 0, nil}
  }
  for i := 1; i < n; i++ {
    var x, y int 
    fmt.Scanf("%d %d", &x, &y)
    x, y = x-1, y-1
    vertexs[x].add(vertexs[y])
    vertexs[y].add(vertexs[x])
  }
  postOrder(vertexs[0], nil)
  fmt.Println((vertexs[0].white + vertexs[0].black) % MOD)
}

func postOrder(current, parent *Vertex) {
  var allWhite, total int64
  allWhite, total = 1, 1
  childCnt := 0
  for i := 0; i < len(current.adj); i++ {
    if current.adj[i] == parent { continue }
    child := current.adj[i]
    postOrder(child, current)
    allWhite *= child.white
    total *= (child.black + child.white)
    allWhite %= MOD
    total %= MOD
    childCnt++
  }
  if childCnt == 0 {
    // no child, only parent, so leaf
    current.white, current.black = 1, 1
  } else {
    current.white = total
    current.black = allWhite
  }
}

Measured memory_bytes: 28864
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int m = sc.nextInt();
			int c = sc.nextInt();
			int n = sc.nextInt();

			if ((m | c | n) == 0) {
				break;
			}

			int[][] qq = new int[n][];

			int sz = 0;
			int maxx = 0;
			for (int i = 0; i < n; i++) {
				int x = sc.nextInt();
				qq[i] = new int[x];
				for (int j = 0; j < x; j++) {
					qq[i][j] = sc.nextInt();
				}
				maxx = Math.max(x, maxx);
				sz += x;
			}

			int[] q = new int[sz];
			int cnt = 0;
			for (int j = 0; j < maxx; j++) {
				for (int i = 0; i < n; i++) {
					if (qq[i].length <= j) {
						continue;
					}
					q[cnt] = qq[i][j];
					cnt++;
				}
			}

			int map[] = new int[100];

			LinkedList<Integer> l = new LinkedList<Integer>();

			int smp[] = new int[m + 2];

			Arrays.fill(smp, c);
			smp[m + 1] = 1000;

			int cost = 0;
			for (int i = 0; i < sz; i++) {

				// get
				if (map[q[i]] == 0) {
					cost += m + 1;
				} else {
					if (map[q[i]] == 1) {
						l.remove((Integer) q[i]);
					}
					cost += map[q[i]];
					smp[map[q[i]]]++;
				}

				l.addFirst(q[i]);
				map[q[i]] = 1;

				if (l.size() > c) { // swap
					int j = 2;
					int k;
					for (; smp[j] == 0; j++)
						;
					smp[j]--;

					k = j;
					int v = l.pollLast();

					cost += k; // put k temp

					cost += 1; // remove 1
					for (; smp[j] == 0; j++)
						;
					smp[j]--;

					cost += j; // 1 to j
					map[v] = j;

					cost += k; // k to 1;
					cost += 1;
					
					smp[k]++;
				} else {
					cost += 1;
				}
				// return
			}
			System.out.println(cost);
		}
	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
ll h;
ll left(ll k){
  k = k * 2 + 1;
  return k;
}
ll right(ll k){
  k = k * 2 + 2;
  return k;
}
void maxheapify(vector<ll> &vec,ll k){
  ll largest;
  ll l = left(k);
  ll r = right(k);
  //cout << l << " " << h-1 << " " << k << endl;
  //左の子、自分、右の子で値が最大のノードを選ぶ
  if(l <= h-1 && vec[l] > vec[k]){
    largest = l;
  }else{
    largest = k;
  }
  if(r <= h-1 && vec[r] > vec[largest]){
    largest = r;
  }

  if(largest != k){
    swap(vec[k],vec[largest]);
    maxheapify(vec,largest);
  }
}
int main(){
  cin >> h;
  vector<ll> vec(h);
  rep(i,h){
    cin >> vec[i];
  }
  rep_rev(i,h){
    maxheapify(vec,i);
  }
  rep(i,h){
    cout << " " << vec[i];
  }
  cout << endl;
}


Measured memory_bytes: 6712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
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; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
const int MOD = 1000000007;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

int main(){
   ll n;cin>>n;
   VI a(n);
   rep(i,n)cin>>a[i];
   bool possible=true;
   if(a[0]>0)possible=false;
   rep(i,n-1)if(a[i+1]-a[i]>1 ||a[i]>i ||a[i+1]>i+1)possible=false;
   if(!possible){
      cout<<-1<<endl;
      return 0;
   }
   ll ans=0;
   rep(i,n-1){
      if(a[i+1]==a[i]+1)continue;
      ans+=a[i];
   }
   ans+=a[n-1];
   cout<<ans<<endl;
}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
int main()
{
    int n;
    cin >> n;
    map<ll,int> mp;
    mp.emplace(0,1);
    ll ans = 0;
    vector<ll> a(n+10,0); 
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        a[i] += a[i-1];
        ans += mp[a[i]];
        mp[a[i]]++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


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

  c_fac();
  ll result = 0, pm = 1;
  rep(i,N+1) {
    // cout << pm * fac[M-i] * inv(fac[M-N]) * nck(N,i) % MOD << endl;
    ll t = fac[M-i] * inv(fac[M-N]) % MOD * nck(N,i) % MOD;
    result = (result + pm * t + MOD ) % MOD;
    pm *= -1;
  }
  result = result * ( fac[M] * inv(fac[M-N]) % MOD ) % MOD;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 11124
import sys
import math
import collections
import decimal
from collections import deque
from functools import reduce
import heapq
#n = int(input())
a, b = map(str, sys.stdin.readline().split())
#n = input()
#a = list(map(int, sys.stdin.readline().split()))

x = int(a)
y = decimal.Decimal(b)
        
print(math.floor(x*y))


Measured memory_bytes: 10180
// <=k を考えて差分。long long にしないと死ぬ。
#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

// a+b=k-1
// a+2b=n-2
// b = n-k-1
// a = 2k-n
// (k-1)!/(2k-n)!(n-k-1)!

using ll = long long;
constexpr int MAX_N = 1000001;
constexpr ll mod = 1000000007;

int N;
ll fact[MAX_N], inv[MAX_N];
ll f[MAX_N];

ll powMod( ll x, ll y )
{
    ll ret = 1;

    while( y > 0 )
    {
        if( y & 1 )
            ret = (ret * x) % mod;

        y >>= 1;
        x = (x*x)%mod;
    }

    return ret;
}

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

    fact[0] = 1;
    rep( i, N )
        fact[i+1] = fact[i]*(i+1)%mod;

    rep( i, N+1 )
        inv[i] = powMod( fact[i], mod-2 );

    // (k-1)!/(2k-n)!(n-k-1)!
    repi( k, 1, N )
        f[k] = fact[k-1]*inv[2*k-N]%mod*inv[N-k-1]%mod*fact[k]%mod*fact[N-k-1]%mod;

    ll ans = 0;
    repi( k, 1, N )
        ans = (ans + (f[k]-f[k-1])*k%mod) % mod;

    while( ans < 0 )
        ans = (ans+mod)%mod;

    printf( "%lld\n", ans );

    return 0;
}

Measured memory_bytes: 23552
//PKMKB
#include <bits/stdc++.h>
#define ll long long int
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define scanarr(a,b,c) for( i=b;i<c;i++)cin>>a[i]
#define showarr(a,b,c) for( i=b;i<c;i++)cout<<a[i]<<' '
#define ln cout<<'\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define MAX 100005
using namespace std;
////////////////////////////////////////////////////////////////CODE STARTS HERE////////////////////////////////////////////////////////////////

void solve(){
    
    int n, k;

    cin >> n >> k;
    vector <int> arr(n);

    for(int i = 0; i < n; ++i)
        cin >> arr[i];
    
    sort(arr.begin(), arr.end());

    ll sum = 0;

    for(int i = 0; i < k; ++i)
        sum += arr[i];
    
    cout << sum << endl;
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    
        solve();
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main() {
    int H, N, Ai, sum=0;
    cin>>H>>N;
    while(N--) {
        cin>>Ai;
        sum+=Ai;
    }
    if (sum>=H) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
    return 0;
}




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

using namespace std;


int check(int *a){
  int s = 0;//s=0なら全てが揃った
  for(int i = 1;i < 10;i++){
    s += a[i];
  }
  return s;
}


void solve(int *a,int n,int ans[10]){
  if(check(a) ==0){//完成した
    ans[n] = 1;
    return;
  }
  for(int i = 1;i <= 7;i++){//まずは順子から探す
    if(a[i]&&a[i+1]&&a[i+2]){
      a[i]--;
      a[i+1]--;
      a[i+2]--;
      solve(a,n,ans);
      a[i]++;
      a[i+1]++;
      a[i+2]++;
    }
  }
  for(int i =1;i <=9;i++){//暗刻を探す
    if(a[i] >=3){
      a[i] -=3;
      solve(a,n,ans);
      a[i] +=3;
	}
    }

}

int main()
{
  string s;
  while(cin >>s){
    int useDigit[10] = {0};//いくつ使用したかどうか記憶
    int ans[10] = {0};

    if(s.length() !=13){
      continue;
    }
    for(int i = 0;i < 13;i++){
    useDigit[s[i]-'0']++;
    }
  
  for(int i = 1;i <=9;i++){
    if(useDigit[i] >=4){
      continue;
    }else{
      useDigit[i]++;
      for(int j = 1;j <=9;j++){//ペアが出来るかどうか判定をして暗刻と順子を探す
	if(useDigit[j] >=2){
	  useDigit[j] -=2;
	  solve(useDigit,i,ans);
	  useDigit[j] +=2;
       }
      }
      useDigit[i]--;
    }
  }
  bool flag = false;
  int Count = 0;
  for(int i =1;i <=9;i++){
    if(ans[i]){//ans[i]が1なら成功
      Count++;
      flag = true;
    }
  }
  if(!flag){
    cout << 0 <<endl;
  }else{
    for(int i = 1;i <=9;i++){
      if(ans[i] ==1){
	cout <<i;
	if(--Count)
	  cout <<" ";
      }
    }
    cout <<endl;
  }
  }
  return 0;
}

Measured memory_bytes: 1184
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

map<int,int> vis;

int main(){
    int n;
    cin >> n;
    rep(i,0,n){
        int x;
        cin >> x;
        rep(d,-1,2) vis[x+d]++;
    }
    int Mx = 0;
    for(auto e : vis) Mx = max(Mx , e.se);
    cout << Mx << endl;
    return 0;
}


Measured memory_bytes: 4736
L,R = [int(i) for i in input().split()]
if R - L > 2019:
    print(0)
    exit()
else:
    li = list(range(L,R+1))
    n = len(li)
ans = 10**9+7
for i in range(n-1):
    for j in range(i+1,n):
        count = (li[i]*li[j]) % 2019
        ans = min(ans,count)
        if ans == 0:
            print(0)
            exit()
print(ans)

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

int main() {
	int a,b,k;
	cin >> k >> a >> b;
	bool flag = false;
	for(int i = a; i <= b; i++) {
		if(i % k == 0) {
			flag = true;
			break;
		}
	}
	if(flag) cout << "OK" << endl;
	else cout << "NG" << endl;
}

Measured memory_bytes: 3632
s = input()
d_memo = [chr(i) for i in range(97, 97+26)]
s_memo = set(list(s))

def next_c(sub_s, b_c):
    c = None
    for d in d_memo:
        if d not in set(list(sub_s)):
            if d > b_c:
                c = d
                break
    return c

if len(s) < len(d_memo):
    c = next_c(s, '')
    ans = s+c
else:
    b_c = ''
    ans = None
    for i in range(len(s)+1):
        c = next_c(s[:len(s)-i], b_c)
        if c is not None:
            ans = s[:len(s)-i]+c
            break
        else:
            b_c = s[len(s)-i-1]

if ans is None:
    print('-1')
else:
    print(ans)

Measured memory_bytes: 9072
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#define f cin
#define NMAX 100010
using namespace std;

//ifstream f("date.in");
long long int n, w;
long long int cost[NMAX], val[NMAX];

long long int dp[100][NMAX];

int main() {

    f >> n >> w;
    for (int i = 0; i < n; ++i) {
        f >> cost[i] >> val[i];
    }

    dp[0][cost[0]] = val[0];
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < cost[i]; ++j) {
            dp[i][j] = dp[i - 1][j];
        }
        for (int j = cost[i]; j <= w; ++j) {
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - cost[i]] + val[i]);
        }
    }

    long long int c_max = 0;
    for (int i = 0; i <= w; ++i) {
        c_max = max(c_max, dp[n - 1][i]);
    }

    cout << c_max;

    return 0;
}


Measured memory_bytes: 77568
s=input()
c_max=0
count=0
for i in range(len(s)):
  if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
    count+=1
  else:
    if c_max < count:
      c_max=count
    count=0

if c_max < count:
  c_max=count
print(c_max)

Measured memory_bytes: 3060
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.regex.Pattern
import java.util.{ArrayList, Collections, Comparator, List => JList}

import scala.math._
import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val n = input.split(LINE_SEPARATOR).head.split(" ").head.toInt
    val m = input.split(LINE_SEPARATOR).head.split(" ").tail.head.toInt
    val k = input.split(LINE_SEPARATOR).tail.reverse.tail.reverse.map(_.split(" ").head.toInt)
    val s = input.split(LINE_SEPARATOR).tail.reverse.tail.reverse.map(_.split(" ").tail.map(_.toInt))
    val p = input.split(LINE_SEPARATOR)(m+1).split(" ").map(_.toInt)

    (0 until 1<<n).count { bit =>
      (0 until m).forall { i =>
        (0 until n).count { j =>
          s(i).contains(j+1) && (1 & bit >> j) == 1
        } % 2 == p(i)
      }
    }.toString
  }

  def divisors(n: Long): Vector[Long] = {
    val halfList = (1 to sqrt(n).toInt).toVector.filter(_ % n == 0).map(_.toLong)
    val reversedList = if (sqrt(n).floor == sqrt(n)) halfList.reverse.tail.map(n/_) else halfList.reverse.map(n/_)
    halfList ++ reversedList
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """2 2
      |2 1 2
      |1 2
      |0 1""".stripMargin -> """1
                                   |
                               |
                                    |""".stripMargin,
    """2 3
      |2 1 2
      |1 1
      |1 2
      |0 0 1""".stripMargin -> """0
                                     |
                                     |""".stripMargin,
    """5 2
      |3 1 2 5
      |2 2 3
      |1 0""".stripMargin -> """8"""
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 31504
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cmath>

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

#define MAX 100000

int main(){
    int N;
    long long int A[MAX+2],res,sum;

    SCANFD(N);

    A[0] = 0;

    for(int i=1;i<N+1;i++){
        scanf("%lld",&A[i]);
    }

    A[N+1] = 0;
    sum = 0;
    
    REPI(N+2){
        sum += abs(A[i+1]-A[i]);
    }

    for(int i=1;i<N+1;i++){
        res = sum - abs(A[i]-A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1]-A[i-1]);
        printf("%lld\n",res);
    }
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};


int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int field[55][55];
    while(true) {
        int H, W;
        cin >> W >> H;
        if(W == 0 && H == 0) break;
        for(int h = 1; h <= H; h++) {
            for(int w = 1; w <= W; w++) {
                cin >> field[h][w];
            }
        }
        UnionFind uni(3001);
        for(int h = 1; h <= H; h++) {
            for(int w = 1; w <= W; w++) {
                if(field[h][w] == 0) continue; 
                for(int dh = -1; dh <= 1; dh++) {
                    for(int dw = -1; dw <= 1; dw++) {
                        int neww = w + dw;
                        int newh = h + dh;
                        if(neww <= 0 || neww > W || newh <- 0 || newh > H) continue;
                        if(field[newh][neww] == 0) continue;
                        uni.merge(h*50+w, newh*50+neww);
                    }
                }
            }
        }
        int ans = 0;
        for(int h = 1; h <= H; h++) {
            for(int w = 1; w <= W; w++) {
                if(field[h][w] == 0) continue;
                if(uni.root(h*50+w) != h*50+w) continue;
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3196
mod=10**6+3
P=[0 for i in range(mod)]
P[0]=1
for i in range(0,len(P)-1):
    P[i+1]=(P[i]*(i+1))%mod
P[0]=0
Q=int(input())
for q in range(Q):
    x,d,n=map(int,input().split())
    if d>0:
        D=pow(d,mod-2,mod)
        L=x*D%mod
        if L+n-1<mod:
            if L>0:
                value=P[L+n-1]*pow(P[L-1],mod-2,mod)*pow(d,n,mod)
            else:
                value=P[L+n-1]*pow(d,n,mod)
            print(value%mod)
        else:
            print(0)
    else:
        print(pow(x,n,mod))


Measured memory_bytes: 114064
a,b,c,x,y = map(int,input().split())
if a+b>2*c:
  if x>y:
    print(min(a*abs(x-y)+ min(x,y)*c*2, max(x,y)*c*2))
  else:
    print(min(b*abs(x-y)+ min(x,y)*c*2, max(x,y)*c*2))
else:
  print(a*x+b*y)

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

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;

//global-----------------------------------------------------------------------------------------------------------------------
LL a, b, c, d, n, ans = 0, cnt = 0;

VI ar;
//function--------------------------------------------------------------------------------------------------------------------
int main() {
	while ( true ) {
		scanf( "%lld", &a );
		if ( !a ) {
			break;
		}
		ans = 0;
		cnt = 0;
		rep( i, a ) {
			scanf( "%lld", &b );
			ar.PB( b );
		}
		SORT( ar );
		rep( i, ar.size() ) {
			ans += cnt;
			cnt += ar[ i ];
		}
		printf( "%lld\n", ans );
		ar = VI();
	}
	return 0;
}

Measured memory_bytes: 1316