akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

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

	int a[n];

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

	sort(a,a+n);
	long long ans=0;

	for(int i=0;i<k;i++)
		ans=ans+a[i];


	cout<<ans<<endl;

	return 0;
}

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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define tc ll t; cin >> t; while (t--)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define sz(c) (ll) c.size()
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define trav(x,c) for(auto &x : c)
#define _for(i,a,n) for(ll i = a ; i < n ; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) trav(x,c) cout << x << " "; cout << endl;
#define dm(m) trav(x,m) cout << x.f << "->" << x.s << endl;
#define godspeed cin.tie(0) -> sync_with_stdio(0);

int main() {
    godspeed;
    ll n; cin >> n;
    ll sum = 0;
    _for(i,1,n+1) {
    	if(i%5 && i%3) sum += i;
    }

    cout << sum;
}

Measured memory_bytes: 3660
fun solver(n: String): String {
    val sum = n.toCharArray().map { (it - 0x30).toInt() }.sum()

    return if (sum % 9 == 0) "Yes" else "No"
}

fun main(args: Array<String>) {
    //val (n, x, t) = readLine()!!.split(" ").map { it.toInt() }
    val n = readLine()!!

    //val n = "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280"

    val result = solver(n)

    println(result)
}


Measured memory_bytes: 41052
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;

const int MOD = 1000000007;
const int INF = 1000000000;

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

int main(){
    int n, k; cin >> n >> k;
    int num = 1;
    REP(i, n){
        num = min(2*num, num+k);
    }
    cout << num << "\n";
    return 0;
}


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


int main(void)
{
	int mati, miti;
	int test[10000];
	cin >> mati >> miti;

	for (int i = 0; i < miti * 2; i++) {
		cin >> test[i];
	}
	
	int ans = 0;

	for (int i = 1; i <=mati ; i++) {
		for (int j = 0; j <miti*2 ; j++) {
			
			if (test[j] == i) {
				ans++;
			}

		}
		cout << ans << endl;
		ans = 0;
	}
}


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

int judge(char s[],char p[]){
	int i,j;
	int slen=strlen(s),plen=strlen(p);
	char c[100];
	for(i=0;i<slen;i++){
		for(j=0;j<plen;j++){
				c[j]=s[(i+j)%slen];
		}
		c[j] = '\0';
		if(!strcmp(p,c))return 1;
	}
	return 0;
}

int main(){
	char s[100],p[100];
	scanf("%s",s);
	scanf("%s",p);

	printf("%s\n",(judge(s,p)?"Yes":"No"));
	return 0;
}

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

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

ll sum[301010];

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) {
        sum[i] += a[i];
        if (i) sum[i] += sum[i-1];
    }
    map<ll, ll> mp;
    rep(i, n) {
        mp[sum[i]]++;
        //cout << sum[i] << " ";
    }
    ll ans = mp[0];
    for (auto tmp : mp) {
        if (tmp.second >= 2) {
            ans += tmp.second * (tmp.second - 1) / 2;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15872
#include"bits/stdc++.h"
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

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

template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }

template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) {
	for (auto& e : u) fill_v<T>(e, v...);
}

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

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}


const int MOD = 1e9 + 7;

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(void) {
	cout.tie(0);
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	ll n, m;
	cin >> n >> m;
	vector<ll> p(m);
	vector<string> s(m);
	rep(i, m) cin >> p[i] >> s[i];
	map<ll, ll> ma;
	ll ac = 0;
	map<ll,ll> wa;
	ll sumwa = 0;
	rep(i, m) {
		if (s[i] == "AC") {
			if (ma[p[i]] == 0) {
				sumwa += wa[p[i]];
				wa[p[i]] = 0;
				ac++;
			}
			ma[p[i]]++;
		}
		if (s[i] == "WA") {
			if (ma[p[i]] == 0) wa[p[i]]++;
		}
	}
	cout << ac << " " << sumwa << endl;
}


Measured memory_bytes: 19072
i1 = int(input())
i2 = list(map(int, input().split()))
    
l = []
for i in range(i1):
  if i2[i] % 2 == 0:
    if i2[i] % 3 == 0 or i2[i] % 5 == 0:
        l.append('APPROVED')
    else:
        l.append('DENEID')
    
if (all(str == 'APPROVED' for str in l)):
	print('APPROVED')
else:
  	print('DENIED')

Measured memory_bytes: 3060
H, W = map(int,input().split())
cost = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

ans = 0
for h in range(H):
    for w in range(W):
        if A[h][w] != -1:
            ans += cost[A[h][w]][1]
print(ans)

Measured memory_bytes: 68300
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e5;

int main(){
    int h, w, V;
    cin >> h >> w;
    V = h * w;

    vector<vector<int>> d(V, vector<int>(V,INF));// d[i][j] = shortest distances between i and j
    for(int i=0; i<V; i++){
        d[i][i] = 0;
    }

    vector<vector<char>> c(h, vector<char>(w));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> c[i][j];
        }
    }

    vector<int> dx = {1, 0, -1, 0};
    vector<int> dy = {0, 1, 0, -1};
    for(int x=0; x<h; x++){
        for(int y=0; y<w; y++){
            for(int i=0; i<4; i++){
                if(0 <= x+dx[i] && x+dx[i] < h
                && 0 <= y+dy[i] && y+dy[i] < w
                && c[x][y] == '.'
                && c[x+dx[i]][y+dy[i]] == '.'){
                    d[w*x + y][w * (x+dx[i]) + (y+dy[i])] = 1;
                    d[w * (x+dx[i]) + (y+dy[i])][w*x + y] = 1;
                }
            }
        }
    }

    // naive DP
    for(int k=0; k<V; k++){// potential relay points
        for (int i=0; i<V; i++){
            for (int j=0; j<V; j++){
                d[i][j] = min(
                    d[i][j],// without going through k
                    d[i][k] + d[k][j]// with going through k
                );
            }
        }
    }

    int ans = 0;
    for (int i=0; i<V; i++){
        for (int j=0; j<V; j++){
            if(d[i][j] != INF) ans = max(ans, d[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i, a, b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= int(b); --i)
#define trav(it, v) for(auto &it : (v))
#define all(v) (v).begin(), (v).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define sz(x) (int)(x).size()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

int main(){
	ios::sync_with_stdio(0);
    int H, W;
    cin >> H >> W;
    vector<string> f(H);
    rep(i,0,H)
        cin >> f[i];
    queue<pair<int, int>> q;
    vector<vector<int>> dis(H, vector<int>(W, 1e9));
    rep(i,0,H)
        rep(j,0,W) {
            if (f[i][j] == '#') {
                dis[i][j] = 0;
                q.push(make_pair(i, j));
            }
        }
    int dx[]={1,0,-1,0};
    int dy[]={0,1,0,-1};
    int ans = 0;
    while (!q.empty()) {
        auto cur = q.front();
        ans = dis[cur.first][cur.second];
        q.pop();
        rep(i,0,4) {
            int x = cur.first + dx[i];
            int y = cur.second + dy[i];
            if (x < 0 || y < 0 || x >= H || y >= W)
                continue;
            if (dis[x][y] <= dis[cur.first][cur.second]+1)
                continue;
            dis[x][y] = dis[cur.first][cur.second]+1;
            q.push(make_pair(x, y));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> ans(n+1, 0);
  for(ll x = 1; x <= n; x++){
    if(x*x > n) break;
    for(ll y = 1; y <= n; y++){
      if(x*x+y*y+x*y > n) break;
      for(ll z = 1; z <= n; z++){
        ll add = x*x + y*y + z*z + x*y + y*z + z*x;
        if(add > n) break;
        ans.at(add)++;
      }
    }
  }
  rep2(i, 1, n+1){
    cout << ans.at(i) << endl;
  }
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

bool isl(int x) {
    int p = x % 10;
    while(x) {
        int c = x % 10;
        if(abs(c - p) > 1) {
            return false;
        }
        p = c;
        x /= 10;
    }
    return true;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;
    int x = 0;
    while(k) {
        x++;
        int p = 1, tp = 10;
        while(x / tp) {
            int u = x / p % 10, d = x / tp % 10;
            if(u == d + 2) {
                x += 8 * p;
                x -= x % p;
            } else if(u < d - 1) {
                x += (d - 1 - u) * p;
                x -= x % p;
            }
            p *= 10, tp *= 10;
        }
        k -= isl(x);
    }
    cout << x << endl;
    return 0;
}


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


int main() {
    int k, x;
    cin >> k >> x;
    int begin = x - (k-1);
    int end = x + (k-1);

    for (int i = begin; i <= end; ++i) {
        cout << i << " "s;
    }
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a==b) printf("Draw\n");
	else if(a==1) printf("Alice\n");
	else if(b==1) printf("Bob\n");
	else if(a>b) printf("Alice\n");
	else printf("Bob\n");
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int main(){
    int a,b;
    char c;
    cin  >> a >> c >> b;
    int res;
    if(c=='+'){
        res = a+b;
    }else{
        res = a-b;
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MOD = 1e9+7;
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;
}

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<int> as = A;
  sort(as.begin(), as.end());
  vector<ll> under(N);
  rep(i, N) {
    for(int j=i+1; j<N; j++) {
      if(A[j] < A[i])
        under[i]++;
    }
  }
  ll ans = 0;
  ll inv = modinv(2, MOD);
  rep(i, N) {
    auto it = lower_bound(as.begin(), as.end(), A[i]);
    ll num = it-as.begin();
    ll tmp = (((((num+num*(K-1))%MOD)*(K-1))%MOD)*inv)%MOD;
    ans = (ans+(under[i]*K)%MOD+tmp)%MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// ABC067_A.cpp : Defines the entry point for the console application.
//

#include <iostream>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;
		return 0;
	}
	cout << "Impossible" << endl;
    return 0;
}



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

using namespace std;

int main()
{
    int N;
    cin >>N;
    vector<int>h(N);
    for(int i=0;i<N;i++)
    {
        cin >> h[i];
    }

    h[0]=max(1, h[0]-1);
    for(int i=1; i<N; i++){
        if(h[i-1]<h[i]){
            h[i]--;
        }
        else if(h[i-1]>h[i]){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    cout << "Yes" <<endl;  
    return 0; 
}


Measured memory_bytes: 640
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<int>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (i & 1) {
			ans -= v[i];
		}
		else {
			ans += v[i];
		}
	}
	cout << ans << endl;

	return 0;
}

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

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

  double L;
  cin >> L;

  double max_vol = 0;
  for(double i = 10e-6; i <= L / 3; i += 10e-6) {
    max_vol = max(max_vol, (i * i * (L - i - i)));
  }

  cout << setprecision(10) << max_vol << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)      //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++) //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)    //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))        //array size
#define SORTD(a) sort(a,a+ASIZE(a),greater<int>()) //sort in descending order for array
#define SORTA(a) sort(a,a+ASIZE(a))                //sort in ascending order for array
#define SORTS(a) sort(a.begin(),a.end())           //sort in ascending order for string type
typedef long long LL;
typedef unsigned int UINT;
 
void SCAN(int *a){scanf("%d",a);}                             //scan for type int
void SCAN(int *a,int n){int i;REP(i,n){scanf("%d",&a[i]);}}   //scan for type int array
void SCAN(UINT *a){scanf("%u",a);}                            //scan for type unsigned int
void SCAN(UINT *a,int n){int i;REP(i,n){scanf("%u",&a[i]);}}  //scan for type unsigned int array
void SCAN(LL *a){scanf("%lld",a);}                            //scan for type long long int
void SCAN(LL *a,int n){int i;REP(i,n){scanf("%lld",&a[i]);}}  //scan for type long long int array
void SCAN(char *c){scanf(" %c",c);}                           //scan for type char
void SCAN(char *c,int n){int i;REP(i,n){scanf(" %c",&c[i]);}} //scan for type char array
 
const int MOD = 1000000007;
const int INF = 1000000000;
 
const int DX4[4]= {-1,0,0,1};
const int DY4[4]= {0,-1,1,0};
 
//fill an N-dimensional array with val
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
	fill((T*)array,(T*)(array+N),val);
}
 
int pascalTri(int n,int r){
	int tri[n+1][n+1];
	int i,j;
	REP(i,n+1){REP(j,n+1){tri[i][j]=0;}}
	REP(i,n+1){
		REP(j,n+1){
			if(j>i){break;}
			if(j==0||j==i){tri[i][j]=1;}else{tri[i][j]=(tri[i-1][j-1]%MOD+tri[i-1][j]%MOD)%MOD;}
		}
	}
	return tri[n][r];
}
 
 
int main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	int x,y,z;
	int i,j;
	
	SCAN(&x);SCAN(&y);SCAN(&z);

 	printf("%d\n",(x-z)/(y+z));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define N 50000
using namespace std;
int main(){
  int n;
  int p[N]={0};
  for(int i=3;i<=N;i+=2) p[i] = 1;
  p[2] = 1;
  for(int i=3;i<=1000;i+=2){
    if(p[i]==1){
      for(int j=2*i;j<=N;j+=i) p[j] = 0;
    }
  }
  while(cin >> n){
    if(n==0) break;
    int count = 0;
    for(int i=2;i<=n/2;i++){
      if(p[i]==1&&p[n-i]==1) count++;
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 1360
#include<bits/stdc++.h>
#define F first
#define S second
#define LL long long
#define PB push_back
#define MP make_pair
#define I insert

const LL N = 2e5+5, mod = 1000000007;

using namespace std;

LL n, m, i, j, k, l, r, t, ans, nn;
LL a[N], b[N], c[N];
LL xe[N*3];

void upd ( LL x ) {
	while ( x <= N ) {
		xe[x]++;
		x += (x & -x);
	}
}
 
LL get ( LL x ) {
	LL k = 0;
	while ( x > 0 ) {
		k += xe[x];
		x -= (x & -x);
	}
	return k;
}

int main(){
	cin >> n;
	for ( i = 1; i < 2*n; ++i ){
		cin >> a[i];
		b[i] = a[i];
	}
	sort ( b + 1, b + 2 * n );
	for ( LL ww = 18; ww >= 0; --ww ){
		k = ans + ( 1 << ww );
		if ( k >= 2 * n ) continue;
		for ( i = 1; i < 2 * n; ++i ){
			if ( a[i] >= b[k] ) c[i] = 1;
			else c[i] = 0;
		}
		for ( l = n; l > 1; --l ){
			if ( c[l] == c[l-1] ) break;
		}
		for ( r = n; r < 2 * n - 1; ++r ){
			if ( c[r] == c[r+1] ) break;
		}
		//cout << k << " " << b[k] << " " << l << " " << r << "  " << c[l] << "->";
		if ( l == 1 && r == 2 * n - 1 ) l = r = n - (1 - n%2);
		if ( l == 1 ) l = r;
		if ( r == 2 * n - 1 ) r = l;
		if ( n - l > r - n ) l = r;
		if ( c[l] ) ans = k;
		//cout << c[l] << endl;
	}
	cout << b[ans] << endl;
	return 0;
}
 
/**/
//      IIIIIIIII      OOOOO             A          NN        N    EEEEEEEEEE
//          I         O     O           A A         N N       N    E
//          I        O       O         A   A        N  N      N    E
//          I        O       O        A     A       N   N     N    E
//          I        O       O       AAAAAAAAA      N    N    N    EEEEEEEE
//          I        O       O      A         A     N     N   N    E
//          I        O       O     A           A    N      N  N    E
//          I         O     O     A             A   N       N N    E
//      IIIIIIIII      OOOOO     A               A  N        NN    EEEEEEEEEE ___ KAPANADZE

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

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long H;
        H = sc.nextLong();
        long W;
        W = sc.nextLong();
        String[] S = new String[(int)(H)];
        for(int i = 0 ; i < H ; i++){
                S[i] = sc.next();
        }

        final Solver solver = new Solver();
        solver.solve(H, W, S);
    }
}

class Solver {
    final static char CLEAR = '.';

    public void solve(long H, long W, String[] S) {
        int[][] L = new int[(int) H][(int) W];
        int[][] R = new int[(int) H][(int) W];
        int[][] U = new int[(int) H][(int) W];
        int[][] D = new int[(int) H][(int) W];

        calc(L, R, U, D, S);

        int max = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                max = Math.max(
                        max,
                        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
                );
            }
        }

        System.out.println(max);
    }

    private void calc(int[][] L, int[][] R, int[][] U, int[][] D, String[] S) {
        final int H = S.length;
        final int W = S[0].length();

        for (int i = 0; i < H; i++) {
            L[i][0] = (S[i].charAt(0) == CLEAR) ? 1 : 0;
            for (int j = 1; j < W; j++) {
                L[i][j] = (S[i].charAt(j) == CLEAR) ? L[i][j - 1] + 1 : 0;
            }

            R[i][W - 1] = (S[i].charAt(W - 1) == CLEAR) ? 1 : 0;
            for (int j = W - 2; j >= 0; j--) {
                R[i][j] = (S[i].charAt(j) == CLEAR) ? R[i][j + 1] + 1 : 0;
            }
        }

        for (int j = 0; j < W; j++) {
            U[0][j] = S[0].charAt(j) == CLEAR ? 1 : 0;
            for (int i = 1; i < H; i++) {
                U[i][j] = (S[i].charAt(j) == CLEAR) ? U[i - 1][j] + 1 : 0;
            }

            D[H - 1][j] = S[H - 1].charAt(j) == CLEAR ? 1 : 0;
            for (int i = H - 2; i >= 0; i--) {
                D[i][j] = (S[i].charAt(j) == CLEAR) ? D[i + 1][j] + 1 : 0;
            }
        }

    }
}



Measured memory_bytes: 120688
#include<iostream>

using namespace std;

int main(char** argv, int argc){
    int N;
    cin >> N;

    N=N%10;
    //cout<<"N="<<N<<endl;
    if(N==2||N==4||N==5||N==7||N==9){
        cout<<"hon"<<endl;
    }else if(N==0||N==1||N==6||N==8){
        cout<<"pon"<<endl;
    }else
    {
        cout<<"bon"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;
const ll I = 1e18;

ll n, a[N];
int main () {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
  	ll ans = 1;
  	for (int i = 0; i < n; i ++) {
  		cin >> a[i];
  		if (!a[i]) {
  			return cout << 0 ,0 ;
		  }
	  }
  	for (int i = 0; i < n; i ++) {
  		ll x;
  		x = a[i];
  		if (ans > I / x) {
  			return cout << -1, 0;
		}
		ans *= x;
	}
	if (ans > I) ans = -1;
	cout << ans;
}

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

int main(){
    string S,a,b;
    cin>>S;
    while(S.size()>1){
        S.pop_back();
        S.pop_back();
        a = S.substr(0,S.size()/2);
        b = S.substr(S.size()/2,S.size()/2);
        if(a == b){
            cout<<a.size()*2<<endl;
            return 0;
        }

    }

    cout<<1<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int a, b, x, y, n;
    while(scanf("%d", &n), n) {
        a = b = 0;
        while(n--) {
            scanf("%d %d", &x, &y);
            x - y ? *(x > y ? &a : &b) += x + y : (a += x, b += y);
        }
        printf("%d %d\n", a, b);
    }
    return 0;
}

Measured memory_bytes: 600
// PRUTHVI_RAJU IS GREAT
//..... COPIED FROM HERE  ....... https://atcoder.jp/contests/abc171/submissions/14578433

#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
    
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// struct chash { int operator()(int x) const { return x ^ RANDOM; }};
// cc_hash_table<int, int, hash<int>> cnt;

const int MOD = 1e9 + 7;
const int MAXN = 2e6 + 10;
int fact[MAXN],invfact[MAXN];

int power(int x,int y){ 
    int res = 1; 
    while(y){
        if(y&1) res = (res*x)%MOD;
        x = (x*x)%MOD; y >>= 1;
    } 
    return res;
}

int nCr(int n,int r){
    int ret = (fact[n]*invfact[r])%MOD;
    ret = (ret*invfact[n-r])%MOD;
    return ret;
}

void solve(){
    int k; string s; cin>>k>>s; int n = sz(s);   

    fact[0] = 1; FOR(i,1,n+k) fact[i] = (fact[i-1]*i)%MOD;
    FOR(i,0,n+k) invfact[i] = power(fact[i],MOD-2);

    int ans = power(26,n+k);

    FOR(len,0,n-1){
        int temp = (nCr(n+k,len)*power(25,n+k-len))%MOD;
        ans = (ans + (MOD-temp))%MOD;
    }
    cout<<ans<<endl;
}
    
signed main(){
    
    FastRead;     
    
    int t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}
    





Measured memory_bytes: 35652
#include <stdio.h>
int main(){
  int a=1 ,b=0 ,c=0 ,tmp;
  char X ,Y;
  while( scanf( "%c,%c" ,&X ,&Y ) != EOF ){
    
    if( X == 'A' ){
      if( Y == 'B' ){
	tmp = a;
	a = b;
	b = tmp;
      }
      else{
	tmp = a;
	a = c;
	c = tmp;
      }
    }
    
    
    if( X == 'B' ){
      if( Y == 'A' ){
	tmp = b;
	b = a;
	a = tmp;
      }
      else{
	tmp = b;
	b = c;
	c = tmp;
      }
    }
    
    if( X == 'C' ){
      if( Y == 'A' ){
	tmp = c;
	c = a;
	a = tmp;
      }
      else{
	tmp = c;
	c = b;
	b = tmp;
      }   
    }
  }
  
  if( a == 1 ){
    printf( "A\n" );
  }
  
  else if( b == 1 ){
    printf( "B\n" );
  }
  
  else{
    printf( "C\n" );
  }
  
  return 0;
}

Measured memory_bytes: 524
require 'set'

N = gets.to_i
X = Hash.new{|h, k| h[k] = []}
Y = Hash.new{|h, k| h[k] = []}
N.times{
  x, y = gets.chomp.split(" ").map(&:to_i)
  X[x] << y
  Y[y] << x
}

sx = Set.new
sy = Set.new
qx = []
qy = []
ans = -N
X.each{|k, v|
  next if sx.include?(k)
  qx << k
  wkx, wky = [sx.size, sy.size]
  until(qx.empty? && qy.empty?) do
    until qx.empty? do
      x = qx.shift
      X[x].each{|y|
        (sy.add(y); qy.push(y)) if !sy.include?(y)
      }
    end
    until qy.empty? do
      y = qy.shift
      Y[y].each{|x|
        (sx.add(x); qx.push(x)) if !sx.include?(x)
      }
    end
  end
  ans += (sx.size - wkx) * (sy.size - wky)
}

puts ans


Measured memory_bytes: 23164
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'

const int INF = 1e9;

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

  int n, k; cin >> n >> k;
  int h[n]; rep(i, n) cin >> h[i];

  int dp[101010];  // dp[i] : i + 1 番目の足場にたどりつくための最小コスト
  fill(dp, dp + 101010, INF);

  dp[0] = 0; dp[1] = abs(h[0] - h[1]);

  for (int i = 1; i < n; ++i){
    for (int j = 0; j < k; ++j){
      if (i - j < 0) break;
      dp[i + 1] = min(dp[i + 1], dp[i - j] + abs(h[i + 1] - h[i - j]));
    }
  }

  print(dp[n - 1]);

  return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int n, A, B, C;

int dfs(vector<int> l, int cur, int a, int b, int c) {
  if (cur == n) {
    if (min({a, b, c}) > 0) return abs(a - A) + abs(b - B) + abs(c - C) - 30;
    else return pow(10, 9);
  }
  int ret0 = dfs(l, cur + 1, a, b, c);
  int ret1 = dfs(l, cur + 1, a + l[cur], b, c) + 10;
  int ret2 = dfs(l, cur + 1, a, b + l[cur], c) + 10;
  int ret3 = dfs(l, cur + 1, a, b, c + l[cur]) + 10;
  return min({ret0, ret1, ret2, ret3});
}

int main() {
  cin >> n >> A >> B >> C;
  vector<int> l(n);
  REP(i, n) cin >> l[i];
  cout <<  dfs(l, 0, 0, 0, 0) << endl;
}


Measured memory_bytes: 888
n=int(input())
blue=[]
red=[]

for i in range(n):
    blue.append(input())

m=int(input())

for j in range(m):
    red.append(input())

ans=[]

for b in blue:
    if blue.count(b)<=red.count(b):
        ans.append(0)

    else:
        ans.append((blue.count(b)-red.count(b)))
print(max(ans))


Measured memory_bytes: 3060
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while(true) {
            int m = scan.nextInt();
            int f = scan.nextInt();
            int r = scan.nextInt();
            if (m == -1 && f == -1 && r == -1) {
                break;
            }
            if (m == -1 || f == -1) {
                sb.append("F").append("\n");
            } else if(m + f >= 80) {
                sb.append("A").append("\n");
            } else if (m + f >= 65) {
                sb.append("B").append("\n");
            } else if (m + f >= 50) {
                sb.append("C").append("\n");
            } else if (m + f >= 30) {
                if (r >= 50) {
                    sb.append("C").append("\n");
                } else {
                    sb.append("D").append("\n");
                }
            } else {
                sb.append("F").append("\n");
            }
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 26224
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

vector<vector<int>> to;
vector<vector<int>> cost;

vector<int> color;
vector<int> x = {1, 0};

void dfs(int v, int c) {
  color[v] = c;
  for (int i = 0; i < to[v].size(); i++) {
    if (color[to[v][i]] != -1) continue;
    if (cost[v][i] % 2 == 0) dfs(to[v][i], c);
    else dfs(to[v][i], x[c]); 
  }
}

void solve() {
  int n;
  cin >> n;
  to.resize(n);
  cost.resize(n);
  color.resize(n, -1);
  rep(i,n-1) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
    cost[a].push_back(c);
    cost[b].push_back(c);
  }

  dfs(0, 1);

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

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

Measured memory_bytes: 15908
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
    ll n;cin >> n;
    string s;cin >> s;
    vector<ll>pre(n+10,0);

    for(ll i = 1;i<=n;i++){
        ll ii = i;
        while(ii){
            ii %= __builtin_popcount(ii);
            pre[i]++;
        }
    }

   ll cnt = 0;
   for(ll i = n-1;i>=0;i--) cnt += s[i]=='1';
   ll m1 = 0;ll m2 = 0;

   if(!cnt){
    for(ll i = 0;i<n;i++)
        cout << 1 <<endl;
    return;
   }

   for(ll i = 0;i<n;i++)if(s[i]=='1'){
    m1 = (m1+modpow(2,n-i-1,cnt+1))%(cnt+1);
    if(cnt>1)m2 = (m2+modpow(2,n-i-1,cnt-1))%(cnt-1);
   }

   ll c1 = 0;ll c2 = 0;
   for(ll i = 0;i<n;i++){
    if(s[i]=='1'&&cnt==1){
        cout << 0 <<endl;
        continue;
    }
    c1 = modpow(2,n-i-1,cnt+1);
    if(cnt>1)c2 = modpow(2,n-i-1,cnt-1);
    else c2 = -1;
    if(s[i]=='0') cout << pre[(m1+c1)%(cnt+1)]+1 <<endl;
    else cout << pre[((m2-c2)+(cnt-1))%(cnt-1)]+1 <<endl;
   }
   return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

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

int main(void){
    int a=0;
    int b=0;
    int k=0;
    int num=0;
    int array[100]={0};
    int count=0;

    cin >> a >> b >> k;

    num=a;
    if(a>b)num=b;

    for(int i=1;i<=num;i++){
        if(a%i==0&&b%i==0){
            array[count]=i;
            count++;
        }
    }

    sort(begin(array),end(array),greater<int>());

    cout << array[k-1] << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int mo = 2019;
LL L, R;

int main(void) {
    cin >> L >> R;

    if (R - L >= 3000) {
        cout << 0 << endl;
        return 0;
    }

    LL mi = LLINF;
    FOR(i, L, R + 1) {
        FOR(j, i + 1, R + 1) {
            chmin(mi, 1ll * i * j % mo);
        }
    }
    cout << mi << endl;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = [int(i) * 2 - 1 for i in STR()]
ss = abs(sum(s))
l = len(s)
ans = (l - ss) // 2
print(ans * 2)


Measured memory_bytes: 66008
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;

typedef long long int ll;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;


int main() {

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

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

	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] >= b[i])
		{
			ans += a[i] - b[i];
		}
	}

	cout << ans << endl;
}





Measured memory_bytes: 256
from heapq import heappop, heappush


def main():
    N, M, S = map(int, input().split())
    adj = [{} for _ in range(N)]
    amax = 0
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        adj[u-1][v-1] = (a, b)
        adj[v-1][u-1] = (a, b)
        amax = max(amax, a)
    C = [0] * N
    D = [0] * N
    for i in range(N):
        C[i], D[i] = map(int, input().split())
    MAX = amax * N
    dp = [[float("inf")] * (MAX+1) for _ in range(N)]
    q = [[0, min(S, MAX), 0, -1]]
    ans = [None] * N
    remain = N
    while len(q) and remain:
        time, coin, cur, prev = heappop(q)
        if dp[cur][coin] <= time:
            continue
        if ans[cur] is None:
            ans[cur] = time
            remain -= 1
        dp[cur][coin] = time
        if coin < MAX:
            heappush(q, [time + D[cur], min(coin + C[cur], MAX), cur, cur])
        for nxt in adj[cur]:
            dcost, dtime = adj[cur][nxt]
            if nxt != prev and dcost <= coin:
                heappush(q, [time + dtime, coin - dcost, nxt, cur])
    for i in range(1, N):
        print(ans[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 146208
N,X,M = map(int, input().split())


A = [-1]*(M+100)
A[0] = X
i = 0
tmpans = 0
flag = False
check = [-1]*(M+1)
slice = -1
while i< N-1:
    newa = A[i]**2%M
    i+= 1
    if check[newa] != -1:
        flag = True
        slice = check[newa]
        break
    A[i] = newa
    check[newa] = i

if not flag:
    print(sum(A[:i+1]))

else:
    print(sum(A[:slice])+ sum(A[slice:i])*((N-slice)//(i-slice))+sum(A[slice:slice + (N-slice)%(i-slice)]))


Measured memory_bytes: 13936
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <math.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define repP(i, a, b) for(int i = a; i < b; i++)
#define repM(i, a, b) for(int i = a - 1; i >= b; i--)

using namespace std;

int main()
{
  int a = 0 , b = 0, c = 0, d = 0, e = 0, f = 0, i = 0, j = 0;
  int sum = 0, num = 0, count = 0, ans = 0, min = 0, max = 0;
  double d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0;
  int a1[999999], a2[999999], a3[999999];
  //char s1[200000], s2[200000], s3[200000];
  string s1, s2, s3;
  
  cin>>s1;
  j = s1.size() - 1;
  for(i = 0; i < s1.size() / 2;i++){
    if(s1[i] != s1[j]){
      c++;
    }
    j--;
  }
  cout << c << endl;
}
  


Measured memory_bytes: 256
use proconio::{fastout, input};
use std::collections::BTreeMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [i32; n],
    }

    let mut ans = 0u64;
    let mut map = BTreeMap::new();

    for i in 0..n {
        ans += *map.get(&(i as i32 - a[i])).unwrap_or(&0);
        map.entry(i as i32 + a[i])
            .and_modify(|e| *e += 1)
            .or_insert(1);
    }

    println!("{}", ans);
}


Measured memory_bytes: 9704
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS

main = do
  [m,d] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ length [(i,j) | i <- [1..m], j <- [10..d], let (d2,d1) = j `quotRem` 10, d1 >= 2, d2 >= 2, i == d1 * d2]


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

const int MAX = 5100000;
const int MOD = 1000000000+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    long x;
    long y;
    long a;
    long b;
    cin >> x >> y;
    a = (2 * x - y);
    b = (-x + 2 * y);
    if(a % 3 == 0 and b % 3 == 0){
        a /= 3;
        b /= 3;
        COMinit();

        // 計算例
        cout << COM(a+b, a) % (MOD) << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 119808
import fractions

N, X = map(int, input().split())
x = list(map(int, input().split()))

if len(x) == 1:
    print(abs(x[0] - X))
else:
    g = x[1] - x[0]
    for i in range(N - 1):
        g = fractions.gcd(g, x[i + 1] - x[i])

    ans = fractions.gcd(g, max(max(x) - X, X - min(x)))
    print(ans)


Measured memory_bytes: 16240
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      PriorityQueue<Integer> pq = new PriorityQueue<>((a, b) -> b - a);
      for(int i = 0; i < n; i++)
        pq.offer(sc.nextInt());
      for(int i = 1; i <= m; i++) {
        int price = pq.poll();
        price = price / 2;
        pq.offer(price);
      }
      long sum = 0;
      while(!pq.isEmpty()) {
        sum += pq.poll();
      }
      System.out.println(sum);
  }
}

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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

bool comp(const pair<ll, ll> v1, pair<ll, ll> v2) {
	return v1.first - v1.second > v2.first - v2.second;
}

int main() {
	ll n;
	cin >> n;
	vector<pair<ll, ll>> vp(n);
	rep(i, n) cin >> vp[i].first;
	rep(i, n) cin >> vp[i].second;
	sort(vp.begin(), vp.end(), comp);
	ll ans = 0;
	ll count = 0;
	rep(i, n) {
		//
		if (vp[i].first < vp[i].second) {
			ans++;
			count += vp[i].second - vp[i].first;
			vp[i].first = vp[i].second;
		}
	}
	rep(i, n) {
		if (count <= 0) break;
		if (vp[i].first > vp[i].second) {
			count -= vp[i].first - vp[i].second;
			ans++;
		}
	}
	if (count > 0) ans = -1;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define allof(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define exists(s, e) (s.find(e)!=s.end())
#define INF 0x3f3f3f3f
#define endl '\n'
#define mp make_pair
#define watch(x) cout << (#x) << " is " << (x) << endl;

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

ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

void solve() {
    string s; cin >> s;
    int cnt = 0;
    if(s[0]=='1') cnt++;
    if(s[1]=='1') cnt++;
    if(s[2]=='1') cnt++;
    cout << cnt << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    solve();
    return 0;
}



Measured memory_bytes: 256