akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const long long INF = 1LL << 60;
const int MOD = 1000000007;
using namespace std;
using vec = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
template <class T> inline bool chmin(T &a, T b) { if ( a > b ) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T &a, T b) { if ( a < b ) { a = b; return 1; } return 0; }
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

ll H, W;
ll A, B, C;

int main(int argc, char *argv[]){
    cin >> H >> W;
    ll res = 1LL << 60;
    ll Max, Min;
    if(H % 3 == 0) res = 0;
    rfor(h, 0, H + 1){
        if(W % 2 == 0){
            A = h * W / 2;
            B = h * W / 2;
        }else{
            A = h * (W - 1) / 2;
            B = h * (W + 1) / 2;
        }
        C = (H - h) * W;
        Max = max(max(A, B), C);
        Min = min(min(A, B), C);
        res = min(res, Max - Min);

        A = h * W;
        if((H - h) % 2 == 0){
            B = (H - h) / 2 * W;
            C = (H - h) / 2 * W;
        }else{
            B = (H - h - 1) / 2 * W;
            C = (H - h + 1) / 2 * W;
        }
        Max = max(max(A, B), C);
        Min = min(min(A, B), C);
        res = min(res, Max - Min);
    }

    // int tmp = H; H = W; W = tmp;

    if(W % 3 == 0) res = 0;
    rfor(w, 0, W + 1){
        if(H % 2 == 0){
            A = H / 2 * w;
            B = H / 2 * w;
        }else{
            A = (H - 1) / 2 * w;
            B = (H + 1) / 2 * w;
        }
        C = H * (W - w);
        Max = max(max(A, B), C);
        Min = min(min(A, B), C);
        res = min(res, Max - Min);

        A = w * H;
        if((W - w) % 2 == 0){
            B = H * (W - w) /2;
            C = H * (W - w) /2;
        }else{
            B = H * (W - w - 1) / 2;
            C = H * (W - w + 1) / 2;
        }
        Max = max(max(A, B), C);
        Min = min(min(A, B), C);
        res = min(res, Max - Min);
    }
    cout << res << endl;
    return 0;
}

    // if(H > W){ int tmp = H; H = W; W = tmp; }
    // if(H % 3 == 0 || (H % 2 == 0 && W % 2 == 0 && H * W % 3 == 0)) res = 0;
    // else{
    //     ll s = H / 2;
    //     ll t = W / 2;
    //     max = H * t;
    //     min = s * (W - t);
    //     res = max - min;
    // }


    // else if(H % 2 == 0){
    //     if(W % 2 == 0){
    //         ll tmp = W / 2 - 1;
    //         min = H * tmp;
    //         max = (H * W - min) / 2;
    //     }else if(W % 3 ==)
    //     max = H * (W / 2);
    //     min = (H * W - max) / 2;
    //     res = max - min;
    // }



Measured memory_bytes: 256
X, K, D = map(int, input().split())
X = abs(X)
dis = X
if X >=D:
    dis = X - D*(min(abs(X)//D,K))
    K = K - min(abs(X)//D,K)
    if K%2==0:
        print(dis)
    else:
        print(abs(dis-D))
else:
    if K%2==0:
        print(dis)
    else:
        print(abs(dis-D))

Measured memory_bytes: 9188
while 1:
    h, w = map(int, input().split())
    if h==0:
        break
    else:
        for i in range(h):
            if i%2==1:
                for k in range(w):
                    if k%2==1:
                        print('#', end='')
                    else:
                        print('.', end='')
                print()
            else:
                for k in range(w):
                    if k%2==1:
                        print('.', end='')
                    else:
                        print('#', end='')
                print()
                
    print()


Measured memory_bytes: 7000
n,x = map(int,input().split())
a = list(map(int,input().split()))

count = 0

for i in range(n-1):
    if a[i] > x:
        count += a[i] - x
        a[i] = x
        
        count += a[i+1]
        a[i+1] = 0
        
    elif a[i]+a[i+1] > x:
        count = count + a[i+1] + a[i] - x
        a[i+1] = x - a[i] 
    
print(count)


Measured memory_bytes: 14068
#include <stdio.h>
#include <stdint.h>
typedef int64_t i64;

int main(void){
    i64 n, sum = 0;
    scanf("%lld", &n);
    for(i64 i=1; i<=n; i++) sum += (i + (n/i)*i)*(n/i)/2;
    printf("%lld", sum);
    return 0;
}

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

const long N=1500000;

int main(){
	bool prime[N];
	
	for(long i=2; i<N; ++i) prime[i]=true;
	
	for(long i=2; i<N; ++i){
		if(prime[i])
			for(long j=2; i*j<N; ++j) prime[i*j]=false;
	}	
	
	while(1){
		long n;
		scanf(" %ld", &n);
		if(n==0) break;
		
		long a, b;
		for(long i=n; i<N; ++i){
			if(prime[i]){
				a=i;	
				break;
			}
		}
		for(long i=n; i>0; --i){
			if(prime[i]){
				b=i;	
				break;
			}
		}
		//printf("%ld-%ld=",a, b);
		printf("%ld\n", a-b);
	}
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    
    map<int, int> mp;
    int A;
    for (int i = 1; i <= N; i++) {
        cin >> A;
        mp[A] = i;
    }

    for (auto x : mp) {
        if (x.first > 1) cout << " ";
        cout << x.second;
    }
    cout << endl;
}

Measured memory_bytes: 5504
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define rad M_PI/3
#define N 20002000
#define Max 10000
#define NTL -1
#define max(a,b) ((a<b)?b:a)

char s[1010], t[1010];
int dp[1010][1010],p[1010][1010];

int LCS(){
  int n = strlen(s);
  int m = strlen(t);
  memset(dp,0,sizeof dp);
  int i,j,mx=0;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      if(i) dp[i][j]=max(dp[i][j],dp[i-1][j]);
      if(j) dp[i][j]=max(dp[i][j],dp[i][j-1]);
      if(s[i]==t[j]){
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
        mx=max(mx,dp[i+1][j+1]);
      }
    }
  }
  return mx;
}
int main(){
  int n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",&s[0]);
    scanf("%s",&t[0]);
    printf("%d\n",LCS());
  }
  return 0;
}


Measured memory_bytes: 5732
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

const int INF = 1000000000000000000;

int n, a[100010];
int ans = 1;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (!a[i]) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		if (INF / ans < a[i]) {
			cout << -1 << endl;
			return 0;
		}
		ans *= a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 4416
n=int(input())
s=input()
a=list("abcdefghijklmnopqrstuvwxyz")
x=[]
y=[]
m=0
for i in range(n-1):
    x=[s[j] for j in range(i)]
    y=[s[j] for j in range(i,n)]
    ans=0
    for j in range(26):
        if a[j] in x and a[j] in y:
            ans+=1
    m=max(ans,m)
print(m)


Measured memory_bytes: 67560
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1e9+7;
const int INF=1e9;
const ll LINF=(ll)1e18;

int main(){
    int n,m;
    cin>>n>>m;
    int x[n*m+1],y[n*m+1];
    memset(x,-1,sizeof(x));
    memset(y,-1,sizeof(y));
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        x[a]=i;
    }
    for(int i=0;i<m;i++){
        int b;
        cin>>b;
        y[b]=i;
    }
    ll ans=1;
    int xx=0,yy=0;
    for(int i=n*m;i>0;i--){
        if(x[i]!=-1&&y[i]!=-1){
            xx++,yy++;
        }
        else if(x[i]==-1&&y[i]==-1){
            ll t=xx*yy-(n*m-i);
            if(t<=0){
                cout<<0<<endl;
                return 0;
            }
            else{
                ans=(ans*t)%MOD;
            }
        }
        else{
            if(x[i]==-1){
                ans=(ans*xx)%MOD;
                yy++;
            }
            else{
                ans=(ans*yy)%MOD;
                xx++;
            }
        }
    }
    cout<<ans<<endl;
}


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



int main() {
  long long N;
  cin >> N;
  vector<long long> vec(N);
  for (long long i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  long long j = vec.at(N/2) - vec.at(N/2 - 1);
  if (j == 0) {
    cout << 0 << endl;
  }
  else {
    cout << j << endl;
  }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> class Segtree {
    inline T merge(const T &a, const T &b) { return min(a, b); }
    inline void act(T &a, const T &b) { a = b; }
    int n;
    T e;
    vector<T> dat;

  public:
    Segtree(int n_, T e) : e(e) {
        n = 1;
        while (n < n_) {
            n <<= 1;
        }
        dat.resize(2 * n, e);
    }
    void upd(int k, const T &x) {
        k += n;
        act(dat[k], x);
        k >>= 1;
        while (k > 0) {
            dat[k] = merge(dat[k << 1], dat[k << 1 | 1]);
            k >>= 1;
        }
    }
    T get(const int &a, const int &b, int k, int l, int r) {
        if (b <= l || r <= a) {
            return e;
        }
        if (a <= l && r <= b) {
            return dat[k];
        }
        return merge(get(a, b, k << 1, l, (l + r) >> 1),
                     get(a, b, k << 1 | 1, (l + r) >> 1, r));
    }
    inline T get(const int &a, const int &b) { //[a,b)
        if (a >= b) {
            return e;
        }
        return get(a, b, 1, 0, n);
    }
    int find(const int &a, const int &b, const T &x, int k, int l, int r) {
        if (b <= l || r <= a || dat[k] > x) {
            return -1;
        }
        if (k >= n) {
            return k - n;
        }
        int il = find(a, b, x, k << 1, l, (l + r) >> 1);
        if (il != -1) {
            return il;
        }
        return find(a, b, x, k << 1 | 1, (l + r) >> 1, r);
    }
    inline int find(const int &a, const int &b, const T &x) {
        if (a >= b) {
            return -1;
        }
        return find(a, b, x, 1, 0, n);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    vector<int> id(n + 1, -1), dp(n + 1, INF);
    Segtree<int> seg(n + 1, INF);
    seg.upd(0, 0);
    for (int i = 1; i <= n; i++) {
        if (s[i] == '1') {
            continue;
        }
        dp[i] = seg.get(max(0, i - m), i) + 1;
        if (dp[i] != INF + 1) {
            int fr = seg.find(max(0, i - m), i, dp[i] - 1);
            id[i] = fr;
            seg.upd(i, dp[i]);
        } else {
            dp[i] = INF;
        }
    }
    if (dp[n] == INF) {
        cout << -1 << endl;
        return 0;
    }
    int k = n;
    vector<int> v;
    while (k != 0) {
        v.push_back(k - id[k]);
        k = id[k];
    }
    reverse(all(v));
    for (int i = 0; i < v.size(); i++) {
        cout << v[i];
        if (i + 1 < v.size()) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
}

Measured memory_bytes: 2888
// ------------------------------------
// Date:2018/ 4/ 3
// Problem:Wall / / a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 201;

int H, W;
int c[10][10];
int A[MAX_N][MAX_N];

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

  cin >> H >> W;
  REP(hi, 10)
    REP(wi, 10)
      cin >> c[hi][wi];

  REP(k, 10) {
    REP(i, 10) {
      REP(j, 10) {
	c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }

  ll ans = 0ll;
  REP(hi, H) {
    REP(wi, W) {
      CIN(a);
      if (a == -1) continue;
      ans += c[a][1];
    }
  }

  cout << ans << endl;
  
  
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>

int n, m, L;

struct Edge {
	Edge() {}
	Edge(int _u, int _v, int _w) {
		u = _u, v = _v, w = _w;
	}
	int u, v, w;
} e[65];

void add(int u, int v, int w) {
	e[++m] = Edge(u, v, w);
}
int main() {
	scanf("%d", &L);
	for (; (1 << n) - 1 < L; n++);
	for (int i = 1; i < n; i++) {
		add(i, i + 1, 1 << (i - 1));
		add(i, i + 1, 0);
	}
	for (int i = 1; i < n; i++) {
		if (L & (1 << (i - 1))) add(i, n, (L >> i) << i);
	}
	printf("%d %d\n", n, m);
	for (int i = 1; i <= m; i++) {
		printf("%d %d %d\n", e[i].u, e[i].v, e[i].w);
	}
	return 0;
}

Measured memory_bytes: 128
import math

def main():
    N, P = map(int, input().split())
    if N == 1: return P
    ans = 1
    v = P
    for i in range(2, int(math.sqrt(P))+1):
        if v % i == 0:
            ct = 0
            while v % i == 0:
                ct += 1
                v = v // i
            # print(i, ct)
            for _ in range(ct//N):
                ans *= i
    return ans


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
#include <chrono>
#include <random>
#include <ctime>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	srand(time(0));
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= 100; i++) {
		for (int j = 1; j <= 100; j++) {
			for (int k = 1; k <= 100; k++) {
				int r = i * i + j * j + k * k + k * i + i * j + j * k;
				if (r <= n)a[r]++;
			}
		}
	}
	for (int i = 1; i <= n; i++)cout << a[i] << "\n";
}

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

#define INF 1000000000

int d[100][100];

int main()
{
  fill((int*)d, (int*)d + 10000, INF);
  
  int N;
  cin >> N;
  for(int i = 0; i < N; i++)
  {
    int r, k, t;
    cin >> r >> k;
    for(int j = 0; j < k; j++)
    {
      cin >> t;
      d[r - 1][t - 1] = 1;
    }
  }

  for(int k = 0; k < N; k++)
    for(int i = 0; i < N; i++)
      for(int j = 0; j < N; j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

  int S, D, V, P;
  cin >> P;
  for(int i = 0; i < P; i++)
  {
    cin >> S >> D >> V;
    if(d[S - 1][D - 1] < V)
      cout << d[S - 1][D - 1] + 1 << endl;
    else
      cout << "NA" << endl;
  }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long

using namespace std;

void solve()
{
	
	string s="",s1,e="";
	cin>>s1;
	ll q;
	cin>>q;
	ll f=true;
	while(q--)
	{
		ll t;
		cin>>t;
		if(t==1)
		{
			if(f)f=false;
			else f=true;
		}
		else
		{
			ll x;
			cin>>x;
			char c;
			cin>>c;
			if(x==1)
			{
				if(f)s=c+s;
				else e=e+c;
			}
			else
			{
				if(!f)s=c+s;
				else e=e+c;
			}
		}
		
	}s1=s+s1+e;
	if(f)cout<<s1<<endl;
		else {
			
			reverse(s1.begin(),s1.end());
			cout<<s1<<endl;
		}
}

int32_t main() 
{
	IOS	
	ll T=1;
	 // cin>>T;
	while(T--)
	{
    		solve();
	}
}

Measured memory_bytes: 1320
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	const ll L = inputVal<ll>();
	const ll R = inputVal<ll>();
	vector<ll> elm;
	const ll mod = 2019;
	const ll nb = min(R - L + 1, mod);
	for (ll i = L; i <= L + nb-1; ++i) {
		elm.push_back(i % mod);
	}

	ll minnb = 3000000000;
	for (ll i = 0; i < nb-1; ++i) {
		for (ll j = i + 1; j < nb; ++j) {
			chMin(minnb, (elm[i] * elm[j]) % mod);
		}
	}

	outputVal(minnb);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	double tmp;
	cin >> tmp;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
 
  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      String t = sc.next();
      int cnt = 0;
      for(int i = 0; i < s.length(); i++)
        if(s.charAt(i) != t.charAt(i))
            cnt++;
      System.out.println(cnt);
  }
}

Measured memory_bytes: 41224
import java.util.Scanner;

public class Main {

	static int n;
	static boolean first;
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		while(true){
			n=cin.nextInt();
			if(n==0)break;
			first=true;
			Page[] pages=new Page[n];
			for(int i=0;i<n;i++){
				pages[i]=new Page(cin.nextInt());
			}
			for(int i=1;i<n;i++){
				if(pages[i].num-1==pages[i-1].num){
					pages[i-1].next=pages[i];
					pages[i].prev=pages[i-1];
				}
			}
			for(int i=0;i<n;i++){
				if(pages[i].out()){
//					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
	static class Page{
		int num;
		Page next;
		Page prev;
		boolean already;
		Page(int a){
			num=a;
			already=false;
		}
		boolean out(){
			boolean re = false;
			if(already)return false;
			already=true;
			if(prev==null){
				if(first){
					first=false;
				}
				else{
					System.out.print(" ");
				}
				System.out.print(num);
				re=true;
			}
			if(next!=null){
				next.out();
			}
			else if(prev!=null){
				System.out.print("-"+num);
				re=true;
			}
			return re;
		}
	}
}

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

using namespace std;


vector<vector<int> > c(10, vector<int>(10));
vector<int> to1(10, 0);



int main(){
    
    int H,W;
    cin >> H >> W;
    
    
    
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
        to1[i] = c[i][1];
    }
    
    for (int k = 0; k < 11; k++) {
        for (int i = 0; i < 10; i++) {
            
            for (int  j = 0; j < 10; j++) {
                if (to1[i] > to1[j] + c[i][j]) {
                    to1[i] = to1[j] + c[i][j];
                }
            }
            
        }
    }
    
    
    
    
    /*
    for (int i = 0; i < 10; i++) {
        cout << to1[i] << " ";
    }
    cout << endl;
    */
    
    
    
    vector<vector<int> > A(H, vector<int>(W));
    int ans = 0;
    
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
            if (A[i][j] != -1 && A[i][j] != 1) {
                ans += to1[A[i][j]];
            }
        }
    }
    
    cout << ans << endl;
    
    
    
    
    
    
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#define N 394
using namespace std;

int main(){
  int n,s[N],l[N],p[N],m,w,a[N],f=0,dp[N];
  cin>>n;
  for(int i=0;i<n;i++) cin>>s[i]>>l[i]>>p[i];
  for(int i=0;i<N;i++) dp[i]=-1;
  dp[0]=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<N;j++)
      for(int k=s[i];k<=l[i];k++)
	if(j-k>=0&&dp[j-k]!=-1) dp[j]=max(dp[j],dp[j-k]+p[i]);
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>w;
    dp[w]==-1?f=1:a[i]=dp[w];
  }
  if(f) cout<<-1<<endl;
  else
    for(int i=0;i<m;i++) cout<<a[i]<<endl;
  return 0;  
}

Measured memory_bytes: 1168
#include<iostream>
#include<string>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
char arr[10];
for(int i=0;i<10;i++){
cin>>arr[i];
}
arr[3]='8';
for(int i=0;i<10;i++)
{
cout<<arr[i];
}
return 0;  
}

Measured memory_bytes: 3676
Q,H,S,D = map(int, input().split())
N = int(input())
a = N//2 * 2
k =  min(a*Q*4, a*H*2, a*S, a*D//2)
if N%2 == 1:
    k += min(Q*4, H*2, S)
print(k)

Measured memory_bytes: 9100
"""
D
"""
mod=10**9+7

inv=[0]*(2*10**5+100)
inv[1]=1
for i in range(2,2*10**5+100):
    inv[i]=-(mod//i)*inv[mod%i]%mod

N,a,b=map(int,input().split())

ans=(pow(2,N,mod)-1)%mod
num=1
for i in range(1,a+1):
    num=num*(N-i+1)*inv[i]%mod
ans=(ans-num)%mod

num=1
for i in range(1,b+1):
    num=num*(N-i+1)*inv[i]%mod
ans=(ans-num)%mod

print(ans)

Measured memory_bytes: 42220
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void orz(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18;
/***********************************************************************/

int32_t main() {
 
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int a, b;
  cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << '\n';
  
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		m[nextInt()]++
	}

	var keys []int
	for k := range m {
		keys = append(keys, k)
	}
	sort.Ints(keys)

	s1 := 0
	s2 := 0
LABEL:
	for i := len(keys) - 1; i >= 0; i-- {
		if m[keys[i]] >= 4 {
			s1 = keys[i]
			s2 = keys[i]
			break
		}
		if m[keys[i]] >= 2 {
			s1 = keys[i]
			for j := i - 1; j >= 0; j-- {
				if m[keys[j]] >= 2 {
					s2 = keys[j]
					break LABEL
				}
			}
		}
	}
	fmt.Println(s1 * s2)
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}
func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 8832
package main

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

type BufferedWriter interface {
    Printf(format string, a ...interface{})
    Flush()
}

type writerImpl struct {
    *bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
    return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
    fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
    impl.Writer.Flush()
}

type WordScanner interface {
    NextInt() int
    NextInt64() int64
    NextString() string
}

type wordScannerImpl struct {
    *bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
    s := bufio.NewScanner(reader)
    s.Split(bufio.ScanWords)
    return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
    impl.Scan()
    bb := impl.Bytes()
    i := 0
    for _, b := range bb {
        i *= 10
        i += int(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
    impl.Scan()
    bb := impl.Bytes()
    i := int64(0)
    for _, b := range bb {
        i *= 10
        i += int64(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextString() string {
    impl.Scan()
    return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
    defer writer.Flush()
    s := reader.NextString()
    writer.Printf("%s\n", sol(s))
}

func sol(s string) string {
    if len(s) < 6 {
        return "No"
    }
    if s[2] == s[3] && s[4] == s[5] {
        return "Yes"
    }
    return "No"
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define H 128
#define W 17
#define INF 1e4
using namespace std;
int h,w;
string str[H];

/*
  short mem[H][W][1<<W];
  bool used[H][W][1<<W];
  int dfs(int y,int x,int bit,int p,int u){
  if( y == h ) return 0;
  if(p+(w-x) < str[y].size()) return -INF;
  if( x == w ) {
  if(p < (int)str[y].size()) return -INF;
  return dfs(y+1,0,bit,0,0);
  }

  if(used[y][x][bit]) return mem[y][x][bit];
  used[y][x][bit] = 1;
  int a=0,b=0;

  //?????????????????????
  int abit = bit & (~(1<<x));
  a = dfs(y,x+1,abit,p,u+(bit>>x&1));
  
  //???????????????
  int bbit = bit | (1<<x);
  if(p<(int)str[y].size()){
  int score = 0;
  score += 2*((bit>>x&1)&&(str[y][p]==str[y-1][u]));
  score += 2*(x>=1&&(bit>>(x-1)&1)&&str[y][p]==str[y][p-1]);
  b = score+dfs(y,x+1,bbit,p+1,u+(bit>>x&1));
  }
  return mem[y][x][bit]=max(a,b);
  }
*/


int Max(int &a,int b){return a=max(a,b);}
int dp[2][W][1<<W];
int A[W][1<<W],B[W][1<<W];
void mkAB(int x,int bit){
  int sum = __builtin_popcount(bit);
  int cnt = 0;
  for(int i=0;i<x;i++)cnt+=(bit>>i&1);
  A[x][bit] = cnt;
  B[x][bit] = sum - cnt;
}

int DP(){
  for(int i=0;i<W;i++)
    for(int j=0;j<(1<<W);j++)mkAB(i,j);

  memset(dp,-1,sizeof(dp));
  dp[0][0][0] = 0;
  int res = 0;
  for(int i=0;i<h;i++){
    int idx = i%2;
    for(int j=0;j<w;j++){
      for(int bit=0;bit<(1<<w);bit++){
        if(dp[idx][j][bit]==-1)continue;
        int p = A[j][bit];
        int u = i? str[i-1].size()-B[j][bit]:0;
        //use space
        int abit = bit & (~(1<<j));
        Max(dp[idx][j+1][abit],dp[idx][j][bit]);
        

        //use character
        if(p>=(int)str[i].size())continue;
        int bbit = bit | (1<<j);
        int score = 0;
        score += 2*((bit>>j&1)&&(str[i][p]==str[i-1][u]));
        score += 2*(j>=1&&(bit>>(j-1)&1)&&str[i][p]==str[i][p-1]);
        Max(dp[idx][j+1][bbit],dp[idx][j][bit]+score);
      }
    }
    for(int bit=0;bit<(1<<w);bit++){
      if(__builtin_popcount(bit) != str[i].size())continue;
      Max(dp[!idx][0][bit],dp[idx][w][bit]);
      Max(res,dp[idx][w][bit]);
    }
  }
  return res;
}

int main(){
  cin>>h>>w;
  for(int i=0;i<h;i++) cin>>str[i];
  //  cout<<dfs(0,0,0,0,0)<<endl;
  cout<<DP()<<endl;
  return 0;
}

Measured memory_bytes: 37944
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define N (1000000000+7)
#define INF (ll)1e16
typedef long long ll;


int main(void){
    ll n;
    cin>>n;
    if(n==1){
        cout<<0<<endl;
    }
    else{
        cout<<n*(n-1)/2<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
  n = int(input().strip())
  a = list(map(int, input().strip().split()))
  result = 1
  LIMIT = 10**18
  if 0 in a:
    print(0)
    sys.exit()
  for i in a:
    result *= i
    if result > LIMIT:
      print(-1)
      sys.exit()
  print(result)

main()

Measured memory_bytes: 21488
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        System.out.println(solve());
    }

    private static int solve() {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] a = new int[N];
        Arrays.fill(a, -1);

        for (int i = 0; i < M; i++) {
            int s = sc.nextInt() - 1;
            int c = sc.nextInt();

            if (a[s] != -1 && a[s] != c) {
                return -1;
            }

            a[s] = c;
        }

        if (a[0] == 0) {
            if (N == 1) {
                return 0;
            } else {
                return -1;
            }

        } else {
            if (a[0] == -1) {
                if (N == 1) {
                    return 0;
                }
                a[0] = 1;
            }

            for (int i = 1; i < N; i++) {
                if (a[i] == -1) {
                    a[i] = 0;
                }
            }

            int ans = 0;
            for (int i = 0; i < N; i++) {
                ans = ans * 10;
                ans += a[i];
            }

            return ans;
        }

    }

}


Measured memory_bytes: 23380
//package AtCoder;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int l=sc.nextInt();
		String[] s=new String[n];
		for(int i=0;i<n;i++)
		{
			s[i]=sc.next();
		}
		sc.close();
		Arrays.sort(s);
		for(int i=0;i<n;i++)
			System.out.print(s[i]);

	}

}


Measured memory_bytes: 22100
#include<stdio.h>
#define N 2000

int solve(int,int);
int num1,A[N];


int main(){


  int num2,B[N],i,result;

  scanf("%d",&num1);
  for(i=0;i<num1;i++){  
    scanf("%d",&A[i]);
  }
 

  scanf("%d",&num2);

  for(i=0;i<num2;i++){
    scanf("%d",&B[i]);    
    result = solve(0,B[i]);
    
    if(result == 1)printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}




/*solve(i,m)において、与えられた整数をつくれる  m=0*/
int solve(int i,int m){
  

  int res;
  if(m == 0)return 1;
  if(i >= num1)return 0;
  res =  (solve(i + 1, m) || solve(i + 1, m - A[i]));
  return res;
}

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

#define faster     ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define read       freopen("input.txt", "r", stdin);
#define write      freopen("output.txt", "w", stdout);
#define endd        '\n'
#define ll         long long
#define sq(a)      ((a) * (a))

using namespace std;
int main()
{
      faster;
      double pi = 2 * acos(0.0);
      ll int n,i,t,j,k,m=0,a=0,b=0,c=0,d=0,p,q,r,x=250,y=10,z,count=0;
      cin>>n;
      m=3*n;
      ll int ara[m];
      for(i=0;i<m;i++){
            cin>>ara[i];
      }
      sort(ara,ara+m,greater<int>());
      for(i=n;i<2*n;i++){
            count+=ara[i];
      }
      for(i=0;i<m-n;i++){
            if(i%2==1)a+=ara[i];
      }
      cout<<max(a,count);
      return 0;
}
//Sheikh Tafsir Rahman
//CSE IUT

Measured memory_bytes: 6000
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

long long int N;

long long int A[200005];

vector<long long int> B;

long long int V(long long int b) {

	long long int count = 0;
	for (long long int i = 1; i <= N; i++) {
		count += abs(B[i] - b);
	}
	return count;
}

long long int T(void) {
	long long int b_max = 999999999999;
	long long int b_min = -9999999999999;

	long long int b_med1, b_med2;

	for (int i = 0; i < 200; i++) {
		b_med1 = (2 * b_min + b_max)/3;
		b_med2 = (b_min + 2 * b_max) / 3;
		if (V(b_med1) < V(b_med2)) { b_max = b_med2; }
		else { b_min = b_med1; }

	}

	return b_med1;
}

int main(void) {

	cin >> N;

	long long int tmp;
	for (long long int i = 1; i <= N; i++) {
		cin >> tmp;
		A[i] = tmp;
	}
	B.push_back(-999999999999);

	for (long long int i = 1; i <= N; i++) {
		B.push_back(A[i] - i);
	}

	sort(B.begin(), B.end());

	long long int b;
	if (N % 2 == 0) {
		b = (B[N / 2] + B[N / 2 + 1]) / 2;
	}
	else {
		b = B[(N + 1) / 2];
	}
	
	long long int ans = 0;
	for (long long int i = 1; i <= N; i++) {
		ans += abs(B[i] - b);
	}


	//long long int ans = 9999999999999999;


	cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3956
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	char s[20];
	int i,l,flag1,flag2,c;
	while(cin>>s){
		l=strlen(s);
		flag1=0;
		flag2=1;
		c=0;
		if(s[0]=='A')flag1=1;
		for(i=2;i<l-1;i++){
			if(s[i]=='C')
			{
				c++;
				continue;
			}
			if(s[i]!='C'&&!(s[i]>='a'&&s[i]<='z'))
				flag2=0;
		}
		if(!(s[1]>='a'&&s[1]<='z'))
			flag2=0;
		if(!(s[l-1]>='a'&&s[l-1]<='z'))
			flag2=0;
		if(flag1&&flag2&&c==1)
			cout<<"AC"<<endl;
		else
			cout<<"WA"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

int n;
cin >> n;
  long long wa=1;
  vector<long long> zero(n);
  long long b;
  for(long long i=0;i<n;i++){cin>>b;zero.at(i)=b;}
  for(long long i=0;i<n;i++){if(zero.at(i)==0){cout<<0<<endl; return 0;}}
for(long long i=0;i<n;i++){long long a; a=zero.at(i);
                     if(1000000000000000000/a+1<wa){cout<<-1<<endl;return 0;}
                       wa=wa*a;
                     if(1000000000000000000<wa){cout<<-1<<endl;return 0;}}
  cout<<wa<<endl;}
                  

Measured memory_bytes: 4000
import java.util.Scanner;
class Main {
  public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] i=new int[n];
long sum=0;
long hikui=0;
long takai=0;
for(int x=0;x<n;x++) {
	i[x]=sc.nextInt();
	sum+=i[x];
}

for(int s=0;s<n;s++) {
	if(s ==0) {
		 hikui=i[s];
		 takai=i[s];
	}
	else{
		if(hikui>i[s]) {
		hikui=i[s];
	}
		else if(takai<i[s]) {
			takai=i[s];
		}
	}
}
System.out.println(hikui +" " + takai + " " + sum);
 sc.close();
  }
	  }




Measured memory_bytes: 41420
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

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

int main() {

    int a,b,c; cin >>a>>b>>c;

    int res = gcd(a, b);
    if (c % res == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    } 
    
    return 0;
}




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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll K, N;
    cin >> K >> N;
    Vl A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll mx = 0;
    for (int i = 0; i < N - 1; i++) {
        mx = max(mx, A[i + 1] - A[i]);
    }
    mx = max(mx, A[0] + K - A[N - 1]);

    cout << K - mx << endl;

    return 0;
}

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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve() 
{
	int n;
	
	cin >> n;
	
	int a[n+1] {};
	
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		
		a[i] += a[i-1];
	}
	
	int id;
	int mx = inf;
	
	for(int i = 1; i < n; ++i) {
		if(abs(a[n] - 2*a[i]) < mx) {
			mx = abs(a[n] - 2*a[i]);
			id = i;
		}
	}
	
	cout << mx;
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


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

int main() {
  int H, W; cin >> H >> W;
  string s[H]; rep(i,H) cin >> s[i];
  rep(i, H+2) {
    rep(j, W+2) {
      if (i == 0 || i == H+1 || j == 0 || j == W+1) {
        cout << "#"; 
      } else {
        cout << s[i-1][j-1];
      }
    }
    cout << endl;
  }
}



Measured memory_bytes: 3636
// AtCoder AGC095 C - Many Medians
// 2020.1.22 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void outs(char *s) { while (*s) pc(*s++); }

char *out(char *b, int n) { // 非負整数の表示（出力）
	int i;
	i = 15, b[i] = 0;
	b[--i] = '\n';
	while (n) b[--i] = n % 10 + '0', n /= 10;
	return b+i;
}

// n番目に小さい値を算出する n:0-index
int selection(int *a, int sz, int n) {
  int i, j, p, l, r, t;
  l = 0, r = sz-1;
  while (l < r) {
    p = a[(l+r)/2];
    i = l-1, j = r+1;
    while (1) {
      while (a[++i] < p);
      while (a[--j] > p);
      if (i > j) break;
      t = a[i], a[i] = a[j], a[j] = t;
    }
    if (n < i) r = j;
    if (n > j) l = i;
  }
  return a[n];
}

int N;
int a[200005];
int b[200005];

int main()
{
	int i, n, a1, a2;
	char *p1, *p2, s1[20], s2[20];
	
	N = in(), n = N / 2;
	for (i = 0; i < N; ++i) a[i] = b[i] = in();
	a1 = selection(b, N, n-1);
	a2 = selection(b, N, n);
//printf("a1=%d, a2=%d\n", a1, a2);
	p1 = out(s1, a1), p2 = out(s2, a2);
	
	for (i = 0; i < N; ++i) outs((a[i] >= a2)? p1: p2);
	return 0;
}


Measured memory_bytes: 3712
#!/usr/bin/env python3
import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    big = N // 500
    N -= big*500
    small = N // 5
    print(big*1000 + small * 5)


main()


Measured memory_bytes: 64900
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a<=c&&c<=b&&b<=d) cout<<b-c<<endl;
  else if(c<=a&&a<=d&&d<=b) cout<<d-a<<endl;
  else if(a<=c&&d<=b) cout<<d-c<<endl;
  else if(c<=a&&b<=d) cout<<b-a<<endl;
  else cout<<"0"<<endl;
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] abt = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        System.out.println((int)((abt[2] + 0.5) / abt[0]) * abt[1]);

    }
}


Measured memory_bytes: 25940
#include <stdio.h>

#define N 10000

int main(){
  int n,q,s[N],t[N],i,j,ans=0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&s[i]);
  scanf("%d",&q);
  for(j=0; j<q; j++) scanf("%d",&t[j]);
  for(j=0; j<q; j++){
    for(i=0; i<n; i++){
      if(s[i]==t[j]){
	ans++;
	break;
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c,k,ans=0;
	cin>>a>>b>>c>>k;
	if(k<=a){
		cout<<k<<endl;
	}
	else{
		ans+=a;
		if(a+b>=k){
			cout<<ans<<endl;
		}
		else{
			cout<<ans-(k-a-b)<<endl;
		}
	}
    return(0);
}

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

int main(){

	  int N; cin >> N;
	  vector<int> L(2*N);
	  for(int i=0; i<2*N; i++)
			cin >> L[i];
	  sort(L.begin(),L.end());
//	  reverse(L.begin(),L.end());

	  int ans = 0;
	  for(int i=0; i<2*N; i+=2){
//			cout << L[i] << " ";
			ans += L[i];
	  }
	  cout << ans << endl;
			
	  

}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

const int MOD = INF + 7;
int main(){
   int n;
   string s, t;
   cin >> n >> s >> t;
   ll res = 1;

   int f = -1;          //0 : s[i] == t[i] / 1 : s[i] != t[i]
   rep(i, n){
       if(s[i] == t[i]){
           if(f == -1){
               res *= 3;
           }
           else if(f == 0){
               res *= 2;
           }

           res %= MOD;
           f = 0;
       }


       else {
           if(f == -1){
               res *= 6;
           }
           else if(f == 0){
               res *= 2;
           }
           else if(f == 1){
               res *= 3;
           }

           res %= MOD;
           f = 1;
           i++;
       }
     //cout << res << endl;
   }

   cout << res << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define max_n 50
#define MOD 1000000007
typedef struct matrix
{
    long long mat[max_n][max_n];
}matrix;
matrix mult(matrix a , matrix b)
{
    matrix ans;
    int k ; 
    for(int i = 0; i < max_n; i++)
    {
        for(int j = 0; j < max_n; j++)
        {
            for(ans.mat[i][j] = k = 0; k < max_n; k++)
            {
                ans.mat[i][j] += (a.mat[i][k] * b.mat[k][j]) % MOD;
                ans.mat[i][j] %= MOD;
            }
        }
    }
    return ans;
}
matrix power(matrix base, long long p)
{
    matrix ans;
    for(int i = 0; i < max_n; i++)
        for(int j = 0; j < max_n; j++)
            ans.mat[i][j] = (i == j);
    while(p)
    {
        if(p & 1)
            ans = mult(ans,base);
        base = mult(base,base);
        p >>= 1;
    }
    return ans;
}
int main()
{   
    int n;
    long long k;
    scanf("%d %lld",&n,&k);
    matrix a;
    
    for(int i = 0; i < n ; i++)
    {
        for(int j = 0 ; j < n; j++)
        {
            scanf("%lld",&a.mat[i][j]);
        }
    }
    
    matrix ans = power(a,k);

    long long res = 0;

    for(int i = 0; i < n ; i++)
    {
        for(int j = 0 ; j < n; j++)
        {
            res += ans.mat[i][j];
            res %= MOD;
        }
    }

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

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int sum[26][500005], n;
char str[500005];
void add(int x, int l, int v)
{
    while(x<=n)
    {
        sum[l][x]+= v;
        x+= (x&-x);
    }
    return;
}
int query(int x, int l)
{
    int res= 0;
    while(x)
    {
        res+= sum[l][x];
        x-= (x&-x);
    }
    return res;
}
int lst[500005];
int main()
{
    char ch[5];
    int q, t, x, y;
    scanf("%d %s %d", &n, str, &q);
    for(int i=0; i<n; i++)
    add(i+1, str[i]-'a', 1), lst[i+1]= str[i]-'a';
    while(q--)
    {
        scanf("%d", &t);
        if(t==1)
        {
            scanf("%d %s", &x, ch);
            add(x, lst[x], -1);
            add(x, ch[0]-'a', 1);
            lst[x]= ch[0]-'a';
        }
        else
        {
            scanf("%d %d", &x, &y);
            int res= 0;
            for(int i=0; i<26; i++)
            if(query(y, i)-query(x-1, i))res++;
            printf("%d\n", res);
        }
    }
    return 0;
}


Measured memory_bytes: 53504
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define ll long long
using namespace std;

ll a[310][310], p[310][310];

int main() {
	int N;
	cin >> N;
	vector<pair<ll, pair<int, int>>> v;
	for(int i=0; i<N; ++i){
		for(int j=0; j<N; ++j){
			cin >> a[i][j];
			if(i==j) p[i][j]=0;
			else p[i][j]=1e13;
			if(i<j) v.push_back(make_pair(a[i][j], make_pair(i, j)));
		}
	}
	sort(v.begin(), v.end());
	ll ans=0;
	for(int x=0; x<v.size(); ++x){
		ll mn=1e13;
		int s=v[x].second.first, t=v[x].second.second;
		for(int i=0; i<N; ++i) mn=min(mn, p[s][i]+p[i][t]);
		if(mn<a[s][t]){
			cout << -1 << endl;
			return 0;
		}
		if(a[s][t]<mn) ans += a[s][t];
		p[s][t]=p[t][s]=a[s][t];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3056