akhauriyash/Code-Regression huggingface dataset:
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    VV vec(2,V(n));
    rep(i,2){
        rep(j,n){
            cin>>vec[i][j];
        }
    }
    ll res=0;
    rep(k,n){
        ll temp=0;
        
        rep(i,k+1){
            temp+=vec[0][i];
        }
        rep3(i,k,n){
            temp+=vec[1][i];
        }
       // cout<<temp<<endl;
        chmax(res,temp);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#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() {
    int n;
    cin >> n;

    vector<string> w(n);
    rep(i,n) {
        cin >> w.at(i);
    }

    char lastChar=w.at(0)[w.at(0).size()-1];
    for (int i=1; i<n; i++) {
        rep(j, i) {
            if (w.at(j) == w.at(i)) {
                cout << "No" << endl;
                return 0;
            }
        }
        if (lastChar != w.at(i)[0]) {
            cout << "No" << endl;
            return 0;
        }
        lastChar = w.at(i)[w.at(i).size()-1];
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3608
from itertools import permutations
from decimal import *
import math

def main():
    N = int(input())
    X = [] 
    for i in range(N):
        x, y = map(int, input().split())
        X.append((x,y))

    ans = 0

    for A in permutations(X):
        tmp = 0
        i = 0
        pre_x = 0
        pre_y = 0
        for x, y in A:
            if i == 0:
                pre_x = x
                pre_y = y
                i += 1
            else:
                tmp = (x - pre_x) ** 2 + (y - pre_y) ** 2
                ans += tmp ** 0.5
                i += 1 
    
    ans = Decimal(ans) / Decimal(math.factorial(N))
    print(ans)




  

if __name__ == "__main__":
    main()

Measured memory_bytes: 60396
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;
        
        vector<pair<int,int> > a(n);
        for(int i=0; i<n; i++){
            int gain, limit;
            cin >> gain >> limit;
            a[i] = make_pair(limit, gain);
        }
        sort(a.begin(), a.end());

        bool ans = true;
        int amount = 0;
        for(int i=0; i<n; i++){
            amount += a[i].second;
            if(a[i].first < amount){
                ans = false;
                break;
            }
        }
        cout << (ans? "Yes" : "No") << endl;
    }
    return 0;
}



Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

void chmax(string &a, string b) {
  if (a == "-") { a = b; }
  else if (a.size() < b.size()) { a = b; }
  else if (a.size() == b.size()) {
    if (a < b) { a = b; }
  }
}

int main(){
  int match[] = {-1,2,5,5,4,5,6,3,7,6};
  int n, m;
  cin >> n >> m;

  vector<int> a(m);
  for (int i = 0; i < m; i++) { cin >> a[i]; }

  vector<string> dp(n+10, "-");
  dp[0] = "";
  for (int i = 0; i < n; i++) {
    if (dp[i] == "-") { continue; }
    for (int j = 0; j < m; j++) {
      chmax(dp[i + match[a[j]]], dp[i] + (char)('0'+a[j]));
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 43648
#include<cstdio>
#include<algorithm>
#include<vector>
#include<sstream>
#include<cstdlib>

using namespace std;

int main(){
	while(1){
		int n,k;
		scanf("%d%d",&n,&k);
		
		if(n==0)
			break;
		
		vector<int> card(n);
		for(int i=0;i<n;i++){
			scanf("%d",&card[i]);
		}
		
		sort(card.begin(),card.end());
		
		vector<int> data;
		do{
			
			stringstream sst;
			for(int i=0;i<k;i++){
				sst<<card[i];
			}
			data.push_back(atoi(sst.str().c_str()));
			
			
			reverse( card.begin()+k,card.end());
		}while( next_permutation(card.begin(),card.end()) );
		
		sort(data.begin(),data.end());
		
		
		printf("%d\n",distance(data.begin(),unique(data.begin(),data.end())) );
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,pown=1,t[7000005],a[200005],b[200005],l,r,ans;
void upd(ll x){
    if(!x)return;
    t[x] = t[2 * x] + t[2 * x + 1];
    upd(x / 2);
}
ll cnt(ll x,ll L,ll R){
    if(L > r || R < l)return 0LL;
    if(L >= l && R <= r)return t[x];
    ll k1 = cnt(2 * x,L,(L + R)/2);
    ll k2 = cnt(2 * x + 1,(L+R)/2+1,R);
    return k1+k2;
}
bool check(ll x){
    for(int i=1; i<=n; i++){
        if(b[i] <= x)a[i] = 1;
        else a[i] = 0;
    }
    for(int i=1; i<=3 * pown; i++){
        t[i] = 0;
    }
    ll rr = 0,raod = 0;
    t[pown + n + 1 - 1]++;
    upd((pown + n + 1 - 1) / 2);
    for(int i=1; i<=n; i++){
        if(a[i] == 1)rr++;
        else rr--;
        l = 1;
        r = rr + n;
    //    cout << l << " " << r << " <--count\n";
        raod += cnt(1 , 1 , pown);
    //    cout << (rr + n + 1) << "<-- add\n";
        t[pown + (rr + n + 1) - 1]++;
        upd((pown + (rr + n + 1) - 1) / 2);
    }
//    cout << x << " " << raod << endl;
    if(raod * 2 > n * (n + 1) / 2)return 1;
    return 0;
}
int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    while(pown <= 3 * n)
        pown *= 2;
    for(int i=1; i<=n; i++)cin >> b[i];
    
    ll l=1,r=1000000000,mid;
    while(r >= l){
        mid = (l + r) / 2;
        if(check(mid)){
            r = mid - 1;
            ans = mid;
        }
        else {
            l = mid + 1;
        }
    }
    
    cout << ans << endl;
    
    
    return 0;
}


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

using namespace std;

#define FOR(i,a,b)  for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n)    FOR(i,0,n)
#define ALL(a)      a.begin(),a.end()
#define vi          vector<int>
#define vvi         vector<vi>
#define P           pair<int,int>
#define vP          vector<P>
#define vvP         vector<vP>

int main(){
    int a,b,k;cin>>a>>b>>k;
    set<int> data;
    REP(i,k){
        if(a+i<=b)data.insert(a+i);
        if(b-i>=a)data.insert(b-i);
    }
    for(auto itr=data.begin();itr!=data.end();itr++){
        cout<<*itr<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int n;
	ll r=1000000000;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		ll t,c=0;
		cin>>t;
		while(t>=0&&t%2==0){t/=2;c++;}
		r=min(r,c);
	}
	cout<<r<<endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double s = 0.0, x;
        String u;
        for (int i = 0;i < n;i++){
            x = sc.nextDouble();
            u = sc.next();
            if(u.equals("JPY")){
                s += x;
            }else if (u.equals("BTC")){
                s += x * 380000.0;
            }
        }
        System.out.println(s);
    }
}


Measured memory_bytes: 23124
S = input()
flag = True

for i in range (0, len(S), 2):
  if S[i] == "L":
    print("No")
    flag = False
    exit()

for j in range (1, len(S), 2):
  if S[j] == "R":
    print("No")
    flag = False
    exit()
    
if flag == True:
  print("Yes")

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

typedef long long LL;
const LL Md=998244353;
const int MAXN=4111;
LL C[MAXN][MAXN], P[MAXN], ans[MAXN];
int n, k;

inline LL Solve(int x) {
    --x;
    if(x&1) {
        int cnt=x/2, oth=k-x;
        LL res=0;
        for(int i=0;i<=cnt && i<=n;++i) {
            res=(res+C[cnt][i]*C[n+oth-1][oth+i-1]%Md*P[i])%Md;
            if(i<n) res=(res+C[cnt][i]*C[n+oth-2][oth+i-1]%Md*P[i])%Md;
        }
        return res;
    } else {
        int cnt=x/2, oth=k-x;
        LL res=0;
        for(int i=0;i<=cnt && i<=n;++i) {
            res=(res+C[cnt][i]*C[n+oth-1][oth+i-1]%Md*P[i])%Md;
        }
        return res;
    }
}

int main() {
    scanf("%d%d", &k, &n);
    P[0]=1;
    C[0][0]=1;
    for(int i=1;i<=4000;++i) {
        P[i]=P[i-1]+P[i-1];
        if(P[i]>=Md) P[i]-=Md;
        C[i][0]=C[i][i]=1;
        for(int j=1;j<i;++j) {
            C[i][j]=C[i-1][j]+C[i-1][j-1];
            if(C[i][j]>=Md) C[i][j]-=Md;
        }
    }
    for(int i=2;i<=k+1;++i) {
        printf("%lld\n", ans[i]=Solve(i));
    }
    for(int i=k;i>=2;--i) {
        printf("%lld\n", ans[i]);
    }
    return 0;
}

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

using namespace std;

#define llong long long
#define ii pair<int, int>
#define xx first
#define yy second
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define len(x) ((int)x.size())

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  llong n, m, k; cin >> n >> m >> k;

  rep(i, n + 1) rep(f, m + 1) {
    if (i * m + f * n - 2 * i * f == k) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";

  return 0;
}


Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc126/tasks/abc126_b
// implementation
import std.algorithm;
import std.conv;
import std.stdio;
import std.string;

void main() {
    const int a = readln.chomp.to!int;

    const int yy = a / 100;
    const int mm = a % 100;

    if(yy >= 1 && yy <= 12) {
        if(mm >= 1 && mm <= 12)
            "AMBIGUOUS".writeln;
        else
            "MMYY".writeln;
    } else {
        if(mm >= 1 && mm <= 12)
            "YYMM".writeln;
        else
            "NA".writeln;
    }
}



Measured memory_bytes: 2620
#include <bits/stdc++.h>
#include <string>
using namespace std;
const int maxn=1e5+10;
int num[6]={100,101,102,103,104,105};
bool f[maxn];
int main(){
	int a;
	cin>>a;
	for(int i=0;i<6;i++) f[num[i]]=true;
	for(int i=200;i<=a;i++){
		for(int j=0;j<6;j++){
			if(f[i-num[j]]) f[i]=true;
//			if(num[i]) break;
		}
	}
	cout<<f[a];
} 

Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>

#define rep(i, n) for (int i = 0; i < n; i++) 
#define rrep(i, n) for(int i = n-1; i>=0; i--)
#define range(i, n, m) for (int i = n; i < m; i++) 
#define rrange(i, n, m) for (int i = n - 1; i => m; i--) 
#define MOD 1000000007
#define MAX 20000000000

typedef long long int ll;
typedef unsigned long long int ull;


using namespace std;

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

ll mydiv(ll a, ll b);
ll modpow(ll a);

ll mydiv(ll a, ll b) {
	a = a % MOD;
	return (a * (modpow(b) % MOD)) % MOD;
}


ll modpow(ll a) {
	ll b = MOD - 2;
	ll res = 1;
	while (b > 0) {
		if (b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res % MOD;

}


inline ll nCr(ll n, ll r) {
	if (n < r)return 0;
	ll bunbo = 1;
	ll bunsi = 1;
	//ll ret = 0;
	for (ll i = 1; i <= r; i++) {
		bunbo = (bunbo * (n - i + 1)) % MOD;
		bunsi = (bunsi * i) % MOD;
		//ret = (ret + (n - i + 1) / i) % MOD;

	}

	return mydiv(bunbo, bunsi);

}

map<ll, ll> prime_factor(ll N) {
	map<ll, ll> ret;

	for (ll i = 2; i * i <= N; i++) {
		while (N % i == 0) {
			ret[i]++;
			N /= i;
		}
	}
	if (N != 1)ret[N] = 1;
	return ret;

}

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

	ll N, M;

	cin >> N >> M;


	map<ll, ll> prime = prime_factor(M);

	ll ret = 1;

	for(pair<ll, ll> p: prime) {
		ret = (ret * nCr(p.second + N - 1, p.second)) % MOD;
	}


	cout << ret << endl;



	
	return 0;
}


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

int main (){
    string S;
    cin>>S;
    int Size=S.size();
    int Count=0;
    
        for(int i=0; i<Size/2; i++){
            if(!(S.at(i)==S.at(Size-1-i))){
                Count ++;
            }
        }
    cout<<Count;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    vector<int> change(256);
    change['A'] = 1;
    for(int i=2; i<=9; ++i)
        change['0'+i] = i;
    change['T'] = 10;
    change['J'] = 11;
    change['Q'] = 12;
    change['K'] = 13;
    change['S'] = 0;
    change['C'] = 1;
    change['H'] = 2;
    change['D'] = 3;

    bool isFirst = true;
    for(;;){
        int n;
        if(!(cin >> n))
            return 0;

        if(isFirst)
            isFirst = false;
        else
            cout << endl;

        vector<vector<int> > basic(4, vector<int>(13));
        for(int i=0; i<4; ++i){
            for(int j=0; j<13; ++j){
                cin >> basic[i][j];
            }
        }

        vector<int> times(9);
        for(int i=0; i<9; ++i)
            cin >> times[i];

        while(--n >= 0){
            vector<pair<int, int> > cards(5);
            for(int i=0; i<5; ++i){
                string s;
                cin >> s;
                cards[i].first = change[s[0]];
                cards[i].second = change[s[1]];
            }
            sort(cards.begin(), cards.end());

            bool flash = true;
            vector<int> same(3, 0);
            int sameNum = 0;
            for(int i=0; i<5; ++i){
                if(i < 4 && cards[i].second != cards[i+1].second)
                    flash = false;
                if(i < 4 && cards[i].first == cards[i+1].first)
                    ++ sameNum;
                else if(sameNum > 0){
                    ++ same[sameNum-1];
                    sameNum = 0;
                }
            }

            int yaku = -1;
            if(same[2] == 1)
                yaku = 6; // tH[J[h
            else if(same[1] == 1){
                if(same[0] == 1)
                    yaku = 5; // tnEX
                else
                    yaku = 2; // X[J[h
            }else if(same[0] == 2){
                yaku = 1; // c[yA
            }else if(same[0] == 1){
                yaku = 0; // yA
            }else if(flash){
                if(cards[0].first == 1 && cards[1].first == 10)
                    yaku = 8; // CXg[gtbV
                else if(cards[4].first - cards[0].first == 4)
                    yaku = 7; // Xg[gtbV
                else
                    yaku = 4; // tbV
            }else{
                if((cards[0].first == 1 && cards[1].first == 10) || cards[4].first - cards[0].first == 4)
                    yaku = 3; // Xg[g
            }

            int ret = 0;
            if(yaku != -1){
                for(int i=0; i<5; ++i)
                    ret += basic[cards[i].second][cards[i].first-1];
                ret *= times[yaku];
            }
            cout << ret << endl;
        }
    }
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  string s;
  cin >> s;
  int a = stoi(s);
  int sum = 0;
  for(int i = 0; i < s.length(); i++) {
    sum += (int)(s[i] - 48);
  }

  if(a % sum) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

n, p = map(int, input().split())
a = list(map(int, input().split()))

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

m = len(even)
count1 = 0
for i in range(m+1):
    count1 += comb(m, i)

k = len(odd)
count2 = 0
if p == 0:
    for i in range(0, k+1, 2):
        count2 += comb(k, i)
else:
    for i in range(1, k+1, 2):
        count2 += comb(k, i)

print(count1*count2)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pii;

int main() {
  ll N, res = 1;
  int mod = 1000000007;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  if (A[0] != 0) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> color(3, 0);
  for (int a : A) {
    int p = 0;
    for (int &c : color) {
      if (c == a) {
        p++;
        if (p == 1) {
          c++;
        }
      }
    }
    res = (res * p) % mod;
  }
  cout << res << endl;
  return 0;
}

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

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

ll power(ll x, int y){
  ll tmp = y;
  ll curr = x;
  ll res = 1;
  while(tmp){
    if(tmp % 2 == 1){
      res = (res * curr) % mod;
    }
    curr = (curr * curr) % mod;
    tmp /= 2;
  }
  return res;
}

ll fac[200001];

ll invfac(int x){
  return power(fac[x], mod - 2);
}

ll comb(ll x, ll y){
  ll res = fac[x];
  res = (res * invfac(y)) % mod;
  res = (res * invfac(x - y)) % mod;
  return res;
}

int main(int argc, char const* argv[])
{
  int n;
  ll m;
  cin >> n >> m;

  fac[0] = 1;
  for(int i = 1; i < 200001; i++){
    fac[i] = (fac[i - 1] * i) % mod;
  }

  unordered_map<ll, int> mp;
  ll tmp = m;
  for(int i = 2; (ll)i * i <= m; i++){
    while(tmp % i == 0){
      tmp /= i;
      mp[i]++;
    }
  }
  if(tmp != 1)mp[tmp]++;

  ll res = 1;
  for(auto itr = mp.begin(); itr != mp.end(); ++itr){
    int alpha = itr->second;
    res = (res * comb(alpha + n - 1, n - 1)) % mod;
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 1792
#Macで実行する時
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../atcoder/input.txt'))
	#print(name)
	sys.stdin = open(name)

a = int(input())

b = a%1000

if b==0:
    print(0)
else:
    print(1000-b)




Measured memory_bytes: 61580
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

	public static void main(String args[]) throws IOException{
		Scanner sc = new Scanner(System.in);
		
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//StringTokenizer st = new StringTokenizer(br.readLine());
		
		//StringBuilder sb = new StringBuilder();
		
		int n = sc.nextInt();
		double x[] = new double[n];
		double y[] = new double[n];
		
		for(int i=0;i<n;i++){
			x[i] = sc.nextDouble();
			y[i] = sc.nextDouble();
		}
		
		for(int i=0;i<n;i++){
			ArrayList<Double> s = new ArrayList<>();
			for(int j=0;j<n;j++){
				if(i!=j){
					s.add(Math.atan2(y[j]-y[i],x[j]-x[i]));
				}
			}
			
			Collections.sort(s);
			
			double max = 0;
			for(int j=0;j<n-2;j++){
				max = Math.max(s.get(j+1)-s.get(j), max);
			}
			
			max = Math.max(max, 2* Math.PI - (s.get(n-2) - s.get(0)));
			
			System.out.println(Math.max((max - Math.PI)/2/Math.PI, 0));
		}
		
		
	}
}

Measured memory_bytes: 25524
tmp = int(input())
arr = [int(x) for x in input().split()]
nep = 0
krat = 0
for elem in arr:
    if elem % 4 == 0:
        krat += 1
        continue
    if elem % 2 == 1:
        nep += 1
if krat - nep >= -1:
    if krat - nep == -1:
        if nep + krat == tmp:
            print("Yes")
        else:
            print("No")
    else:
        print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a,b,k;
  cin >> a >> b >> k;
  int ans;
  int count=0;
  int m=(max(a,b));
    for(int i=m;i>0;i--){
    if(a%i==0&&b%i==0){
      ans=i;
      count++;
    }
    if(count==k){
      break;
    }
}
  cout<<ans<<endl;
}

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

int n, a, b, c;
vector<int> v;
int ans = 1000000000;

int check(string s) {
  if (s.size() > n || s.size() == 0) return 10000000;

  int cont_A = 0, cont_B = 0, cont_C = 0;
  int sum_A = 0, sum_B = 0, sum_C = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'a') {
      cont_A++;
      sum_A += v.at(i);
    }
    if (s.at(i) == 'b') {
      cont_B++;
      sum_B += v.at(i);
    }
    if (s.at(i) == 'c') {
      cont_C++;
      sum_C += v.at(i);
    }
  }

  if (cont_A == 0 || cont_B == 0 || cont_C == 0) return 10000000;
  int mp = abs(a - sum_A) + abs(b - sum_B) + abs(c - sum_C);
  int cnt = (cont_A + cont_B + cont_C - 3) * 10;
  mp += cnt;
  return mp;
}

void dfs(string s) {
  ans = min(ans, check(s));

  if (s.size() <= n) {
    dfs(s + "a");
    dfs(s + "b");
    dfs(s + "c");
    dfs(s + "d");
  }
}

int main() {
  cin >> n >> a >> b >> c;
  v.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }

  string s = "";
  dfs(s);
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		// 整数の入力
		int a = in.nextInt();
		// スペース区切りの整数の入力
		int b = in.nextInt();
		int c = in.nextInt();

		int ans = c*(a+b)/2;
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
int main ( ) {
	long long q,h,s,d,n;
	cin>>q>>h>>s>>d>>n;
	s=min(q*4,min(h*2,s));
	d=min(s*2,d);
	if (n%2==1) {
		cout<<n/2*d+s<<endl;
	}
	else {
		cout<<n/2*d<<endl;
	}
	return 0;
}
/*

*/

Measured memory_bytes: 256
/*
Written By mafailure
*/
//In the name of God
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
//#define int long long 
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
const long long mod = 1e9 + 7;
#define int long long 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define frr(i,init,final) for(int i=init;i>=final;i--)
#define Fr(i,final) for(int i=0;i<final;i++)
#define Frr(i,first) for(int i=first;i>=0;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
#define setb __builtin_popcount
#define lsone(n) (n&(-n))
#define rlsone(n) (n&(n-1))
#define clr(a,b) memset(a,b,sizeof(a))
const int inf= INT_MAX;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  ordered_set; 
vi init(string s)
{
	istringstream sin(s);
	int n;
	vi arr;
	while(sin>>n)arr.push_back(n);
	return arr;
}
int power(int x, int y)
{ 
	if(y==0)return 1;
	int u=power(x,y/2);
	u=(u*u)%mod;
	if(y%2)u=(x*u)%mod;
	return u;
    
}
int gcd(int a,int b)
{
	if(a<b)return gcd(b,a);
	return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{
	
	if(b==0){x=1; y=0; return a;}
	int x1,y1;
	int p=gcd_e(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;
	return p;
}
int dist(int x,int y){return x*x+y*y;}
signed main()
{
	IOS
	int n;
	cin>>n;
	int d;
	cin>>d;
	int lim=d*d;
	int cnt=0;
	fr(i,0,n)
	{
		int x,y;
		cin>>x>>y;
		if(dist(x,y)<=lim)cnt++;
	}
	cout<<cnt<<endl;
	
}



Measured memory_bytes: 3640
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;

int N;
double dp[305][305][305];
bool flag[305][305][305];

double rec(int i, int j, int k) {

    if (flag[i][j][k]) return dp[i][j][k];
    flag[i][j][k] = true;

    if (i == 0 && j == 0 && k == 0) return 0.0;

    double res = 0.0;

    if (i > 0) res += rec(i-1, j, k) * ((double)i / N);
    if (j > 0) res += rec(i+1, j-1, k) * ((double)j / N);
    if (k > 0) res += rec(i, j+1, k-1) * ((double)k / N);
    res += 1;
    res *= (double)N / (i+j+k);

    return dp[i][j][k] = res;
}


void solve() {
    cin >> N;
    vector<int> cnt(4);
    int one = 0, two = 0, three = 0;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        cnt[a]++;
    }

    cout << setprecision(15) << rec(cnt[1], cnt[2], cnt[3]) << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 127152
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define PI 3.14159265359
 
int main(){
  ll X, A, B, i, j;
  
  cin >> X;
  
  for (ll A = -500; A <= 500; A++){
    for(ll B = -500; B <= 500; B++){
      if(pow(A, 5) - pow(B, 5) == X){
        cout << A << " " << B << endl;
        return 0;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 4068
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();
		long sum = 0;
		
		ArrayList<Long> h = new ArrayList<Long>();
		
		for(int i = 0; i < n; i++){
			h.add(scan.nextLong()); 
		}
		
		Collections.sort(h,Collections.reverseOrder());
		
		for(int i = k; i < n; i++){
			sum += h.get(i);
		}
		
		System.out.println(sum);
		
	}
}

Measured memory_bytes: 91960
# coding: utf-8
h, w = map(int,input().split())
alp=[chr(i) for i in range(65, 65+26)]
for i in range(h):
    l=list(map(str,input().split()))
    if "snuke" in l:
        print(alp[l.index("snuke")]+str(i+1))
        break

Measured memory_bytes: 61984
#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=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

void solve()
{
  vector<string> words = {"dream", "dreamer", "erase", "eraser"};
  string s;
  cin >> s;

  bool p = true;
  while(!s.empty()) {
    bool flg = false;
    for (int i=0; i<4; i++) {
      int l = words[i].length();
      if ((int)s.length()>=l && s.substr(s.length()-l, l) == words[i]) {
        s = s.substr(0, s.length()-l);
        flg = true;
      }
    }
    if (!flg) {
      p = false;
      break;
    }
  }

  if (p)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <climits>
#include <vector>
#include <stdlib.h>
#include <memory.h>
using namespace std;
#define M 50000
typedef unsigned long long big;

int main()
{
	string s;
	cin>>s;
	big ans=0;
	for(int i=0;i<s.size()-1;i++)
	if(s[i]!=s[i+1])
	ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{   
    int N; cin>>N;
    string s=to_string(N);
    int sum1=0,sum2=0;
    REP(i,s.size()){
        sum1+=s[i]-'0';
        if(i==0) sum2+=s[i]-'1';
        else sum2+=9;
    }
    cout<<max(sum1,sum2)<<endl;
}


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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int h1,m1,h2,m2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  int h = (h2 - h1)*60;
  h += (m2-m1);
  cout << h - k << endl;
  return 0;
}



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
#define PB push_back
#define loop(i,x,y) for(int i=x;i<y;i++)
#define rloop(i,x,y) for(int i=x;i>y;i--)
#define NL cout<<"\n"
#define ans(x) cout<<x<<"\n"
#define out(x) cout<<x<<" "
#define F first
#define S second
#define ansf(x,y) cout<<fixed<<setprecision(y)<<x<<endl;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
void solve()
{
  int cc=0;
  string s;
  cin>>s;
  loop(i,0,s.length()/2)
    if(s[i]!=+s[s.length()-i-1])
      cc++;
  ans(cc);
}
signed main()
{
  // FAST;
  int T=1;
  // cin>>T;
  while(T--) solve();
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
A = Array.new(40){Array.new(40, 0)}

N.times do |i|
    s = gets.chomp
    num = 0
    if s.include?('.')
        ss = s.split('.')
        l = ss[1].size
        num = (ss[0].to_i * 10**l + ss[1].to_i) * 10**(9-l)
        A.push(num)
    else
        num = s.to_i * 10**9
    end
    n2 = 0
    n5 = 0
    while num%2 == 0 && n2 < 18
        n2 += 1
        num /= 2
    end
    while num%5 == 0 && n5 < 18
        n5 += 1
        num /= 5
    end
    A[n2][n5] += 1
end

B = Array.new(40){Array.new(40, 0)}
ans = 0
19.times do |i|
    19.times do |j|
        num = A[i][j]
        if i*2 >= 18 && j*2 >= 18
            ans += num*(num-1)/2
        end
        19.times do |x|
            19.times do |y|
                if i+x >= 18 && j+y >= 18
                    ans += num * B[x][y]
                end
            end
        end
        B[i][j] += num
    end
end
puts ans

Measured memory_bytes: 16144
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def warshall_floyd(g):
    d = defaultdict(dict)
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v))
    V = set(V)
    for i in V:
        for j in V:
            if i in g and j in g[i]:
                d[i][j] = g[i][j]
            else:
                d[i][j] = sys.maxsize
    for k in g:
        for i in g:
            for j in g:
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]

    return d


@mt
def slv(N, A):
    c = Counter(A)
    ks = list(c.keys())
    ks.sort()

    ans = 0
    for k in ks:
        if c[k] % 2 == 1:
            c.pop(k)
            ans += 1
        else:
            c[k] = 2

    ans += len(c)
    if len(c) % 2 == 1:
        ans -= 1

    return ans


def main():
    N = read_int()
    A = read_int_n()

    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 83376
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int N;
	scanf("%d",&N);
	if((N/100)==(N%10)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

void chmin(int &a, int b){
  if(a > b)
    a = b;
}
void chmax(int &a, int b){
  if(a < b)
    a = b;
}

void llchmin(ll &a, ll b){
  if(a > b)
    a = b;
}
void llchmax(ll &a, ll b){
  if(a < b)
    a = b;
}

int main(){
  int n;
  cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  
  rep(i, 0, n){
    string s;
    cin >> s;
    if(s == "AC")
      ac++;
    if(s == "WA")
      wa++;
    if(s == "TLE")
      tle++;
    if(s == "RE")
      re++;
  }
  
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  
  return 0;
  
}

Measured memory_bytes: 3644
package main
import "fmt"
func main() {
  var n,a,b int
  fmt.Scan(&n,&a,&b)
  if a > b || (a != b && n == 1) {
    fmt.Println(0)
  } else {
    var max int64 = int64(b)*int64(n-1)+int64(a)
    var min int64 = int64(a)*int64(n-1)+int64(b)
    fmt.Println(max-min+1)
  }
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset  set<int>::reverse_iterator rit; for(rit=s.rbegin();rit!=s.rend();rit++)
#include <vector>
#include <stack>
#include <cmath>
#include <utility>
#include <sstream>
#include <string>
#define mod 1000000007
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const db eps=1e-6;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=1e6+8;
using namespace std;

int t,n,m,cnt=0,ans=1;
string s;
char a;
int main(){
    cin>>s;
    scanf("%d",&m);
    while(m--){
        scanf("%d",&n);
        ans+=n;
        if(ans>=2) ans-=2;
        if(n==1) continue;
        if(ans==1){
            scanf("%d",&t);
            cin>>a;
            if(t==1) s.insert(s.begin(),a);
            else s.insert(s.end(),a);
        }else{
            scanf("%d",&t);
            cin>>a;
            if(t==2) s.insert(s.begin(),a);
            else s.insert(s.end(),a);
        }
    }
    if(ans==0) reverse(s.begin(),s.end());
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 1020
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn main(){
    let line = read_as_vec::<usize>();
    let (n, t) = (line[0], line[1]);
    let mut ans = 10000;
    for _ in 0..n{
        let line = read_as_vec::<usize>();
        let (c, ex) = (line[0], line[1]);
        if ex <= t && ans > c{
            ans = c;
        }
    }

    if ans == 10000{
        println!("TLE");
    }else{
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,K;
    cin >> N >> K;
    vector<int> x(N);
    int S = 0;
    for(int i = 0; i < N; i++){
        cin >> x[i];
        S += 2 * min(x[i],abs(x[i]-K));
    }
    cout << S << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
minus=[i for i in a if i<0]
plus=[i for i in a if i>=0]
if len(minus)==0:
    print(a[-1]-a[0]+sum(a[1:n-1]))
    for i in range(n-1):
        if i==n-2:
            print(a[-1],a[n-2])
        else:
            print(a[i],a[i+1])
            a[i+1]=a[i]-a[i+1]
elif len(plus)==0:
    print(a[-1]-a[0]-sum(a[1:n-1]))
    print(a[-1],a[0])
    a[-1]=a[-1]-a[0]
    for i in range(1,n-1):
        print(a[-1],a[i])
        a[-1]-=a[i]
else:
    print(a[-1]-a[0]-sum(minus[1:])+sum(plus[0:-1]))
    for i in range(len(plus)-1):
        print(minus[0],plus[i])
        minus[0]-=plus[i]
    for i in range(len(minus)):
        print(a[-1],minus[i])
        a[-1]-=minus[i]

Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

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

const ll MOD = 998244353;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<pii> D(k);
	for (int i = 0; i < k; i++) {
		cin >> D[i].first >> D[i].second;
	}
	sort(all(D));
	vector<ll> dp(n + 1, 0);
	dp[1] = 1;
	ll cnt = 0;
	for (int i = 1; i <= n; i++) {
		cnt += dp[i];
		cnt %= MOD;
		if (cnt < 0) cnt += MOD;
		for (auto d: D) {
			if (i + d.first <= n) {
				dp[i + d.first] += cnt;
				dp[i + d.first] %= MOD;
				if (dp[i + d.first] < 0) dp[i + d.first] += MOD; 
			}
			if (i + d.second + 1 <= n) {
				dp[i + d.second + 1] -= cnt;
				dp[i + d.second + 1] %= MOD;
				if (dp[i + d.second + 1] < 0) dp[i + d.second + 1] += MOD; 
			}
		}
	}
	cout << dp[n] << endl;
}


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

int main() {
	int r, g, b, x;
	cin >> r >> g >> b;

	x = g * 10 + b;
	if (x % 4 == 0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}


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

int p[300000];

int main(){
    int n;
    p[0]=p[1]=-1;
    for(int i=2;i<300000;i++){
        if(!p[i]){
            p[i]=1;
            for(int j=i+i;j<300000;j+=i)p[j]=-1;
        }
    }
    while(1){

        int ans=0;
        cin >> n;

        if(n==0)break;

        for(int i=n+1;i<=n+n;i++){
            if(p[i]==1)ans++;
        }
        cout << ans <<endl;
    }
}


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


int main(){
  ll n;
  cin >> n;
  vector<ll>pos;
  vector<ll>neg;
  vector<ll>pos1;
  bool zero = false;
  for(int i=0; i<n; ++i){
    ll a;
    cin >> a;
    if(a>0){ pos.push_back(a);pos1.push_back(a);}
    else if(a<0){neg.push_back(a);pos1.push_back(abs(a));}
    else if(a==0)pos1.push_back(abs(a));
  }
  sort(neg.begin(), neg.end());
  sort(pos1.begin(), pos1.end());
  ll sum=0;
  for(int i=0; i<n; ++i){
    
    sum += pos1[i];
  }
 ll res = sum-pos1[0]*2;
  if(neg.size()%2==0)
    cout << sum << endl;
  else if(neg.size()%2!=0)
    cout << res << endl;
 
}

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


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

    int n;
    cin>>n;
    vector<long long> a(n), b(n);

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


    long long ans = 0;
    for (int i=n-1; i>=0; i--) {
        a[i] += ans;
        int d = a[i] % b[i];
        if (d == 0) continue;
        ans += b[i]-d;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int r,D,x;
    cin>>r>>D>>x;
    for(int i=0;i<10;i++){
        x=r*x-D;
        cout<<x<<endl;
    }
}


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

using namespace std;
const int mod = 1e9+7;
int add(int a, int b) {
	return a + b < mod ? a + b : a + b - mod;
}
int mul(int a, int b) {
	return int(1LL * a * b % mod);
}
int fexp(int b, int e = mod - 2) {
	int ans = 1;
	while(e) {
		if(e & 1) ans = mul(ans, b);
		b = mul(b, b);
		e /= 2;
	}
	return ans;
}

const int N = 2005;

int dp[N];

int f(int n) {
	if(n < 0) return 0;
	if(n == 0) return 1;
	int &ans = dp[n];
	if(~ans) return ans;
	ans = 0;
	for(int i = 3; i <= n; i++) {
		ans = add(ans, f(n - i));
	}
	return ans;
}

int main() {
	memset(dp, -1, sizeof dp);
	int n;
	scanf("%d", &n);

	printf("%d\n", f(n));
}


Measured memory_bytes: 3840
import heapq

N,M=map(int,input().split())
B=list(map(int,input().split()))
def hu(n):
    return n*(-1)
A=list(map(hu,B))
heapq.heapify(A)
for i in range(M):
    x=heapq.heappop(A)/2
    heapq.heappush(A,x)
A1=list(map(int,A))
print(-sum(A1))

Measured memory_bytes: 14180
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
v = LIST()
v.sort()
ans = v[0]

for x in v:
	ans = (ans+x)/2
print(ans)


Measured memory_bytes: 5156
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, x) for (int i = x; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;

const int mxn = 200000;

vii a;
vi p;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    a.assign(n, vi(n));

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

    p.assign((1 << n), 0);

    for (int j = 0; j < (1 << n); ++j) {
        for (int i = 0; i < n; ++i) {
            if (!(j & (1 << i))) continue;
            for (int k = i + 1; k < n; ++k) {
                if (!(j & (1 << k))) continue;

                p[j] += a[i][k];
            }
        }
    }

    vi dp(1 << n, 0);
    
    for (int i = 0; i < n; ++i) {
        for (int j = (1 << i); j <= (1 << (i + 1)) - 1; ++j) {
            for (int k = j; k; k = (k - 1) & j) {
                dp[j] = max(dp[j], p[k] + dp[j - k]);
            }
        }
    }

    cout << dp[(1 << n) - 1];
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=250010;
const int mod=1e9+7;
int a[maxn],dp[maxn][405],dpm[maxn][405],cnt[maxn],C[410][410],fac[410];
inline int get_mod(int x){
	return x<mod?x:x-mod;
}
inline int mul(int x,int y){
	return (ll)x*y%mod;
}
inline int qpow(int base,int pw){
	int res=1;
	while(pw){
		if(pw&1) res=mul(res,base);
		base=mul(base,base);
		pw>>=1;
	}
	return res;
}
inline int get_inv(int x){
	return qpow(x,mod-2);
}
int main(){
	int n,k,m;
	scanf("%d%d%d",&n,&k,&m);
	for(int i=1;i<=m;i++)
		scanf("%d",a+i);
	fac[0]=1;
	C[0][0]=1;
	for(int i=1;i<=k;i++){
		C[i][0]=1;
		fac[i]=mul(fac[i-1],i);
		for(int j=1;j<=i;j++)
			C[i][j]=get_mod(C[i-1][j-1]+C[i-1][j]);
	}
	int type_num=0;
	bool colorful=false;
	for(int i=1;i<=m;i++){
		if(i-k>=1){
			cnt[a[i-k]]--;
			if(!cnt[a[i-k]]) type_num--;
		}
		if(!cnt[a[i]]) type_num++;
		cnt[a[i]]++;
		if(type_num==k) colorful=true;
	}
	int tot=mul(n-m+1,qpow(k,n-m));
	if(colorful){
		printf("%d\n",tot);
	}else if(type_num==m){
		dp[1][1]=k;
		if(m==1) dpm[1][1]=k;
		for(int i=2;i<=n;i++){
			int suff=0,suffm=0;
			for(int j=k-1;j>=1;j--){
				suff=get_mod(suff+dp[i-1][j]);
				suffm=get_mod(suffm+dpm[i-1][j]);
				dp[i][j]=get_mod(mul(dp[i-1][j-1],k-j+1)+suff);
				dpm[i][j]=get_mod(suffm+mul(dpm[i-1][j-1],k-j+1));
				if(j>=m) dpm[i][j]=get_mod(dpm[i][j]+dp[i][j]);
			}
		}
		int minus=0;
		for(int j=1;j<k;j++)
			minus=get_mod(minus+dpm[n][j]);
		minus=mul(minus,get_inv(mul(C[k][m],fac[m])));
		printf("%d\n",get_mod(tot+mod-minus));
	}else{
		for(int i=1;i<=k;i++)
			cnt[i]=0;
		type_num=0;
		int F,B;
		for(int i=1;i<=m;i++){
			if(i-k>=1){
				cnt[a[i-k]]--;
				if(!cnt[a[i-k]]) type_num--;
			}
			if(!cnt[a[i]]) type_num++;
			cnt[a[i]]++;
			if(type_num==i) F=i;
		}
		for(int i=1;i<=k;i++)
			cnt[i]=0;
		type_num=0;
		reverse(a+1,a+1+m);
		for(int i=1;i<=m;i++){
			if(i-k>=1){
				cnt[a[i-k]]--;
				if(!cnt[a[i-k]]) type_num--;
			}
			if(!cnt[a[i]]) type_num++;
			cnt[a[i]]++;
			if(type_num==i) B=i;
		}
		dp[0][F]=1;
		dpm[0][B]=1;
		for(int i=1;i<=n;i++){
			int suff=0,suffm=0;
			for(int j=k-1;j>=1;j--){
				suff=get_mod(suff+dp[i-1][j]);
				suffm=get_mod(suffm+dpm[i-1][j]);
				dp[i][j]=get_mod(mul(dp[i-1][j-1],k-j+1)+suff);
				dpm[i][j]=get_mod(mul(dpm[i-1][j-1],k-j+1)+suffm);
			}
		}
		int minus=0;
		for(int i=0;i<=n-m;i++){
			int f=0,b=0;
			for(int j=1;j<k;j++){
				f=get_mod(f+dp[i][j]);
				b=get_mod(b+dpm[n-m-i][j]);
			}
			minus=get_mod(minus+mul(f,b));
		}
		printf("%d\n",get_mod(tot+mod-minus));
	}
	return 0;
}

Measured memory_bytes: 85376