akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;

#define updmax(dp,x) dp=(dp.first == 0 ? x : max(dp,x))

using P = pair<int,int>;

int main(void){
    int n;
    while(cin>>n, n){
        vector<int> p(n);
        rep(i,n) cin>>p[i];
        map<int,P> cur; // cur[coin] = <get,pay>
        cur[0] = {0,0};
        rep(i,n){
            map<int,P> nxt;
            for(auto &itr : cur){
                int coin = itr.first;
                int k = itr.second.first;
                int pay = itr.second.second;
                updmax(nxt[coin], P(k,pay));
                pay -= p[i];
                int mod = p[i]%500;
                if(p[i]%1000 == 0){
                    if(coin>=500) updmax(nxt[coin-500], P(k+1,pay));
                }else if(p[i]%1000 == 500){
                    updmax(nxt[coin], P(k+1,pay));
                }else if(p[i]%1000 <= 500){
                    updmax(nxt[coin+500-mod],P(k+1, pay));
                }else if(mod <= coin){
                    updmax(nxt[coin-mod], P(k+1,pay));
                }else{
                    updmax(nxt[coin+500-mod], P(k,pay));
                }
            }
            cur = move(nxt);
        }
        P res = {0,0};
        for(auto itr : cur){
            res = max(res,itr.second);
        }
        cout<<res.first<<" "<<-res.second<<endl;
    }
    return 0;
}



Measured memory_bytes: 4884
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, unsigned long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll n;
  std::cin>>n;

  std::vector<ll> a(n);
  for(auto&& e:a)std::cin>>e;
  
  std::vector<ll> cnt(1e6+10);
  rep(i,0,n)cnt[a[i]]++;

  ll ans=n;

  for(const auto& e:a){
    if(cnt[e]>1){
      ans--;
      continue;
    }
    if(e!=1&&cnt[1]>0){
      ans--;
      continue;
    }
    for(ll i=2;i*i<=e;i++){
      if(e%i==0){
        if(cnt[i]>0||cnt[e/i]>0){
          ans--;
          break;
        }
      }
    }
  }

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 12700
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

        long K=gl();
        Map<Long, Boolean> m = new HashMap<Long, Boolean>();
        
        //System.out.println(Math.min(ans,  ans2));

        long ans =0;
        long mod =0;
        while(true) {
        	ans++;
        	long mod2 = modpow(10, ans-1, K);
        	mod2 = (7%K * mod2)%K;
        	mod = (mod+mod2)%K;
        	if(m.containsKey(mod)) {
        		System.out.println(-1);
        		return;
        	} else {
        		m.put(mod, true);
        	}
        	if(mod == 0) {
        		break;
        	}
        }
        System.out.println(ans);
	}
	
	public static long modpow(long a, long n, long mod) {
		long res=1;
		while(n>0) {
			if((n & 1) == 1) res=res*a%mod;
			a=a*a%mod;
			n=n>>1;
		}
		
		return res;
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 131916
import scala.util.control.Breaks
object Main extends App {
  val maxn = 1000000
  val sqrtmaxn = 1000
  val isprime = Array.fill(maxn)(true)
  isprime(0) = false
  isprime(1) = false

  for (i <- 2 to sqrtmaxn) {
    if (isprime(i)){
      for (j <- 2*i until maxn by i) isprime(j) = false
    }
  }

  val bs = Breaks

  bs.breakable {
    for (line <- io.Source.stdin.getLines()) {
      if (line.isEmpty) bs.break()

      println((0 to line.toInt).count(isprime(_)))
    }
  }
}


Measured memory_bytes: 273320
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end


str = gc
s = []

str.each do |ss|
	if ss == '0'
		s << 0
	elsif ss == '1'
		s << 1
	else
		s.pop
	end
end
puts s.join

Measured memory_bytes: 2172
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define REP(i, n) for(ll 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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    ll N;
    cin >> N;
    ll sum = 0;
    REP(i,N + 1){
        if(i %3 != 0 && i % 5 != 0 ){
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
def main():
  n, y = map(int, input().split())
  for i in range(n + 1):
    for j in range(n + 1 - i):
      z = n - i - j
      if i * 10000 + j * 5000 + z * 1000 == y:
        print(i, j, z)
        exit()
  print('-1 -1 -1')
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 9116
// finish date: 2018/01/21
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int N;
    cin >> N;
    cout << (int) sqrt(N)*(int)sqrt(N) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N, K;
    cin >> N >> K;
    vl A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    ll ans = 0;
    rep(i, N) if (A[i] == 0) ans += B[i];

    for (ll bit = K; bit > 0; bit &= K, K -= -K & K, bit--) {
        ll tmp = 0;
        rep(i, N) if ((bit | A[i]) == bit) tmp += B[i];
        chmax(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 4756
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll f(ll x,ll c,ll d){
    ll res =x;
    res -=x/c;
    res -=x/d;
    res+= x/lcm(c,d);
    return res;
}

vector<int> to[100005];
const ll inf =100000000;

vector<ll>a,b,c,d;
ll n,m,q;
ll ans=0;
void bfs(vector<ll> v){
   if(v.size()==n+1) {
       ll sum=0;
       rep(i,q){
           if(v[b[i]]-v[a[i]]==c[i])sum+=d[i];
       }
       ans=max(ans,sum);
       return;
   }
   v.push_back(v.back());
   bfs(v);
   while(v.back()<m){
       v.back()++;
       bfs(v);
   }
}

int main(){
ll n;
cin>>n;
vector<ll>v(n);
rep(i,n)cin>>v[i];
ll max=v[0];
ll ans=0;
rep(i,n){
    if(max<=v[i])max=v[i];
    if(v[i]<max)ans+=max-v[i];
}
cout<<ans<<endl;
}


Measured memory_bytes: 7212
#include<iostream>
#include<vector>

#define ll long long

using namespace std;

const int limit = 100010;

struct edge {
    int to;
    ll cost;
};

vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d) {
    depth[v] = d;
    for (auto& e : tree[v]) {
        if (e.to == p) continue;
        dfs(e.to, v, d + e.cost);
    }
}

int main(void) {
    int n;
    int i;
    cin >> n;
    int a,b,c;
    for (i=0; i<n-1; i++) {
        cin >> a >> b >> c;
        a--, b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }

    int q,k;
    cin >> q >> k;
    k--;
    dfs(k, -1, 0);
    for (i=0; i<q; i++) {
        int x,y;
        cin >> x >> y;
        x--, y--;
        cout << depth[x] + depth[y] << endl;
    }
    return 0;
}


Measured memory_bytes: 14336
N = int(input())
P = list(map(int, input().split()))
ans = 0
for i in range(N):
    if i == N-1:
        if P[i] == i+1:
            ans +=1
        break
    a, b = P[i], P[i + 1]
    if a == i + 1:
        ans += 1
        P[i] = b
        P[i + 1] = a
print(ans)


Measured memory_bytes: 20540
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

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

    if (A + B >= C) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import Counter as cl

def solve(N: int, A: "List[int]", Q: int, B: "List[int]", C: "List[int]"):
    d = [0]*(10**5)
    for ai in A:
        d[ai-1] +=1

    ans = 0
    for i, di in enumerate(d):
        ans += di*(i+1)

    for bi, ci in zip(B,C):
        t_ = d[bi-1]
        ans = ans - bi*t_ + ci*t_
        d[ci-1] += t_
        d[bi-1] = 0
        print(ans)




    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    Q = int(next(tokens))  # type: int
    B = [int()] * (Q)  # type: "List[int]"
    C = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, A, Q, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 22376
r,c = map(int, input().split())
L=[]
for i in range(r):
 al = input()
 print(al, end="")
 AL = list(map(int, al.split()))
 S = sum(AL)
 print(" " + str(S))
 AL. append(S)
 L.append(AL)

for i in range(c):
 S = 0
 for j in range(r):
  S += L[j][i]
 print(str(S) + " ", end="")

S = 0
for j in range(r):
 S += L[j][-1]
print(str(S))

Measured memory_bytes: 7760
#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<vector<int> > Vec(n);
		for(int i = 0; i < n; ++i)
		{
			Vec[i].resize(n);
		}
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cin >> Vec[i][j];
			}
		}
		vector<int> sum(2 * n + 1);
		sum.assign(2 * n + 1, 0);
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				printf("%5d", Vec[i][j]);
				sum[i] += Vec[i][j];
			}
			printf("%5d\n",sum[i]);
		}
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				sum[n + i] += Vec[j][i];
			}
			printf("%5d", sum[n + i]);
		}
		for(int i = 0; i < n; ++i)
		{
			sum[2 * n] += sum[i];
		}
		printf("%5d\n", sum[2 * n]);
	}
}

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

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
#define vi vector<int>
#define vvi vector<vector<int> > 
#define vl vector<long long>
#define vpi vector<pair<int,int> >
#define ll long long 
#define all(x) x.begin(),x.end()
#define vpl vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
// #define mod 998244353
#define mod 1000000007
#define MAXN  1000001
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)



void solve()
{  
    int x,n;
    cin>>x>>n;
    int ans = -1;
    int diff = INT_MAX;
    vector<bool> visited(110,false);
    for(int i = 1 ; i <= n ; i++)
    {
        int temp;
        cin>>temp;
        visited[temp] = true;
    }
    for(int i = 0 ; i <= 110 ; i++)
    {
        if(!visited[i])
        {
            if(abs(x-i) < diff)
            {
                diff = abs(x-i);
                ans = i;
            }
        }
    }
    cout<<ans<<endl;
}


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


Measured memory_bytes: 3660
N,X = map(int, input().split())
L = list(map(int, input().split()))

l = []
cnt = 0
l.append(int(0))
for i in range(N):
  l.append(l[i]+L[i])
  if l[i] <= X:
    cnt += 1
if l[-1] <= X:
  cnt += 1
print(cnt)
  


Measured memory_bytes: 9112
import sys

L,R = map(int,input().split())

ans = 2019
for i in range(L,R):
    for j in range(i+1,R+1) :
        pro = (i*j) %2019
        ans = min(ans,pro)
        if ans == 0 :
            print(0)
            sys.exit()

print(ans)


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

int main() {
  string s;
  cin >> s;
  int a, b;
  rep(i, s.size()) {
    if (s[i] == 'A') {
      a = i;
      break;
    }
  }
  rep(i, s.size()) {
    if (s[s.size() - 1 - i] == 'Z') {
      b = s.size() - 1 - i;
      break;
    }
  }
  // cerr << a << ' ' << b << endl;
  cout << b - a + 1 << endl;
  return 0;
}


Measured memory_bytes: 640
d = dict()
for i in range(100000):
	d[i+1] = 0

n,k = map(int,input().split())
for i in range(n):
	a,b = map(int,input().split())
	d[a] += b

sum = 0
i = 1
while sum < k:
	sum += d[i]
	i += 1
print(i-1)

Measured memory_bytes: 15084
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			int K = scan.nextInt();
			int A = scan.nextInt();
			int B = scan.nextInt();
			
			for(int i = A;i<=B;i++) {
				if(i%K==0) {
					System.out.println("OK");
					System.exit(0);
				}
			}
			
			System.out.println("NG");
		}
		
		
	}
		

}


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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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; }

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

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> s(n);
  REP(i, n) cin >> s[i];
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  REP(i, n){
    string tmp = s[i];
    if (tmp == "AC") ac++;
    if (tmp == "WA") wa++;
    if (tmp == "TLE") tle++;
    if (tmp == "RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa<< endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re<< endl;
  return 0;
}



Measured memory_bytes: 6432
#include <stdio.h>
int Pow(int a,int b){
    int c=1,i=0;
    while(i<b)
    {
        c*=a;
        i++;
    }
    return c;
}
int Pow(int a,int b);
int main(void){
    unsigned int n=0,k=0;
    scanf("%d %d",&n,&k);
    unsigned int sum=0;
    sum=k*Pow((k-1),(n-1));
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 128
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e15;
const int mod=1e9+7;
const int M=100005;
vector<pi>adj[M];
vector<int>Dijkstra(int root)
{
    vector<int>di(M,1e18+7);
    vector<bool>done(M);
    di[root]=0;
    priority_queue<pi,vector<pi>,greater<pi> >q;
    q.push(mp(0,root));
    while(q.size())
    {
        int u=q.top().si;
        int w=q.top().fi;
        q.pop();
        if(done[u])continue;
        done[u]=1;
        for(pi x:adj[u])
        {
            int nw=x.si+w;
            int v=x.fi;
            if(di[v]<=nw)continue;
            di[v]=nw;
            q.push(pi(di[v],v));
        }
    }
    return di;
}
int val[M];
 main()

{
    fast
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    int u[m+2],v[m+2],b[m+2];
    f(i,1,m)
    {
        int a;
        cin>>u[i]>>v[i]>>a>>b[i];
        adj[u[i]].pb(mp(v[i],a));
        adj[v[i]].pb(mp(u[i],a));
    }
   vector<int>dy=Dijkstra(s);
   f(i,1,n)adj[i].clear();
   f(i,1,m)
   {
       int a=b[i];
       adj[u[i]].pb(mp(v[i],a));
       adj[v[i]].pb(mp(u[i],a));
   }
   vector<int>ds=Dijkstra(t);
   set<pi>yo;
   f(i,1,n)
   {
       int x=dy[i];
       int y=ds[i];
       int z=x+y;
       val[i]=z;
       yo.insert(mp(z,i));
   }
   f(i,0,n-1)
   {
       if(i!=0)
       {
           yo.erase(mp(val[i],i));
       }
       int cost=yo.begin()->fi;
       cost=inf-cost;
       cout<<cost<<"\n";
   }
    return 0;

}





































Measured memory_bytes: 21748
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
int main() 
{
	priority_queue<int>x;
	int m, n, t;
	cin >> n >> m;
	for (int i = 0; i < n; i++) 
	{
		scanf("%d",&t);
		x.push(t);
	}
	long long sum = 0;
	while (m) 
	{
		t = x.top() / 2;
		x.pop();
		x.push(t);
		m--;
	}
	while (!x.empty()) 
	{
		sum += x.top();
		x.pop();
	}
	cout << sum<<endl;
	return 0;
}

Measured memory_bytes: 892
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            var min = A.Min();
            var max = A.Max();

            Console.WriteLine(max - min);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

string dp[11111];

int main(){
    const int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for(int i=0; i<M; i++)
        cin >> A[i];

    dp[0] = "";

    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            if(i!=0 && dp[i] == "") continue;
            int num = A[j];
            int c = cost[num];
            if(c+i > N) continue;
            string tmp1 = dp[c+i];
            string tmp2 = dp[i] + to_string(num);
            if(tmp1.size() > tmp2.size()) continue;

            sort(tmp2.rbegin(), tmp2.rend());
            if(tmp1.size() < tmp2.size()) dp[c+i] = tmp2;
            else dp[c+i] = max(tmp1, tmp2);
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 26880
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
int n,a,b;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>a>>b;
	cout<<min(a*n,b)<<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
ls = list(map(int,input().split()))
che = [[0,0] for i in range(len(ls))]
for i in range(len(ls)):
    che[i] = [ls[i],i+1]
che.sort(key=lambda x:x[0])
for i,v in che:
    print(v,end = ' ')
print()

Measured memory_bytes: 76140
import java.util.Scanner;

public class Main {

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

	public static void main(String[] args) {
		String s = sc.next();
		String correct  = "CODEFESTIVAL2016";
		int ans = 0;
		for (int i = 0; i < correct.length(); i++) {
			if(s.charAt(i) != correct.charAt(i)){
				ans++;
			}
		}
		System.out.println(ans);
	}
}

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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
//RNG based on mersenne_twister 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }


int _runtimeTerror_()
{
	ll n;
	cin>>n;
	ll i,a[n];
	for(i=0;i<n-1;++i)
		cin>>a[i];
	ll ans[n+1];
	mem0(ans);
	for(i=0;i<n-1;++i)
		ans[a[i]]++;
	for(i=1;i<=n;++i)
		cout<<ans[i]<<endl;
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	cerr<<"\n"<<_time_;
	return 0;
}


Measured memory_bytes: 6944
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int
main(void){  
  ios_base::sync_with_stdio(false);

  int n, a, b;
  string s;
  cin >> n >> a >> b;
  int ans1, ans2;
  ans1 = min(a, b);
  ans2 = max(0, a+b-n);

  cout << ans1 << " " << ans2 << endl;
  
  return 0;
}


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

#define ll long long

int main(){
    ll H, ans = 0, buf = 0;
    cin >> H;
    while(true){
        if(H >= 1){
            H = floor(H/2);
            ans += pow(2, buf++);
        }
        else break;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    
       long long int n;
       cin>>n;
       long long int m=(n/1000)+(bool)(n%1000);
       m=(1000*m)-n;
       cout<<m;
	// your code goes here
	return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>

void main()
{
    int a;
    char buf[30];
    
    fgets(buf , sizeof(buf),stdin);
    a = atoi(buf);
    a = a+(a*a)+(a*a*a);
    printf("%d\n",a);
}

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

int main(void){
  vector<int> airport(3);
  cin >> airport[0] >> airport[1] >> airport[2];
  sort(airport.begin(), airport.end());
  cout << airport[0] + airport[1] << endl;
  return 0;
}


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

int dist[105][105];
char grid[105][105];
int dp[105][105];
int main(){
    int h,w;cin >> h >> w;
    rep(i,105)rep(j,105) grid[i][j] = '.';
    rep(i,105)rep(j,105) dp[i][j] = 10000;
    rep(i,h)rep(j,w) cin >> grid[i][j+1];
    dp[0][0] = 0;
    auto update = [&](int i,int j,int y,int x){
        if(grid[i][j]=='.' && grid[i+y][j+x]=='#'){
            dp[i+y][j+x] =  min(dp[i+y][j+x],dp[i][j] + 1);
        }else dp[i+y][j+x] =  min(dp[i+y][j+x],dp[i][j]);
        return;
    };
    rep(i,h)rep(j,w+1){
        if(j == 0){
            if(i > 0) continue;
            update(i,j,0,1);
        }else{
            update(i,j,0,1);
            update(i,j,1,0);
        }
    }
    // rep(i,h){
    //     rep(j,w) cout << dp[i][j+1] << " ";
    //     cout << endl;
    // }
    cout << dp[h-1][w] << endl;


    
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  int h[n];
  rep(i,n) cin>>h[i];
  sort(h,h+n);
  int ans=0;
  rep(i,n-k){
    ans+=h[i];
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int>A(N + 1);
  vector<int>B(N + 1);
  vector<int>C(N + 1);
  for (int i = 0; i < N; i ++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i ++) {
    cin >> B[i];
  }
  for (int i = 0; i < N; i ++) {
    cin >> C[i];
  }
  A[N] = B[N] = C[N] = 1e9 + 7;
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  vector<long long>A_a(N + 1);
  vector<long long>B_a(N + 1);
  A_a[N] = B_a[N] = 0;
  for (int i = N - 1; i >= 0; i --) {
    int ma = N;
    int mi = 0;
    while (ma != mi) {
      int mu = (ma + mi) / 2;
      if (C[mu] > B[i]) ma = mu;
      else mi = mu + 1;
    }
    long long kj = (long long)N - ma;
    B_a[i] = kj + B_a[i + 1];
  }
  for (int i = N - 1; i >= 0; i --) {
    int ma = N;
    int mi = 0;
    while (ma != mi) {
      int mu = (ma + mi) / 2;
      if (B[mu] > A[i]) ma = mu;
      else mi = mu + 1;
    }
    A_a[i] = B_a[mi] + A_a[i + 1];
  }
  cout << A_a[0] << endl;
}

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

#include<algorithm>

using namespace std ;

typedef long long llong ;

typedef struct
{
	llong size ;
	llong value ;

} Data ;

#define N_MAX 500000
Data art[ N_MAX ] ;

/*
int cmp( const void *a ,const void *b )
{
	if( (( Data* )a )->size == (( Data* )b )->size )
	{
		return (( Data* )a )->value - (( Data* )b )->value ;
	}
	
	return (( Data* )a )->size - (( Data* )b )->size ;
}
*/

bool cmp( const Data& a ,const Data& b )
{
	return a.size == b.size ? a.value < b.value : a.size < b.size ;
}

inline llong max( llong a ,llong b )
{
	return a > b ? a : b ;
}


int main( void )
{
	int N ;
	scanf( "%d" ,&N ) ;

	int i ;
	for( i = 0 ; i < N ; ++i )
	{
		scanf( "%lld %lld" ,&art[ i ].size ,&art[ i ].value ) ;
	}

	/*
	qsort( art ,N ,sizeof( Data ) ,cmp ) ;	// ちゃんとsortできない！！
	qsort( art ,N ,sizeof( Data ) ,cmp ) ;
	*/

	sort( art ,art + N ,cmp ) ;

	llong min_size	= art[ 0 ].size		;
	llong sum_value	= art[ 0 ].value	;

	llong ans = art[ 0 ].value ;
	for( i = 1 ; i < N ; ++i )
	{
		llong value	= art[ i ].value	;
		llong size	= art[ i ].size		;

		llong tmp =  sum_value + value  - ( size -  min_size ) ;
		if( tmp < value )
		{
			ans = max( ans ,value ) ;

			sum_value	= value	;
			min_size	= size	;
		}

		else
		{
			ans = max( ans ,tmp ) ;

			sum_value += value ;
		}
	}

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

	return 0 ;
}


Measured memory_bytes: 10592
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;

int main(){
  string aa;
  string bb;
  string cc;
  int am;
  int ai = 0;
  int bm;
  int bi = 0;
  int cm;
  int ci = 0;
  char n = 'a';
  string ans;

  cin >> aa >> bb >> cc;

  am = aa.length();
  bm = bb.length();
  cm = cc.length();

  for( ; ; ){
    if(n == 'a'){
      if(am == 0){
        ans = 'A';
        break;
      }
      n = aa[ai];
      ai = ai + 1;
      am = am - 1;
    }else if(n == 'b'){
      if(bm == 0){
        ans = 'B';
        break;
      }
      n = bb[bi];
      bi = bi + 1;
      bm = bm - 1;
    }else if(n == 'c'){
    if(cm == 0){
      ans = 'C';
      break;
      }
      n = cc[ci];
      ci = ci + 1;
      cm = cm - 1;
    }
  }
  cout << ans;
}


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

int main() {
	int N, M;
	cin >> N >> M;

	priority_queue<int> que;

	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		que.push(tmp);
	}

	for (int i = 0; i < M; i++) {
		int tmp;
		tmp = que.top();
		tmp /= 2;
		que.pop();
		que.push(tmp);
	}

	long long int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += que.top();
		que.pop();
	}

	cout << sum << endl;
}

Measured memory_bytes: 892
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <time.h>
#include <stdio.h>

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

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mpa make_pair
#define all(a) a.begin(), a.end()

template<typename T>
void vdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		if (i == size - 1) {
			cout << da[i] << endl;
		}
		else {
			cout << da[i] << ' ';
		}
	}
}
template<typename T>
void vvdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		vdeb(da[i]);
	}
}

int merge(vector<int> &da, int le, int mi, int ri, int &co) {
	int n1 = mi - le;
	int n2 = ri - mi;
	vector<int> L(n1 + 1), R(n2 + 1);
	for (int i = 0;i < n1;i++) {
		L[i] = da[le + i];
	}
	for (int i = 0;i < n2;i++) {
		R[i] = da[mi + i];
	}
	L[n1] = INT_MAX;R[n2] = INT_MAX;
	int i = 0, j = 0;
	for (int k = le;k < ri;k++) {
		if (L[i] < R[j]) {
			da[k] = L[i];
			i++;
		}
		else {
			da[k] = R[j];
			j++;
			co += n1 - i;
		}
	}
	return co;
}

int mergesort(vector<int> &da, int le, int ri) {
	int ret = 0;
	if (le + 1 < ri) {
		int mi = (le + ri) / 2;
		ret += mergesort(da, le, mi);
		ret += mergesort(da, mi, ri);
		merge(da, le, mi, ri, ret);
	}
	return ret;
}


int n, ans = 100000;

int cal(vector<int> da) {
	return mergesort(da, 0, n);
}

const P DEFF = mpa(100000, -1);
vector<P> a(18,DEFF), b(18,DEFF), A(9, DEFF), B(9,DEFF);
vector<int> da(18);

void gen(int now, int po, vector<bool> &ju) {//po = 0から
	if (po == (n+1)/2) {
		int aa = 0, bb = 0;
		rip(i, n, 0) {
			if (ju[i]) {
				A[aa] = a[i];
				aa++;
			}
			else {
				B[bb] = b[i];
				bb++;
			}
		}
		sort(all(A));sort(all(B));
		da[0] = A[0].second;
		rip(i, n, 1) {
			if (i % 2 == 0) {
				if (A[i/2].first < b[da[i - 1]].first) return;
				da[i] = A[i/2].second;
			}
			else {
				if (B[i/2].first < a[da[i - 1]].first) return;
				da[i] = B[i/2].second;
			}
		}
		ans = min(ans, cal(da));
		//cout << ans << endl;
		//vdeb(da);
	}
	else {
		if (now >= 18) return;
		rip(i, n, now) {
			ju[i] = true;
			gen(i + 1, po + 1, ju);
			ju[i] = false;
		}
		return;
	}
}

int main() {
	cin >> n;
	/*rip(i, n, 0) {
		if (i % 2 == 0) cin >> a[i].first >> b[i].first;
		else cin >> b[i].first >> a[i].first;
	}*/
	rip(i, n, 0) {
		cin >> a[i].first;
	}
	rip(i, n, 0) {
		cin >> b[i].first;
	}
	rip(i, n, 0) {
		a[i].second = i;b[i].second = i;
		if (i % 2) swap(a[i], b[i]);
	}
	//sort(all(a)), sort(all(b));
	vector<bool> ju(n, false);
	gen(0, 0, ju);
	if (ans == 100000) cout << -1 << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	k := stdin.ReadInt()
	p := make([]float64, n)
	for i := 0; i < n; i++ {
		p[i] = stdin.ReadFloat64()
	}

	s := make([]float64, n+1)
	for i := 0; i < n; i++ {
		s[i+1] = s[i] + (1+p[i])*p[i]/2/p[i]
	}

	ans := 0.0
	for i := 0; i < n-k+1; i++ {
		ans = Max(ans, s[i+k]-s[i])
	}
	stdout.Println(ans)
}

func Max(a ...float64) float64 {
	v := a[0]
	for i := 1; i < len(a); i++ {
		if v < a[i] {
			v = a[i]
		}
	}
	return v
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


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

#define MAX 1000000001
long long ans = 0;

void merge(int A[], int left, int mid, int right){
    int n1 = mid-left;
    int n2 = right-mid;
    int L[n1+1];
    int R[n2+1];
    for(int i = 0; i < n1; i++) L[i] = A[left+i];
    for(int i = 0; i < n2; i++) R[i] = A[mid+i];
    L[n1] = MAX;
    R[n2] = MAX;

    int li = 0;
    int ri = 0;

    for(int i = left; i < right; i++){
        if(L[li] <= R[ri]){
            A[i] = L[li];
            li++;
        }else{
            A[i] = R[ri];
            ri++;
            ans += n1-li;
        }
    }
}

void mergeSort(int A[], int left, int right){
    if(left+1 < right){
        int mid = (left+right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(){
    int n;
    cin >> n;
    int A[n];
    for(int i = 0; i < n; i++)  cin >> A[i];
    mergeSort(A, 0, n);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4656
n = int(input())
a_lst = []
for i in range(n):
    a = int(input())
    a_lst.append(a)

sorted_a_lst = sorted(a_lst)
max_a = sorted_a_lst[-1]

for a in a_lst:
    if a == max_a:
        print(sorted_a_lst[-2])
    else:
        print(max_a)

Measured memory_bytes: 14152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}
 
int main()
{
    char b;
  	cin >> b;
  	switch(b){
      case'A':
        cout << 'T' << endl;
        break;
      case'T':
        cout << 'A' << endl;
        break;
      case'C':
        cout << 'G' << endl;
        break;
      case'G':
        cout << 'C' << endl;
        break;
    }
  	return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z,a,b;
    cin>>n;
    a = 1;b = 1;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        z = max(a/x+(a%x!=0),max(b/y+(b%y!=0),1ll));
        a = x*z;
        b = y*z;
    }
    cout<<a+b;
    


    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = NewScanner(os.Stdin, 1000000)

func main() {
	N := sc.readInt()
	W := sc.readInt()
	w := make([]int, 0)
	v := make([]int, 0)
	for i := 0; i < N; i++ {
		w = append(w, sc.readInt())
		v = append(v, sc.readInt())
	}

	current := make([]int, W+1)
	next := make([]int, W+1)

	for i := 0; i < N; i++ {
		for j := 0; j <= W; j++ {
			if j >= w[i] {
				next[j] = max(current[j-w[i]]+v[i], current[j])
			} else {
				next[j] = current[j]
			}
		}
		for j := 0; j <= W; j++ {
			current[j] = next[j]
		}
	}

	result := 0
	for _, v := range current {
		if v > result {
			result = v
		}
	}

	fmt.Println(result)
}

type Scanner struct {
	*bufio.Scanner
}

func (scn *Scanner) readInt() int {
	scn.Scanner.Scan()
	i, _ := strconv.Atoi(scn.Scanner.Text())
	return i
}

func NewScanner(r io.Reader, bufSize int) *Scanner {
	buf := make([]byte, bufSize)
	scn := bufio.NewScanner(r)
	scn.Buffer(buf, bufSize)
	scn.Split(bufio.ScanWords)
	return &Scanner{scn}
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 2304
a = int(input())
b = int(input())
c = int(input())
x = int(input())


count = 0
for i in range(a + 1):
    for j in range(b + 1):
        for l in range(c + 1):
            total = i * 500 + j * 100 + 50 * l
            if(total == x):
                count += 1

print(count)

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

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

map<string, int> mp1, mp2;

int main() {
    int n, m, ans = 0;
    cin >> n;
    rep(i, n) {
        string tmp; cin >> tmp;
        mp1[tmp]++;
    }
    cin >> m;
    rep(i, m) {
        string tmp; cin >> tmp;
        mp2[tmp]++;
    }
    for (auto s : mp1) {
        string tmp = s.first;
        int score = s.second;
        for (auto t : mp2) {
            if (tmp == t.first) score -= t.second;
        }
        ans = max(ans, score);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int x,y,i,j;
    while (cin >>x>>y) {
        if(x==0 && y==0) break;
        for (j=0; j<x; j++) {
            for (i=0; i<y; i++) {
                if (j ==0 || j == (x-1)) cout<<"#";
                else if(i == 0 || i==(y-1))cout << "#";
                else if (i >0 && i<(y-1))cout <<".";
            }
            cout<<endl;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1152
#include <iostream>

int main() {
  int x, y, z;
  int temp;

  std::cin >> x >> y >> z;

  if(y<x){
    temp = x;
    x = y;
    y = temp;
  }
  if(z<y){
    temp = y;
    y = z;
    z = temp;
  }
  if(y<x){
    temp = x;
    x = y;
    y = temp;
  }
  std::cout << x << " " << y << " " << z << std::endl;
  return 0;
}



Measured memory_bytes: 3104
x,k,d=map(int,input().split())
x=abs(x)
num1=x//d
if num1>k:
    print(x-(k*d))
else:
    k-=num1
    if k%2==0:
        print(x-(d*num1))
    else:
        print(abs(x-(d*(num1+1))))


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
 
int main (){
 
  long x, rx;
  cin >> x;
  rx = sqrt(x);
  
  int ans=100003;
  bool exist =0;
    for(int i=0; i<=100000-x; i++){
      exist =0;
    	for(int j=2; j<=rx; j++){
       		if((x+i)%j == 0){
          		exist =1;
              	break;
            }
        }
      if(exist==0){
        ans = x+i;
      	break;
      }
    }
  
 cout << ans << endl;
 
  
 
}

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

using namespace std;

int gcd(int a, int b) {
	int r;

	while(b > 0) {
		r = a % b;
		a = b;
		b = r;
	}

	return a;
}

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

int main() {
	int n;
	vector<int> a;

	cin >> n;

	a.resize(n);

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

	for(int i = 1;i < n;i++) {
		a[i] = lcm(a[i - 1], a[i]);
	}

	cout << a[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 3096