akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}

int main(){
    ll n;cin >> n;
    vl t(3);rep(i,3)cin >> t[i];
    vpl que;rep(i,n){
        string s;cin >> s;
        if(s=="AB")que.pb({0,1});
        if(s=="BC")que.pb({1,2});
        if(s=="AC")que.pb({0,2});
    }
    vl ans(n);
    rep(i,n){
        ll x=que[i].fi,y=que[i].se;
        if(t[x]+t[y]>2){
            if(t[x]>t[y])swap(x,y);
            t[x]++;t[y]--;
            ans[i]=x;
        }
        else if(t[x]+t[y]==2){
            if(t[x]==t[y]&&i<n-1){
                ll p=que[i+1].fi,q=que[i+1].se;
                if(x==p||x==q){
                    ans[i]=x;t[x]++;t[y]--;
                }
                else{
                    ans[i]=y;t[y]++;t[x]--;
                }
            }
            else{
                if(t[x]>t[y])swap(x,y);
                t[x]++;t[y]--;
                ans[i]=x;
            }
        }
        else if(t[x]+t[y]==1){
            if(t[x])ans[i]=y,t[x]--,t[y]++;
            else ans[i]=x,t[x]++,t[y]--;
        }
        else{
            cout << "No" <<endl;
            return 0;
        }
    }
    cout << "Yes" <<endl;
    rep(i,n)cout << (char)('A'+ans[i]) <<endl;
}


Measured memory_bytes: 5540
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
ll a[maxn], q, t, n, m, k, ans;
priority_queue<ll> pr;
string s, ss, str;
void sol()
{
    cin >> s;
    n = s.length();
    s = " " + s;
    for(int i = 1; i <= n; i ++)
    {
        if(i % 2 == 0)
        {
            if(s[i] == 'R')
            {
                cout << "No";
                return;
            }
        }
        else
        {
            if(s[i] == 'L')
                {
                    cout << "No";
                    return;
                }
        }
    }
    cout <<"Yes";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    sol();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

// using namespace __gnu_pbds;
#define Init1 ios::sync_with_stdio(false)
#define Init2 cin.tie(0)
#define INF 0x3f3f3f3f
// #pragma GCC optimize(2)

const int N = 55555 + 105;

int prime[N], vis[N], tot = 0;
int c[6] = {0};
int main(){
    for(int i = 2; i < N; ++i){
        if(!vis[i]){
            prime[++tot] = i;
            for(int j = i + i; j < N; j += i)
                vis[j] = 1;
        }
    }
    vector<int>ans;
    for(int i = 1; i <= tot; ++i){
        if(prime[i] % 5 == 1) ans.push_back(prime[i]);
    }
    int n; cin>>n;
    for(int i = 1; i <= n; ++i) cout<<ans[i]<<" ";
    cout<<endl;
    // system("pause");
}

Measured memory_bytes: 512
#include <iostream>
#include<bits/stdc++.h>
#include <deque>
using namespace std;
int main()
{
deque <char> s;
deque <char> d;
string z; cin>>z;
for(int i=0 ; i<z.size() ; i++){
    s.push_back(z[i]);
}
cin>>z;
for(int i=0 ; i<z.size() ; i++){
    d.push_back(z[i]);
}
char a;
for(int i=0 ; i<z.size() ; i++){
    if(s==d){
        cout<<"Yes";
        return 0 ;
    }
    a=s[z.size()-1];
    s.pop_back();
    s.push_front (a);
}
cout<<"No";
    return 0;
}


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

ans = True
li = [input() for _ in range(n)]

said =[li[0]]
for i in range(1, n):
    if li[i] in said or li[i-1][-1] != li[i][0]:
        print("No")
        break
    else:
        said.append(li[i])
else:
    print("Yes")


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N;
	string S;
	cin >> N >> S;
	int E = 0;
	int W = 0;
	for(int i = 1;i < N;i++) {
		if(S.at(i) == 'E') {
			E++;
		}
	}
	int ret = E;
	for(int i = 0;i < N - 1;i++) {
		ret = min(ret,E + W);
		if(S.at(i) == 'W') {
			W++;
		}
		if(S.at(i + 1) == 'E') {
			E--;
		}
    }
  	ret = min(ret,W);
	cout << ret << endl;
}

Measured memory_bytes: 900
#メモ代わりの写経
n,k=map(int,input().split())
p=998244353
f=[1]
#階乗のリストを先に作っておく
for i in range(k):
    #f+=[-~i*f[i]%p]
    f+=[(i+1)*f[i]%p]
    
#combinationsの総和    
print(sum(f[-2]*pow(f[i]*f[-2-i],-1,p)for i in range(n-1,k))%p)


Measured memory_bytes: 28824
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;
const int MAX_V = 100100;

int main() {
  ll N, W;
  cin >> N >> W;
  vector<ll> w(N);
  vector<ll> v(N);
  vector<vector<ll> > dp(N+10, vector<ll>(MAX_V+1, INF));

  rep(i, N){
    cin >> w[i] >> v[i];
  }
  dp[0][0] = 0;
  for(int i = 0; i < N; i++){
    for (int sum_v = 0; sum_v <= MAX_V; sum_v++) {
      // i 番目の品物を選ぶ場合
      if (sum_v - v[i] >= 0) {
        dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i]);
      }

      // i 番目の品物を選ばない場合
      dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v]);
    }
  }
  
   // 最適値の出力
  long long res = 0;
  for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
      if (dp[N][sum_v] <= W) res = sum_v;
  }
  cout << res << endl;
}


Measured memory_bytes: 87296
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+18;

int main() {
    ios::sync_with_stdio(false);   
    Int h, w;
    cin >> h >> w;
    map<char, Int> mp;
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            char a;
            cin >> a;
            mp[a]++;
        }
    }
    if (h % 2 == 0 && w % 2 == 0) {
        for (auto v : mp) {
            if (v.second % 4 != 0) {
                dump("No");
                return 0;
            }
        }
        dump("Yes");
    }
    else if ((h % 2 == 0 && w % 2 == 1) || (h % 2 == 1 && w % 2 == 0)) {
        Int cnt_4 = 0;
        Int limit_4 = (h / 2) * (w / 2);
        for (auto v : mp) {
            while (v.second >= 4 && cnt_4 < limit_4) {
                v.second -= 4;
                cnt_4++;
            }
        }
        if (cnt_4 != limit_4) {
            dump("No");
            return 0;
        }
        for (auto v : mp) {
            if (v.second % 2 != 0) {
                dump("No");
                return 0;
            }
        }
        dump("Yes");
    }
    else {
        Int cnt_4 = 0;
        Int limit_4 = (h / 2) * (w / 2);
        for (auto v : mp) {
            while (v.second >= 4 && cnt_4 < limit_4) {
                v.second -= 4;
                cnt_4++;
            }
        }
        if (cnt_4 != limit_4) {
            dump("No");
           //  dump("MO")
            return 0;
        }
        Int cnt = 0;
        for (auto v : mp) {
            if (v.second % 2 == 1) cnt++;
        }
        dump(cnt == 1 ? "Yes" : "No");
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

s = deque(input().rstrip())

sw = True

nq = int(input().rstrip())
for _ in range(nq):
    query = input().rstrip()
    if query[0] == '1':
        sw = (sw == False)
    else:
        c = query[4]
        if (query[2] == '1') == sw: 
            s.appendleft(c)
        else:
            s.append(c)
if sw:
    print("".join(s))
else:
    print("".join(reversed(s)))



Measured memory_bytes: 8436
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/30 09:22:54 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

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

// TOP
void	Main()
{
	int	n, k;
	cin >> n >> k;
	vector<int>	V(n);
	vector<int>	dp(n);
	rep(i, n)
		cin >> V.at(i);
	rep2(i, 1, n)
	{
		dp.at(i) = dp.at(i - 1) + abs(V.at(i) - V.at(i - 1));
		rep2(j, 1, k)
		{
			if (i - 1 - j < 0)
				continue;
			dp.at(i) = min(dp.at(i), dp.at(i - 1 - j) + abs((V.at(i) - V.at(i - 1 - j))));
		}
	}
	cout << dp.at(n - 1) << endl;


}
// END

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N , X;
  cin >> N >> X;
  vector<int> ms(N);
  int sum = 0;
  for(int i = 0; i < N; i++){
    cin >> ms.at(i) ;
    sum += ms.at(i);
  }
  sort(ms.begin(), ms.end());
  cout << N + (int)((X-sum)/ms.at(0)) << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int, Int> pii;
typedef pair<Int, double> pid;
typedef pair<double, double> pdd;
typedef pair<Int, pii> pip;
typedef pair<pii, Int> ppi;
typedef pair<double, Int> pdp;
typedef vector<Int> veci;
typedef vector<double> vecd;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<pii> vecpii;
typedef vector<ppi> vecppi;
typedef vector<veci> mati;
typedef vector<vecll> matll;
typedef vector<vecd> matd;
#define PB(x) push_back(x)
#define EB(x) emplace_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define REP(i, a, b) for(int i = (a);i <= (b);i++)
#define FORO(i, n) REP(i,0,(int)n-1)
#define FORI(i, n) REP(i,1,(int)n)
#define FORIT(i, t) for(auto i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a, _b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
#define DEBUG 1
#if DEBUG
#define DUMP(a) do { std::cout << #a " = " << (a) << ", "; } while(false)
#define DUMPLN(a) do { std::cout << #a " = " << (a) << std::endl; } while(false)
#else
#define DUMP(a)
#define DUMPLN(a)
#endif
template<typename T, typename U>
inline void getMin(T &a, U b) { if (a > b) a = b; }
template<typename T, typename U>
inline void getMax(T &a, U b) { if (a < b) a = b; }
template<typename T>
vector<T> getVector(const int n) { return vector<T>(n); }
template<typename T>
vector<T> getVector(const int n, const T a) { return vector<T>(n, a); }
template<typename T>
vector<T> getEmptyVector() { return vector<T>(); }
template<typename T>
void appendAll(vector<T> &a, vector<T> b) { a.insert(a.end(), b.begin(), b.end()); }
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
// #define X first
// #define Y second
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const ll MOD = 1000000007;
const int MAXN = 1 << 17;
const int inf = 1 << 27;
const ll llinf = 1LL << 50;
const int NIL = -inf;
int popcount(int x) { return __builtin_popcount(x); }


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

    int N;
    ll D;
    cin >> N >> D;
    int ans = 0;
    FORO(i, N) {
        ll X, Y;
        cin >> X >> Y;
        if(X * X + Y * Y <= D * D) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
//abc158_b.cpp
//Sat Mar  7 20:43:13 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

int main(){
	ll n,a,b;
	cin >> n >> a >> b;

	ll sho = n/(a+b);
	ll ama = n%(a+b);

	ll ans = sho*a;
	ans += min(ama,a);

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
N = int(input())
An = list(map(int,input().split(' ')))
Bn = list(map(int,input().split(' ')))
Cn = list(map(int,input().split(' ')))

sum_count = 0
previous_number = -100
for a in An:
    sum_count += Bn[a-1]
    if previous_number + 1 == a:
        sum_count += Cn[previous_number-1]
    previous_number = a
print(sum_count)

Measured memory_bytes: 3064
C = input()

alf = [
    'a',
    'b',
    'c',
    'd',
    'e',
    'f',
    'g',
    'h',
    'i',
    'j',
    'k',
    'l',
    'm',
    'n',
    'o',
    'p',
    'q',
    'r',
    's',
    't',
    'u',
    'v',
    'w',
    'x',
    'y',
    'z',
]
i = alf.index(C)

print(alf[i + 1])


Measured memory_bytes: 38256
#include<stdio.h>
int main(void)
{
  char c;
  while((c = getchar ()) != '\n'){
    if((c >= 'A') && (c <= 'Z')){
      c += 'a' - 'A';
    }
    else if((c >= 'a') && (c <= 'z' )){
      c -= 'a' - 'A';
    }
    putchar(c);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
def main():
    N = int(input())
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        exit(0)

    total = 1
    for a in A:
        total *= a

        if total > 10 ** 18:
            print(-1)
            exit(0)
    print(total)

if __name__ == '__main__':
    main()

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

#define all(A) begin(A), end(A)
#define sz(A) int(A.size())

using namespace std;

typedef long long ll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector <int> ac(n + 1, 0);
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == 'A' and s[i] == 'C') {
      ac[i + 1] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    ac[i] += ac[i - 1];
  }
  while (q--) {
    int l, r;
    cin >> l >> r;
    int x = ac[r] - ac[l - 1];
    if (ac[l] - ac[l - 1] == 1) x--;
    cout << x << '\n';
  }
  return (0);
}


Measured memory_bytes: 1488
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n';
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int64_t, int >prime_factor(int64_t n){map< int64_t, int > ret;for(int64_t i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    VVI a(n,VI(2)); REP(i,n){cin >> a[i][0]; a[i][1]=i+1;} SORT(a);
    REP(i,n) out(a[i][1]);

    return 0;
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int n;
    cin>>n;
    int sam=0;
    int sim=0;
    int sum=0;
    int sem=0;
    int som=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        for(int j=0;j<1;j++){
            if(s[0]=='M'){
                sam++;
            }
            if(s[0]=='A'){
                sim++;
            }
            if(s[0]=='R'){
                sum++;
            }
            if(s[0]=='C'){
                sem++;
            }
            if(s[0]=='H'){
                som++;
            }
        }
    }
    cout<<sam*sim*sum+sam*sim*sem+sam*sim*som+sam*sum*sem+sam*sum*som+sam*sem*som+sim*sum*sem+sim*sum*som+sim*sem*som+sum*sem*som<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <cstdint>
#include <algorithm>
using namespace std;



int64_t h,w;
vector<pair<int64_t,int64_t>> heap;
uint64_t ans=0;
int64_t oper[2];
int main()
{
    cin>>w>>h;
    oper[0]=w+1;
    oper[1]=h+1;
    for (int i=0;i<w;i++)
    {
     int64_t temp;
     cin>>temp;
     heap.push_back(make_pair(temp,0));
    }
    for (int i=0;i<h;i++)
    {
     int64_t temp;
     cin>>temp;
     heap.push_back(make_pair(temp,1));
    }
    //while (!heap.empty())
    sort(heap.begin(),heap.end());
    for (auto f:heap)
    {
    // auto f=heap.top();
     //heap.pop();
     ans+=oper[1-f.second]*f.first;
     //cout<<f.first<<' '<<oper[1-f.second]<<' '<<oper[f.second]<<' '<<f.second<<' '<<ans<<endl;
     oper[f.second]--;
    // cout<<f.first<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

ll GCD(ll a, ll b) {
    return (b > 0) ? GCD(b, a % b) : a;
}

ll LCM(ll a, ll b) {
    return a / GCD(a, b) * b;
}

int main() {
    int k;
    cin >> k;
    int ans = 0;
    rep(a, k)rep(b, k)rep(c, k){
        ans += GCD(a+1, GCD(b+1, c+1));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<=(int)(n);i++)

int main()
{
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;

  //なるべくfに近付けたい
  //濃度はs/s+w
  double max=0;
  ll sugwat=100*a,sugar=0;
  rep(i,f/100/a)
  rep(j,(f/100-a*i)/b)
  rep(k,(f-100*(a*i+b*j))/c)
  rep(l,(f-k*c-100*(a*i+b*j))/d)
  {
    if (k+l != 0) {
           double x = 1.0*(c*k+d*l)/(double)((c*k+d*l)+100*(a*i+b*j));
           if (max<x && (100+e)*x<=e) {
             max = 1.0*(c*k+d*l)/(double)((c*k+d*l)+100*(a*i+b*j));
             sugar = c*k+d*l;
             sugwat = sugar + 100*(a*i+b*j);
           }
    }
  }

   cout << sugwat << ' ' << sugar;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int m = a[0], M = a[0];
    
    for (int i = 0; i < N; i++){
        if (m > a[i]){
            m = a[i];
        }
        if(M < a[i]){
            M = a[i];
        }
    }
    cout << M - m << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int e, x, y, z;
	int i, j, min;
	
	while(1)
	{		
		scanf("%d", &e);
		
		if(e == 0) break;
		
		min = -1;
		
		z = 0;
		while(z * z * z <= e)
		{
			z++;
		}
		
		for(i = 0; i < z; i++)
		{
			y = 0;
			while(y * y <= (e - i * i * i))
			{
				y++;
			}
			
			for(j = 0; j < y; j++)
			{
				x = e - i * i * i - j * j;
				if(min < 0 || min > i + j + x)
				{
					min = i + j + x;
				}
			}
		}
		
		printf("%d\n", min);
	}
	
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

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

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

    if (n == 0){
        cout << 0 << endl;
        return 0;
    }

    stack<int> ans;

    while(n){
        int r = n % -2;
        if (r >= 0){
            ans.push(r);
            n /= -2;
        }else{
            ans.push(1);
            (n /= -2) += 1;
        }
    }
    
    while(ans.size()){
        int num = ans.top(); ans.pop();
        cout << num;
    }

    cout << endl;

    return 0;
}

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

const int MAX = 1000000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int x, y, hon, a, b;
    cin >> x >> y;
    bool flag=false;
    
    COMinit();

    hon = (x+y)/3;
    for(int i=0; i<hon+2; i++){
	if(x == 2*(hon-i)+1*(i) && y == 1*(hon-i)+2*(i)){
	    a=hon-i;
	    b=i;
	    flag=true;
	    break;
	}
    }
    if(!flag){
	cout << 0 << endl;
	return 0;
    }
	

    
    long long ans = COM(a+b, a);
    cout << ans << endl;
    
}



Measured memory_bytes: 23680
#include <iostream>

using namespace std;

int main() {
    int ch[3]={0};
    string str;
	cin >> str;
    bool flag = true;
    for(int i=0; i<3; i++) {
        if(ch[(int)(str[i]-'a')]==0) {
            ch[(int)(str[i]-'a')]++;
        } else {
            flag = false;
            break;
        }
    }
    if(flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
    
}

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

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = ReadLongs();
            var N = inputs[0];
            var K = inputs[1];
            var S = ReadText();

            var blocks = GetBlocks(N, S);

            // すべてひっくり返しきれるケース
            if (blocks.Count(x => !x.IsSakadati) <= K) return N;

            var max = 0L;
            for (int i = 0; i < blocks.Count; i++)
            {
                var count = 0L;
                if (blocks[i].IsSakadati)
                {
                    var from_m1 = i - 1;
                    var to = Math.Min(i + 2 * K, blocks.Count - 1);
                    count = blocks[(int)to].RuisekiCount
                        - (i == 0 ? 0 : blocks[from_m1].RuisekiCount);
                }
                else
                {
                    var from_m1 = i - 1;
                    var to = Math.Min(i + 2 * K - 1, blocks.Count - 1);
                    count = blocks[(int)to].RuisekiCount
                        - (i == 0 ? 0 : blocks[from_m1].RuisekiCount);
                }

                max = Math.Max(max, count);
            }

            return max;
        }

        private static List<Block> GetBlocks(long N, string S)
        {
            var blocks = new List<Block>();
            var pre = S[0];
            var currentCount = 0L;
            for (int i = 0; i < N; i++)
            {
                if (pre == S[i])
                {
                    currentCount++;
                }
                else
                {
                    blocks.Add(new Block
                    {
                        IsSakadati = pre == '1',
                        Count = currentCount,
                        RuisekiCount = !blocks.Any() ? currentCount : (blocks.Last().RuisekiCount + currentCount),
                    });

                    pre = S[i];
                    currentCount = 1L;
                }
            }

            // 最後の一つを足す
            blocks.Add(new Block
            {
                IsSakadati = pre == '1',
                RuisekiCount = !blocks.Any() ? currentCount : (blocks.Last().RuisekiCount + currentCount),
            });
            return blocks;
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }

    class Block
    {
        public bool IsSakadati { get; set; }
        public long Count { get; set; }
        public long RuisekiCount { get; set; }
    }
}


Measured memory_bytes: 21596
s = int(input())
a=[]
a.append(s)
count = 0
while True:
    if a[-1]%2 != 0:
        a.append(3*a[-1]+1)
    else:
        a.append(a[-1]/2)
    count += 1
    if a[-1] in a[:len(a)-1]:
        break
print(count+1)


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

using namespace std;

int main()
{
    int n, k; cin >> n >> k;
    string s; cin >> s;
    vector < pair <int , int> > vec;
    vec.push_back({0, -1});
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') continue ;
        int r = i;
        while (r < n && s[r] == s[i]) r++;
        r--;
        vec.push_back({i, r});
        i = r;
    }
    vec.push_back({n, n - 1});
    int ans = 0;
    for (int i = 0; i < vec.size(); i++) ans = max(ans, vec[min(i + k, (int)vec.size() - 1)].second - vec[i].first + 1);
    cout << ans << "\n";
}


Measured memory_bytes: 1020
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())
struct P{
  int tx,ty,kx,ky;
  int t;
  P(int tx,int ty,int kx,int ky,int t) : tx(tx),ty(ty),kx(kx),ky(ky),t(t) {}
};
bool operator < (P p, P q){
  return p.t > q.t;
}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
bool memo[51][51][51][51];
int main(void){
  int w,h;
  while(cin>>w>>h,w){
    memset(memo,0,sizeof(memo));
    int grid[51][51];
    int tx,ty,kx,ky;
    cin>>tx>>ty>>kx>>ky;
    tx--;ty--;kx--;ky--;
    REP(y,h)REP(x,w)cin>>grid[y][x];
    priority_queue<P> que;
    que.push(P(tx,ty,kx,ky,0));
    int ans=-1;
    while(!que.empty()){
      P p = que.top(); que.pop();
      if(memo[p.tx][p.ty][p.kx][p.ky])continue;
      memo[p.tx][p.ty][p.kx][p.ky] = true;
      if(p.t>=100){
        ans = -1;
        break;
      }
      if(p.tx==p.kx&&p.ty==p.ky){
        ans = p.t;
        break;
      }
      REP(r,4){
        int ntx = p.tx + dx[r];
        int nty = p.ty + dy[r];
        int nkx = p.kx - dx[r];
        int nky = p.ky - dy[r];
        if(!(ntx>=0&&ntx<w&&nty>=0&&nty<h&&grid[nty][ntx]==0)){
          ntx = p.tx;
          nty = p.ty;
        }
        if(!(nkx>=0&&nkx<w&&nky>=0&&nky<h&&grid[nky][nkx]==0)){
          nkx = p.kx;
          nky = p.ky;
        }
        que.push(P(ntx,nty,nkx,nky,p.t+1));
      }
    }
    if(ans==-1) cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 8776
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>

#define ld long double
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll,ll>
#define MP make_pair
#define MT make_tuple
#define SZ(a) ll((a).size())
#define X first
#define Y second
#define endl '\n'
#define PB push_back
#define has(i, m) (m.find(i) != m.end())

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REPEAT(t) FOR(name_that_will_never_apper, 0, t)
#define iter(el, arr) for(auto& el : arr)
#define ALL(a) a.begin(), a.end()

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define vch vector<char>
#define vb vector<bool>
#define vvi vector<vi>
#define vvll vector<vll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvch vector<vch>
#define vvb vector<vb>
#define vs vector<string>
#define vss vector<vs>
#define pdd pair<ld, ld>
#define vpll vector<pll>
#define vpdd vector<pdd>
#define PI 3.141592653589793
using namespace std;

#define alphabet_size 26
#define mod 1000000007
#define INF (ll)1e18
#define MAXN 100001

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	//freopen("door.in", "r", stdin);
	//freopen("door.out", "w", stdout);

	int n;
	cin >> n;
	vll a(n);
	FOR(i, 0, n)
		cin >> a[i];

	ll ans = 0;
	FOR(i, 0, n - 1)
		if (a[i] == i + 1)
			swap(a[i], a[i + 1]), ans++;

	if (a[n - 1] == n)
	{
		ans++;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; }


#define INF 21474836

ll N, A, B;

int main() {

	cin >> N >> A >> B;

	ll ans = 0;

	ans = (N / (A + B))*A;
	if (N - (N / (A + B))*(A + B) > A)ans += A;
	else ans += N - (N / (A + B))*(A + B);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[3][3],n,x;
int main(){
	for(int i=0;i<3;i++)for(int j=0;j<3;j++)scanf("%d",a[i]+j);
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		for(int i=0;i<3;i++)for(int j=0;j<3;j++)if(a[i][j]==x)a[i][j]=0;
	}
	for(int i=0;i<3;i++){
		bool fl=1;
		for(int j=0;j<3;j++)if(a[i][j])fl=0;
		if(fl)return puts("Yes"),0;
		fl=1;
		for(int j=0;j<3;j++)if(a[j][i])fl=0;
		if(fl)return puts("Yes"),0;
	}
	bool fl=1;
	for(int i=0;i<3;i++)if(a[i][i])fl=0;
	if(fl)return puts("Yes"),0;
	fl=1;
	for(int i=0;i<3;i++)if(a[i][2-i])fl=0;
	if(fl)return puts("Yes"),0;
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
const int MAX_N=50;
const int MAX_D=30;
set<int> own[MAX_N];
set<int> date[MAX_D];
int n,m,tmp;

int main(){ _;
  while(cin>>n,n!=0){
    REP(i,MAX_D)date[i].clear();
    REP(i,n){
      own[i].clear();
      own[i].insert(i);
      cin>>m;
      REP(j,m){
	cin>>tmp;
	date[tmp-1].insert(i);
      }
    }
    REP(i,MAX_D){
      set<int> update;
      for(int p:date[i])
	for(int o:own[p])
	  update.insert(o);
      if(update.size()==n){
	cout<<i+1<<endl;
	goto OK;
      }
      for(int p:date[i])
	own[p]=set<int>(update);
    }
    cout<<-1<<endl;
    continue;
  OK:;
  }
}

Measured memory_bytes: 1396
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

int main(){
  int n; cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  sort(all(s));
  map<string,int> C;
  rep(i,n) C[s[i]]++;
  int MAX = 0;
  for(auto c : C) {
    chmax(MAX,c.second);
  }
  vector<string> ans;
  for(auto c : C) {
    if(c.second == MAX){
      ans.pb(c.first);
    }
  }
  sort(all(ans));
  for(auto c : ans) {
    cout << c << endl;
  }

}

Measured memory_bytes: 30324
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h1,m1,h2,m2,k;
    scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);
    if(h1==h2 && m2>m1)
    {
        printf("%d\n",m2-m1 - k);
        return 0;
    }
    if(h2<=h1) h2+=24;
    int minutes = (60 - m1)%60;
    if(minutes) h1++;
    minutes+=m2;
    int hours = h2 - h1;
    minutes+=hours*60;
    minutes-=k;

    printf("%d\n",minutes);

}


Measured memory_bytes: 3828
n = gets.to_i
b1f1 = [0,0,0,0,0,0,0,0,0,0]
b1f2 = [0,0,0,0,0,0,0,0,0,0]
b1f3 = [0,0,0,0,0,0,0,0,0,0]
b2f1 = [0,0,0,0,0,0,0,0,0,0]
b2f2 = [0,0,0,0,0,0,0,0,0,0]
b2f3 = [0,0,0,0,0,0,0,0,0,0]
b3f1 = [0,0,0,0,0,0,0,0,0,0]
b3f2 = [0,0,0,0,0,0,0,0,0,0]
b3f3 = [0,0,0,0,0,0,0,0,0,0]
b4f1 = [0,0,0,0,0,0,0,0,0,0]
b4f2 = [0,0,0,0,0,0,0,0,0,0]
b4f3 = [0,0,0,0,0,0,0,0,0,0]
n.times do
 x = gets()
 y = x.split()
 b = y[0].to_i
 f = y[1].to_i
 r = y[2].to_i
 v = y[3].to_i
 if b == 1
  if f == 1
   b1f1[r-1] += v 
  elsif f == 2
   b1f2[r-1] += v
  else
   b1f3[r-1] += v
  end
 elsif b == 2
  if f == 1
   b2f1[r-1] += v 
  elsif f == 2
   b2f2[r-1] += v
  else
   b2f3[r-1] += v
  end
 elsif b == 3
  if f == 1
   b3f1[r-1] += v 
  elsif f == 2
   b3f2[r-1] += v
  else
   b3f3[r-1] += v
  end
 else
  if f == 1
   b4f1[r-1] += v 
  elsif f == 2
   b4f2[r-1] += v
  else
   b4f3[r-1] += v
  end
 end
end
i = 0
b1f1.each do |b1|
 if i != (b1f1.length - 1)
  print " #{b1}"
 else
  puts " #{b1}"
 end
 i += 1
end

i = 0
b1f2.each do |b2|
 if i != (b1f2.length - 1)
  print " #{b2}"
 else
  puts " #{b2}"
 end
 i += 1
end

i = 0
b1f3.each do |b1|
 if i != (b1f3.length - 1)
  print " #{b1}"
 else
  puts " #{b1}"
 end
 i += 1
end
puts "#"*20
i = 0
b2f1.each do |b1|
 if i != (b2f1.length - 1)
  print " #{b1}"
 else
  puts " #{b1}"
 end
 i += 1
end

i = 0
b2f2.each do |b1|
 if i != (b2f2.length - 1)
  print " #{b1}"
 else
  puts " #{b1}"
 end
 i += 1
end

i = 0
b2f3.each do |b1|
 if i != (b2f3.length - 1)
  print " #{b1}"
 else
  puts " #{b1}"
 end
 i += 1
end
puts "#"*20
i = 0
b3f1.each do |b1|
 if i != (b3f1.length - 1)
  print " #{b1}"
 else
  puts " #{b1}"
 end
 i += 1
end

i = 0
b3f2.each do |b1|
 if i != (b3f2.length - 1)
  print " #{b1}"
 else
  puts " #{b1}"
 end
 i += 1
end

i = 0
b3f3.each do |b1|
 if i != (b3f3.length - 1)
  print " #{b1}"
 else
  puts " #{b1}"
 end
 i += 1
end
puts "#"*20
i = 0
b4f1.each do |b1|
 if i != (b4f1.length - 1)
  print " #{b1}"
 else
  puts " #{b1}"
 end
 i += 1
end
i = 0
b4f2.each do |b1|
 if i != (b4f2.length - 1)
  print " #{b1}"
 else
  puts " #{b1}"
 end
 i += 1
end

i = 0
b4f3.each do |b1|
 if i != (b4f3.length - 1)
  print " #{b1}"
 else
  puts " #{b1}"
 end
 i += 1
end


Measured memory_bytes: 6908
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=1e7+10;
ll a[505][505];
int prime[maxn],isprime[maxn],tmp;
int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
void init(int n){
	REP(i,2,n){
		if(!isprime[i]) prime[++tmp]=i;
		REP(j,1,tmp){
			if((ll)i*prime[j]>n) break;
			isprime[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
}
ll lcm(ll x,ll y){
	return (x/__gcd(x,y))*y;
}
int main(){
	int n=read();
	if(n==2){
		printf("4 7\n23 10\n");
		return 0;
	}
	init(1e7);
	int l=1,r=n;
	for(int i=2;i<=2*n;i+=2){
		int u;
		if(i%4) u=prime[r--];
		else u=prime[l++];
		REP(j,1,n){
			int k=i-j;
			if(k>=1 && k<=n) a[j][k]=u;
		}
	}
	l=n+1,r=n*2;
	for(int i=(n&1)?2:3;i<=2*n;i+=2){
		int u;
		if(i%4) u=prime[r--];
		else u=prime[l++];
		REP(j,1,n){
			int k=n+1+j-i;
			if(k>=1 && k<=n) a[j][k]*=u;
		}
	}
	REP(i,1,n) REP(j,1,n) if((i+j)&1){
		a[i][j]=1;
		REP(k,0,3){
			int u=i+dir[k][0],v=j+dir[k][1];
			if(u>=1 && u<=n && v>=1 && v<=n) a[i][j]=lcm(a[i][j],a[u][v]);
		}
		a[i][j]++;
	}
	REP(i,1,n) REP(j,1,n) printf("%lld%c",a[i][j],j==jend?'\n':' ');
    return 0;
}

Measured memory_bytes: 48384
#include<stdio.h>

int isPrime(int n){
    if(n==1){
        return 0;
    }
    if(n==2||n==3){
        return 1;
    }
    if(n%2==0||n%3==0){
        return 0;
    }
    for(int i=5;i*i<=n;i+=2){
        if(i%3==0){
            continue;
        }
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

int main(){
    int x;
    scanf("%d", &x);
    if(x>2 && x%2==0){
        x++;
    }
    while(!isPrime(x)){
        x++;
    }
    printf("%d", x);

    return 0;
}

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

typedef long long ll;

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;

#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
 
template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
    return out <<  "(" << a.first << ", " << a.second << ")";
}
 
template<class A> ostream& operator << (ostream& out, const vector<A> &a) {			
    out << "[";
    for (auto it = a.begin(); it != a.end(); ++it) {
        if (it != a.begin())
            out << ", ";
        out << *it;
    }
    return out << "]";
}

void solve(){
    ll n;
    cin >> n;
    ll temp;
    ll cnt = 0;
    for(int i=0;i<n;i++){
        cin >> temp;
        if(i%2==0 && temp&1){
            cnt++;
        }
    }
    cout<<cnt<<"\n";
}

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

	return 0;
}


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

public class Main {
	static public void main(String[] argv) {
		try{
//			FileWriter fw = new FileWriter("output.txt");
//			BufferedWriter bw = new BufferedWriter(fw);
//			PrintWriter pw = new PrintWriter(bw, true);
			
//			FileReader fr = new FileReader("input.txt");
//			BufferedReader br = new BufferedReader( fr );
			
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));	
			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
			PrintWriter pw = new PrintWriter(bw, true);
			
			while(true) {
				String buf = br.readLine();
				StringTokenizer st = new StringTokenizer(buf);
				int n, m;
				n = Integer.valueOf(st.nextToken());
				m = Integer.valueOf(st.nextToken());
				
				if(n == 0 && m == 0) break;
				
				int[] count = new int[m];
				for(int i = 0; i < n; i++) {
					buf = br.readLine();
					st = new StringTokenizer(buf);
					for(int j = 0; j < m; j++) {
						int e = Integer.valueOf(st.nextToken());
						if(e == 1) ++count[j];
					}
				}
				
				ArrayList<Integer> res = solve(count, n, m);
				
				int num = res.size();
				for(int i = 0; i < num; i++) {
					pw.print(res.get(i));
					if(i < num-1) pw.print(" ");
				}
				pw.println();
			}
			
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	static ArrayList<Integer> solve(int[] count, int n, int m) {
		ArrayList<Integer> ret = new ArrayList<Integer>();
		for(int i = n; i >= 0; i--) {
			for(int j = 0; j < m; j++) {
				if(count[j] == i) ret.add(new Integer(j+1));
			}
		}
		return ret;
	}
}

Measured memory_bytes: 34540
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long lli;
lli n,m;
vector<multimap<lli,lli> > g;
priority_queue<vector<lli>,vector<vector<lli> >,greater<vector<lli> > > pq;
set<pair<lli,lli> > vs;
vector<lli> res;

void dijekstra(){
    vector<lli> p{0,0,1};//cost,last_c,node;
    pq.push(p);
    while(!pq.empty()){
        vector<lli> p = pq.top();
        pq.pop();
        if(vs.find(make_pair(p[1],p[2])) != vs.end()) continue;
        vs.insert(make_pair(p[1],p[2]));
        if(p[1] == 0){
            res[p[2]] = p[0];
            //cout << "-------" << p[2] << endl;
            for(auto x = g[p[2]].begin();x != g[p[2]].end();x++){
                //cout << x->first << " " << x->second << endl;
                if(vs.find(make_pair(x->first,x->second)) != vs.end()) continue;
                vector<lli> ins{p[0]+1,x->first,x->second};
                //cout << x->first << " " << x->second << endl;
                pq.push(ins);
            }
        }else{
            if(vs.find(make_pair((lli)0,p[2])) == vs.end()){
                vector<lli> ins{p[0],0,p[2]};
                pq.push(ins);
            }
            auto from = g[p[2]].lower_bound(p[1]);
            auto to = g[p[2]].upper_bound(p[1]);
            for(auto x = from;x != to;x++){
                if(vs.find(make_pair(x->first,x->second)) != vs.end()) continue;
                vector<lli> ins{p[0],x->first,x->second};
                pq.push(ins);
            }
        }

    }
}

int main(int argc, char const *argv[]) {
    cin >> n >> m;
    g = vector<multimap<lli,lli> > (n+1);
    for(lli i = 0;i < m;i++){
        lli p,q,c;
        cin >> p >> q >> c;
        g[p].insert(make_pair(c,q));g[q].insert(make_pair(c,p));
    }
    res = vector<lli> (n+1);
    dijekstra();
    cout << (res[n] ? res[n] : -1) << endl;

    return 0;
}


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

public class Main {

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

		String[] nk = scanner.nextLine().split(" ");
		int n = Integer.parseInt(nk[0]);
		int k = Integer.parseInt(nk[1]);

		int[] ar = new int[n];

		for (int i = 0; i < n; i++) {
			ar[i] = scanner.nextInt();
		}

		Arrays.sort(ar);

		int sum = 0;
		for (int i = 0; i < k; i++) {
			sum += ar[i];
		}

		System.out.println(sum);

	}

}

Measured memory_bytes: 39148
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;

int main()
{
	long n;
	cin >> n;
	vector<long>d(n);
	for (int i = 0; i < n; i++)cin >> d[i];
	sort(d.begin(), d.end());
	n = n - 1;
	cout << (d[n / 2] == d[n / 2 + 1] ? 0 : d[n / 2+1] - d[n / 2]) << endl;
}


Measured memory_bytes: 1024