akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline ll getint() {
	ll A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(ll X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[15];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	ll tmp[100001];
	rep(k, 8) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

int main() {


	int A = getint(), B = getint(), Q = getint();
	ll s[100100], t[100100];
	s[0] = -1e12;
	t[0] = -1e12;
	s[A + 1] = 1e12;
	t[B + 1] = 1e12;
	rep1(i, A) s[i] = getint();
	rep1(i, B) t[i] = getint();

	ll X[100000];
	rep(i, Q) {
		X[i] = (getint() << 20) + i;
	}
	pakuri_sort(Q, X);

	int ks = 0, kt = 0;
	ll kotae[100000];
	rep(i, Q) {
		ll x = X[i] >> 20;
		while (s[ks] < x) ks++;
		while (t[kt] < x) kt++;

		ll s1 = s[ks - 1];
		ll s2 = s[ks];
		ll t1 = t[kt - 1];
		ll t2 = t[kt];

		ll saishou = 1e13;
		saishou = min(saishou, abs(min(s1, t1) - x));
		saishou = min(saishou, abs(max(s2, t2) - x));
		ll k1 = abs(s1 - x);
		ll k2 = abs(t2 - x);
		saishou = min(saishou, k1 + k2 + min(k1, k2));
		ll k3 = abs(t1 - x);
		ll k4 = abs(s2 - x);
		saishou = min(saishou, k3 + k4 + min(k3, k4));

		kotae[X[i] & (1 << 20) - 1] = saishou;
	}

	rep(i, Q) putint(kotae[i]);

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

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

pair<int, int> arr[100009];
bool bitK[33];
int top=0;

void go(int now)
{
    if(now == 0) return;
    go(now/2);
    bitK[top++] = now%2;
}

int main()
{
    int n,k,nowk;
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; i++) scanf("%d%d", &arr[i].first, &arr[i].second);
    go(k);

    long long s = 0; nowk = k;
    for(int i=0; i<n; i++) if((nowk | arr[i].first) == nowk) s += (long long)arr[i].second;
    long long ans = s;

    for(int i=0; i<top; i++) {
        if(bitK[i] == 1) {
            nowk = 0;
            for(int j=0; j<i; j++) nowk = nowk*2 + (int)bitK[j];
            nowk *= 2;
            for(int j=i+1; j<top; j++) nowk = nowk*2 + 1;

            s = 0;
            for(int j=0; j<n; j++) if((nowk | arr[j].first) == nowk) s += (long long)arr[j].second;
            ans = max(ans, s);
        }
    }
    printf("%lld",ans);
    return 0;
}



Measured memory_bytes: 1532
/*input
7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <functional>
#include <cmath>
#include <cstring>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <list>
#include <cstdlib>
#include <list>
#include <cassert>
#include <ctime>
#include <fstream>
#include <sstream>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define N 300005
// const int INF = 1e18;
#define int ll
int n, m;
vector<pair<int, int> > seg;

class ITmax {
private:
	int f[4 * N], lazy[4 * N];
public:
	ITmax() {
		memset(f, 0, sizeof(f)); memset(lazy, 0, sizeof(lazy));
	}
	void dolazy(int k, int l, int r) {
		if (lazy[k] == 0) return;
		f[k] += lazy[k] * (r - l + 1);
		if (l != r) {
			lazy[k * 2] += lazy[k];
			lazy[k * 2 + 1] += lazy[k];
		}
		lazy[k] = 0;
	}
	void update(int k, int l, int r, int L, int R, int val) {
		dolazy(k, l, r);
		if (r < L || R < l) return;
		if (L <= l && r <= R) {
			f[k] += val * (r - l + 1);
			if (l != r) {
				lazy[k * 2] += val; lazy[k * 2 + 1] += val;
			}
			return;
		}
		int mid = (l + r) / 2;
		update(k * 2, l, mid, L, R, val); update(k * 2 + 1, mid + 1, r, L, R, val);
		f[k] = f[k * 2] + f[k * 2 + 1];
	}
	int get(int k, int l, int r, int L, int R) {
		dolazy(k, l, r);
		if (R < l || r < L) return 0;
		if (L <= l && r <= R) return f[k];
		int mid = (l + r) / 2;
		return get(k * 2, l, mid, L, R) + get(k * 2 + 1, mid + 1, r, L, R);
	}
} IT, ans;

bool cmp1(pair<int, int> x, pair<int, int> y) {
	return (x.se - x.fi) < (y.se - y.fi);
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		int l, r; cin >> l >> r;
		seg.push_back(mp(l, r));
		ans.update(1, 1, m, 1, r - l + 1, 1);
	}
	sort(seg.begin(), seg.end(), cmp1);
	int it = 0;
	for (int i = 1; i <= m; i++) {
		if (it != n) {
			while (it != n && i > seg[it].se - seg[it].fi + 1) {
				IT.update(1, 1, m, seg[it].fi, seg[it].se, 1);
				it++;
			}
		}
		for (int j = i; j <= m; j += i) {
			ans.update(1, 1, m, i, i, IT.get(1, 1, m, j, j));
		}
	}
	for (int i = 1; i <= m; i++) cout << ans.get(1, 1, m, i, i) << endl;
}

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

int main() {
    long n, odd = 0, even = 0, temp = 0;
    cin >> n;
    vector<long> a(n);
    rep(i, n) cin >> a.at(i);
    rep(i, n) {
        temp += a.at(i);
        if((i % 2 == 0 && temp < 0) || (i % 2 == 1 && temp > 0)) continue;
        if(i % 2) {
            odd += 1 - temp;
            temp = 1;
        } else {
            odd += temp + 1;
            temp = -1;
        }
    }
    temp = 0;
    rep(i, n) {
        temp += a.at(i);
        if((i % 2 == 0 && temp > 0) || (i % 2 == 1 && temp < 0)) continue;
        if(i % 2) {
            even += temp + 1;
            temp = -1;
        } else {
            even += 1 - temp;
            temp = 1;
        }
    }
    cout << min(odd, even) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int ll 
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = -1;
#ifndef LOCAL
#define cerr if(0)cout
#endif
 
int32_t main() 
{
	IAMSPEED
	ll a; cin >> a;
	cout << a + a*a + a*a*a;
}


Measured memory_bytes: 3688
#include<iostream>
using namespace std;
int main(){
  int n, a[100], b[100];
  cin >> n;
  for(int i=1; i<n; i++){
	cin >> b[i];
  }
  b[0] = 1000000;
  a[n-1] = b[n-1];
  int cnt = 0;
  for(int i=n-2; i>=0; i--){
    a[i] = min(b[i], b[i+1]);
  }
  for(int i=0; i<n; i++){
    cnt += a[i];
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=2e5+10, mod=1e9+7;

int main ()
{
    FASTIO
    double r;
    cin >> r;
    cout << setprecision(12) << 2*Pi*r << endl;
    return 0;
}
/**

*/


Measured memory_bytes: 3784
#include<stdio.h>
#include<stdlib.h>

int asc(const void *a,const void *b){
    return *(int *)a-*(int *)b;
}

int main(){
    int N,i;
    scanf("%d",&N);
    int D[N];
    for(i=0;i<N;i++)scanf("%d",&D[i]);

    qsort(D,N,sizeof(int),asc);
    printf("%d\n",D[N/2]-D[N/2-1]);
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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(a>b){a=b;return true;}return false;}

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    int n;
    cin>>n;
    int sum=0;
    int m;
    REP(i,1,n+1){
        sum+=i;
        if(sum>=n){
            m=i;
            break;
        }
    }
    int il=sum-n;
    REP(i,1,m+1){
        if(i!=il){
            cout<<i<<endl;
        }
    }
    return 0;
}

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

int main(){
  ll x,k,d;
  cin >> x >> k >> d;
  if(x<0){
    x *= -1;
  }
  
  if(x/d>=k){
    cout << x-k*d << endl;
    return 0;
  }
  
  if((x/d)%2==k%2){
    cout << x%d << endl;
  }else{
    cout << d-x%d << endl;
  }
}


Measured memory_bytes: 3632
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var y = o.a();
  y /= 1000;
  for(var i = 0; i <= n; i++){
    for(var j = 0; j <= n-i; j++){
      var k = n - i - j;
      if(i + j * 5 + k * 10 === y)return k + " " + j + " " + i;
    }
  }
  return "-1 -1 -1";
}

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

void DFS(int h, int w, int H, int W, vector<vector<char>> &S, queue<pair<int, int>> &to_expand, vector<vector<bool>> &visited) {
    if (h < 0 || h >= H || w < 0 || w >= W) {
        return;
    }
    if (S[h][w] == '#') {
        return;
    }
    if (!visited[h][w]) {
        to_expand.push({h, w});
        visited[h][w] = true;
        DFS(h - 1, w, H, W, S, to_expand, visited);
        DFS(h + 1, w, H, W, S, to_expand, visited);
        DFS(h, w - 1, H, W, S, to_expand, visited);
        DFS(h, w + 1, H, W, S, to_expand, visited);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H, W, Ch, Cw, Dh, Dw;
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    --Ch;
    --Cw;
    --Dh;
    --Dw;
    vector<vector<char>> S(H, vector<char>(W));
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> S[i][j];
        }
    }
    queue<pair<int, int>> to_expand;
    vector<vector<bool>> visited(H, vector<bool>(W));
    DFS(Ch, Cw, H, W, S, to_expand, visited);
    for (int T = 0; !to_expand.empty(); ++T) {
        int N = to_expand.size();
        for (int i = 0; i < N; ++i) {
            auto P = to_expand.front();
            to_expand.pop();
            int h = P.first, w = P.second;
            // cout << "(" << h << ", " << w << ") : " << T << '\n';
            if (h == Dh && w == Dw) {
                cout << T << '\n';
                return 0;
            }
            for (int next_h = max(0, h - 2); next_h <= min(H - 1, h + 2); ++next_h) {
                for (int next_w = max(0, w - 2); next_w <= min(W - 1, w + 2); ++next_w) {
                    // cout << "magic -> (" << next_h << ", " << next_w << ")\n";
                    if (!visited[next_h][next_w] && S[next_h][next_w] != '#') {
                        DFS(next_h, next_w, H, W, S, to_expand, visited);
                    }
                }
            }
        }
    }
    cout << "-1\n";
    return 0;
}

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

int main() {
string s,t;
  cin>>s>>t;
  int a=0;
  for(int i=0;i<s.size();i++){
  if(s.at(i)!=t.at(i)){a=1; break;}
  }
  if(a==0){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

int h;

string s1, s2;

const int MN = 330;
ll dp_sm[MN][MN], dp_calc[MN][MN];
ll sm(int n, int m) {
    if (n == 0 or m == 0) return 0;
    if (dp_sm[n][m] != -1) return dp_sm[n][m];
    ll &ans = dp_sm[n][m];
    ans = sm(n-1, m-1);
    if (s1[n-1] == s2[m-1]) ans++;
    return ans;
}

ll calc(int n, int m) {
    if (n == 0 or m == 0) return 0;
    if (dp_calc[n][m] != -1) return dp_calc[n][m];
    ll &ans = dp_calc[n][m];
    ans = min(calc(n-1, m), calc(n, m-1)) + sm(n, m);
    return ans;
}

ll solve() {
    memset(dp_sm, -1, sizeof(dp_sm));
    memset(dp_calc, -1, sizeof(dp_calc));
//    cout << s1 << " " << s2 << " " << calc(h, h) << endl;
    return calc(h, h);
}

int main() {
    int w;
    cin >> h >> w;
    string s[MN];
    for (int y = 0; y < h; y++) {
        cin >> s[y];
    }
    ll ans = 0;
    for (int x = 0; x < w-1; x++) {
        s1 = ""; s2 = "";
        for (int y = 0; y < h; y++) {
            s1 += s[y][x];
            s2 += s[y][x+1];
        }
        ans += solve();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
     
    int main(){
        int n;
        int a = 1000;
        scanf("%d", &n);
        
        if (n <= 1000){
            printf("%d\n", 1000 - n);
        }
        
        else{
            while (1){
                a += 1000;
                if (n <= a){
                    printf("%d\n", a - n);
                    break;
                }
            }
        }
        
     
        return 0;
    }

Measured memory_bytes: 1732
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>

#ifdef PRINTERS
#include "printers.hpp"
using namespace printers;
#define tr(a)		cerr<<#a<<" : "<<a<<endl;
#else
#define tr(a)    
#endif

#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
using namespace std;

void solve(){
	ll N,A,B;
	cin>>N>>A>>B;
	if(A>B)cout<<0;
	else if(N==1 and A!=B)cout<<0;
	else if(N<3)cout<<1;
	else cout<<B*(N-2)-A*(N-2)+1;
}

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

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = RInt();
            Console.WriteLine(180 * (n - 2));
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}


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

typedef long double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long> vl;
typedef vector<double> vd;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

#define pi 3.14159265358979
#define eps 1e-9
#define inf 1<<30

ll ex[10] {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};

int main()
{
	string s;
  ul num = 1;
  ll ret = 0;

	cin >> s;
  for(uint i=0;i<s.size()-1;i++) num*=2;
  for(uint i=0;i<s.size(); i++){
    ul n = num;
    uint j = 0;
    for(;j<s.size()-i-1;j++){
      n /= 2;
      ret += (s[i]-'0')*ex[j]*n;
    }
    ret += (s[i]-'0')*ex[j]*n;
  }

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <assert.h>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;


int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n;
    cin >> n;

    cout << (n * (n - 1) / 2) << endl;

    return 0;
}


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

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

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

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

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

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

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,x; cin>>n>>x;
  ll g=0;
  rep(i,n){
    ll a; cin>>a;
    g=gcd(abs(x-a),g);
  }
  cout<<g<<endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define min(a,b)(a)<(b)?(a):(b)
 
char s[1005],t[1005];
int n,m,x,i,j;
int dp[1005][1005]={0};
 
int main()
{
    s[0]=t[0]=' ';
    gets(s+1);
    gets(t+1);
    n=strlen(s),m=strlen(t);
    for(i=0;i<=(n<m?m:n);i++)
        dp[i][0]=dp[0][i]=i;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            dp[i][j]=min(min(dp[i-1][j]+1,dp[i][j-1]+1),dp[i-1][j-1]+(s[i-1]==t[j-1]?0:1));
    printf( "%d\n",(dp[n][m]));
    return 0;
}

Measured memory_bytes: 4452
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var u, v int
	N, u, v = ReadInt(), ReadInt()-1, ReadInt()-1
	adjL = make([][]int, N)
	for i := 0; i < N-1; i++ {
		A, B := ReadInt()-1, ReadInt()-1
		adjL[A] = append(adjL[A], B)
		adjL[B] = append(adjL[B], A)
	}
	du := dist(u)
	dv := dist(v)
	goal := v
	for i := 0; i < N; i++ {
		if dv[i] > du[i] && dv[goal] < dv[i] {
			goal = i
		}
	}
	fmt.Println(dv[goal] - 1)
}

var adjL [][]int
var N int

func dist(s int) []int {
	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i] = -1
	}
	dfs(d, s, 0)
	return d
}

func dfs(d []int, s int, c int) {
	d[s] = c
	for _, t := range adjL[s] {
		if d[t] >= 0 {
			continue
		}
		dfs(d, t, c+1)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 24956
n = int(input())

a = n // 1000
b = (n // 100) % 10
c = (n // 10) % 10
d = n % 10

for o1 in range(2):
    for o2 in range(2):
        for o3 in range(2):
            e = a
            if o1 == 0:
                e += b
            else:
                e -= b
            if o2 == 0:
                e += c
            else:
                e -= c
            if o3 == 0:
                e += d
            else:
                e -= d
            if e == 7:
                if o1 == 0:
                    op1 = "+"
                else:
                    op1 = "-"
                if o2 == 0:
                    op2 = "+"
                else:
                    op2 = "-"
                if o3 == 0:
                    op3 = "+"
                else:
                    op3 = "-"
                print(str(a) + op1 + str(b) + op2 + str(c) + op3 + str(d) + "=7")
                exit(0)

Measured memory_bytes: 3064
k = int(input())
l = []
if 7 % k == 0:
    print(1)
    exit(0)
l.append(7 % k)
for i in range(1,k):
    a = (10 * l[i-1] + 7)
    if a % k == 0:
        print(i+1)
        exit(0)
    else:
        l.append(a % k)
print(-1)    

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

using namespace std;

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

int n, k;

void solve0()
{
	if (n == 1) {
		cout << k / 2;
		cout << endl;
		return;
	}
	cout << k / 2 << " ";
	rep(i, n-2) {
		cout << k << " ";
	}
	cout << k << endl;
}

void sub(vector<int>& v, int& pos)
{
	if (v[pos] == 1) {
		v[pos] = 0;
		pos--;
	} else {
		v[pos]--;
		for (int i = pos+1; i < n; i++) v[i] = k;
		pos = n-1;
	}
}

void solve1()
{
	vector<int> res(n, k / 2 + 1);
	long long a = n / 2;
	int pos = n-1;
	while (a--) {
		sub(res, pos);
	}
	for (int i = 0; i < pos; i++) {
		cout << res[i] << " ";
	}
	cout << res[pos] << endl;
}

int main()
{
	cin >> k >> n;
	if (k % 2) solve1();
	else solve0();
}


Measured memory_bytes: 3456
import math
t = 1
# t = input()
# t = int(t)
def max(a,b):
	if a > b:
		return a
	return b
while t > 0:
	t -= 1
	a,b = map(int,input().strip().split())
	j = 1
	ma = {}
	mb = {}
	if a%2 == 0:
		ma[2] = 1
		while a%2 == 0:
			a /= 2
	p = math.sqrt(a) + 1
	p = int(p)
	for i in range(3,p,2):
		if a%i == 0:
			ma[i] = 1
			while a%i == 0:
				a /= i
	if a > 2:
		ma[a] = 1
	if b%2 == 0:
		mb[2] = 1
		while b%2 == 0:
			b /= 2
	p = math.sqrt(b) + 1
	p = int(p)
	for i in range(3,p,2):
		if b%i == 0:
			mb[i] = 1
			while b%i == 0:
				b /= i
	if b > 2:
		mb[b] = 1
	ans = 1
	for x,y in ma.items():
		if x in mb:
			ans += 1
	print(ans)


Measured memory_bytes: 64724
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define LL long long
#define R register
LL n,ans,s;
int main()
{
    scanf("%lld",&n);
    for(R int i=sqrt(n);i>0;--i)if(n%i==0){ans=n/i;break;}
    while(ans>0){++s;ans/=10;}
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const int INF=1000100010;
const int D=60;
const int MAX_N=200010;
//ダブリング
int t[D][MAX_N];
int main(){
    int n;
    ll k;
    cin>>n>>k;
    rep(i,n){
        cin>>t[0][i];
        t[0][i]--;
    }
    rep(i,D-1)rep(j,n){
            t[i+1][j]=t[i][t[i][j]];
        }
    int v=0;
    for(int i=D-1;i>=0;i--){
        ll l=1LL<<i;
        if(k>=l){
            v=t[i][v];
            k-=l;
        }
    }
    cout<<v+1<<endl;
    return 0;
}

Measured memory_bytes: 50424
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
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; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_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); }


struct UnionFind {
	vector<int> parent;
	int size;
	UnionFind(int n) :parent(n, -1), size(n) {}
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y)return false;
		if (sizeOf(x) < sizeOf(y))swap(x, y);
		parent[x] += parent[y]; parent[y] = x; size--;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
	int sizeOf(int x) { return -parent[root(x)]; }
};

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

	int N, M; cin >> N >> M;
	vector<int> A(M), B(M); rep(i, 0, M) {
		cin >> A[i] >> B[i];
		A[i]--, B[i]--;
	}

	if (M % 2) {
		cout << -1 << endl;
		return 0;
	}

	UnionFind uf(N);
	vector<vector<int>> G(N);
	vector<int> out(N);
	rep(i, 0, M) {
		if (uf.same(A[i], B[i])) {
			out[A[i]]++;
			cout << A[i] + 1 << " " << B[i] + 1 << endl;
		}
		else {
			uf.unite(A[i], B[i]);
			G[A[i]].push_back(B[i]);
			G[B[i]].push_back(A[i]);
		}
	}

	function<int(int, int)> dfs = [&](int v, int p) {
		dump(v, p);
		if (G[v].size() == 1 && G[v].front() == p) {
			return out[v] % 2;
		}
		int k = out[v];
		for (auto x : G[v]) {
			if (x == p)continue;
			auto res = dfs(x, v);
			if (res == 0) {
				cout << v + 1 << " " << x + 1 << endl;
				k++;
			}
			else {
				cout << x + 1 << " " << v + 1 << endl;
			}
		}
		return k % 2;
	};
	dfs(0, -1);

	return 0;
}

Measured memory_bytes: 19328
import sys

import numpy as np

input = sys.stdin.readline


def dfs(H, W, D, A, Q, LR, ans):
    position = [(-1, -1)] * (H * W + 1)
    for h in range(H):
        for w in range(W):
            position[A[h][w]] = (h, w)

    mp = np.zeros(shape=(H * W + 1), dtype=np.int64)

    for i in range(1, H * W + 1 - D):
        h, w = position[i]
        y, x = position[i + D]
        mp[i + D] = abs(x - w) + abs(y - h)

    for d in range(1, D + 1):
        mp[d::D] = np.cumsum(mp[d::D])

    for i in range(Q):
        l, r = LR[i]
        ans[i] = mp[r] - mp[l]


def main():
    H, W, D = map(int, input().split())
    A = np.zeros(shape=(H, W), dtype=np.int64)
    for i in range(H):
        A[i] = tuple(map(int, input().split()))
    Q = int(input())
    LR = np.zeros(shape=(Q, 2), dtype=np.int64)
    for i in range(Q):
        LR[i] = tuple(map(int, input().split()))

    ans = np.zeros(shape=Q, dtype=np.int64)
    dfs(H, W, D, A, Q, LR, ans)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 38252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // メインプログラムここから
    ll s, c; cin >> s >> c;
    ll ans = min(s, c/2);
    s = s - ans;
    c = c - ans*2;
    ans = ans + c/4;
    cout << ans << endl;
    // ここまで
}


Measured memory_bytes: 256
require 'matrix'

n, m, l = gets.split(" ").map(&:to_i)

a = []
n.times do |i|
    a[i] = gets.split(" ").map(&:to_i)
end
aa = Matrix[*a]

b = []
m.times do |i|
    b[i] = gets.split(" ").map(&:to_i)
end
bb = Matrix[*b]

cc = aa * bb

cc.row_size.times do |i|
    print cc.row(i).to_a.join(" "), "\n"
end



Measured memory_bytes: 7704
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	string S;
	cin >> S;
	
	// 解法
	ll ans1 = 0;
	REP(i, S.size()/2){
		if (S[i*2+1]=='0') ans1++;
	}
	
	
	ll ans2 = 0;
	// cout<<(S.size()+1)/2<<endl;
	REP(i, (S.size()+1)/2){
		if (S[i*2]=='1') ans2++;
	}
	
	ll ans = min(ans1+ans2, ll(S.size())-ans1-ans2);
	
	//出力
	// printf("%lld, %lld, %lld\n", ans1, ans2, ans);
	cout << ans << endl;
}


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

const ll MOD = 1e9+7;

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

// A  C  G  T
// 00 01 10 11

// .A.G.C.
// ?AGC A?GC ?GAC ?ACG AG?C

int masks[5]    = { 0b00111111, 0b11001111, 0b00111111, 0b00111111, 0b11110011 };
int patterns[5] = { 0b00001001, 0b00001001, 0b00100001, 0b00000110, 0b00100001 };

const int S = 4*4*4;

bool ok(int s) {
  rep(i,5) {
    if((s & masks[i]) == patterns[i]) {
      return false;
    }
  }
  return true;
}

int main () {
  int n;
  cin >> n;
  using mint = Fp<MOD>;

  vector<vector<mint>> dp(S, vector<mint>(n+1, 0));
  dp[0b111111][0] = 1;

  rep(i,n) {
    rep(j, S) {
      rep(k, 4) {
        int s = (j << 2) | k;
        if(ok(s)) {
          dp[s & 0b111111][i+1] += dp[j][i];
        }
      }
    }
  }

  mint ans  = 0;
  rep(i,S) ans += dp[i][n];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int[] a = new int[5];
    for (int i = 0; i < 5; i++) a[i] = scanner.nextInt();
    int sum = 0;
    int max = 0;
    for (int i = 0; i < 5; i++) {
      int d = (a[i] + 9) / 10 * 10;
      sum += d;
      max = Math.max(max, d - a[i]);
    }
    System.out.println(sum - max);
  }
}


Measured memory_bytes: 22996
from collections import Counter
N = int(input())
D = list(map(int, input().split()))

c = Counter(D)

mod = 998244353

L = list(set(D[:]))

L.sort(reverse=True)
if (D[0] != 0):
    print(0)
    exit()

if (c[0] > 1):
    print(0)
    exit()

if (N == 1):
    print(1)
    exit()

ans = []
for i in L:
    if (i == 0):
        break
    else:
        ans.append(c[i - 1] ** c[i])

# print(ans)
if (len(ans) == 0):
    print(0)
    exit()

multi_ans = 1
for i in ans:
    multi_ans *= i

print(multi_ans % mod)


Measured memory_bytes: 28560
#include<iostream>
#include<algorithm>
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
int main(){
	int m,n;
	int M[101][21],S[101],P[101]={0};
	while(cin>>m>>n,m){
		rep1(i,n)cin>>S[i],P[i]=P[i-1]+S[i];
		rep1(i,n)rep1(j,m)if(i!=1&&j!=1){
			int t,mi,mn=1<<30;
			rep1(x,i-1){
				t=max(M[x][j-1],P[i]-P[x]);
				if(mn>t)mn=t,mi=x;
			}
			M[i][j]=mn;
		}else M[i][j]=(i-1?P[i]:S[1]);
		cout<<M[n][m]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++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 all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,D,X;
  cin>>N>>D>>X;
  int A[N];
  rep(i,N)
    cin>>A[i];
  int cnt=N;
  rep(i,N){
    cnt+=(D-1)/A[i];
  }
  cout<<cnt+X<<endl;

 
}
  





Measured memory_bytes: 256
#include<stdio.h>


int main() {
    long long int n;
    scanf("%lld", &n);
    long long int a[n];
    for(long long int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
    }
    long long int x = 1000;
    long long int y = 0;
    for(long long int i = 1; i < n; i++) {
        if(a[i] > a[i - 1]) {
            y += x / a[i - 1];
            x %= a[i - 1];
        }
        else if (a[i] < a[i - 1]) {
            x += y * a[i - 1];
            y = 0;
        }
    }
    x += y * a[n - 1];
    y = 0;
    printf("%lld\n", x);
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define EPB emplace_back
#define MP make_pair
#define d(x) cerr << #x << ":" << x << endl;
#define da(x) cerr << #x << endl; for (auto a : x) cerr << a << " "; cerr << endl;
const int MOD = 1000000007;


int main() {
	fastio();
	int n, m, k;
	cin >> n >> m >> k;
	ll a[n], b[m];
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int j=0;j<m;j++)
		cin >> b[j];
	int i;
	for(i=0;i<n;i++) {
		if(a[i] > k)
			break;
		else
			k -= a[i];
	}
	int ans = i;
	/* d(i); */
	/* d(k); */
	int j;
	for(j=0;j<m && i >= 0;){
		if(k >= b[j]) {
			ans = max(ans, i+j+1);
			k -= b[j];
			j++;
		}
		else if(k + (i == 0 ? 0 : a[i-1]) >= b[j]) {
			ans = max(ans, i+j);
			k += (i == 0 ? 0 : a[i-1]);
			k -= b[j];
			i--;
			j++;
		}
		else {
			k += (i == 0 ? 0 : a[i-1]);
			i--;
		}
		/* d(ans); */
	}
	cout << ans << "\n";
	return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int main()
{
	ld a, b = 0;
	cin >> a >> b;
	if (a > b)
	{
		COUT("GREATER");
	}
	else if (a < b)
	{
		COUT("LESS");
	}
	else
	{
		COUT("EQUAL");
	}
	return 0;
}

Measured memory_bytes: 384
/**
 *	Author: houtaru
 *	Create: 28.04.2018 19:16:16
 */

#include <iostream>
#include <map>

using namespace std;

const int maxn = 5e5 + 10;

int n;
map <long long, int> f;
long long a[maxn];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    long long answer = 0;
    f[0] = 1;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] += a[i - 1];
        answer += f[a[i]];
        f[a[i]]++;
    }
    cout << answer << "\n";
    return 0;
}

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


const int INF = 1e9 + 7;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<vector<long long> > dp(n+1, vector<long long>(m+1, 0));
	vector<string> g(n);
	for(int i = 0; i <n; ++i){
		cin >> g[i];
	};
	dp[n-1][m-1] = 1;
	for(int i = n-1; i >= 0; --i){
		for(int j = m-1; j >= 0; --j){
			if(!(i == n-1 && j == m-1))
			dp[i][j] = (g[i][j] == '.') ? (dp[i+1][j]%INF + dp[i][j+1]%INF)%INF : 0;	
		}
	}
	cout << dp[0][0]%INF;
	return 0;
}

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

typedef long long ll;
const int maxn = 2e5;
int n, a[maxn + 3], b[maxn + 3], lst[maxn + 3], nxt[maxn + 3];
priority_queue<pair<int, pair<int, int> > > H;

void insert(int i) {
	if (b[i] - b[lst[i]] - b[nxt[i]] >= a[i]) {
		H.push(make_pair(b[lst[i]] + b[nxt[i]], make_pair(i, b[i])));
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= n; i++) {
		scanf("%d", &b[i]);
	}
	for (int i = 1; i <= n; i++) {
		lst[i] = i - 1, nxt[i] = i + 1;
	}
	nxt[n] = 1, lst[1] = n;
	for (int i = 1; i <= n; i++) {
		insert(i);
	}
	ll ans = 0;
	while (!H.empty()) {
		pair<int, pair<int, int> > top = H.top();
		H.pop();
		int x = top.first, i = top.second.first, v = top.second.second;
		if (b[i] != v) {
			continue;
		}
		int t = (b[i] - a[i]) / x;
		b[i] -= t * x, ans += t;
		insert(lst[i]), insert(nxt[i]);
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] != b[i]) {
			puts("-1");
			return 0;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4984
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a,b;cin >> a >>b;
  if(a.size() > b.size()){
    cout << "GREATER" << endl;
    return 0;
  }
  else if(a.size() < b.size()){
    cout << "LESS" << endl;
    return 0;
  }
  else{
    for(int i = 0; i < a.size();i++){
      if(a.at(i) > b.at(i)){
    	cout << "GREATER" << endl;
        return 0;
      }
	  else if(a.at(i) < b.at(i)){
    	cout <<"LESS" << endl;
        return 0;
      }
    }
  }
  cout << "EQUAL" << endl;
}
  
  

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long x = N / (A + B);
		N = N - (A + B) * x;
		long ret = A * x + Math.min(N, A);
		System.out.println(ret);
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
   	#endif
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());
    cout<<((s<t)?"Yes":"No");
   	return 0;
}

Measured memory_bytes: 3580
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N, W;
	cin >> N >> W;
	vector<int> weight(N), value(N);
	for (int i = 0; i < N; ++i) {
		cin >> weight[i] >> value[i];
	}
	vector<long long> dp(W + 1);
	for (int i = 0; i < N; ++i) {
		for (int j = W; j >= weight[i]; --j) {
			dp[j] = max(dp[j], dp[j - weight[i]] + value[i]);
		}
	}
	cout << dp[W] << '\n';
	return 0;
}

Measured memory_bytes: 1024