akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
using namespace std;

long long a[100010];
long long mask[61];

int main()
{
    int n;cin >> n;
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    for (int i=0;i<n;++i)
        cin >> a[i];

    long long ans=0;
    long long tmp=0;
    for (int i=0;i<n;++i)
        tmp^= a[i];

    ans=tmp;
    tmp= (1LL << 61)-1-tmp;
    //cout << tmp << endl;
    for (int i=0;i<n;++i)
        a[i]&=tmp;
    //cout << ans <<endl;
    tmp=0;
    for (int i=0;i<n;++i)
    {
        for (int j=60;j>=0;--j)
        {
            if ( (a[i]&(1LL<<j))==0 ) continue;
            if ( !mask[j] ){
                mask[j]=a[i];
                break;
            }
            a[i]^=mask[j];
        }
    }
    for (int i=59;i>=0;--i)
    {
       // cout << i << ' ' << mask[i] << tmp <<endl;
        if (mask[i] && (tmp^mask[i])>tmp)
            tmp^=mask[i];
          //cout << i << ' ' << mask[i] << tmp <<endl;
    }
    ans+=tmp*2;
    cout << ans <<endl;

}


Measured memory_bytes: 1024
//
//  main.cpp
//  Sample
//
//  Created by h3037183 on 2017/07/31.
//  Copyright ?? 2017??´ ?°????. All rights reserved.
//

#include <iostream>
#include<algorithm>
using namespace std;
int main(){
    int a[10],i;
    for(i=0;i<10;i++){
        cin>>a[i];
    }
    sort (a,a+10);
    cout<<a[9]<<endl<<a[8]<<endl<<a[7]<<endl;
    return 0;
}

Measured memory_bytes: 3152
//051 A- Haiku 2017/01/07

#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    string s; cin >> s;
    rep(i ,s.size()){
        if(s[i]==',') s[i]=' ';
    }
    cout << s << endl;
}

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

int main(){
  int a,b,C;
  double S,L,h;

  scanf("%d %d %d",&a,&b,&C);

  S = (a*b*sin(C*M_PI/180.0))/2;
  L = a+b+sqrt(a*a+b*b-2*a*b*cos(C*M_PI/180.0));
  h = 2*S/a;

  printf("%f\n%f\n%f\n",S,L,h);
  return 0;
}

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

using namespace std;

int main()
{
    uint32_t N;
    uint32_t sum=0;
    
    cin >> N;
    vector<uint32_t> L(N);
    
    for(auto i = 0; i < N; i++){
        cin >> L[i];
    }
    
    sort(L.begin(), L.end(), greater<uint32_t>());
    
    for(auto i = 0; i < N - 2; i++){
        if(L[i] >= (L[i+1] + L[i+2]))continue;
        for(auto j = i+1; j < N - 1; j++){
            if(L[j] >= (L[i] + L[j+1]))break;
            for(auto k = j + 1; k < N && L[k] < (L[i] + L[j]); k++){
                if((L[i] < (L[j] + L[k])) && L[j] < L[i] + L[k])sum++;
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 384
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad


r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

main :: IO ()
main = do
    [a,b,c] <- r'
    let rest = a-b
    print $ max 0 (c-rest)


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n;
    cin >> n;
    string s;
    cin >> s;


    ll rcnt = 0;
    rep(i, n){
        if(s[i] == 'E') rcnt++;
    }

    ll lcnt = 0;
    ll minn = 1e10;
    rep(i, n){
        if(s[i] == 'E') rcnt--;
        minn = min(minn, rcnt+lcnt);
        if(s[i] == 'W') lcnt++;
    }

    cout << minn << endl;


    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <vector>
#include <cstdlib>
#include <set>
using namespace std;
string s,t;
set<string> str;
void luoji()
{
        int ls=s.size();
        int lt=t.size();
        for(int i=0;i<ls;i++)
        {
            if(s[i]=='?'||s[i]==t[0])
            {
                string temp=s;
                for(int j=0;j<i;j++)
                {
                        if(temp[j]=='?')temp[j]='a';
                }
                bool judge=false;
                for(int j=0;j<lt;j++)
                {
                        if(temp[i+j]!='?'&&temp[i+j]!=t[j])break;
                        temp[i+j]=t[j];
                        if(j==lt-1)judge=true;
                }
                if(judge)
                {
                        for(int j=i+lt;j<ls;j++)if(temp[j]=='?')temp[j]='a';
                        str.insert(temp);
                }
            }
        }
        if(str.size()==0)cout<<"UNRESTORABLE"<<endl;
        else cout<<*str.begin()<<endl;
}
int main()
{
        cin>>s>>t;
        luoji();
}

Measured memory_bytes: 256
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let a_b_x = lines.next().unwrap().unwrap();
    let mut a_b_x = a_b_x.split_whitespace();
    let a = a_b_x.next().unwrap().parse::<f64>().unwrap();
    let b = a_b_x.next().unwrap().parse::<f64>().unwrap();
    let x = a_b_x.next().unwrap().parse::<f64>().unwrap();

    let ans = if x <= a * a * b / 2.0 {
        a * b * b / (2.0 * x)
    } else {
        2.0 / (a * a * a) * (a * a * b - x)
    };
    let ans = ans.atan().to_degrees();
    println!("{}", ans);
}


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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

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

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

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

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    set<string> set;
    REP(i, N)
    {
        string s; cin >> s;
        set.insert(s);
    }
    cout << set.size() << endl;
}

Measured memory_bytes: 19180
from collections import Counter

N = int(input())

target_list = list(map(int, input().split()))
check = Counter(target_list)
result = sum(target_list)


for index in range(int(input())):
    B, C = map(int, input().split())
    if B in check:
        result = result + (check[B]) * (C - B)
        if C in check:
            check[C] = check[C] + check[B]
        else:
            check[C] = check[B]
        check[B] = 0
    print(result)


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

int main(){
    ll N;
    cin >> N;
    ll tmp, sum = 0, ans = 0;
    map<ll, ll> mp;
    // 累積和の初期値は0
    mp[0] = 1;
    for(int i=0;i<N;i++){
        cin >> tmp;
        // 累積和をとる
        // 累積和が同じ部分をとれば総和が0になる
        sum += tmp;
        // 今までにsumが現れた回数だけの組合せがつくれる
        ans += mp[sum];
        // sumが現れた回数を加算
        mp[sum]++;
    }

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


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

using namespace std;
const int max_r = 123456 * 2 + 1;
const int sqrt_max = int(sqrt(max_r));

bool np[max_r];

int main()
{
    np[0] = np[1] = true;
    for(int i=2; i<=sqrt_max; i++)
    {
        if(!np[i])
        {
            for(int j=2*i; j<max_r; j+=i)
            {
                np[j] = true;
            }
        }
    }
    
    int n;
    while(cin >> n, n)
    {
        int ct = 0;
        for(int i=n+1; i<=2*n; i++)
        {
            if(!np[i])
            {
                ct++;
            }
        }
        cout << ct << endl;
    }

}

Measured memory_bytes: 3304
import java.util.*;

public class Main{
    class Island implements Comparable{
        public int weight;
        public int limit;
        public Island(int weight, int limit){
            this.weight = weight;
            this.limit = limit;
        }
        public int compareTo(Object other){
            Island is = (Island)other;
            return this.limit - is.limit;
        }
    }
    void run(){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            if(n == 0){
                break;
            }
            Island[] islands = new Island[n];
            for(int i = 0; i < n; i++){
                islands[i] = new Island(sc.nextInt(), sc.nextInt());
            }
            /*
            for(int i = 0; i < n; i++){
                System.out.println(i + ": " + islands[i].weight + " " + islands[i].limit);
            }
            */
            Arrays.sort(islands);
            boolean ans = true;
            int sum = 0;
            for(Island is: islands){
                sum += is.weight;
                if(is.limit < sum){
                    ans = false;
                    break;
                }
            }
            System.out.println(ans?"Yes":"No");
        }
        
    }

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

Measured memory_bytes: 24304
S = input()
T = input()

def matchcount(x, y):
    ret = 0
    for i in range(len(x)):
        if x[i] == y[i]: ret += 1
    return ret

rec = len(T)
for i in range(len(S)-len(T)+1):
    subst = S[i:i+len(T)]
#    print(subst, matchcount(subst, T))
    rec = min(rec, len(T) - matchcount(subst, T))

print(rec)



Measured memory_bytes: 9124
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <list>
using namespace std;

struct Node { int key; Node *next, *prev; };
Node *nil;

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil, nil->prev = nil;
}
Node *searchKey(int key) {
	Node *x = nil->next;
	while (x->key != key && x != nil)x = x->next;
	return x;
}

void printlist() {
	Node *cur = nil->next;
	for (int i = 0; cur != nil;i++) {
		if (i)cout << " ";
		cout << cur->key;
		cur = cur->next;
	}
	cout << endl;
}

void popback(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	nil->prev->next = x;
	x->prev = nil->prev;
	x->next = nil;
	nil->prev = x;
	x->key = key;
}

void popfront(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	nil->next->prev = x;
	x->next = nil->next;
	x->prev = nil;
	nil->next = x;
	//if (nil->prev = nil)nil->prev = x;
	x->key = key;
}

void deleteNode(Node *t) {
	if (t == nil)return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deleteKey(int key) {
	deleteNode(searchKey(key));
}

void print(list<int> x) {
	list<int>::iterator it = x.begin();
	while (it != x.end()) {
		cout << *(it++);
	}
}

int main() {
	init();
	int n, x;
	string s;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		if (s[0] == 'i')cin >> x, popfront(x);
		if (s == "delete")cin >> x, deleteKey(x);
		if (s == "deleteFirst")deleteFirst();
		if (s == "deleteLast")deleteLast();
	}
	printlist();
	return 0;
}

Measured memory_bytes: 34296
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007

ll now,n,k;

int main(){
  ll ans=0LL;
  cin >> n;
  vector<ll> a(n),x(n);
  REP(i,n){
      cin>>a[i];
  }

  ll sgn=1LL;
  REP(i,n){
    x[0]+=a[i]*sgn;
    sgn*=-1LL;
  }

    sgn=1LL;

    cout<<x[0]<<endl;

 for(int i=1;i<n;i++){
    x[i]=-x[i-1]+a[i-1]*2LL;
    cout<<x[i]<<endl; 
 }
  return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
  long long int N,i,a,b,c,ans;
  scanf("%lld",&N);
  a=1;
  b=1;
  c=1;
  for(i=0;i<N;i++){
    a=a*10%1000000007;
    b=b*9%1000000007;
    c=c*8%1000000007;
  }
  if(a+c>2*b) ans=(a-2*b+c)%1000000007;
  else ans=(a-2*b+c+2*1000000007)%1000000007;
  printf("%lld",ans);
  return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ACはうれCすぎてうれD */

int main(void){ 
    int x,y;
    cin >> x >> y;
    int ans = 0;
    if(x == 1) ans += 300000;
    else if(x == 2) ans += 200000;
    else if(x == 3) ans += 100000;

    if(y == 1) ans += 300000;
    else if(y == 2) ans += 200000;
    else if(y == 3) ans += 100000;

    if(x == 1 && y == 1) ans += 400000;
  
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int k, s; cin >> k >> s;
	int ans = 0;
	FORR(i, 0, k) {
		FORR(j, 0, k) {
			int tmp = s - i - j;
			if (0 <= tmp && tmp <= k && i + j + tmp == s) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.array;
import std.conv;
import std.string;
import std.algorithm;

void main()
{
   string[string] cards;
    auto n = readln.strip.to!int;

    foreach(i;0..n) {
        auto s = readln;
        cards[s] = s;
    }

    foreach(i;["S","H","C","D"]) {
        foreach(j;0..13){
            string str = i ~ " " ~ (j+1).to!string ~ "\n";
            if(cards.get(str,"")=="") {
                write(str);
            }
        }
    }
}

Measured memory_bytes: 2508
n = int(input())
s = input()
t = input()
u = []
flg = 0
mod = 10**9+7
for i in range(n):
	if s[i] == t[i]:
		u.append(1)
	else:
		if flg == 1:
			u.append(0)
			flg = 0
		else:
			flg = 1
if u[0] == 1:
	ans = 3
else:
	ans = 6
for i in range(len(u)-1):
	if u[i] == 1 and u[i+1] == 1:
		ans *= 2
	elif u[i] == 1 and u[i+1] == 0:
		ans *= 2
	elif u[i] == 0 and u[i+1] == 1:
		continue
	else:
		ans *= 3
	ans %= mod
print (ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


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

int main(){
    ll n;cin>>n;
    ll p[n];
    rep(i,0,n-1){
        cin>>p[i];
    }
    ll ans=0;
    ll l;
    rep(i,0,n-2){
        if(p[i]==i+1){
            ans++;
            l=p[i];
            p[i]=p[i+1];
            p[i+1]=l;
        }
    }
    if(p[n-1]==n){
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}







Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << 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; }
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}
void solve(long long N, long long M){
    cout<<N*(N-1)/2+M*(M-1)/2<<endl;
}
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int h, a; cin >> h >> a;

    if (h % a == 0) {
        cout << h / a << endl;
    } else {
        cout << h / a + 1 << endl;
    }
}

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

int main() {
  string a, b;
  cin >> a >> b;
  int num_a = stoi(a); //stoi(''''string''')
  int num_b = stoi(b);
  string cmp_a;
  rep(i, num_b) cmp_a += a;
  string cmp_b;
  rep(i, num_a) cmp_b += b;
  if(cmp_a <= cmp_b) cout << cmp_a << endl;
  else cout << cmp_b << endl;
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
#define fi first
#define se second

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

int n;
int a[200010];
vvi vec(200010+1,vi(0));
int ans[200010];

void dfs(vi &dp,int c,int now,int frm){
    int num=a[now];
    int index=lower_bound(all(dp),num)-dp.begin();
    int num1=dp[index];
    dp[index]=num;
    if (num1==1e9+1)c+=1;
    int ans1=0;
    for (int x:vec[now]){
        if (x!=frm){
            dfs(dp,c,x,now);
        }
    }
    ans[now]=c;
    dp[index]=num1;


}

int main() {
    cin>>n;
    rep(i,n)cin>>a[i+1];
    rep(i,n-1){
        int u,v;
        cin>>u>>v;
        vec[u].push_back(v);
        vec[v].push_back(u);
    }
    vi dp(n+1,1e9+1);
    dp[0]=0;
    dfs(dp,0,1,-1);
    rep(i,n)cout<<ans[i+1]<<endl;


    return 0;
}

Measured memory_bytes: 33756
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <stdio.h>
#include <queue>
#define pb push_back
#define ppb pop_back
#define nd second
#define st first
#define ll long long
#define pi 3.1415926535897932384626433832795028841971
using namespace std;

int a[3]; 
int k; 

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> a[0] >> a[1] >> a[2] >> k;
	
	sort(a, a + 3);
	for (int i = 0; i < k; i++)
		a[2] *= 2; 
	
	cout << a[0] + a[1] + a[2] << endl; 
	
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() (ret string) {

	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			return ""
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

type Utls struct {
}

type uString string

var utls = &Utls{}

func (u *Utls) readLineU() uString {
	return uString(readLine())
}

func (u *Utls) atoi(str string) int {
	r, _ := strconv.Atoi(str)
	return r
}
func (u *Utls) itoa(n int) string {
	r := strconv.Itoa(n)
	return r
}
func (u uString) atoi() int {
	r, err := strconv.Atoi(string(u))
	if err != nil {
		return -1
	}
	return r
}
func (u uString) atoiArr() []int {
	ret := make([]int, 0)

	l := strings.Split(string(u), " ")

	for i := 0; i < len(l); i++ {
		s := (uString(l[i]))

		ret = append(ret, s.atoi())

	}
	return ret
}
func (u uString) String() string {
	return string(u)
}

func main() {
	 s:= readLine()
	 t:= readLine()
 		cnt:=0
	 for i,_:= range s {
		 if s[i] != t[i]{
			 cnt++
		 }
	 }
//	 r :=  (a)+ (a*a) + (a*a*a)
	 fmt.Println(cnt)
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  ll x;
  cin >> x;
  ll f = x / 500;
  ll g = (x - f * 500) / 5;
  cout << f * 1000 + g * 5 << endl;
  return 0;
}

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

int main(){
  int a[] = {0,1,2,1,3,1,3,1,1,3,1,3,1};
  int x,y;
  cin >> x >> y;

  if(a[x]==a[y]) puts("Yes");
  else puts("No");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		for(int i=A; i<=B; i++) {
			if(i%K==0) {
				System.out.println("OK");
				return;
			}
		}
		System.out.println("NG");
	}

}

Measured memory_bytes: 35692
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;

int main()
{
	int n;
	string a[3];
	int ans=0;
	cin>>n;
	for(int i=0;i<3;i++)
		cin>>a[i];
	
	for(int i=0;i<n;i++)
	{
		int c[30];
		fill(c,c+30,0);
		for(int j=0;j<3;j++)
		{
			//cerr<<a[j][i]-'a'<<endl;
			c[a[j][i]-'a']++;
		}
		sort(c,c+30);
		reverse(c,c+30);
		//cerr<<c[0]<<endl;
		ans+=(3-c[0]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)

using namespace std;

int main(void){
    
    int student = 0;
    int maxN,minN = 0;
    int gap = 0,gapMax = 0,gapnumber  = 0;
    int score[1020] = {0};
    
    while(cin >> student >>minN >>maxN,student+maxN+minN)
    {
        REP(i,student)
        cin >> score[i];
  
    
    FOR(j,minN,maxN+1)
        {
            gap = score[j-1] - score[j];

            if(gapMax <= gap)
            {
                gapnumber = j;
                gapMax = gap;
                
            }
        }
        cout << gapnumber << endl;
        gapMax  =-1;
        gapnumber = 0;
    
    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	map<int, int>m;
	for (int x = 1; x * x <= N; x++) {
		for (int y = 1; y * y <= N; y++) {
			for (int z = 1; z * z <= N; z++) {
				int res = x * x + y * y + z * z + x * y + y * z + z * x;
				m[res]++;
			}
		}
	}
	for (int i = 1; i <= N; i++)cout << m[i] << endl;
}

Measured memory_bytes: 6004
#include <stdio.h>
#include <algorithm>
#include <vector>

int main(int argc, char **argv) {
  int N, K;
  scanf("%d %d", &N, &K);

  std::vector<int> l(N, 0);
  for (int i = 0; i < N; ++i)
    scanf("%d", &l[i]);

  std::sort(l.begin(), l.end());

  int total = 0;
  for (int i = 0; i < K; ++i)
    total += l[N - 1 - i];
  printf("%d\n", total);

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
int n;
cin>>n;
vector<int>v;
for(int i=0;i<n;i++){
    int z;
    cin>>z;
    z--;
    v.push_back(z);
}
int now=0,c=0;
for(;;){
    if(now==1){
        cout<<c<<endl;
        break;
    }
    if(c>=n){
        cout<<"-1"<<endl;
        break;
    }
    c++;
    now=v[now];
}
}

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

int main(){
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  int l[k]={0}, r[k]={0};
  int x=0;
  for(int i=0;i<k;i++){
    while(s[x]=='x'){
      x+=1;
    }
    l[i]=x;
    //cout << x << endl;
    x += c+1;
  }
  int y=n-1;
  for(int i=k-1;i>=0;i--){
    while(s[y]=='x'){
      y-=1;
    }
    //cout << y << endl;
    r[i]=y;
    y -= c+1;
  }
  for(int i=0;i<k;i++){
    if(r[i]==l[i]){
      cout << r[i]+1 << endl;
    }
  }
}

Measured memory_bytes: 3332
using static System.Console;

class Program {
	static void Main() {
		var A = NextInt();
		var B = NextInt();
		var C = NextInt();
		var X = NextInt();

		var ans = 0;

		for (var a = 0; a <= A; a++) {
			for (var b = 0; b <= B; b++) {
				for (var c = 0; c <= C; c++) {
					if (a * 500 + b * 100 + c * 50 == X) {
						ans++;
					}
				}
			}
		}
		WriteLine(ans);
	}

	static int NextInt() {
		return int.Parse(ReadLine());
	}
}

Measured memory_bytes: 13140
/* -- Basic Headers -- */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>

/* -- STL Iterators -- */
#include <vector>
#include <string>
#include <stack>
#include <queue>

/* -- External Headers -- */

/* -- Defined Functions -- */
#define For(a,x,y) for (int a = x; a <= y; ++a)
#define Forw(a,x,y) for (int a = x; a < y; ++a)
#define Bak(a,y,x) for (int a = y; a >= x; --a)

/* -- Defined Words -- */

using namespace std;

namespace FastIO {
    void DEBUG(char comment[], int x) {
        cerr << comment << x << endl;
    }

    inline int getint() {
        int s = 0, x = 1;
        char ch = getchar();
        while (!isdigit(ch)) {
            if (ch == '-') x = -1;
            ch = getchar();
        }
        while (isdigit(ch)) {
            s = s * 10 + ch - '0';
            ch = getchar();
        }
        return s * x;
    }
    inline void __basic_putint(int x) {
        if (x < 0) {
            x = -x;
            putchar('-');
        }
        if (x >= 10) __basic_putint(x / 10);
        putchar(x % 10 + '0');
    }

    inline void putint(int x, char external) {
        __basic_putint(x);
        putchar(external);
    }
}

namespace Solution {
    const int MAXN = 100 + 10;

    struct Point {
        int x, y, h;
    } pts[MAXN];

    void Work(int n) {
        using FastIO::getint;
        int u = 0;
        For (i, 1, n) {
            int x = getint();
            int y = getint();
            int h = getint();
            pts[i].x = x;
            pts[i].y = y;
            pts[i].h = h;
            if (h > 0) u = i;
        }
        For (i, 0, 100) {
            For (j, 0, 100) {
                int Cx = i, Cy = j;
                int H = std::abs(pts[u].x - Cx) + std::abs(pts[u].y - Cy) + pts[u].h;
                For (a, 1, n) {
                    if (pts[a].h != std::max(H - std::abs(pts[a].x - Cx) - std::abs(pts[a].y - Cy), 0)) break;
                    if (a == n) {
                        printf("%d %d %d", Cx, Cy, H);
                        return;
                    }
                }
            }
        }
    }
}

int main() {
    #define HANDWER_FILE
    #ifndef HANDWER_FILE
    freopen("testdata.in", "r", stdin);
    freopen("testdata.out", "w", stdout);
    #endif
    using namespace Solution;
    using namespace FastIO;
    int n = getint();
    Work(n);
    return 0;
}





Measured memory_bytes: 256
"use strict";

const fs = require("fs");
const readline = require("readline");

const main = (argv: string[]) => {
  const [H, N] = argv[0].split(" ").map(Number);
  const attacks = argv[1].split(" ").map(Number);
  const allDamage = attacks.reduce((a, c) => a + c);
  if (allDamage >= H) console.log("Yes");
  else console.log("No");
}

const parser = (argv: any) => {
  main(argv.split("\n"));
}

parser(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;

int main(){
  string S; cin>> S;
  if( (int)S.size() < 4){ cout << "No" <<endl; return 0;}
 
  if( S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I'){
    cout << "Yes" << endl;}
  else{ cout << "No" <<endl;}
  
  return 0;}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
		var moneyNum = input[0];
		var totalMoney = input[1];
		var answerArray = new int[3] { -1, -1, -1 };
		var answerFlag = false;

		for (int x = 0; x <= moneyNum; x++)
		{
			if (answerFlag)
				break;

			for (int y = 0; y <= moneyNum - x; y++)
			{
				var answer = 10000 * x + 5000 * y + 1000 * (moneyNum - x - y);
				if (totalMoney == answer)
				{
					answerArray[0] = x;
					answerArray[1] = y;
					answerArray[2] = moneyNum - x - y;
					answerFlag = true;
					break;
				}
			}
		}

		Console.WriteLine(answerArray[0] + " " + answerArray[1] + " " + answerArray[2] + " ");
	}

}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int a[100],b[100];
int main(){
	int n,w=0;scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i),b[i]=a[i];sort(a,a+n);
	for(int i=0;i<n;i++)if(b[i]!=a[i])w++;
	if(w<=2)puts("YES");
	else puts("NO");
	return 0;
}

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

#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
void input(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}

void swap(int& a, int& b){
	int t=a;
	a = b;
	b = t;
}


void solveTest(){
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	long double ans = v[0];
	for(int i=1;i<n;i++){
		ans = (ans+v[i])/2.0;
	}
	cout<<ans<<endl;
	return ;
}

int main(){
	fastio();
	//input();

	int t=1;
	//cin>>t;
	while(t--){
		solveTest();

	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  string s;
  cin>>s;
  if(s.at(0) == 'S'){
    cout << "Cloudy" << endl;
  }
  else if(s.at(0) == 'C'){
    cout << "Rainy" << endl;
  }
  else{
    cout << "Sunny" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

using ull = unsigned long long;
using ll = long long;

// code
// ------------------------------------------------
int main() {

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

  ll m = 0; // 累積和
  ll p = 0; // 同じく
  ll m_cnt = 0; // 各スタートでの操作回数
  ll p_cnt = 0;

  rep(i,n)
  {
    // minus start
    if( (i % 2 ? 1 : -1 ) * (m + a[i]) < 0)
    {
      // 符号が違っていたら
      ll b_m = m + a[i];
      m_cnt += 1 + abs(b_m);
      m = i % 2 ? 1 : -1;
    }
    else if(m + a[i] == 0)
    {
      m = i % 2 ? 1 : -1;
      m_cnt++;
    }
    else
    {
      // あっているなら次に行くだけ
      m += a[i];
    }
    
    // plus start
    if( (i % 2 ? -1 : 1 ) * (p + a[i]) < 0)
    {
      // 符号が違っていたら
      ll b_p = p + a[i];
      p_cnt += 1 + abs(b_p);
      p = i % 2 ? -1 : 1;
    }
    else if(p + a[i] == 0)
    {
      p = i % 2 ? -1 : 1;
      p_cnt++;
    }
    else
    {
      // あっているなら次に行くだけ
      p += a[i];
    }
  }

  cout << min(m_cnt,p_cnt) << endl;


  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}

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

Measured memory_bytes: 1160
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

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

#define P (1'000'000'007)

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

    int res = 0;
    rep(i, s.size()) {
        int x = s[i] - '0';
        res += x;
    }

    if (res % 9 == 0) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 3376
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] chars = new char[h][w];
		int count = 0;
		for(int i = 0; i < h; i++) {
			chars[i] = sc.next().toCharArray();
		}
		for(char[] a : chars) {
			for(char c : a) {
				if(c=='#') {
					count++;
				}
			}
		}
		System.out.println(h+w-1==count ? "Possible" : "Impossible");
	}
}

Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double T = sc.nextInt();
		double A = sc.nextInt();
		double []H = new double[N];
		for(int i = 0; i < N; i++) H[i] = sc.nextInt();
		sc.close();
		int id = 0;
		double min = Math.abs(T - H[0] * 0.006 - A);
		for(int i = 1; i < N; i++) {
			double t = Math.abs(T - H[i] * 0.006 - A);
			if(t < min) {
				min = t;
				id = i;
			}
		}
		System.out.println(id + 1);
	}
}

Measured memory_bytes: 25940
function Main(input) {
    input.trim().split("\n").forEach(line => {
        var a = line.split(" ").map(i => parseInt(i));
        var x = a[0];
        var y = a[1];
        if (x <= 9 && y <= 9) {
            console.log(x * y);
        } else {
            console.log(-1);
        }
    });
}

process.stdin.resume();
process.stdin.setEncoding("utf8");
var globalInput = '';
process.stdin.on('data', function(chunk) {
    globalInput += chunk;
})
process.stdin.on('end', function() {
    Main(globalInput)
})

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

Measured memory_bytes: 9548
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FFrogJump solver = new FFrogJump();
        solver.solve(1, in, out);
        out.close();
    }

    static class FFrogJump {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] arr = new long[n];
            for (int i = 0; i < n; i++)
                arr[i] = in.nextLong();
            //long res = solveSimple(n, arr);
            long res = solveMe3(n, arr);
            out.println(res);
        }

        private long solveMe3(int n, long s[]) {
            long ans = 0;
            for (int c = 1; c < n; c++) {
                long sum = 0;
                Set<Integer> set = new TreeSet<>();
                for (int k = 1; (k + 1) * c < n; k++) {
                    if (!set.add(k * c)) break;
                    if (!set.add(n - 1 - k * c)) break;
                    sum += s[k * c];
                    sum += s[n - 1 - k * c];
                    ans = Math.max(ans, sum);
                }
            }
            return ans;
        }

    }
}



Measured memory_bytes: 97084
#include<bits/stdc++.h>
using namespace std;
int main()
{
  char a[100],s[100];
  cin>>a;
  cin>>s;
  for(int i=0;i<strlen(s);++i)
  {
    cout<<s[i];
  }
  for(int i=0;i<strlen(a);++i)
  {
    cout<<a[i];
  }
  
}

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

using namespace std;
using ll = long long;

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

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

  map<int, int> m;
  for (int i = 0; i < n; i++) {
    m[i - a[i]]++;
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    m[i - a[i]]--;
    ans += m[i + a[i]];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 21888
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
/*		if(N == 2){
			Console.Writeline(1);
			return;
		}
*/		if(N % 2 == 1){
			long v = (2 + N - 1) * (N - 2) / 2;
			v += N % 2;
			Console.WriteLine(v);
		} else {
			long v = (1 + N - 1) * (N - 1) / 2;
			Console.WriteLine(v);
		}
	}
	long N;
	public Sol(){
		N = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#create date: 2020-04-19 21:02

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m = na()
    a = na()
    ans = n - sum(a)
    print(ans if ans >= 0 else -1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 10048
x,y = gets.chomp.split(" ").map(&:to_i)

n = (x + y) / 3
k = y - n

if (x + y) % 3 != 0
  puts 0
  exit
end

MOD = 10 ** 9 + 7
# 繰り返し二乗法(x.pow(n, mod)でもOK)
def pow(x, n, mod = MOD)
  ans = 1
  # 下位ビットから繰り返し計算を行う
  while n > 0 do
    ans = ans * x % mod if n.odd? # 下位ビットが1かどうか
    x = x * x % mod
    n >>= 1 # 右ビットシフト
  end
  return ans
end

# (mod p)下での逆元
# フェルマーの小定理より a^(p-1) = 1 (mod p) (aは整数, pは素数, aとpは互いに素)
# a * a^(p-2) = 1 なので, aの逆元が a^(p-2) となる
def inv(a, mod = MOD)
  pow(a, mod - 2, mod)
end

# 階乗
# 再利用できるようグローバル変数化
$fact = [1] # 0! = 1
def fact(n, mod = MOD)
  # 計算済ならそれを返す
  return $fact[n] unless $fact[n].nil?

  # 階乗を求めながら$factへ格納
  f = $fact[-1]
  ($fact.size).upto(n) do |i|
    f = (f * i) % mod
    $fact << f
  end
  return $fact[n]
end

# 順列
def perm(n, r, mod = MOD)
  # n*(n-1)*(n-2)*...*(n-r+1)
  return n.downto(n - r + 1).reduce(1) {|ans, x| (ans * x) % mod }
end

# 組み合わせ
def comb(n, r, mod = MOD)
  return 0 unless 0 <= r && r <= n
  return 1 if r == 0 || r == n
  # nCk = n!/(n-k)! * 1/k!
  return perm(n, r, mod) * inv(fact(r, mod) % mod, mod) % mod
end

puts comb(n, k)


Measured memory_bytes: 17700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        a--;
        ans += a;
    }
    cout << ans;
}   

Measured memory_bytes: 256
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl     '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii      map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
  ll s,w;
  cin>>s>>w;
  if(w>=s)
  {
    cout<<"unsafe\n";
  }
  else cout<<"safe\n";
}
signed main()
{
  
    /***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS=1;
//  cin>>TESTS;
  while(TESTS--)
  {
    solve();
    
  }
  TIME
  return 0;
}

Measured memory_bytes: 3796
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    ll a, b, c;
    cin >> a >> b >> c;
    if (a + b == c || a + c == b || b + c == a)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
x,k,d = gets.split(" ").map{|i| i.to_i}
x *= -1 if x < 0
d *= -1 if d < 0

if x > d*k
    print(x-d*k)
    return
end

sa = d*k - x
n = sa/(2*d)
n_over = n + 1


l1 = sa-n*2*d
l2 = (sa-n_over*2*d)*-1

print([l1,l2].min)


Measured memory_bytes: 14380
n = int(input())
s = {}
for i in range(n):
    word = input()
    if word in s:
        s[word] += 1
    else:
        s[word] = 1

s_sorted = sorted(s.items(), key=lambda x: -x[1])

max_num = s_sorted[0][1]
results = []

for ss in s_sorted:
    if ss[1] == max_num:
        results.append(ss[0])

results.sort()

for r in results:
    print(r)

Measured memory_bytes: 45788
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
#define Would
#define you


int main() {
	string h;
	while (1) {
		cin >> h;
		if (h == "#") { break; }
		int a, b, c;
		cin >> a >> b >> c;
		if (a > 31||(a==31&&b>=5)) {
			cout << "?" << " ";
			a -= 30;
		}
		else { cout << "HEISEI" << " "; }
		cout << a << " " << b << " " << c << endl;
	}
}



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

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

int main(){
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i,n){
    cin >> b[i];
  }
  int ans[110];
  rep(i,n){
    for(int j=b.size()-1; j>=0; j--){
      if(b[j] == j+1){
        b.erase(b.begin()+j);
        ans[n-i-1] = j+1;
        break;
      }
      if(j==0){
        cout << -1 << endl;
        return 0;
      }
    }
  }

  rep(i,n){
    cout << ans[i] << endl;
  }
}

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

int main(){
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    
    long long range = 0LL, ans = 0LL;
    
    range = b - a + 1;
    
    // 最大公約数gcdを求める
    long long gcd;
    long long maxc = max(c,d), mind = min(c,d);
    long long cc = maxc;
    long long dd = mind;
    long long r = cc % dd;
    while (r != 0) {
        cc = dd;
        dd = r;
        r = cc % dd;
    }
    gcd = dd;
    
    // 最小公倍数lcmを求める
    long long lcm = c * d / gcd;
    
    long long divisible_c = b / c - (a - 1) / c;
    long long divisible_d = b / d - (a - 1) / d;
    long long divisivle_cd = b / lcm - (a - 1) / lcm;
    
    ans = range - divisible_c - divisible_d + divisivle_cd;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256