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

using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pll = pair<ll, ll>;
using tp3 = tuple<ll, ll, ll>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

vector<pll> prime_factorization(ll N) {
    map<ll, ll> mp;
    ll num = 2;
    while (num <= sqrt(N)) {
        while (N%num == 0) {
            mp[num]++;
            N /= num;
        }
        num++;
    }
    if (N != 1)mp[N]++;
    vector<pll> primes;
    for (auto[key, val] : mp)primes.push_back({ key,val });
    return primes;
}

vector<pll> enumarate_all_pair(vector<pll> primeP) {
    const int N = primeP.size();
    const int allway = 1 << N;

    vector<ll> primeL;
    for (auto[prime, mul] : primeP) {
        ll num = 1;
        rep(i, mul)num *= prime;
        primeL.push_back(num);
    }

    vector<pll> res;
    rep(way, allway) {
        pll p = { 1,1 };
        int buf = way;
        rep(i, N) {
            bool left = buf % 2 == 0;
            (left ? p.first : p.second) *= primeL[i];
            buf /= 2;
        }
        res.push_back(p);
    }
    return res;
}

ll extGCD(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}

ll safety_mul(ll a, ll b) {
    double da = log10(a);
    double db = log10(b);
    if (17 < da + db)return INFL;
    return a * b;
}

bool div2safe(ll x, ll y) {
    return x % 2 == 0 || y % 2 == 0;
}

int main()
{
    ll N;
    cin >> N;
    auto primes = prime_factorization(N);
    auto candidates = enumarate_all_pair(primes);

    ll res = INFL;
    for (auto[l, r] : candidates) {
        ll x, y;
        extGCD(r, l, y, x);

        if (y <= 0) {
            y += l;
            x -= r;
        }
        if (x >= 0) {
            y += l;
            x -= r;
        }
        rep(i, 10) {
            if (div2safe(x, y))break;
            y += l;
            x -= r;
        }

        assert(y > 0 && x < 0);
        ll tres = safety_mul(r, y);
        res = min(res, tres);
        /*
        const ll X = abs(x), Y = abs(y);
        {
            // yについて、正になるまでlを付加
            ll mul = 0;
            if (y <= 0) {
                mul = Y / l + 1;
            }
            else {
                mul = (Y - 1) / l;
            }

            ll newy = y % l;
            if (newy <= 0) {
                newy += l;
            }
            assert(0 < newy && newy <= l);
            res = min(res, safety_mul(r, newy));
        }
        */
    }
    cout << res - 1 << endl;
    return 0;
}


Measured memory_bytes: 3960
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())

def query(x):
  print(x)
  sys.stdout.flush()
  re = input()
  return 0 if re == "Male" else 1 if re == "Female" else -1

def clear_checker(a):
  if a == -1: exit()

rq = query(n-1)
clear_checker(rq)
lq = query(0)
clear_checker(lq)

l,r = 0,n-1

while True:
  mid = (l+r)//2
  midq = query(mid)
  clear_checker(midq)
  if ((mid-l) % 2 == 1 and lq == midq) or ((mid-l) % 2 == 0 and lq != midq):
    r,rq = mid,midq
  else:
    l,lq = mid,midq

    

Measured memory_bytes: 38944
#include <bits/stdc++.h>
#define FASTIO
#define endl "\n" // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n)             \
	for (int i = 0; i < (n); i++) \
		cin >> (c)[i];
#define exit_message(s) return 0 * printf(s)
#define show(c)           \
	for (auto i : (c))      \
		cout << i << " "; \
	cout << "\n";
#define display(c, n)           \
	for (int i = 0; i < (n); i++) \
		cout << (c)[i] << " ";    \
	cout << "\n";
#define forl(i, a, n) for (int (i) = (a); (i) < (n); (i)++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;

	return res;
}

const int N = 100 + 5;
const int SZ = 1e5 + 5;

int n, k;
int a[N];
int dp[N][SZ];
int cf[N][SZ];

int32_t main()
{
#ifdef FASTIO
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#endif
	// freopen("in.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	memset(dp, 0, sizeof dp);

	cin >> n >> k;
	forl(i, 1, n + 1)
	{
		cin >> a[i];
	}

	// dp[i][j] = No. of ways to distribute j candies amongst n chiddlers.

	for (int j = 0; j <= k; j++)
	{
		if (j <= a[1])
			dp[1][j] = 1;
		else
			dp[1][j] = 0;

		cf[1][j] = dp[1][j];
		if (j)
			cf[1][j] += cf[1][j - 1];
	}

	for (int i = 2; i <= n; i++)
	{
		for (int j = 0; j <= k; j++)
		{
			int l = max(0, j - a[i]);

			dp[i][j] = cf[i - 1][j];
			if (l)
				dp[i][j] = (dp[i][j] - cf[i - 1][l - 1] + mod) % mod;

			// for (int t = j; t >= max(0, j - a[i]); t--)
			// {
			// 	dp[i][j] += dp[i - 1][t];
			// }
			cf[i][j] = dp[i][j];
			if (j)
				cf[i][j] = (cf[i][j] + cf[i][j - 1]) % mod;
		}
	}

	int ans = dp[n][k];
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 81920
#include <stdio.h>
#include <math.h>

#define M 256
typedef long double ldbl;

int l[M], r[M];
int main(void)
{
    int n;
    while (scanf("%d", &n), n) {
        int i, S, A, C, s, a, c;
        ldbl H=256;
        for(i=0;i<n;++i) scanf("%d", l+i+1);
        for(s=0;s<16;++s) for(a=0;a<16;++a) for(c=0;c<16;++c) {
            int o[M]={0};
            ldbl h=0;
            r[0]=s;
            for(i=1;i<=n;++i) r[i]=(a*r[i-1]+c)%M;
            for(i=1;i<=n;++i) o[(l[i]+r[i])%M]++;
            for(i=0;i<M;++i) if (o[i]) h-=logl((ldbl)o[i]/n)*o[i]/n;
            if (H>h+1e-9) { H=h, S=s, A=a, C=c; }
        }
        printf("%d %d %d\n", S, A, C);
    }

    return 0;
}

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

char a[10];
int main(){
	cin >> a;

	for(int i = 0;i < 4;i++) {
		a[i] -= '0';
	}

	for(int i = 0;i < (1 << 3);i++) {

        int s = a[0];

		for(int j = 0;j < 3;j++) {
			if((i & (1 << j)) != 0) {
                s = s + a[j + 1];
			}else {
                s = s - a[j + 1];
			}
		}

		if(s == 7) {
			printf("%d",a[0]);
			for(int j = 0;j < 3;j++) {
				if((i & (1 << j)) != 0) {
					printf("+");
				}else {
					printf("-");
				}
				printf("%d",a[j + 1]);
			}
			printf("=7\n");
			break;
		}
	}
	return 0;
}

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

int main() {
	int K;
	while (cin >> K, K) {
		int sum = 0;
		for (int i = 0; i < K * (K - 1) / 2; i++) {
			int c;
			cin >> c;
			sum += c;
		}
		cout << sum / (K - 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
U=""

candidate=[]
count=0

for i in range(len(S)-len(T)+1):#Sの上を走る時のスタート地点
    for j in range(len(T)):#Tの上を走る
        if match(T[j],S[i+j]):
            count+=1
        else:
            count=0
            break#一つでも違ったら次のiへ
    if count==len(T):
        count=0
        U=S[:i]+T+S[i+len(T):]
        U=U.replace('?','a')
        candidate.append(U)
        
if len(candidate)==0:
    print('UNRESTORABLE')
else:
    candidate.sort()
    print(candidate[0])

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

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

    int n,ans,sum=0;
    cin>>n;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
                ans = __gcd(i,__gcd(j,k));
                sum += ans;
            }
        }
    }
    cout<<sum<<"\n";

    return 0;
}

Measured memory_bytes: 3600
"""
挿入ソート
"""
def insertion_sort(args):
    results = []
    for i in range(0, len(args)):
        v = args[i]
        j = i - 1
        while (j >= 0 and args[j] > v):
            args[j+1] = args[j]
            j -= 1
        args[j+1] = v
        results.append(args[:])
    return results

if __name__ == '__main__':
    n = int(input())
    args = list(map(int, input().split()))[0:n]
    results = insertion_sort(args)
    for result in results:
        print(' '.join(map(str, result)))



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

int main(){
    string s;
    cin>>s;
    stack<char> p;
    int ans=0;
    for(int i=0;i<s.size();i++){
        if(p.empty()){
            p.push(s[i]);
        }
        else if(s[i]!=p.top()){
            p.pop();
            ans+=2;
        }
        else{
            p.push(s[i]);
        }
    }
    
    cout<<ans<<endl;
}

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

using namespace std;

#define pb push_back
#define eb emplace_back
#define ll long long
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define ok puts("ok");
#define whatis(x) cerr << #x << " = " << x << endl;

const int N = (1 << 16) + 777;
const int inf = (int)1e9 + 7;
int mod = inf;

int n, m;
int dp[20][N];

int sum(int a, int b) {
  return (a + b) % mod;
}

int sub(int a, int b) {
  return (a - b + mod) % mod;
}

int mult(int a, int b) {
  return (a * 1LL * b) % mod;
}

int a[20], f[N], inv[N];

int binpow(int a, int n) {
  if (n == 0) return 1;
  if (n & 1) return a * 1LL * binpow(a, n - 1) % mod;
  int t = binpow(a, n >> 1);
  return t * 1LL * t % mod;
}

void precalc() {
  f[0] = inv[0] = 1;
  f[1] = inv[1] = 1;
  for (int i = 2; i < (1 << 16); i++) {
    f[i] = mult(f[i - 1], i);
    inv[i] = binpow(f[i], mod - 2);
  }
}

int cnk(int n, int k) {
  if (n < k) return 0;
  return mult(f[n], mult(inv[k], inv[n - k]));
}

main() {
  precalc();
  scanf("%d %d", &n, &m);
  dp[0][0] = 1;
  for (int i = 0; i < m; i++) {
    scanf("%d", &a[i]);
  }
  reverse(a, a + m);
  for (int i = 0; i < m; i++) {
    for (int mask = 0; mask < (1 << n); mask++) {
      if (dp[i][mask] < 1) continue;
      dp[i + 1][mask] = sum(dp[i + 1][mask], dp[i][mask]);
      for (int j = 0; j < n; j++) {
        if ((mask >> j) & 1 ^ 1) {
          dp[i + 1][mask + (1 << j)] = sum(dp[i + 1][mask + (1 << j)], mult(dp[i][mask], mult(cnk((1 << n) - mask - a[i], (1 << j) - 1), f[1 << j])));
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i < (1 << n); i++) {
    if (__builtin_popcount(i) % 2 == 0) {
      res = sum(res, mult(dp[m][i], f[(1 << n) - i - 1]));
    } else {
      res = sub(res, mult(dp[m][i], f[(1 << n) - i - 1]));
    }
  }
  res = mult(res, (1 << n));
  printf("%d", res);
}


Measured memory_bytes: 4352
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

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

    usize n;
    std::cin >> n;
    vec<i64> a(n);
    for (i64& x: a) std::cin >> x;
    std::sort(ALL(a));

    auto is_ok = [&](usize p) -> bool {
        auto b = a;
        std::swap(b.front(), b.at(p));
        for (usize i=0; i<n-1; i++) {
            if (b.at(i)*2 < b.at(i+1)) {
                return false;
            }
            b.at(i+1) += b.at(i);
        }
        return true;
    };

    if (is_ok(0)) {
        std::cout << n << '\n';
        return 0;
    }
    usize l=0, r=n-1;
    while (1<r-l) {
        usize c=l+(r-l)/2;
        (is_ok(c) ? r : l) = c;
    }
    usize ans = n - r;
    std::cout << ans << '\n';
}


Measured memory_bytes: 1792
{-# LANGUAGE BangPatterns #-}
import Control.Arrow (second)
import Control.Monad
import Control.Monad.Fix
import Data.Foldable (foldl')
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread i v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite i a v = accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

uswap :: VUM.Unbox a => Int -> Int -> VUM.IOVector a -> VUM.IOVector a
uswap i j v = accursedUnutterablePerformIO $ VUM.unsafeSwap v i j >> return v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw v = accursedUnutterablePerformIO $ VU.unsafeThaw v

newtype UnionFind = UnionFind (VUM.IOVector Int, VUM.IOVector Int)

findUF :: UnionFind -> Int -> Int
findUF (UnionFind (elems, _)) k = fix
  ( \f (elems, k, path) -> case uread k elems of
    n | n == k -> {- foldl' (\acc p -> uwrite p n acc) elems path `seq` -}n
    n -> f (elems, n, n : path)
  )
  (elems, k, [k])

sizeUF :: UnionFind -> Int -> Int
sizeUF (UnionFind (_, sizes)) i = uread i sizes

uwriteElem :: Int -> Int -> UnionFind -> UnionFind
uwriteElem i a (UnionFind (elem, sizes)) = UnionFind (uwrite i a elem, sizes)

uwriteSize :: Int -> Int -> UnionFind -> UnionFind
uwriteSize i a (UnionFind (elem, sizes)) = UnionFind (elem, uwrite i a sizes)

unionUF :: UnionFind -> Int -> Int -> (UnionFind, Int)
unionUF uf@(UnionFind (elem, sizes)) i j =
  let pi  = findUF uf i
      pj  = findUF uf j
      si  = uread pi sizes
      sj  = uread pj sizes
      sij = si + sj
  in  if pi == pj
      then
        (uf, 0)
      else
        let (t1, t2) = if si < sj then (pi, pj) else (pj, pi)
        in  ( UnionFind (uwrite t1 t2 elem, uwrite t1 0 $ uwrite t2 sij sizes)
            , si * sj
            )

comb2 k = k * (k - 1) `div` 2

solve :: Int -> Int -> VU.Vector (Int, Int) -> VU.Vector Int
solve n m abs = ufreeze $ (\(_, _, acc) -> acc) $ VU.foldr'
  go
  (group, 0, accursedUnutterablePerformIO $ VUM.replicate m 0)
  abs
 where
  go (a, b) (uf, k, acc) =
    let (uf', d) = unionUF uf a b
        prev     = if k == 0 then 0 else uread (k - 1) acc
    in  (uf', k + 1, uwrite k (prev + d) acc)

  nC2 = comb2 n

  group :: UnionFind
  group = UnionFind
    (uthaw $ VU.enumFromN 0 n, accursedUnutterablePerformIO $ VUM.replicate n 1)

main = do
  let readInt = fmap (second B.tail) . B.readInt

  nm  <- VU.unfoldrN 2 readInt <$> B.getLine
  abs <- VU.replicateM
    (nm VU.! 1)
    (   (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
    )

  let solutions = solve (nm VU.! 0) (nm VU.! 1) abs
  let nC2       = comb2 $ nm VU.! 0

  mapM_ (print . (nC2 -) . (solutions VU.!)) [nm VU.! 1 - 2, nm VU.! 1 - 3 .. 0]
  print nC2


Measured memory_bytes: 34044
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
using namespace std;
#define mod 1000000007

int main(){
    int n,y;cin>>n>>y;
    int n1=0,n2=0,k;
    for(int i=0;i<=n;i++){
        n1=y-i*10000;
        if(n1<0)break;
        for(int j=0;j<=n-i;j++){
            n2=n1-j*5000;
            if(n2<0)break;
            k=n2/1000;
            if(i+j+k==n){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
                
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N; cin >> N;
	vector<long long>A(N);
	for (long long i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	long long ans = 0;
	for (long long i = 0; i < N; i += 2) {
		if (A.at(i) % 2 != 0) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  string s;
  cin >> s;
  int count = 0;
  REP(i, s.length())
  {
    if (s[i] == 'R')
      count++;
    else
      count--;
  }
  cout << (0 < count ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<20)
#define LLINF (1LL<<60)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int n,m,q,ans=0;
vector<int> a,b,c,d;

void dfs(vector<int> A){
    if(A.size()==n+1){
        int now=0;
        rep(i,q){
            if(A[b[i]]-A[a[i]]==c[i])now+=d[i];
        }
        ans=max(ans,now);
        return;
    }
    A.pb(A.back());
    while(A.back()<=m){
        dfs(A);
        A.back()++;
    }
}

int main(){
    cin>>n>>m>>q;
    a=b=c=d=vector<int>(q);
    rep(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    dfs(vector<int>(1,1));
    cout<<ans;
    return 0;
}


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

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

    for (int i=1; i<4; i++) {
        n = A * B * i;
        if (n % 2 == 1) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())

if a == 5:
    if b == 5:
        if c == 7:
            print("YES")
        else:
            print("NO")
    elif b == 7:
        if c == 5:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
elif a == 7:
    if b == 5:
        if c == 5:
            print("YES")
        else:
            print("NO")
    elif b == 5:
        if c == 7:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
else:
    print("NO")


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true) {
            String Cards = sc.next();
            int i, j;
            int l = Cards.length();
            char w[] = new char[l];
            char R[] = new char[l];
            for (i = 0; i < l; i++) {
                w[i] = Cards.charAt(i);
            }
            if(w[0] == '-') break;
            int m = sc.nextInt();
            for (i = 0; i < m; i++) {
                int h = sc.nextInt();
                for (j = 0; j < l; j++) {
                    if (j < h) {
                        R[j] = w[j];
                    } else {
                        w[j - h] = w[j];
                    }
                }
                for (j = 0; j < h; j++) {
                    w[l - h + j] = R[j];
                }
            }
            for (i = 0; i < l; i++) {
                System.out.printf("%c", w[i]);
            }
            System.out.printf("\n");
        }
    }
}



Measured memory_bytes: 26396
"use strict";
function main(input) {
    var line = input.split(/\r?\n/g);
    const A = line[1].split(" ").map(Number);
    var flg = true;
    for (var i in A)
        if (!(A[i] % 2) && A[i] % 3 && A[i] % 5) {
            flg = false;
            break;
        }
    console.log(flg ? "APPROVED" : "DENIED");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7496
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
typedef long long LL;
string s;
LL A[5] = {0};// A[0]:M  A[1]:A  A[2]:R  A[3]:C  A[4]:H
int Method[10][3] = {//10种选法 
	{0,1,2},{0,1,3},{0,1,4},{0,2,3},{0,2,4},{0,3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4}
} ;

int main(){
//	freopen("in26.txt","r",stdin);
	int n;
	long long ans = 0;
	scanf("%d", &n);
	while(n--){
		cin>>s;
		switch(s[0]){
			case'M':
				A[0]++;
				break;
			case'A':
				A[1]++;
				break;
			case'R':
				A[2]++;
				break;
			case'C':
				A[3]++;
				break;
			case'H':
				A[4]++;
				break;
		}
	}
	for(int i=0;i<10;i++){
		ans += A[Method[i][0]]*A[Method[i][1]]*A[Method[i][2]];
	} 
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] X = new int[N][D];
		for(int i = 0;i < N;i++) {
			for(int  j = 0;j < D;j++) {
				X[i][j] = Integer.parseInt(sc.next());
			}
		}
		sc.close();
		int ans = 0;
		for(int i = 0;i < N;i++) {
			for(int j = i+1;j < N;j++) {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    R, C, K, *RCV = map(int, read().split())

    item = [[0] * C for _ in range(R)]
    for r, c, v in zip(*[iter(RCV)] * 3):
        item[r - 1][c - 1] = v

    dp = [0] * (C + 1)
    for i in range(R):
        dp, dp_prev = [0] * (C + 1), dp
        v = [0] * 4
        for j in range(C):
            for k in range(4):
                if v[k] < dp_prev[j + 1]:
                    v[k] = dp_prev[j + 1]
            if item[i][j] > 0:
                for k in range(2, -1, -1):
                    if v[k + 1] < v[k] + item[i][j]:
                        v[k + 1] = v[k] + item[i][j]
            dp[j + 1] = v[3]

    print(dp[C])

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 198404
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()
p = nl()
c = nl()

for i in range(n):
  p[i]-=1

ans = -10**(18)
for si in range(n):
  x = si
  s = []
  tot = 0
  while(True):
    x = p[x]
    s.append(c[x])
    tot += c[x]
    if x == si:
      break
  l = len(s)
  t = 0
  for i in range(l):
    t += s[i]
    if i+1>k:
      break
    now = t
    if tot > 0:
      e = (k-(i+1))//l
      now += tot*e
    ans = max(ans,now)

print(ans)

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

using namespace std;
typedef long long ll;

ll N;
ll A[100001];
deque<ll> v;

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    v.push_back(A[0]);
    for(int i=1;i<N;i++){
        auto itr = lower_bound(v.begin(),v.end(),A[i]);
        if(itr == v.begin()) v.push_front(A[i]);
        else *(itr-1) = A[i];
    }
    cout << v.size() << endl;
    return 0;
}

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

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

    for(int i=0;i<n-1;i++){
        if(a[i]+1==a[i+1]) 
          count+=c[a[i]-1];
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
//#include<iostream>
using namespace std;

int n,m;
#define maxn 200011
struct Edge{int to,next;}edge[maxn];int first[maxn],le=2;
void in(int x,int y) {Edge &e=edge[le];e.to=y;e.next=first[x];first[x]=le++;}
void insert(int x,int y) {in(x,y);in(y,x);}
bool flag=0;
bool vis[maxn],mark[maxn];
int hei,bai;
bool dfs(int x)
{
	if (!mark[x]) hei++;else bai++;
	vis[x]=1;
	for (int i=first[x];i;i=edge[i].next)
	{
		const Edge &e=edge[i];
		if (vis[e.to])
			if (mark[e.to]==mark[x]) return 0;else;
		else
		{
			mark[e.to]=!mark[x];
			if (!dfs(e.to)) return 0;
		}
	}
	return 1;
}
int x,y;
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) scanf("%d%d",&x,&y),insert(x,y);
	hei=0,bai=0;
	mark[1]=0;
	if (dfs(1)) printf("%lld\n",1ll*hei*bai-m);
	else printf("%lld\n",1ll*n*(n-1)/2-m);
	return 0;
}

Measured memory_bytes: 2560
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def main():
    l, r = list(map(int, input().split()))
    diff = r-l
    if diff >= 2018:
        return 0

    else:
        min_ = 2 ** 20
        # l の商と余り
        p = l // 2019 ; q = l % 2019
        for xi in range(l, r):
            qi = (q + (xi - l)) % 2019
            if qi == 0:
                return 0
            for xj in range(xi+1, r+1):
                qj = (q + (xj - l)) % 2019
                if qj == 0:
                    return 0
                else:
                    qij = (qi * qj) % 2019
                    if qij < min_:
                        min_ = qij

    return min_

print(main())

Measured memory_bytes: 9108
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,n,d;
    cin>>n>>d;
    ans=n/(2*d+1);
    ans+=(n%(2*d+1)>0)?1:0;

    cout <<ans<<endl;

    return 0;

}

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

int N, T, L, B;
int type[101];			//type[i] = 0:no, 1:lose, 2:back
double dp[101][101];	//dp[turn][pos] = probably.

void init() {
	for (int i = 0; i < 101; i++) type[i] = 0;
	for (int i = 0; i < 101; i++) for (int j = 0; j < 101; j++) dp[i][j] = 0;
}

int main() {
	int i, j, k, p;
	
	while (cin >> N >> T >> L >> B) {
		if (!N) break;
		init();
		for (i = 0; i < L; i++) {
			cin >> p;
			type[p] = 1;
		}
		for (i = 0; i < B; i++) {
			cin >> p;
			type[p] = 2;
		}
	
		dp[0][0] = 1;
		for (i = 0; i < T; i++) {
			for (j = 0; j < N; j++) {
				for (k = 1; k <= 6; k++) {
					int npos = j + k;
					if (npos > N) npos = 2 * N - npos;
					if (type[npos] == 0) {
						dp[i + 1][npos] += dp[i][j] * 1 / 6.0;
					}
					if (type[npos] == 1) {
						dp[i + 2][npos] += dp[i][j] * 1 / 6.0;
					}
					if (type[npos] == 2) {
						dp[i + 1][0] += dp[i][j] * 1 / 6.0;
					}
				}
			}
			dp[i + 1][N] += dp[i][N];
		}
		
		printf("%.14f\n", dp[T][N]);
	}
	return 0;
}

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

table = [[0]*10 for _ in range(10)]
for i in range(1,n+1):
  t = int(str(i)[0])
  b = i%10
  table[t][b] += 1
  
ans = 0  
for i in range(10):
  for j in range(10):
    ans += table[i][j] * table[j][i]
    
print(ans)    

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string op;
    cin >> op;
    int n = op.size();
    int ans = 0;
    if(op[0] == op[n - 1])
    {
        ans = n - 3;
    }
    else
    {
        ans = n - 2;
    }
    
    if(ans % 2)
    {
        cout << "First" << endl;
    }
    else
    {
        cout << "Second" << endl;
    }
    
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();
            var c = n.ToCharArray();

            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] == '1')
                {
                    c[i] = '9';
                }
                else
                {
                    c[i] = '1';
                }
            }

            Console.WriteLine(new string(c));
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int n;
    cin >> n;
    vector<ll> a(n),ap(n),am(n);
    map<ll, ll> apm, amm;
    rep(i,0,n-1){
        cin >> a[i];
        ap[i] = (i+1) + a[i];
        am[i] = (i+1) - a[i];
        apm[ap[i]]++;
        amm[am[i]]++;
    }
    ll ans = 0;
    for(auto itr = apm.begin(); itr != apm.end(); ++itr) {
        //first:key, second:value
        ans += itr->second * amm[itr->first];
        // cout << itr->first << " " << itr->second << endl;
    }
    

    // SORT(ap);
    // SORT(am);

    // vecprint(ap);
    // vecprint(am);
    // int apn = 0,amn = 0;
    // int ans = 0;
    // while(apn != n-1 || amn != n-1){
    //     // cout << apn << " " << amn << endl;
    //     if(ap[apn] == am[amn]){
    //         ans++;
    //         if(apn == n-1)amn++;
    //         else if(amn != n-1 && am[amn] == am[amn+1])amn++;
    //         else apn++;
    //         continue;
    //     }
    //     if(ap[apn] > am[amn]){
    //         if(amn == n-1)break;
    //         amn++;
    //         continue;
    //     }
    //     if(ap[apn] < am[amn]){
    //         if(apn == n-1)break;
    //         apn++;
    //         continue;
    //     }
    // }



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

    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    int t[m], c[m];
    for(int i = 0; i < m; i++)  cin >> t[i] >> c[i];
    int ret = -1;
    for(int i = 0; i < 1000; i++){
        string s = to_string(i);
        if(s.length() != n) continue;
        bool val = true;
        for(int j = 0; j < m; j++)  val &= s[t[j]-1]-'0'==c[j];
        if(val){
            ret = i;
            break;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {


        Scanner scan = new Scanner(System.in);

        for (int i = 1; i<=5; i++ ) {
            int x = scan.nextInt();
            if (x == 0) {
                System.out.println(i);
                break;
            }

        }


    }


}

Measured memory_bytes: 35580
/**
 *   author: malviyanshiv
 *   created: 09 January 2019  23:27:27
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define MAX 100005

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

void fastscan(int &x){
    bool neg=false;
    register int c;
    x =0;
    c=getchar();
    if(c=='-'){
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}

void optimizeIO(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}

vector< vector<ll> > dp(101, vector<ll>(MAX, -1));
int wi[101];
int vi[101];

ll cal(int idx, int w){
    if( idx == 0 || w == 0 )
        return 0;
    if( dp[idx][w] != -1 )
        return dp[idx][w];
    if( wi[idx] > w )
        return dp[idx][w] = cal(idx-1, w);
    else
        return dp[idx][w] = max( vi[idx] + cal(idx-1, w-wi[idx]), cal(idx-1, w));
}

int main(){
	optimizeIO();
    int n, w;
    cin >> n >> w;
    REP(i, 1, n+1)
        cin >> wi[i] >> vi[i];

    cout << cal(n, w) << endl;

	return 0;
}

Measured memory_bytes: 80256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int N, A, B;
  cin >> N >> A >> B;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int temp = i;
    int tempsum = 0;
    while (temp > 0) {
      tempsum += temp % 10;
      temp /= 10;
    }
    if (tempsum >= A and tempsum <= B) ans += i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    double thresh = sum / (4.0 * m);
    sort(a.begin(), a.end(), greater<int>());
    for (int i = 0; i < m; i++) {
        if ((double)a[i] < thresh) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

int n, k;
int de[200005];
int d = 0;
int ans = 0;

int cmp(const void *x, const void *y);

int main()
{
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);

        if (de[a] == 0) {
            d++;
        }
        
        de[a]++;
    }

    qsort(de, n + 1, sizeof(int), cmp);

    for (int i = 1; i <= n; i++) {
        if (de[i] != 0 && d > k) {
            d--;
            ans += de[i];
        }
    }

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

    return 0;
}

int cmp(const void *x, const void *y)
{
    if (*(int *)x > *(int *)y) {
        return 1;
    } else if (*(int *)x == *(int *)y) {
        return 0;
    } else {
        return -1;
    }
}


Measured memory_bytes: 1788
a = input()
b = 0
c = 0
for i in range(len(a)):
    if i == 0 and a[i] != "A":
        print("WA")
        exit()
    elif 2 <= i <= len(a)-2:
        if a[i] == "C":
            b += 1
    if a[i].lower() == a[i]:
        c += 1
if b == 1 and c == len(a)-2:
    print("AC")
else:
    print("WA")


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

int calculate_f(int x,int y,int z){
    return x*x + y*y + z*z + x*y + y*z + z*x;
}

void make_result_array(int &n,vector<int> &result_array){
    int up = sqrt(n);
    for(int i=1; i<=up ; i++){
        for(int j=1; j<= up; j++){
            for(int k=1; k<= up;k++){
                int result = calculate_f(i,j,k);
                if(result <= n){
                    result_array.at(result-1) += 1;
                }
            }
        }
    }
}

int main(){
    int n;
    cin >> n;
    vector<int> array(n);
    make_result_array(n,array);
    for(int i=0; i<n; i++){
        cout << array.at(i) << endl;
    }
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#pragma region DEBUG
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
lli arr[MAX]; 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    lli t;
    t =1 ;
    while(t--){
        string s;
        cin>>s;
        lli sum = 0;
        for(lli i = 0; i<s.length(); i++){
            sum += s[i] - '0';
        }
        if(sum%9)
            cout<<"No"<<endl;
        else{
            cout<<"Yes"<<endl;
        }
      
        
    }
}

Measured memory_bytes: 3744
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int dx[5]={0,1,-1,0,0};
int dy[5]={0,0,0,1,-1};
char mp[105][105];
int h,w;
int vis[105][105];
int ans;
void dfs(int x,int y,char c)
{
    for(int i=1;i<=4;i++)
    {
        int xx=x+dx[i];
        int yy=y+dy[i];
        if(xx>0&&xx<=h&&yy>0&&yy<=w&&!vis[xx][yy]&&mp[xx][yy]==c)
        {
            vis[xx][yy]=1;
            dfs(xx,yy,c);
        }
    }
}
int main()
{
    
    while(1)
    {
    	scanf("%d%d",&h,&w);
    	if(h==0&&w==0)
    	{
    		break;	
    	}
        getchar();
        for(int i=1;i<=h;i++)
        {
            scanf("%s",mp[i]+1);
        }
        memset(vis,0,sizeof vis);
        ans=0;
        for(int i=1;i<=h;i++)
        {
            for(int j=1;j<=w;j++)
            {
                if(!vis[i][j])
                {
                    ans++;
                    dfs(i,j,mp[i][j]);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}







Measured memory_bytes: 3304
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int32_t main()
{
    
    // w(t)
    {
        char c;
        cin>>c;
        if( c >= 'a' and c   <= 'z') cout<<'a';
        else cout<<'A';
    }
    return 0;
}

Measured memory_bytes: 3600
ret =[-1 for i in range(26)]

n=int(input())
s=input()
for j in range(26):
  ret[j]=s.count(chr(97+j))
   
for i in range(n-1):
  s=input()
  for j in range(26):
    ret[j]=min(ret[j],s.count(chr(97+j)))
    
for i in range(26):
  print(chr(97+i)*ret[i],end="")
print()

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

int main(){
	int value;
	double quantity;
	char c;
	int total = 0;
	double count = 0;
	double sales = 0;
	while(cin >> value >> c >> quantity){
		total += value * quantity;
		sales += quantity;
		count++;
	}
	if(count != 0){
		cout << total << endl;
		cout << (int)((sales / count) + 0.5) << endl;
	}else {
		cout << 0 << endl;
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int k,i=0,a=1,res=0;
int main()
{
	;;;;;
    cin>>k;
    while (i<=k)
    {
        res+=a*7;
        res%=k;
        a=a*10%k;
        i++;
        if (res==0) break;
    }
    if (i<=k) cout<<i<<endl;
    else cout<<-1<<endl;
	return 0;
}

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

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ll n, k;
  cin >> n >> k;
  if (n <= k) {
    ll ans = min(n, k-n);
    cout << ans << endl;
    return 0;
  }
  ll x = n / k;
  ll ans = min(n - k*x, k*(x+1)-n);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

const int maxn = 310;
int cnt[5], n;
double dp[maxn][maxn][maxn];

int main()
{
    ios::sync_with_stdio(false);
    cout << setprecision(9) << fixed;
    cin >> n;
    for (int i = 1, x; i <= n; i++)
        cin >> x, ++cnt[x];
    for (int k = 0; k <= n; k++)
        for (int j = 0; j <= n; j++)
            for (int i = 0; i <= n; i++)
                if (i || j || k)
                {
                    int s = i + j + k;
                    if (i)
                        dp[i][j][k] += (dp[i - 1][j][k] + 1) * i / s;
                    if (j)
                        dp[i][j][k] += (dp[i + 1][j - 1][k] + 1) * j / s;
                    if (k)
                        dp[i][j][k] += (dp[i][j + 1][k - 1] + 1) * k / s;
                    dp[i][j][k] += 1.0 * (n - s) / s;
                }

    cout << dp[cnt[1]][cnt[2]][cnt[3]];

    return 0;
}


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


public class Main {
	
	public static void main(String[] args) throws Exception {
		
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int n = Integer.parseInt(br.readLine()); 
        
        boolean odd = false;
        
        
        String str = br.readLine();
        String boxstr[] = str.split(" ");
        int box[] = new int[n+1];
        box[n] = 0;
        for(int i = 0;i<n;i++){
        box[i] = Integer.parseInt(boxstr[i]);
        box[i] = -box[i];
   //     System.out.println(box[i]);
     //   
        }
        Arrays.sort(box);
        
        for(int i = 0 ;i<n+1;i++){
 //       	System.out.print(box[i]+" ");
        }
        

        int sum1 = 0;
        int sum2 = 0;
        int box1[] = new int [n+1/2];
    	int box2[] = new int[n+1/2];
        for(int i = 0;i<n+1/2;i+=2){
        	box1[i] = box[i];
        	box2[i] = box[i+1];
        	
        //	System.out.println(box1[i]+"-"+box2[i]);
        	sum1 += box1[i];
        	sum2 += box2[i];
        }
        System.out.println(-(sum1-sum2));
        
        
        
        
        
        
	}
}

Measured memory_bytes: 20692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=1001001001001001;
const int Inf=1001001001;
const int mod=1000000007;
int main(){
    int l,m=-1;cin>>l;
    vi v;
    while(l!=0){
        if((l&1)==1){
            v.pb(1);
            m++;
        }
        else v.pb(0);
        l>>=1;
    }
    int n=v.size();
    m+=(n-1)*2;
    cout<<n<<' '<<m<<endl;
    int sum=1;
    rep(i,n-1){
        int j=n-i-2;
        cout<<i+1<<' '<<i+2<<' '<<0<<endl;
        cout<<i+1<<' '<<i+2<<' '<<sum<<endl;
        sum*=2;
        if(v[j]==1){
            cout<<1<<' '<<i+2<<' '<<sum<<endl;
            sum++;
        }
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 2e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int N, opt[(int)2e5 + 5], MOD = 998244353;
pair<int, int> info[(int)2e5 + 5];
stack<pair<int, int>> nxt;

int main(){
  FAST_IO
  cin >> N;
  for(int rep = 0, x, d; rep < N; ++rep){
    cin >> x >> d;
    info[rep] = MP(x, d);
  }
  sort(info, info + N);

  nxt.push(MP(N, INF));
  opt[N] = 1;

  for(int idx = N - 1, reach, r; idx >= 0; --idx){
    reach = info[idx].F + info[idx].S;
    while(nxt.top().S < reach) nxt.pop();

    r = nxt.top().F;
    opt[idx] = (opt[idx + 1] + opt[r]) % MOD;
    nxt.push(MP(idx, info[idx].F));
  }

  cout << opt[0];
  return 0;
}


Measured memory_bytes: 3456
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   char[] c = sc.next().toCharArray();
   boolean b = true;
   int count=1;
   Arrays.sort(c);
   for(int i = 1;i<c.length;i++)
   {
     if(c[i]==c[i-1]) 
     {
       count++;
     }
     else
     {
       if(count%2!=0)
       {
         b = false;
         break;
       }
       else
       {
         count=1;
       }
     }
   }
   if(count%2!=0) b= false;
   String ans;
   if(b) ans = "Yes";
   else ans = "No";
   System.out.println(ans);
 }
}

Measured memory_bytes: 21716