akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans=0, tmp=0, tmpp=0, tmpn=0;
vector<ll> A;
string S;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

signed main(){
    cin >> N >> S;
    for(int i=0;i<N;i++) {
        ll num = S[i]-'0';
        if(num==1) tmp++;
        A.push_back(num);
    }
    if(tmp==0) {
        for(int i=0;i<N;i++) {
            cout << 1 << endl;
        }
        return 0;
    }
    if(tmp==1) {
        for(int i=0;i<N;i++) {
            if(A[N-1-i]==1) {
                tmpp += modpow(2,i,2);
                tmpp %= 2;
                if(tmpp<0) tmpp += 2;
            }
        }
        for(int i=0;i<N;i++) {
            if(A[i]==1) {
                cout << 0 << endl;
                continue;
            }
            ll id = tmpp;
            id += modpow(2,N-1-i,2);
            id %= 2;
            if(id<0) id += 2; 
            if(id==0) cout << 1 << endl;
            else cout << 2 << endl;
        }
        return 0;
    }

    for(int i=0;i<N;i++) {
        if(A[N-1-i]==1) {
            tmpp += modpow(2,i,tmp+1);
            tmpp %= (tmp+1);
            if(tmpp<0) tmpp += tmp+1;
            tmpn += modpow(2,i,tmp-1);
            tmpn %= (tmp-1);
            if(tmpn<0) tmpn += tmp-1;
        }
    }
    for(int i=0;i<N;i++) {
        //cout << "OK" << endl;
        ans = 1;
        if(A[i]==0) {
            ll tmp2 = tmpp;
            ll tmp3 = tmp+1;
            tmp2 += modpow(2,N-1-i,tmp3);
            tmp2 %= tmp3;
            if(tmp2<0) tmp2 += tmp3;
            while(tmp2!=0) {
                //cout << i << " " << tmp2 << endl;
                tmp3 = __builtin_popcount(tmp2);
                tmp2 %= tmp3;
                if(tmp2<0) tmp2 += tmp3;
                ans++;
            }
        }
        else {
            ll tmp2 = tmpn;
            ll tmp3 = tmp-1;
            tmp2 -= modpow(2,N-1-i,tmp3);
            tmp2 %= tmp3;
            if(tmp2<0) tmp2 += tmp3;
            while(tmp2!=0) {
                //cout << i << " " << tmp2 << endl;
                tmp3 = __builtin_popcount(tmp2);
                tmp2 %= tmp3;
                if(tmp2<0) tmp2 += tmp3;
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5524
#include<bits/stdc++.h>
using namespace std;int d[10010],t=0,n,i,j;int main(){cin>>n;while(t<n)d[t]=114514810,t++;d[0]=0;for(i=1;i<n;i++){cin>>t;for(j=0;j<=i/2;j++)d[j]=min(d[j],d[i-j]+t),d[i-j]=min(d[i-j],d[j]+t);}cout<<d[n/2]<<endl;return 0;}

Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

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 long long INF = 1LL << 60;

#define MAX_N 1010
#define MAX_M 200000100

int main(){
    ll n,y;
    cin >> n >> y;
    for (ll i=0;i<=n;++i)for (ll j=0;j+i<=n;++j){
        if (i*10000+j*5000+(n-i-j)*1000==y){
            cout << i << " " <<  j << " " << n-i-j << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef vector <int> VI;
typedef vector <VI> VVI;
int main( void )
{
	int r, c;
	while ( cin >> r >> c && r && c )
	{
		VVI O( r, VI( c ) );
		for ( int i = 0; i < r; i++ ) for ( int j = 0; j < c; j++ ) cin >> O[i][j];

		int answer = 0;
		VVI backup = O;
		for ( int i = 0; i < 1 << r; i++ )
		{
			O = backup;
			for ( int j = 0; j < r; j++ )
				if ( i & 1 << j ) for ( int k = 0; k < c; k++ ) O[j][k] = !O[j][k];
			int sum = 0;
			for ( int j = 0; j < c; j++ )
			{
				int colsum = 0;
				for ( int k = 0; k < r; k++ )
				{
					colsum += O[k][j];
				}
				if ( colsum > (r/2) ) sum += r - colsum;
				else sum += colsum;
			}

			answer = max( answer, r*c - sum );
		}

		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 1728
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long i = 1;
            var xys = new List<long[]>();
            while (i <= Math.Sqrt(n))
            {
                if (n%i ==0)
                {
                    var xy = new long[] { i, n/i };
                    xys.Add(xy);
                }
                i++;
            }
            long[] sums = xys.Select(e => (e[0] - 1) + (e[1] - 1)).ToArray();
            Console.WriteLine(sums.Min());
        }
    }
}


Measured memory_bytes: 13524
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <utility>
#include <queue>
#include <climits>
using namespace std;

#define endl '\n'
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
typedef pair<int, int> ii;
typedef long long LL;
typedef long double LD;

void solve(int kase){
    cout << "Case #" << kase << ": " << 0 << endl;
}

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s;
	cin >> s;
	cout << s.substr(0, 4) << " " << s.substr(4) << endl;
    return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll n;cin >> n;
	vector<ll> v(n);REP(i, n)cin >> v[i];
	sort(ALL(v));

	REP(i, n-1){
		if(v[i] == v[i+1]){
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <set>
#include <cstdio>
using namespace std;

typedef long long ll;
typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const int inf=1000000000;
struct edge{
	int to,cost;
};

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

	P1 a[100001]={};
	for(int i=0;i<n;++i){
		int a1;
		cin>>a1;
		a[i].first=a1;
		a[i].second=i;
	}
	sort(a,a+n);
	int t=0;
	for(int i=0;i<n;++i){
		if(a[i].second%2!=i%2)t++;
	}
	cout<<t/2<<endl;

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
	int R[MAX], n;
	
	cin >> n;
	for( int i = 0; i < n; i++ ) cin >> R[i];
	
	int maxv = -2000000000;
	int minv = R[0];
	
	for( int i = 1; i < n; i++ ) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	
	cout << maxv << endl;
	
	return 0;
}

Measured memory_bytes: 3872
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;


int n;
int ans = 0;
void dfs(int x, int a, int b, int c) {
	if (x > n)return;
	if (a&&b&&c)ans++;
	dfs(10 * x + 3, 1, b, c);
	dfs(10 * x + 5, a, 1, c);
	dfs(10 * x + 7, a, b, 1);
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	dfs(0, 0, 0, 0);
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    int n;
    cin >> n;

    vector<string> w;
    bool flag = false;
    char tail = '?';
    rep(i, n){
        string in;
        cin >> in;
        auto itr = w.begin();
        itr = find(ALL(w), in);
        if(itr != w.end())flag = true;
        if(in.front() != tail && tail != '?')flag = true;
        tail = in.back();
        w.push_back(in);
    }

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

}

Measured memory_bytes: 256
import java.util.*
import kotlin.math.acos
import kotlin.math.cos
import kotlin.math.round
import kotlin.math.sin

fun main(args: Array<String>) {
    val n = readInt()
    val list = List(n) { readIntList() }.reversed()

    var ans = 0L
    for (i in 0 until n) {
        val (a, b) = list[i]
        val r = (a + ans) % b
        if (r == 0L) continue
        ans += b - r
    }
    println(ans)
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

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

public class AtCoder_154_C
{
    public static void Main()
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int n = int.Parse(Console.ReadLine());
        int[] A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        bool[] array = new bool[1001001001];

        for (int i = 0; i < n; i++)
        {
            if (array[A[i]])
            {
                Console.WriteLine("NO");
                return;
            }
            array[A[i]] = true;
        }

        Console.WriteLine("YES");
    }
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
    int n; cin >> n;
    string s;
    vector<int> v(5,0);
    long long ans = 0;
    rep(i, n) {
        cin >> s;
        if(s[0] == 'M'){
            v[0]++;
        }
        if(s[0] == 'A'){
            v[1]++;
        }
        if(s[0] == 'R'){
            v[2]++;
        }
        if(s[0] == 'C'){
            v[3]++;
        }
        if(s[0] == 'H'){
            v[4]++;
        }
    }
    sort(v.begin(), v.end());
    vector<int> per = {0,0,1,1,1};
    do {
        long long tmp = 1;
        for(int i = 0; i < 5;i++){
            if(per[i] != 0)
                tmp *= v[i]*per[i];
        }
        ans += tmp;
    } while (next_permutation(per.begin(), per.end()));
    cout << ans << endl;
}



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

using namespace std;

const int N = (int)3e3 + 7;

string a, b;
int dp[N][N];
int pr[N][N];

main() {
	cin >> a;
	cin >> b;
	a = " " + a;
	b = " " + b;
	int n, m;
	n = a.size() - 1;
	m = b.size() - 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			dp[i][j] = -1;
			if (dp[i - 1][j] > dp[i][j]) {
				dp[i][j] = dp[i - 1][j];
				pr[i][j] = 1;
			}
			if (dp[i][j - 1] > dp[i][j]) {
				dp[i][j] = dp[i][j - 1];
				pr[i][j] = 0;
			}
			if (a[i] == b[j]) {
				if (dp[i - 1][j - 1] + 1 > dp[i][j]) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
					pr[i][j] = 2;
				}
			}
		}
	}
	string ans;
	while (n > 0 && m > 0) {
		if (pr[n][m] == 2) {
			ans.push_back(b[m]);
			n--;
			m--;
		} else if (pr[n][m] == 1) {
			n--;
		} else {
			m--;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
}


Measured memory_bytes: 70784
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
vector<ll> v[200006];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int a;
        cin>>a;
        v[a].push_back(i);
    }
    if(v[1].size()!=0){
        ll val=v[1][0];
        val++;
        int cnt=1;
        for(int i=2;i<=n;i++){
            int j= lower_bound(v[i].begin(),v[i].end(),val)-v[i].begin();
            if(j!=v[i].size()){
                val=v[i][j];
                val++;
                cnt++;
            }
            else break;
        }
        cout<<n-cnt<<endl;
    }
    else cout<<-1<<endl;
    
}

Measured memory_bytes: 11264
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> pii;
using namespace std;
using ll = long long;


int main(){
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    
    int dp[n+1][m+1];
    memset(dp,0,sizeof dp);
    
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            if(s[i-1] == t[j-1]) dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);            
        }
    }
    string ans = "";
    int i = n, j = m;
    
    while(i && j){
        if (s[i-1] == t[j-1]){
            ans = s[i-1]+ ans;
            i--;j--;
        }    
        else if (dp[i][j] == dp[i][j-1]){
            j--;
        }
        else if (dp[i][j] == dp[i-1][j]){
            i--;
        }
        else{
            cout << "BUG";
        }
    }
    
    // for(int i = 0; i <= n; i++){
    //     for(int j = 0; j <= m; j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << ans;
    
    
}









Measured memory_bytes: 35456
K,N=[int(x) for x in input().rstrip().split()]
A=[int(x) for x in input().rstrip().split()]

A14=K-A[N-1]+A[0]
sa=[A14]

for i in range(N-1):
  sa.append(A[i+1]-A[i])
sa.sort()
ans=0
for i in range(N-1):
  ans+=sa[i]
print(ans)

Measured memory_bytes: 24948
#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 a;
    cin >> a;
    cout << a+a*a+a*a*a << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define For(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
	int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}

const int N = 110;
int a[N], n;

int ans = 0x7f7f7f7f;
#define pow2(x) ((x) * (x) )
int Calc(int x) {
	int res = 0;
	For (i, 1, n)
		res += pow2(a[i] - x);
	return res;
}

int main () {
	n = read();
	For (i, 1, n)
		a[i] = read();
	sort (a + 1, a + 1 + n);
	For (i, -100, 100)
		chkmin(ans, Calc(i) );
	cout << ans << endl;
    return 0;
}


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

int main(){
  while(true){
    int n;
    cin>>n;
    if(n==0)break;
    int a[1000];
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    int dif=1000001;
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        int d=abs(a[i]-a[j]);
        if(d<dif){
          dif=d;
        }
      }
    }
    cout<<dif<<endl;
  }
  return 0;
}



Measured memory_bytes: 3012
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define deb(x) cout << #x << " is " << x << "\n";

using namespace std;
using namespace __gnu_pbds;

const double PI = 2 * acos(0.0);
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

bool checkPalindrome(string s) {
	int n = s.size();
	int i = 0, j = n - 1;
	while(i < j) {
		if(s[i] != s[j])
			return false;
		i++;
		j--;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin >>s;
	if(!checkPalindrome(s)) {
		cout <<"No\n";
		return 0;
	}
	int n = s.size();
	int l = (n - 1) / 2;
	int e = (n + 1) / 2;
	string a = s.substr(0, l);
	string b = s.substr(e, l);
	if(checkPalindrome(a) && checkPalindrome(b)) {
		cout <<"Yes\n";
	}
	else {
		cout <<"No\n";
	}
	return 0;
}


Measured memory_bytes: 256
import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))
a = list(map(lambda x: x*(-1), a))
heapq.heapify(a)         
k=m
while k>0:
  b=heapq.heappop(a)*(-1)//2  
  heapq.heappush(a, b*(-1))   
  k-=1
print(sum(a)*(-1))

Measured memory_bytes: 73196
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define ll            long long

#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void sb()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int main()
{
	//sb();
    ll n,w;
    cin>>n>>w;
    vector<vector<ll>> dp(n+1,vector<ll> (w+1,0));
    
    vector<long int> wa(n,0);
    vector<long int> v(n,0);
    for(int i=0;i<n;i++){
        cin>>wa[i]>>v[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            ll maxx =0;
            if(j-wa[i-1]>=0){
//maxx = max(maxx,(dp[i-1][j-wa[i-1]]+v[i-1]));
 if((dp[i-1][j-wa[i-1]]+v[i-1])>maxx)
 maxx = (dp[i-1][j-wa[i-1]]+v[i-1]);
 //cout<<i<<":"<<j<<":"<<v[i-1]<<":"<<dp[i-1][j-wa[i-1]]+v[i-1]<<endl;
            }
            

           
            if(dp[i-1][j]>maxx)
            maxx = dp[i-1][j];
            dp[i][j] = maxx;
        }
    }
    // for(int i=0;i<=n;i++){
    //     for(int j=0;j<=w;j++){
    //         cout<<dp[i][j]<<"    ";
    //     }
    //     cout<<endl;
    // }
    cout<<dp[n][w];





return 0;
}



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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    ll n, m; cin >> n >> m;
    V<ll> x(m);
    for(int i = 0; i < m; i++) cin >> x[i];
    sort(ALL(x));

    V<ll> x2;
    for(int i = 0; i < m - 1; i++){
        x2.push_back(x[i + 1] - x[i]);
    }
    sort(ALL(x2));

    ll ans = 0;
    for(int i = 0; i < (int)x2.size() - (n - 1); i++){
        ans += x2[i];
    }
    cout << ans << endl;

}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
long double PI= 3.141592653589793238463;
const int N = 1e5+5;
const int MOD = 1e9+7;

ll w[109],v[109],dp[109][N];
int n,ww;

void KP(int m, int W)
{
    for(int i=1;i<=m;i++){
        for(int j=1;j<=W;j++){
            if(w[i]>j){
                    dp[i][j]=dp[i-1][j];
                    //cout<<dp[i][j]<<' ';
                    continue;
            }
            dp[i][j]=max( dp[i-1][j-w[i]]+v[i] , dp[i-1][j]);
            //cout<<dp[i][j]<<' ';
        }
       // cout<<endl;
    }
}


int main()
{
//int t; cin>>t;

//while(t--){
    cin>>n>>ww;
    for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
    KP(n,ww);
    cout<<dp[n][ww];

//}


    return 0;
}



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

const int os=6500;

int h,w,ans;
int a[85][85];
int b[85][85];
int dp[85][85][13005];

int main(){

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

    cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>b[i][j];
        }
    }
    dp[0][1][os]=1;
    dp[1][0][os]=1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            for(int k=-6400;k<=6400;k++){
                dp[i][j][k+os]|=dp[i-1][j][k-a[i][j]+b[i][j]+os];
                dp[i][j][k+os]|=dp[i-1][j][k+a[i][j]-b[i][j]+os];
                dp[i][j][k+os]|=dp[i][j-1][k-a[i][j]+b[i][j]+os];
                dp[i][j][k+os]|=dp[i][j-1][k+a[i][j]-b[i][j]+os];
            }
        }
    }
    ans=114514;
    for(int k=-6400;k<=6400;k++){
        if(dp[h][w][k+os])ans=min(ans,abs(k));
    }
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 346496
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

# @njit
def solve(n,a,b):
  delta = [b[i] - a[i] for i in range(n)]
  need = list(x for x in delta if x > 0)
  amari = list(sorted((abs(x) for x in delta if x < 0),reverse=True))
  needScore = sum(need)
  if needScore > sum(amari):
    return -1
  k = 0
  s = 0
  while s < needScore:
    s += amari[k]
    k += 1
  return k + len(need)
  


def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  b = list(map(int,input().split()))
  print(solve(N,a,b))
  return

if __name__ == '__main__':
  main()


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll a, b, c, d; cin >> a >> b >> c >> d;
	print(max(max(b * d, b*c), max(a*c, a*d)));
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
int n, c[N], cnt[N], siz[N];
ll cal(int x) {
	return 1ll * x*(x+1)/2;
}
ll ans[N];
vector<int>G[N];
	void dfs(int v, int fa) {
		int tmp = cnt[c[v]];
		siz[v] = 1;
		for(int u:G[v]) {
			if(u==fa) continue;
			cnt[c[v]] = 0;
			dfs(u, v);
			siz[v] += siz[u];
			ans[c[v]]+=cal(siz[u]-cnt[c[v]]);
		}
		cnt[c[v]] = tmp + siz[v];
	}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%d", &c[i]);
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		printf("%lld\n", cal(n) - ans[i] - cal(n - cnt[i]));
	}
	return 0;
}


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

const int maxn=5e5+10;

int n,m;
LL d[maxn],pre[maxn],suf[maxn];

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i,x;
	scanf("%d%lld",&n,&pre[0]);
	for (i=1;i<=n;i++)
	{
		scanf("%lld",&d[i]);
		pre[i]=min(pre[i-1],abs(pre[i-1]-d[i]));
	}
	suf[n+1]=0;
	for (i=n;i>=1;i--)
		suf[i]=suf[i+1]+(suf[i+1]>=d[i]>>1?d[i]:0);
	scanf("%d",&m);
	while (m--)
	{
		scanf("%d",&x);
		puts(pre[x-1]<=suf[x+1]?"NO":"YES");
	}
}


Measured memory_bytes: 13696
#include<bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
#define debug(a,b) cerr << #a<<" = "<<a<<"   |   "<<#b<<" = "<<b<<'\n'
#define endl '\n'
#define SZ(a) ((int)a.size())
using namespace std;
typedef pair<int, int> pi32;
typedef pair<ll, ll> pi64;
typedef vector<int> vi32;
typedef vector<ll> vi64;
typedef vector<pi32> vp32;
typedef vector<pi64> vp64;
const ll mod = 1e9 + 7;
const int MX = 1e5+7;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	string s,p;
	cin>>s;
	int len=SZ(s);
	for(int i=0;i<len;i++){
		if(s[i]=='?')s[i]='D';
	}
	cout<<s<<endl;
			
	return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

string yes = "Yes";
string no = "No";

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

signed main() {
    int T;
    cin >> T;

    rep(_, T) {
        int A, B, C, D;
        cin >> A >> B >> C >> D;

        if (B > D || B > A) {
            cout << no << endl;
            continue;
        }
        if (C >= B - 1) {
            cout << yes << endl;
            continue;
        }
        int step = D == B ? B : gcd(B, D - B);
        int times = (A - (C + 1)) / step;
        int val = A - times * step;
        //cerr << "step:" << step << " times:" << times << " val:" << val << endl;
        if (val < B) cout << no << endl;
        else cout << yes << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

vector<pair<int,int>> d(4);

int H, W;

void check(int h, int w,vector<vector<char>>& V,vector<vector<bool>>& C,int& ptr){
  //黒の連結成分に含まれる黒の数をadjにpush_back
  C[h][w] = true;
  ptr++;
    for(int i = 0; i < 4; i++){
      int hp = 0;
      hp = h + d[i].first;
      int wp = 0;
      wp = w + d[i].second;
      if(wp < 0 || wp > W-1 || hp < 0 || hp > H-1) continue;
      if(C[hp][wp]) continue;
      if(V[hp][wp] == '#'){
        check(hp, wp, V, C, ptr);
      }
    }
  return;
}

int main(){
  d[0] = make_pair(1,0);
  d[1] = make_pair(0,1);
  d[2] = make_pair(-1,0);
  d[3] = make_pair(0,-1);
  
  cin >> H >> W;
  vector<vector<char>> V(H,vector<char> (W, 'x'));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> V[i][j];
    }
  }
  vector<int> adj;
  vector<vector<bool>> C(H,vector<bool> (W,false));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(C[i][j])continue;
      if(V[i][j] == '#'){
        int cnt = 0;
        check(i ,j ,V, C, cnt);
        adj.push_back(cnt);
      }
      C[i][j] = true;
    }
  }
  sort(adj.begin(), adj.end());
  if(adj.size() > 0 && adj[0] <= 1) cout << "No";
  else cout << "Yes";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define vi vector<int>
#define rep(i, xtz, n) for(int i=xtz; i<n; i++)
#define repx(i, xtz, n) for(int i=xtz; i>=n; i--)
#define lli long long int

using namespace std;

lli dp[3005][3005];

int main(){
    //freopen("i.in", "r", stdin);
    int n;
    scanf("%d", &n);
    vector<lli> vec(n);
    rep(i, 0, n) scanf("%d", &vec[i]);
    repx(L, n-1, 0){
        rep(R, L, n){
            if(L==R) dp[L][R] = vec[L]; 
            else{
                dp[L][R] = max(vec[L]-dp[L+1][R], vec[R]-dp[L][R-1]);
            }
        }
    }
    cout<<dp[0][n-1];
}

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

using namespace std;
int n;

int main()
{
	cin>>n;
	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++)
		{
			if(i*4+j*7==n)
				return cout<<"Yes",0;
		}
	cout<<"No";
}

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

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;

	if (A == 1) {
		A += 13;
	}
	if (B == 1) {
		B += 13;
	}

	if (A > B) {
		cout << "Alice" << endl;
	}
	else if (A == B) {
		cout << "Draw" << endl;
	}
	else {
		cout << "Bob" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan =  new Scanner(System.in);
        
        int count = 0;
        
        int n = scan.nextInt();
        
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        
        int m = scan.nextInt();
        
        int[] b = new int[m];
        for(int i = 0; i < m; i++){
            b[i] = scan.nextInt();
            for(int j = 0; j < n; j++){
                if(b[i] == a[j]){
                    count++;
                    break;
                }
            }
        }
        
        System.out.println(count);
        
        scan.close();
    }
}



Measured memory_bytes: 40516
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    ll a, b, h, m; cin >> a >> b >> h >> m;
    double long_p = 2 * PI * m / 60;
    double short_p = 2 * PI * (h * 60 + m) / 720;
    double rad = min(abs(long_p - short_p), abs(long_p - short_p + 2*PI));
    double ret = std::sqrt(a*a + b*b - 2*a*b*cos(rad));
    cout << ret << endl;
}

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

Measured memory_bytes: 4212
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

typedef vector<int> V;
typedef vector<V> M;

enum Status{OK, AMB, NONE};
Status gauss_jordan(M m, V v) {
  for (int r = m.size(); r--; ) {
  back:;
    int p = r;
    rep (i, r) if (abs(m[i][r]) > abs(m[p][r])) p = i;
    swap(m[r], m[p]);
    swap(v[r], v[p]);
    if (m[r][r] == 0) {
      rep (j, r) if (m[r][j]) {
	rep (k, m.size()) swap(m[k][j], m[k][r]);
	goto back;
      }
      if (v[r]) return NONE;
    }
    rep (i, m.size()) if(i != r) {
      v[i] ^= m[i][r] & v[r];
      rep (k, r) m[i][k] ^= m[i][r] & m[r][k];
    }
  }
  if (m[0][0] == 0) return AMB;
  return OK;
}

int main() {
  while (true) {
    int m, n, d;
    cin >> m >> n >> d;
    if (m == 0 && n == 0 && d == 0) break;
    V v(n * m);
    rep (i, n * m) cin >> v[i];
    M mat(n * m, V(n * m, 0));
    rep (i, n * m) mat[i][i] = 1;
    rep (i, n) rep (j, m) rep (ii, n) rep (jj, m) if (abs(i - ii) + abs(j - jj) == d) mat[i * m + j][ii * m + jj] = 1;
    if (gauss_jordan(mat, v) == NONE) cout << 0 << endl;
    else cout << 1 << endl;
  }
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int main()
{
    int n,q; cin >> n >> q;
    priority_queue<int> S[n];
    rep(i,q){
        int query; cin >> query;
        if(query == 0){
            int t, x; cin >> t >> x;
            S[t].push(x);
        }else if(query == 1){
            int t; cin >> t;
            if(!S[t].empty()) cout << S[t].top() << endl;
        }else{
            int t; cin >> t;
            if(!S[t].empty()) S[t].pop();
        }
    }
}


Measured memory_bytes: 4148
#include <iostream>
 using namespace std ; 
 
 int main ()
 {
 	int limit , sum , abs = 0, counter =0;
 	cin >> limit >> sum ; 
 	
 	for (int i=0;i<=limit ; i++)
 	{
 		for (int j =0; j<= limit ; j++)
 		{
 			abs = i + j -sum ; 
 			abs *=-1 ; 
 			if (abs <= limit && abs >=0) 
 			{
 				counter ++ ;
			 }
			 abs = 0 ;
		 }
	 }
	 cout << counter ; 
 	return 0 ;
 }
 
 
 

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

int main(){
	ios::sync_with_stdio(false);

	long long n;
	cin >> n;

	vector<long long> a(n), p(n);

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

	set<long long> s;

	long long ans = 0;

	vector<long long> b(n);

	for(int i = 0; i < n; i++){
		auto it = s.upper_bound(a[i]);
		if(it == s.begin()){
			b[i] = (a[i]+1)*(i+1);
			ans += b[i];
		}
		else{
			--it;
			b[i] = b[p[*it]] + (a[i]+1)*(i-p[*it]);
			ans += b[i];
		}
		it = s.upper_bound(a[i]);
		while(it != s.end()){
			auto it2 = it;
			++it;
			s.erase(it2);
		}
		s.insert(a[i]);
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 14336
#include<stdio.h>
#define N 101

int A[N][N],x;



int main(){

  int i,j,v,g,u;

  scanf("%d",&x);
  
  for(i=0;i<x;i++){
    for(j=0;j<x;j++){
      A[i][j]=0;
    }
  }
  
  for(i=0;i<x;i++){
    scanf("%d",&u);
    scanf("%d",&v);
    for(j=0;j<v;j++){
      scanf("%d",&g);
      A[u-1][g-1]=1;
    }
  }
  for(i=0;i<x;i++){
    for(j=0;j<x;j++){
      if(j==x-1)printf("%d",A[i][j]);
      else printf("%d ",A[i][j]);
      
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0},b[LIMIT1]={0};
  ll c[LIMIT1]={0};
  char s[LIMIT1];
  
  scanf("%lld %lld",&n,&m);
  scanf("%s",s);
  rep(i,m){
    scanf("%d %d",&a[i],&b[i]);
    a[i]--;
    b[i]-=2;
  }
  rep(i,n-1){
    if(i==0) c[i]=0;
    else c[i]=c[i-1];
    if(s[i]=='A'&&s[i+1]=='C') c[i]++;
  }
  rep(i,m){
    printf("%lld\n",c[b[i]]-(a[i]>=1 ? c[a[i]-1] : 0));
  }
  
  return 0;
}



Measured memory_bytes: 5120
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    ll cnt[10][10]; F0R(i, 10) F0R(j, 10) cnt[i][j] = 0;
    FOR(i, 1, N+1) {
        int lst;
        int lo = i % 10;
        int cur = i;
        while (cur > 0) {
            lst = cur % 10;
            cur /= 10;
        }
        cnt[lo][lst]++;
    }
    ll ans = 0;
    F0R(i, 10) {
        FOR(j, 0, 10) {
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

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

  
  	if(k%2!=0){
    	cout<<"No"<<endl;
    }
  	else{
   	bool nikai=true;
      for(int i=0;i<(k/2);i++){
      	if(n[i]!=n[k/2+i]){
        	nikai=false;
        }
      }
         if(nikai){
        	cout<<"Yes"<<endl;
        }
        
        else{
        	cout<<"No"<<endl;
        }
        
      }
      
      
    
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>
#include <queue>
#include <stack>

using namespace std;



int main() {
	int x, y;
	char s[55][55];
	int i, j;
	cin >> x >> y;
	
	for (int k = 0; k <= y + 1; k++) {
		s[0][k] = '.';
	}
	for (i = 1; i <= x; i++) {
		s[i][0] = '.';
		for (j = 1; j <= y; j++) {
			cin >> s[i][j];
		}
		s[i][y + 1] = '.';
	}
	for (int k = 0; k <= y + 1; k++) {
		s[x+1][k] = '.';
	}
	bool tf = true;
	for (int i = 1; i <= x; i++) {
		for (int j = 1; j <= y; j++) {
			if (s[i][j] == '.')continue;
			if (s[i][j - 1] != '#' && s[i][j + 1] != '#' && s[i - 1][j] != '#' && s[i + 1][j] != '#') {
				tf = false;
			}

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

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[105];
int main()
{
    int a,p;
    while(~scanf("%d%d",&a,&p))
    {
       int sum=0;
       sum=3*a+p;
       printf("%d\n",sum/2);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<ll, ll> mpii;
typedef unordered_map<ll, ll> umpii;
 
#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define upb(v, key) (upper_bound(all(v), key) - v.begin())
#define lob(v, key) (lower_bound(all(v), key) - v.begin())
 
ll inf = 1e9;
ll INF = inf * 1ll * inf;
ll mod = 1e9 + 7;
double eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
ll dr[] = {-1, 0, 0, 1};
ll dc[] = {0, 1, -1, 0};

void mod_add(ll &a, ll b) {
  a += b;
  if(a > mod) a -= mod;
}
void mod_sub(ll &a, ll b) {
  a -= b;
  if(a < 0) a += mod;
}

//only for variables and vectors; 
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

/*...................................................*/

main()
{
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);

  ll t, n, m, i, j, k, q, u, v;
  // cin >> t;
  // ll tc = t;
  t = 1;
  while (t--)
  {
    cin >> u >> v;
    ll ans = 1;
    ll g = __gcd(u, v);
    for(i = 2; i * i <= g; i++) {
      if(g % i == 0) {
        while(g % i == 0) {
          g /= i;
        }
        ans++;
      }
    }
    ans += g > 1;
    cout << ans;
    // cout << "Case #" << tc - t << ": ";

    cout << '\n';
  }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;
        Solver s = new Solver();
        for (int i = 1; i <= t; i++) {
            s.solve(i, in, out);
        }
        out.close();
    }

}

class Solver {

    void solve(int test, InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();
        Arrays.sort(a);
        int s1 = 0, s2 = 0;
        for (int i = n - 1; i >= 0; i -= 2) s1 += a[i];
        for (int i = n - 2; i >= 0; i -= 2) s2 += a[i];
        out.println(s1 - s2);
    }
}

class InputReader {
    BufferedReader br;
    StringTokenizer st;

    public InputReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
        st = null;
    }

    public String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public String nextLine() throws IOException {
        return br.readLine();
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 23380