akhauriyash/Code-Regression huggingface dataset:
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (a,b) = scan "%d %s" Tuple2.make

let () =
  let b = 100 * (atoi @@ String.get b 0) +
          10 * (atoi @@ String.get b 2) +
          1 * (atoi @@ String.get b 3) in
  Printf.printf "%d\n"  (a * b /100)


Measured memory_bytes: 5472
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int

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

int main()
{
    ll n, x[100], y[100], h[100];
    ll cx, cy, H;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i] >> h[i];
    }
    for (int i = 0; i <= 100; i++)
    {
        for (int j = 0; j <= 100; j++)
        {
            cx = i;
            cy = j;
            for (int k = 0; k < n; k++)
            {
                bool f = true;
                H = h[k] + abs(x[k] - cx) + abs(y[k] - cy);
                // if (i == 5 && j == 5)
                //     cout << cx << " " << cy << " " << H << endl;
                for (int l = 0; l < n; l++)
                {
                    // if (i == 5 && j == 5)
                    //     cout << (h[l] != maxll(0, H - abs(x[l] - cx) - abs(y[l] - cy))) << " ";
                    if (h[l] != maxll(0, H - abs(x[l] - cx) - abs(y[l] - cy)))
                    {
                        f = false;
                        break;
                    }
                }
                //cout << endl;
                if (f)
                {
                    cout << cx << " " << cy << " " << H << endl;
                    return 0;
                }
            }
        }
    }
}


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

int main() {
  string S;
  getline(cin,S);
  for(int i=0;i<S.size();i++){
   if(S.at(i)>='a'&&S.at(i)<='z'){S.at(i)=(char)toupper(S.at(i));}
    else {S.at(i)=(char)tolower(S.at(i));} 
  }  
  for(int i=0;i<S.size();i++){
   cout<<S.at(i);
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <vector>

int main() {
	int N, M;
	unsigned long long K;
	std::vector<unsigned long long> A;
	std::vector<unsigned long long> B;
	std::cin >> N >> M >> K;
	A.resize(N+1);
	B.resize(M+1);
	for (int i = 1; i < N+1; ++i) {
		unsigned long long a;
		std::cin >> a;
		A.at(i) = a + A.at(i - 1);
	}

	for (int i = 1; i < M + 1; ++i) {
		unsigned long long b;
		std::cin >> b;
		B.at(i) = b + B.at(i-1);
	}
	
	int max = 0;
	int startM = 0;
	for (int i = 0; i < N + 1; ++i) {
		for (int j = startM; j < M+1; ++j) {
			unsigned long long cost = A.at(i) + B.at(j);
			if (cost > K) {
				break;
			}
			int newMax = i + j ;
			if (max < newMax)
				max = newMax;
		}
		startM = max - i;
		if (startM < 0)
			break;
	}

	std::cout << max << std::endl;
}

Measured memory_bytes: 6384
#include <stdio.h>
int main() {
	int n, p, max = 0, sum = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p);
		sum += p;
		if (max < p) {
			max = p;
		}
	}
	printf("%d", sum - (max / 2));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int n;
  cin >> n;
  ll ans = 1;
  ll mod = 1e9 + 7;
  REP2(i,1,n+1){
    ans *= i;
    ans %= mod;
  }
  cout << ans%mod << endl;
  return 0;
}

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

#define p pair<ll, ll>
#define pi pair<ll, p>
#define f second.first
#define s second.second
#define INF (ll)(2e13)
using namespace std;
typedef long long ll;
vector<pi> a;

int main() {
    ll N, t1, t2, i, j;
    cin >> N;
    while (N--) {
        cin >> t1 >> t2;
        a.push_back(pi(t1+t2, p(t1, t2)));
    }
    sort(a.begin(), a.end(), less<pi>());

    ll r[10000], H = 0;
    r[0] = 0;
    for (i = 1; i < 10000; i++) r[i] = INF;
    for (i = 0; i < a.size(); i++) {
        //printf("(%lld, %lld)\n", a[i].f, a[i].s);
        for (j = H; j >= 0; j--) {
            // if you CAN extend it, TRY extending it
            if (a[i].f >= r[j]) {
                ll nex = r[j]+a[i].s;
                if (nex < r[j+1]) {
                    r[j+1] = nex;
                    //printf("r[%lld] = %lld (from %lld)\n", j+1, r[j+1], r[j]);
                }
                H = max(H,j+1);
            }
        }
    }
    cout << H << '\n';
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
ll modinv(ll a, ll m) {
    ll b=m,u=1,v=0;
    while(b){
        ll t = a/b;
        a -= t*b; swap(a,b);
        u -= t*v; swap(u,v);
    }
    u %= m;
    if (u<0) u += m;
    return u;
}

int main(){
    vector<ll> k(200000,1);
    rep(i,1,200000) k.at(i)=(k.at(i-1)*i)%MOD;
    int n,m;
    cin>>n>>m;
    vector<ll> vec;
    rep(i,2,(int)pow(m,0.5)+2){
        if(m%i!=0) continue;
        ll cnt=0;
        while (m%i==0) {
            m/=i;
            cnt++;
        }
        vec.push_back(cnt);
    }
    if(m!=1) vec.push_back(1);
    
    ll ans=1;
    for(ll r:vec){
        ans*=k.at(r+n-1)*modinv(k.at(r),MOD)%MOD;
        ans%=MOD;
        ans*=modinv(k.at(n-1),MOD);
        ans%=MOD;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 1792
def d():
    N = int(input())
    A = list(map(int, input().split()))

    money = 1000
    stock = 0

    for i in range(1, N):
        if A[i-1] < A[i]:
            stock += money // A[i-1]
            money -= A[i-1] * (money // A[i-1])
            # print('buy  - stock: {}, money: {}'.format(stock, money))

        elif A[i-1] > A[i]:
            money += stock * A[i-1]
            stock = 0
            # print('sell - stock: {}, money: {}'.format(stock, money))

    if A[N-2] <= A[N-1]:
        money += stock * A[N-1]
        stock = 0
        # print('sell - stock: {}, money: {}'.format(stock, money))

    print(money)


##########
if __name__ == "__main__":
    d()


Measured memory_bytes: 9160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		String s = scan.nextLine();

		char[] c = s.toCharArray();
		String ans = "";

		for(int i = 0; i<s.length();i+=2){
			System.out.print(String.valueOf(c[i]));
		}
		
		
	}
}

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int a,b;
  string op;

  cin >> a >> op >> b;

  if (op == "+") printf("%d\n",a + b);
  else printf("%d\n",a - b);

}


Measured memory_bytes: 256
S = input()
s1 = int(S[:2])
s2 = int(S[2:])
 
if 0 < s1 < 13:
    if 0 < s2 < 13:
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif 0 < s2 < 13:
    if 0 < s1 < 13:
        print('AMBIGUOUS')
    else:
        print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=(a);i<(int)(n);i++)
using namespace std;
typedef long long ll;
struct start { start() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(10);
}; }start;
void in() {}
template <class Head , class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(move(tail)...);
}
template <class T>
  void out(T& t) {
  cout << t << '\n';
}
template <class Head , class... Tail>
void out(Head& head , Tail&... tail) {
  cout << head << ' ';
  out(move(tail)...);
}
int main(void) {
  int k,ans=0;
  in(k);
  rep(i,1,k+1){
    if(i%2==0){
      rep(j,1,k+1){
      	if(j%2==1)ans++;
      }
    }
  }
  out(ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

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

    sort(niz.begin(), niz.end(), greater<int>());
    long long cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (k > 0)
        {
            k--;
            continue;
        }
        else if (niz[i] > 0)
                cnt += niz[i];
    }
    cout << cnt;
}

Measured memory_bytes: 4052
import numpy as np
n= int(input())
ppp = list(map(float,input().split()))
dp = np.array([0.0]*(n+1),dtype=np.float64)
dp[0]=1
for p in ppp:
  ndp = dp*(1-p)
  ndp[1:] += dp[:-1]*p
  dp = ndp
print(sum(dp[n//2+1:]))

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

using ll = long long;
using P = pair<int, int>;

int main()
{
    string divider[4] = {"dream", "dreamer", "erase", "eraser"};

    rep(i, 4)
    {
        reverse(divider[i].begin(), divider[i].end());
    }

    string S;
    cin >> S;

    reverse(S.begin(), S.end());

    bool can_divide = true;
    for (int i = 0; i < S.length();)
    {
        bool can_divide_by_i = false;
        for (int j = 0; j < 4; j++)
        {
            if (S.substr(i, divider[j].length()) == divider[j])
            {
                can_divide_by_i = true;
                i += divider[j].length();
            }
        }
        if (can_divide_by_i == false)
        {
            can_divide = false;
            break;
        }
    }

    if (can_divide)
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}

Measured memory_bytes: 3764
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int K, X;
    std::cin >> K >> X;
    int count=X-K+1;
    for (int i=0; i < 2*K-1 ;i++){
        std::cout << count << std::endl;
        count++;
        }
}


Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m,l,x,y,a,b;
	string s, t, u;
	cin>>s>>t>>a>>b>>u;
	if(u==s)a--;
	if(u==t)b--;
	cout << a << ' ' << b <<endl;

	return 0;
}


Measured memory_bytes: 256
def subst(S, T)-> int:
  lenT = len(T)
  result = lenT
  for i in range(len(S) - lenT + 1):
    # tempS = S[i-lenT:i]
    tempResult = 0
    for j in range(lenT):
      if T[j] != S[j + i]:
        tempResult += 1
    if tempResult < result:
      result = tempResult
    
  return result

if __name__ == "__main__":
  S = input()
  T = input()
  print(subst(S, T))

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

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



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; string s; cin>>n>>s;
  ll ans=0;
  rep(i,10){
    rep(j,10){
      rep(k,10){
        string t={'0'+i,'0'+j,'0'+k};
        ll pos=0;
        rep(ki,n){
          if(t[pos]==s[ki]){
            pos++;
            if(pos>2){
              ans++;
              break;
            }
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ld long double
#define mem(a,b) memset(a,b,sizeof(a) )
#define M 2005
#define md 1000000007

ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}
//inline ll add(ll a,ll b){return (a+b)%md;}
//inline ll mul(ll a,ll b){return (a*b)%md;}
//ll f[M],iv[M];
//ll C(ll n,ll r){return mul(f[n],mul(iv[r],iv[n-r]));}
//void prep_fac(){
//    f[0]=1;
//    rep(i,1,M)f[i]=mul(i,f[i-1]);
//    iv[M-1]=power(f[M-1],md-2,md);
//    for(ll i=M-2;i>=0;--i)iv[i]=mul(i+1,iv[i+1]);
//}



int main()
{
	IOS;
	int n;
	cin>>n;
	map<int,int>m1,m2;
	int a1[n],a2[n];
	for(int i=0;i<n;i++){
		cin>>a1[i];
		m1[a1[i]]++;
	}
	for(int i=0;i<n;i++){
		cin>>a2[i];
		m2[a2[i]]++;
	}
	for(auto it=m1.begin();it!=m1.end();it++){
		int p=it->ff;
		if(m1[p]+m2[p]>n){
			return cout<<"No",0;
		}
	}
	sort(a2,a2+n);
	reverse(a2,a2+n);
	for(int i=0;i<n;i++){
		if(a1[i]!=a2[i])continue;
		for(int j=0;j<n;j++){
			if(i!=j&&a1[i]!=a2[j]&&a1[j]!=a2[i]){
				swap(a2[i],a2[j]);
				break;
			}
		}
	}
	cout<<"Yes\n";
	for(int i=0;i<n;i++)
	cout<<a2[i]<<" ";	
}



Measured memory_bytes: 23824
// #include <iostream>
// #include <string>
// #include <math.h>
// #include <map>
// #include <vector>
// #include <tuple>
// #include <algorithm>
// #include <queue>
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
int main(){
  long long a, b;
  cin >> a >> b;
  long long big = max(a, b);
  long long sm = min(a, b);
  if((big - sm)%2 == 0){
    cout << (big - sm) / 2 + sm<< endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int n = x;
    int f =0;
    while(n>0){
      f += n%10;
      n=n/10;
    }
    if(x%f==0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
import sys

N, M = map(int, sys.stdin.readline().strip().split())

paths = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().strip().split())
    paths[a].append(b)
    paths[b].append(a)

for i in paths[1]:
    for j in paths[i]:
        if j == N:
            print("POSSIBLE")
            sys.exit()
print("IMPOSSIBLE")

Measured memory_bytes: 38424
import math

n = input()
for i in xrange(n):
    xa, ya, ra, xb, yb, rb = map(float, raw_input().split())
    l = math.hypot(xa - xb, ya - yb)
    if l + rb < ra:
        print 2
    elif l + ra < rb:
        print -2
    elif l <= ra + rb:
        print 1
    else:
        print 0

Measured memory_bytes: 4368
#include <stdio.h>
#define DIGIT 1000000

int prime[DIGIT];

void eratosthenes(void) {
    int i, j;
    prime[1] = 1;
    for(i = 2; i * i < DIGIT + 1; i++ ) {
        for(j = i; j * i < DIGIT; j++ ) {
            prime[i * j] = 1;
        }
    }
}

int main(void) {
    int a, d, n, i, count, num;
    eratosthenes();
    while(scanf("%d %d %d",&a, &d, &n), a != 0) {
        for(count = 0, num = a; ;num += d) {
            if(!prime[num]) { 
                count++;
            }
            if(count == n) {
                break;
            }
        }
        printf("%d\n",num);
    }
    return 0;
}

Measured memory_bytes: 4504
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int X, N;
	vector<int> mpi(110, 0);
	
	cin >> X >> N;

	int t;
	rep(i, N)
	{
		cin >> t;
		mpi.at(t)++;
	}

	int ret = -1;
	rep(i, 100)
	{
		if (mpi.at(X - i) == 0)
		{
			ret = X - i;
			break;
		}
		else if (mpi.at(X + i) == 0)
		{
			ret = X + i;
			break;
		}
	}
	
	if (ret != -1)
	{
		cout << ret << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;

    if (m1 != m2) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    
    return 0;
}


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

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

  vector<int> city(n+1, 0);

  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;

    city[a]++;
    city[b]++;

  }

  for(int i = 0; i < n; i++){
    cout << city[i+1] << endl;
  }

  return 0;

}


Measured memory_bytes: 256
h,w = map(int,input().split())

while True:
    for i in range(h):
        for j in range(w):
            if i == 0 or i == h -1:
                print("#",end="")
            else:
                if j == 0 or j == w -1:
                    print("#",end="")
                else:
                    print(".",end="")
        print("")

    print("")
    h,w = map(int,input().split())
    if  h == 0 and w ==0:
        break


Measured memory_bytes: 7012
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int a, b;
	cin >> a >> b;
	if (a <= 0 && b >= 0) cout << "Zero\n";
	else if (a > 0) cout << "Positive\n";
	else if ((a - b) & 1ll) cout << "Positive\n";
	else cout << "Negative\n";
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int n;
VI pena;
VVI gain;
int eval(VI &order)
{
    VI last(26, -1);
    int ret = 0;
    rep(i, n)
    {
        ret += gain[i][order[i]];
        last[order[i]] = i;
        rep(j, 26)
        {
            ret -= pena[j] * (i - last[j]);
        }
        cout << ret << endl;
    }

    return ret;
}

int main()
{
    cin >> n;
    pena = VI(26);
    gain = VVI(n, VI(26));
    rep(i, 26)
    {
        cin >> pena[i];
    }
    rep(i, n)
    {
        rep(j, 26)
        {
            cin >> gain[i][j];
        }
    }
    VI order(n);
    rep(i, n)
    {
        cin >> order[i];
        order[i]--;
    }
    eval(order);
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main() {
long long A, B;
  cin >> A >> B;
if(A % 2 != B % 2) {
cout << "IMPOSSIBLE" << endl;
} else {
 cout << (A + B) / 2 << endl;
 }
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
static const int MAXN = 100000;
static const int MAX = 1000000000;

int main(){
    string S, T;
    cin >> S >> T;
    rep(i, S.size()){
        if(S[i] != T[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    if(T.size() == S.size() + 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

ll gcd(ll m, ll n) {
  if(m < n) swap(m, n);
  if(n == 0) return abs(m);
  else return gcd(n, m % n);
}

ll lcm(ll m, ll n) {
  return abs(m*n) / gcd(m, n);
}

int main() {
  ll A, B, C, D; cin >> A >> B >> C >> D;
  ll ans = (B-A+1) - B/C - B/D + B/lcm(C, D) + (A-1)/C + (A-1)/D - (A-1) / lcm(C, D);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.io.StdIn._
object Main extends App {

//  val n: Int = readInt()
//  val testimoniesPerPerson: Seq[Seq[(Int, Int)]] = (1 to n).map { _ =>
//    val numOfTestimonies = readInt()
//    val testimonies: Seq[(Int, Int)] = Seq.fill(numOfTestimonies) {
//      val testimony: Array[Int] = readLine().split(" ").map(_.toInt)
//      (testimony(0) - 1, testimony(1)) // Modify to 0 origin
//    }
//    testimonies
//  }
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val testimoniesPerPerson: Array[Map[Int, Boolean]] = Array.fill(n){
    Array.fill(sc.nextInt)(sc.nextInt - 1 -> (sc.nextInt == 1)).toMap
  }


  def solve(): Int = {
    val valids = (1 until (1 << n)).map{ i =>
      val valid = (0 until n)
        .filter{j => ((1 << j) & i) != 0}
        .forall{j => testimoniesPerPerson(j).forall{case (k, b) => (((1 << k) & i) != 0) == b}
        }
      if (valid) Integer.bitCount(i) else 0
    }
    valids.max
  }

  def isHonestPerson(personIndex: Int, bit: Int): Boolean =
    testimoniesPerPerson(personIndex).forall { case (x, y) =>
      y == isBitOn(bit, x)
    }

  def isBitOn(bit: Int, digit: Int): Boolean =
    ((bit >> digit) & 1) != 0

  def countHonest(bit: Int): Int=
    Integer.bitCount(bit)


  println(solve())

}


Measured memory_bytes: 41028
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;

int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	string s[200001];
	//cout << fixed << setprecision(10);
	long long int n, m, k, a[200005] = {}, L[200001], R[200001], p[200001], res = 0, now = 0;
	long long int sum=0;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> s[i] >> p[i];
	}
	s[0] = "zzzzzzzzzzzzz";
	for (int j = 1; j <= n; j++) {
		res = -1;
		now = 0;
		for (int i = 1; i <= n; i++) {
			if (s[i] < s[now] &&a[i]==0) {
				res = p[i];
				now = i;
			}
			else if (p[i] > res && a[i] == 0 && s[i] == s[now]) {
				res = p[i];
				now = i;
			}
		}
		cout << now << endl;
		a[now] = 1;
	}

}


Measured memory_bytes: 4992
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

int gcd(int a, int b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

//-----------------------ここから-----------


int main(void){
    ll n, k;

    cin >> n >> k;

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

    ll ans = 1e9;
    for(int s = 0; s < n - k + 1; s++){
        int g = s + k - 1;
        ll total = 0;
        if((x[s] < 0 && x[g] > 0)){
            total = min(abs(0 - x[s]) * 2 + abs(0 - x[g]), abs(0 - x[s] + abs(0 - x[g]) * 2));
        } else {
            total = max(abs(x[s]), abs(x[g]));
        }

        ans = min(ans, total);
    }

    cout << ans << endl;


}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define ll long long
#define ld long double

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)

#define pii pair<int, int>
#define pll pair<ll, ll>

#define fi first
#define se second

#define pb push_back
#define eb emplace_back

#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()

#define endl '\n'
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const int MOD=1e9+7;
const ll INF=1e18;
const double PI=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;

int dist[110][110];
int a[1000],b[1000],c[1000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n, m;
  cin >> n >> m;
  
  rep(i,n)rep(j,n) dist[i][j]=MOD;
  rep(i,n)dist[i][i]=0;
  
  rep(i,m){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    
    chmin(dist[a[i]][b[i]],c[i]);
    chmin(dist[b[i]][a[i]],c[i]);
    
  }
  rep(k,n)rep(i,n)rep(j,n){
    chmin(dist[i][j],dist[i][k]+dist[k][j]);
  }
  
  int ans = m;
  rep(i,m){
    bool ok = false;
    rep(j,n) if(dist[j][a[i]]+c[i] == dist[j][b[i]]) ok = true;
    if(ok)ans--;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

const int MOD = 1e9 + 7;
const int MAX_N = 200005;
int fact[MAX_N];
int fact_inv[MAX_N];
int bin_pow_mod(int x, int y) {
      if (x == 0) return 0;
      int prod=1;
      while(y>0) {
          if (y & 1) prod = (prod * x) % MOD;
          x = (x * x) % MOD;
          y >>= 1;
      }
      return prod % MOD;
}
struct init_fact {
    init_fact() {
        fact[0] = 1, fact_inv[0] = 1;
        for (int i = 1; i < MAX_N; ++i) {
            fact[i] = (fact[i - 1] * i) % MOD;
            fact_inv[i] = bin_pow_mod(fact[i], MOD - 2);
        }
    }
} init_fact;
int combination(int n, int r) {
    if (n < r) return 0;
    return ((fact[n] * fact_inv[n - r]) % MOD * fact_inv[r]) % MOD;
}

signed main() {
    int n;
    cin >> n;
    vi a(n + 1);
    cin >> a;
    
    map<int, int> cnt;
    FORE(x, a) cnt[x]++;
    
    int tmp = 0;
    vi cont;
    REP(i, n + 1) {
        if (cnt[a[i]] == 2) {
            cont.pb(tmp);
            tmp = 0;
        } else {
            tmp++;
        }
    }
    cont.pb(tmp);
    dump(cont);

    REPF(k, 1, n + 2) {
        int ans = combination(n + 1, k);
        ans -= combination(cont[0] + cont[2], k - 1);
        ans = (ans + MOD) % MOD;
        cout << ans << endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 11392
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int toi, drink;
  cin >> toi;
  vector<int> mondai(toi);
  for (int i = 0; i < toi; i++)
  {
    cin >> mondai.at(i);
  }
  
    cin >> drink;
    int which[drink];
    int how[drink];
    for (int i = 0; i < drink; i++)
    {
      cin >> which[i] >> how[i];
  }

  int p = 0;
  vector<int> sum(drink);
  while (true)
  {
    int sum = 0;
    int tmp = mondai.at(which[p]-1);
    mondai.at(which[p]-1) = how[p];
    //cout <<"deta" <<mondai.at(which[p]) << endl;

    for (int i = 0; i < toi; i++)
    {
      sum+=mondai.at(i);
    }

    cout << sum << endl;
    mondai.at(which[p]-1) = tmp;
    p++;
    if(p==drink){
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    cnt = 0
    for a in range(A+1):
        for b in range(B+1):
            for c in range(C+1):
                price = 500 * a + 100 * b + 50 * c
                if price == X:
                    cnt +=1

    print(cnt)

main()

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

bool is_prime[100010];
int c[100010];
int n, l, r;

int main() {
	for (int i = 2; i <= 100000; i++)if (!is_prime[i])for (int j = i + i; j <= 100000; j += i)
		is_prime[j] = true;
	for (int i = 3; i <= 100000; i += 2)if (!is_prime[i] && !is_prime[(i + 1) / 2])c[i]++;
	for (int i = 3; i <= 100000; i++)c[i] += c[i - 1];

	scanf("%d", &n);
	while (n--) {
		scanf("%d%d", &l, &r);
		printf("%d\n", c[r] - c[l - 1]);
	}

	
	return 0;
}

Measured memory_bytes: 1152
import sys
input = sys.stdin.readline
ri = lambda: int(input())
#rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

N=ri()
A=list(rl())
cnt = [0]*3
ans = 0
sei = []
for a in A:
    sei.append(abs(a))
    ans += abs(a)
    if a > 0:
        cnt[0] += 1
    elif a == 0:
        cnt[1] += 1
    elif a < 0:
        cnt[2] += 1

if cnt[1] > 0 or cnt[2]%2 == 0:
    None
else:
    ans -= 2 * min(sei)

print(ans)

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

int mean(int *a, int n) {
    int sum = 0;
    for(int i = 0; i < n; i++) {
        sum += a[i];
    }
    return sum / n;
}

int main() {
    int N;
    int X[100];
    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> X[i];
    }
    int p = mean(X, N);
    int p2 = p + 1;
    int sum1 = 0;
    int sum2 = 0;
    for (int i = 0; i < N; i++) {
        sum1 += (X[i] - p) * (X[i] - p);
        sum2 += (X[i] - p2) * (X[i] - p2);
    }
    if (sum1 < sum2) cout << sum1;
    else cout << sum2;
    cout << endl;
    return 0;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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 long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

int main() {
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;

    string s;
    cin >> s;

    int c1 = 0;
    int c2 = 0;
    int max_space = 0;
    rep(i,A,max(C,D)) {
        if(s[i]=='.') {
            c1 = 0;
            if(B-2<=i && i<=D) c2++;
        } else {
            c1++;
            c2 = 0;
        }

        chmax(max_space,c2);

        if(c1>=2) {
            // 連続２個があるのでこえられない
            cout << "No" << endl;
            return 0;
        }
    }

    // AとBの大小関係とCとDの大小関係が一致していればOK
    if(C < D){
        cout << "Yes" << endl;
        return 0;
    }

    // 追い抜かせればOK
    if(max_space >= 3) {
        cout << "Yes" << endl;
        return 0;
    }

    // 近い方の前後が岩だと、実質２連続岩
    if(s[D-2]=='#' || s[D]=='#') {
        cout << "No" << endl;
        return 0;
    }

    // その他はOK
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long N, M, A[1 << 18];

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> A[i];
		N -= A[i];
	}
	if (N < 0) cout << "-1" << endl;
	else cout << N << endl;
	return 0;
}

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

int main(void){
	int D;
	cin >> D;
	int c[26];
	int s[D][26];
	rep(i,26) cin >> c[i];
	rep(i,D) rep(j,26) cin >> s[i][j];

	int t[D];
	rep(i,D) cin >> t[i];
	long long v = 0;
	int last[26];
	rep(i,26) last[i] = 0;
	rep(i,D){
		v += s[i][t[i]-1];
		int dec = 0;
		last[t[i]-1] = i+1;
		int d = i+1;
		rep(j,26) dec += c[j]*(d-last[j]);
		v -= dec;
		cout << v << endl;
	}


return 0;
}


Measured memory_bytes: 3672
#include<iostream>
#include<vector>
#define ll long long int 
using namespace std;
 
int main()
 
{
	ll n,sum=0;
	cin >> n;
	int lim = 1e5 +90;
	ll  cnt[lim]= {};
	
	for(int i=0; i<n; i++){
        ll x;
		cin >> x;
		sum = sum + x;
        cnt[x]++;
	}
	
	ll m;
	cin>>m;
	
	for(int i=0; i<m; i++){
		ll b, c;
		cin >> b >> c;

        if (cnt[b]){
            sum += (c-b)*cnt[b];
            ll p = cnt[b] ;
            cnt[c] += p ;
            cnt[b] = 0;
        }
        cout << sum << endl ;
	}
		
	return 0;
}





Measured memory_bytes: 4372
#include<stdio.h>

void heapsort(int n, int a[]) {
	int i, j, k;
	int x;

	for (k = n / 2; k >= 1; k--) {
		i = k;
		x = a[i];
		while ((j = 2 * i) <= n) {
			if (j < n && a[j] < a[j + 1])j++;
			if (x >= a[j])break;
			a[i] = a[j];
			i = j;
		}
		a[i] = x;
		//for (int i = 1; i <= n; i++)printf("%2d ", a[i]);
		//printf("\n");
	}
	while (n > 1) {
		x = a[n];
		a[n] = a[1];
		n--;
		i = 1;
		while ((j = 2 * i) <= n) {
			if (j < n && a[j] < a[j + 1])j++;
			if (x >= a[j])break;
			a[i] = a[j];
			i = j;
		}
		a[i] = x;
		//for (int i = 1; i <= n; i++)printf("%2d ", a[i]);
		//printf("\n");
	}
}

int main(void) {

	int n, k, l = 0;
	int h[200000];
	int max = 0;
	long long int sum = 0;

	scanf("%d %d", &n, &k);

	for (int i = 1; i <= n; i++) {
		scanf("%d", &h[i]);
	}

	heapsort(n, h);

	for (int i = 1; i <= n - k; i++)sum += h[i];

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

	return 0;
}

Measured memory_bytes: 896
#include<functional>
#include<algorithm>
#include<exception>
#include<stdexcept>
#include<streambuf>
#include<iterator>
#include<string.h>
#include<stdlib.h>
#include<typeinfo>
#include<valarray>
#include<iostream>
#include<sstream>
#include<istream>
#include<stdio.h>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<ctype.h>
#include<cassert>
#include<cstdlib>
#include<utility>
#include<cstring>
#include<numeric>
#include<ostream>
#include<cwctype>
#include<fstream>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cctype>
#include<string>
#include<vector>
#include<limits>
#include<locale>
#include<memory>
#include<cerrno>
#include<time.h>
#include<iosfwd>
#include<cfloat>
#include<cstdio>
#include<cwchar>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<ios>
#include<map>
#include<set>
#include<new>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,w[1005];
int main()
{
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n;
	for (int i=2;i<=n;i++)
	{
		int x=i;
		for (int j=2;j<=i;j++)
		{
			while(x%j==0)
			{
			    x/=j;
			    w[j]++;
		    }
		}
	}
	long long ans=1;
	for (int i=2;i<=1000;i++)
	ans=ans*(w[i]+1)%mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] v=new int[n];
		for(int i=0;i<n;i++){
			v[i]=sc.nextInt();
		}
		Arrays.sort(v);
		double ans=v[0];
		for(int i=1;i<n;i++){
			ans=(ans+v[i])/2;
		}
		System.out.println(ans);
			
	}
	
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define length size()
#define int long long
#define ll long long
const int MOD = 1000000007;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
template<typename T> string join(vector<T> &vec ,const string &sp){
    int si = vec.length;
    if(si==0){
        return "";
    }else{
        stringstream ss;
        rep(i,si-1){
            ss << vec[i] << sp;
        }
        ss << vec[si - 1];
        return ss.str();
    }
}
signed main(void){
    int n;
    cin >> n;
    COMinit();
    int sum = 0;
    for(int i=1;i<=n/3;i++){
        //iH(n-i*3)
        sum += COM(i+(n-i*3)-1,(n-i*3));
        //cout << sum << " " << i << " " << i+(n-i*3)-1 << endl;
        sum %= MOD;
    }
    cout << sum << endl;
}


Measured memory_bytes: 15580
package main

import "fmt"

func main() {
	var (
		n, m, c, num int
	)
	fmt.Scan(&n, &m)

	point := make(map[int]int, m)
	for i := 0; i < n; i++ {
		fmt.Scan(&c)
		for j := 0; j < c; j++ {
			fmt.Scan(&num)
			point[num]++
		}
	}

	var count int
	for _, val := range point {
		if val == n {
			count++
		}
	}
	fmt.Print(count)
}


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

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}


void solve()
{
    ll n,s;
    cin>>n>>s;
    vl a(n+1);
    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }

    vector<vl> dp(n+1,vl(s+1,0));
    dp[0][0]=1;
    for(int i=1;i<=n;i++) {
        for(int j=0;j<=s;j++) {
            dp[i][j] = (dp[i-1][j]*2)%MOD;
            if(j-a[i]>=0) {
                dp[i][j] = (dp[i][j]+dp[i-1][j-a[i]])%MOD;
            }
        }
    }

    cout<<dp[n][s];


}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 73688