akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

class UnionFind {
private:
	vector<Int> data;

public:
	Int root(Int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	UnionFind(Int size) : data(size, -1) { }
	bool same(Int x, Int y) { return root(x) == root(y); }
	Int size(Int x) { return -data[root(x)]; }

	bool unite(Int x, Int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
			return true;
		}
		else {
			return false;
		}
	}
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, M;
	cin >> N >> M;

	UnionFind f(N);

	vector<Int> seen(N);//決まっていれば1
	Int x, y,z;
	for (Int i = 0; i < M; i++) {
		cin >> x >> y>>z;
		x--;
		y--;
		f.unite(x, y);
	}
	
	Int cnt = 0;
	Int temp;
	for (Int i = 0; i < N; i++) {
		temp = f.root(i);
		if (seen[temp]) {
			seen[i] = 1;
			continue;
		}
		else {
			seen[temp] = 1;
			seen[i] = 1;
			cnt++;
		}
	}

	cout << cnt << "\n";

}


Measured memory_bytes: 1792
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        //System.out.println(a);
        
        //int b = sc.nextInt();
        long temp = 0;
        for(long i=1; i <= a ; i++) {
            if( i%3 == 0 || i%5 == 0 || i%15 == 0){
            }else{
                temp = temp + i;
                //System.out.println(i);
            }
        }
        //System.out.println(String.format("%d",(int)temp));
        System.out.println(temp);

    }
}

Measured memory_bytes: 35540
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  getc (map (solve . wrds toDbl)) >>= mapM_ print

solve :: [Double] -> Double
solve [a, l, x] = abecd a l x
  where
    abc a l = sqrt (4 * l ^ 2 - a ^ 2) * a / 4
    adc l x = sqrt (2 * l * x + x ^ 2) * l / 4
    abecd a l x = abc a l + 2 * (adc l x)
    
toDbl :: String -> Double
toDbl = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

getc :: ([String] -> a) -> IO a
getc f = f . lines <$> getContents

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

using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;

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

  vector<int> ans(n, 0);
  for (int i = 0; i < m; i++) {
    vector<int> b(n);
    for (int j = 0; j < n; j++) {
      cin >> b[j];
      b[j]--;
    }

    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (j == a[i]) continue;
      ans[j] += b[j] == a[i];
      cnt += b[j] != a[i];
    }
    ans[a[i]] += cnt + 1;
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>

using namespace std;

bitset<1000000001> bs;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    bs[a] = !bs[a];
  }
  cout << bs.count() << endl;
}

Measured memory_bytes: 122112
#include<bits/stdc++.h>
using namespace std;
int main(){long n,m,k;cin>>n>>m>>k;
       vector<long> a(n),b(m);int p=0;
       for(long i=0;i<n;i++)cin>>a.at(i);
           for(long i=0;i<m;i++)cin>>b.at(i);
     long s=0,c=-1;
           for(long i=0;i<n&&s<=k;i++){if(s+a.at(i)<=k){c++;s+=a.at(i);}else break;}
          p=c+1;
for(long i=0;i<m;i++){s+=b.at(i);while(s>k&&c>=0){s-=a.at(c);c--;}
                            if(s>k)break;if(c+i+2>p)p=c+i+2;}
cout<<p<<endl;} 

Measured memory_bytes: 6372
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int a, b, c, d, p;

    cin >> a >> b >> c >> d >> p;

    int sum1, sum2;

    sum1 = a * p;

    if (p > c) {
        sum2 = b + d * (p - c);
    } else {
        sum2 = b;
    }

    cout << min(sum1, sum2) << endl;

    return 0;

}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

// ^= -> ビットごとの排他的論理和を計算する


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>a(n),b(n);
	int suma = 0;
	int sumb = 0;
	rep(i, n) {
		cin >> a[i];
		suma += a[i];
	}
	rep(i, n) {
		cin >> b[i];
		sumb += b[i];
	}
	int k = sumb - suma;
	int cnt1=0, cnt2=0;
	rep(i, n) {
		if (a[i] > b[i])cnt1 += a[i] - b[i];
		else cnt2 += (b[i] - a[i] + 1) / 2;
	}
	if (k < cnt1 || k < cnt2)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 384
import heapq
n, m = map(int, input().split())
a = []
for i in list(map(int, input().split())):
    heapq.heappush(a,-i)

for _ in range(m):
    p = heapq.heappop(a)
    heapq.heappush(a, int(p/2))

print(-sum(a))

Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s; cin >> s;
  if (s=="RRR"){cout << 3;}
  else if (s=="SSS"){cout << 0;}
  else if (s=="RRS" || s=="SRR"){cout << 2;}
  else {cout << 1;}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N; cin >> N;
    N %= 10;

    switch (N)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        OUT("hon")
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        OUT("pon")
        break;
    case 3:
        OUT("bon");
        break;
    default:
        break;
    }

    return 0;
}

Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
#define rep(i,n) for(ll i = 0;i<(ll)n;i++)
using namespace std;
typedef long long ll;
static const int MAX = 50;
static const long long INFTYL = 9223372036854775807;
ll mod = 1000000007;

int main()
{
	int N;
	string S1, S2;
	cin >> N >> S1 >> S2;

	string T;
	int index = 0;
	while (true)
	{
		if (S1[index] == S2[index]) {
			T += 'X';
			index++;
		}
		else {
			T += 'Y';
			index += 2;
		}

		if (index >= N) {
			break;
		}
	}

	//cout << T << endl;
	ll a = (T[0] == 'X') ? 3 : 6;

	rep(i, T.size() - 1) {
		if (T[i] == 'X') {
			if (T[i + 1] == 'X') {
				a = a * 2 % MOD;
			}
			else {
				a = a * 2 % MOD;
			}
		}
		else {
			if (T[i + 1] == 'X') {
				a = a * 1 % MOD;
			}
			else {
				a = a * 3 % MOD;
			}
		}
	}

	cout << a << endl;
	return 0;
}

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


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

Measured memory_bytes: 256
package main

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

func main() {
	N, K := ReadInt(), ReadInt()
	A := ReadInts(N)

	sort.Ints(A)
	ans := 0
	for i := 0; i < N; i++ {
		if i >= K-1 {
			ans += A[i] * ModCombination(i, K-1)
			ans %= Mod
		}
	}
	for i := 0; i < N; i++ {
		if N-i-1 >= K-1 {
			ans += Mod - A[i]*ModCombination(N-i-1, K-1)%Mod
			ans %= Mod
		}
	}
	fmt.Println(ans)
}

const Mod = int(1e9) + 7

func ModAdd(a, b int) int  { return ((Mod + a%Mod) + (Mod + b%Mod)) % Mod }
func ModMul(a, b int) int  { return (Mod + a%Mod) * (Mod + b%Mod) % Mod }
func ModInverse(n int) int { return ModPow(n, Mod-2) }
func ModDiv(a, b int) int  { return a * ModInverse(b) }
func ModPow(a, b int) (x int) {
	for x = 1; b > 0; b >>= 1 {
		if b&1 == 1 {
			x = x * a % Mod
		}
		a = a * a % Mod
	}
	return
}
func ModFactorial(n int) int      { return fac[n] }
func ModPermutation(n, r int) int { return fac[n] * finv[n-r] % Mod }
func ModCombination(n, k int) int { return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod }

var fac, finv, inv []int

func init() {
	const MAX = 1e5 + 1
	fac, finv, inv = make([]int, MAX+1), make([]int, MAX+1), make([]int, MAX+1)
	fac[0], fac[1], finv[0], finv[1], inv[1] = 1, 1, 1, 1, 1
	for i := 2; i <= MAX; i++ {
		fac[i] = fac[i-1] * i % Mod
		inv[i] = Mod - inv[Mod%i]*(Mod/i)%Mod
		finv[i] = finv[i-1] * inv[i] % Mod
	}
}

var reader = bufio.NewReader(os.Stdin)

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


Measured memory_bytes: 6272
import sys
from bisect import bisect_left

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def neighborhood(L, now):
    tmp = bisect_left(L, now)
    if tmp == 0:
        return [tmp, None]
    elif tmp == len(L):
        return [tmp - 1, None]
    else:
        return [tmp - 1, tmp]


def dist_calc(now, p1, p2):
    if p1 is None or p2 is None:
        return f_inf
    res1 = abs(now - p1) + abs(p1 - p2)
    res2 = abs(now - p2) + abs(p1 - p2)
    return min(res1, res2)


def resolve():
    a, b, q = map(int, input().split())
    S = list(int(input()) for _ in range(a))
    T = list(int(input()) for _ in range(b))
    query = list(int(input()) for _ in range(q))

    for x in query:
        dist1 = f_inf
        s1, s2 = neighborhood(S, x)
        for s in [s1, s2]:
            if s is not None:
                t1, t2 = neighborhood(T, S[s])
                for t in [t1, t2]:
                    if t is not None:
                        dist1 = min(dist1, dist_calc(x, S[s], T[t]))

        dist2 = f_inf
        t1, t2 = neighborhood(T, x)
        for t in [t1, t2]:
            if t is not None:
                s1, s2 = neighborhood(S, T[t])
                for s in [s1, s2]:
                    if s is not None:
                        dist2 = min(dist2, dist_calc(x, S[s], T[t]))

        res = min(dist1, dist2)
        print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 20848
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <math.h>

int main()
{
	long N;
	
	std::cin >> N;

	long result = 0;
	long xmax = sqrt(N);
	for (long x = 1; x <= xmax; ++x) {
		if (N % x == 0 && (N / x) - 1 > x)
			result += (N / x) - 1;
	}
	
	std::cout << result << "\n";
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXIST2(s,e) (find(ALL(s),(e))!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);


	int n;
int sum(vvi &m,int index,vi &used,int t,vi &leaves){
	used[index]=1;
	int ret=0;
	bool flag=false;
	REP(i,n){
		if(m[index][i]&&!used[i]){
			int s=sum(m,i,used,m[index][i],leaves);
			if(s!=-1){
				ret+=s+m[index][i]*2;
			}
			flag=true;
		}
	}
	if(!flag){
		leaves[index]=1;
		return -1;
	}
	return ret;
}


int farthest(vvi &m, int index,vi &used,vi &leaves){
	used[index]=1;
	int ret=0;
	REP(i,n){
		if(m[index][i]&&!used[i]&&!leaves[i]){
			ret=max(ret,farthest(m,i,used,leaves)+m[index][i]);
		}
	}
	return ret;
}

int main(){
	while(cin>>n,n){
		vvi m(n,vi(n));
		REP(i,n-1){
			int a,b,t;
			cin>>a>>b>>t;
			a--;b--;
			m[a][b]=t;
		}
		vi used(n);
		vi leaves(n);
		
		int total=sum(m,0,used,0,leaves);
		vi used2(n);
		int minus=farthest(m,0,used2,leaves);
		cout<<total-minus<<endl;
	}
}

Measured memory_bytes: 1224
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define MOD 1000000007LL

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

long long int powmod(long long int a, long long int k, long long int m){
	if(a==0){
		return 0;
	}
	long long int ap=a;
	long long int ans=1;
	for(int i=0; i<30; i++){
		if(k%2==1){
			ans*=ap;
			ans%=m;
		}
		ap=ap*ap;
		ap%=m;
		k/=2;
	}
	return ans;
}
 
ll inv(ll x, ll p){
  return powmod(x, p-2, p);
}

int main()
{
	int m, n, k;
	cin>>n>>m>>k;
	ll f[220001], invf[220001];
	f[0]=1;
	for(ll i=1; i<=m+n+2*k; i++){
		f[i]=f[i-1]*i%MOD;
	}
	invf[m+n+2*k]=inv(f[m+n+2*k], MOD);
	for(ll i=m+n+2*k-1; i>=0; i--){
		invf[i]=invf[i+1]*(i+1)%MOD;
	}
	ll ans=0;
	for(int x=0; x<=k; x++){
		int y=k-x;
		ll c1=f[m+n+2*k]*invf[m+2*x]%MOD*invf[n+2*y]%MOD;
		ll c2, c3;
		if(x==0){
			c2=1;
		}else{
			c2=(f[m+2*x]*invf[x]%MOD*invf[m+x]%MOD+MOD-f[m+2*x]*invf[x-1]%MOD*invf[m+x+1]%MOD)%MOD;
		}
		if(y==0){
			c3=1;
		}else{
			c3=(f[n+2*y]*invf[y]%MOD*invf[n+y]%MOD+MOD-f[n+2*y]*invf[y-1]%MOD*invf[n+y+1]%MOD)%MOD;
		}
		ans+=(c1*c2%MOD*c3%MOD);
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6524
#include "bits/stdc++.h"
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")

using namespace std;

using ll = long long;
#define all(x) begin(x), end(x)
const int MAXN = 1e5 + 10;
const int INF = 2*1e9;

int dp[MAXN],N,K,h[MAXN];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	K=2;
	for(int i{1}; i<=n; i++) cin >> h[i];
	// dp[i] means the i'th stone cost
	for(int i{2}; i<=n; i++){
		dp[i] = INF;
		for(int j = i-1; j>=max(i-K, 1); j--){
			dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]));}
		}

		cout << dp[n] << "\n";
}


Measured memory_bytes: 4444
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <stdexcept>
#include <algorithm>
using namespace std;
int main(){
    int N,K,i,p,a;
    cin >> N >> K;
    int l[N] = {};
    for(i = 0;i < N;i++){
        cin >> p;
        l[i] = p;
    }
    sort(l, l + N, greater<int>());
    a = 0;
    for(i = 0;i < K;i++){
        a += l[i];
    }
    cout << a << endl;
}

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

int main() {
  long int N, A, B;
  cin >> N >> A >> B;


 long int count = N % (A + B);
 long int waru =N / (A + B);
    if (A + B == 0) {
    cout << 0 << endl;
    }
    else if (count == 0) {
      cout << A*waru << endl;
    }
    else if(count <= A) {
      cout <<A*waru + count << endl;
    }

    else {
      cout << A*waru + A<< endl;
  }

}

Measured memory_bytes: 256
use input::Input;
use std::collections::VecDeque;

fn main() {
    let mut input = Input::default();

    let n = input.parse();
    let m = input.parse();
    let mut g = vec![Vec::new(); n];
    for _ in 0..m {
        let (a, b) = (input.parse::<usize>(), input.parse::<usize>());
        let (a, b) = (a - 1, b - 1);
        g[a].push(b);
        g[b].push(a);
    }

    let mut path = vec![0; n];
    let mut dist = vec![-1i32; n];
    f(0, &g, &mut path, &mut dist);

    println!("Yes");
    for i in 1..n {
        println!("{}", path[i] + 1);
    }
}

fn f(v: usize, g: &Vec<Vec<usize>>, path: &mut Vec<usize>, dist: &mut Vec<i32>) {
    let mut q = VecDeque::new();
    q.push_back(v);
    path[v] = 0;
    dist[v] = 0;
    while !q.is_empty() {
        let v = q.pop_front().unwrap();
        for nv in g[v].iter() {
            if dist[*nv] == -1 {
                dist[*nv] = dist[v] + 1;
                path[*nv] = v;
                q.push_back(*nv);
            }
        }
    }
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 12196
#include <bits/stdc++.h>
#define N 110
#define ll long long
#define For(i,x,y) for(int i=(x);i<=(y);++i)
#define Rof(i,x,y) for(int i=(x);i>=(y);--i)
#define Edge(x) for(int i=head[x],to=e[i].v;i;i=e[i].nxt,to=e[i].v)
#define Cur(x) for(int &i=cur[x],to=e[i].v;i;i=e[i].nxt,to=e[i].v)
#define mset(x,y) memset(x,y,sizeof(x))
using namespace std;
const int S=0,T=102;
int dep[N],n,head[N],cur[N],cnt=1,a[N];
queue<int> q;
struct ed{ int v,nxt;ll f; }e[N*32];
void add(int u,int v,ll f){
	e[++cnt]=(ed){v,head[u],f},head[u]=cnt;
	e[++cnt]=(ed){u,head[v],0},head[v]=cnt;
}
bool bfs(){
	while(!q.empty()) q.pop();
	For(i,0,T) cur[i]=head[i],dep[i]=0;
	dep[S]=1,q.push(S);
	while(!q.empty()){
		int x=q.front();q.pop();
		Edge(x) if(!dep[to] && e[i].f) dep[to]=dep[x]+1,q.push(to);
	}
	return dep[T];
}
ll dfs(int x,ll f){
	if(x==T) return f;
	ll use=0;
	Cur(x){
		if(dep[to]==dep[x]+1 && e[i].f){
			ll o=min(f-use,e[i].f);
			ll w=dfs(to,o);
			use+=w,e[i].f-=w,e[i^1].f+=w;
			if(f==use) return f;
		}
	} return use;
}
int main(){
	ll ans=0,sum=0;
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]),a[i]=-a[i];
	For(i,1,n) for(int j=2*i;j<=n;j+=i) add(i,j,(ll)1e18);
	For(i,1,n){
		if(a[i]>0) add(S,i,a[i]);
		else add(i,T,-a[i]),sum+=-a[i];
	}
	while(bfs()) ans+=dfs(S,(ll)1e18);
	printf("%lld\n",sum-ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    std::string s; std::cin>>s;
    int ans=1145141919;
    for(int i=0; i<s.size()-2; i++){
        int b = abs(std::stoi(s.substr(i,3)) - 753);
        ans = std::min(ans, b);
    }
    std::cout << ans << "\n";
    return 0;
}


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

struct st {
	int id, score, time, wrong[10];
};
int main() {
	int M, T, P, R;
	while (scanf("%d%d%d%d", &M, &T, &P, &R), M) {
		st team[50]{};
		rep(i, T)team[i].id = i + 1;
		rep(i, R) {
			int m, t, p, j; scanf("%d%d%d%d", &m, &t, &p, &j);
			t--; p--;
			if (j)team[t].wrong[p]++;
			else {
				team[t].score++;
				team[t].time += m + 20 * team[t].wrong[p];
			}
		}
		sort(team, team + T, [](st a, st b) {
			if (a.score != b.score)return a.score > b.score;
			if (a.time != b.time)return a.time < b.time;
			return a.id > b.id;
		});
		printf("%d", team[0].id);
		for (int i = 1; i < T; i++) {
			if (team[i - 1].score == team[i].score&&team[i - 1].time == team[i].time)
				printf("=");
			else printf(",");
			printf("%d", team[i].id);
		}
		printf("\n");
	}
}

Measured memory_bytes: 3176
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k;
    cin>>n>>k;
    ll a[n], i, ans[n+1], sum = 0;
    map<ll, ll> m;
    for(i=0; i<n; i++) {
    	cin>>a[i];
    }
    vector<ll> pre(n+1, 0);
    for(i=0; i<n; i++) {
    	pre[i+1] = pre[i] + a[i];
    }
    for(i=0; i<=n; i++) {
    	ans[i] = (pre[i] - i)%k;
    	if(ans[i] < 0)
    		ans[i] += k;
    	if(i - k >= 0) {
    		m[ans[i-k]]--;
    	}
    	sum += m[ans[i]];
    	m[ans[i]]++;
    }
    cout<<sum<<"\n";
}

Measured memory_bytes: 17408
import java.util.*;

public class Main {

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

        String[] l = scanner.nextLine().trim().split(" ");
        int n = Integer.valueOf(l[0]);
        int m = Integer.valueOf(l[1]);

        Set<Integer> accepted = new HashSet<>();
        Map<Integer, Integer> wrongSubmissions = new HashMap<>();

        for (int i = 0; i < m; i++) {
            String[] submission = scanner.nextLine().trim().split(" ");
            int problem = Integer.valueOf(submission[0]);
            String result = submission[1];

            if ("AC".equalsIgnoreCase(result)) {
                accepted.add(problem);
            } else if (!accepted.contains(problem)) {
                wrongSubmissions.put(problem, wrongSubmissions.getOrDefault(problem, 0) + 1);
            }

            if (accepted.size() == n) {
                break;
            }
        }

        int correct = accepted.size();
        int failed = wrongSubmissions
                .entrySet()
                .stream()
                .filter(e -> accepted.contains(e.getKey()))
                .mapToInt(Map.Entry::getValue)
                .sum();

        System.out.println(correct + " " + failed);
    }
}


Measured memory_bytes: 122964
words = lambda t : list(map(t, input().split()))
n = int(input())
n_lst = n % 10
n_hd = n
n_d = 1
while n_hd // 10 != 0:
    n_hd //= 10
    n_d += 1
#print(n_hd, n_lst, n_d)
ans = 0
for i in range(1,n+1):
    if i % 10 == 0:
        continue
    d = 2
    b_hd = i % 10
    b_lst = i
    while b_lst // 10 != 0:
        b_lst //= 10
    if b_hd == b_lst:
        if b_hd <= n:
            #print("add0")
            ans += 1
    while 10**(d-1) < n:

        if d < n_d:
            #print("add1", 10**(d-2))
            ans += 10**(d-2)
        elif d == n_d:
            if b_hd < n_hd:
                #print("add2",10**(d-2) )
                ans += 10**(d-2)
            elif b_hd == n_hd:
                #print(i,d, b_hd, b_lst)
                #print("add3",n - (n_hd)*(10**(d-1)) - (n_lst) )
                ans += (n - (n_hd)*(10**(d-1)) - (n_lst)) // 10
                if b_lst <= n_lst:
                    #print("add4")
                    ans += 1
        d += 1

print(ans)


Measured memory_bytes: 3064
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;
template<class T>
T gcd(T a, T b){
  if(a > b) swap(a, b);
  if(a == 0) return b;
  return gcd(b % a, a);
}


int main(){
  const int n = getInt();
  vector<int> v(n);
  REP(i,n) v[i] = getInt();
  int ans = v[0];
  REP(i,n){
    ans = gcd(ans, v[i]);
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 640
n = gets.to_i
vs = gets.split.map(&:to_i)
odds = vs.select.with_index { |v, i| i.odd? }.group_by(&:itself)
evens = vs.select.with_index { |v, i| i.even? }.group_by(&:itself)

ob = [0, 0]
osb = [0, 0]
odds.each do |v, arr|
  if arr.count > ob[1]
    osb = ob
    ob = [v, arr.count]
  elsif arr.count > osb[1]
    osb = [v, arr.count]
  end
end

eb = [0, 0]
esb = [0, 0]
evens.each do |v, arr|
  if arr.count > eb[1]
    esb = eb
    eb = [v, arr.count]
  elsif arr.count > esb[1]
    esb = [v, arr.count]
  end
end

if ob[0] != eb[0]
  puts n - ob[1] - eb[1]
elsif osb[0] != 0 && esb[0] != 0
  if ob[1] - osb[1] > eb[1] - esb[1]
    puts n - ob[1] - esb[1]
  else
    puts n - osb[1] - eb[1]
  end
else
  if osb[0] == 0 && esb[0] == 0
    puts n/2
  else
    puts n/2 - (osb[0] == 0 ? esb[1] : osb[1])
  end
end


Measured memory_bytes: 18964
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe





vector<int> enum_div(int n){
    vector<int> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}
int main(void){ios::sync_with_stdio(false);cin.tie(0);
///////////////////////////////////////////////////////
int n;
cin >> n;
int a[n];
rep(i,n){
	cin >> a[i];
}

sort(a,a+n);
cout << a[n-1]-a[0] << endl;
///////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int a,b,c,x,y;
int main(){
    cin >> a >> b >> c >> x >> y;
    int maxi = max(x,y);
    int mini = min(x,y);
    if(2 * c > a + b){
        cout << a*x + b*y << endl;
    }
    else{
        if(2*c > a && 2*c > b){
            if(x < y){
                cout << mini*2*c + (y-x)*b << endl;
            }
            else{cout << mini*2*c + (x-y)*a << endl;}
        }
        else if(2*c <= a && 2*c <= b){
            cout << 2*c*mini + 2*c*(maxi-mini)<<endl;
        }
        else if(2*c <= a && 2*c > b){
            if(x < y){cout << 2*c*mini + b*(maxi-mini) << endl;}
            else{cout << 2*c*maxi << endl;}
        }
        else{
            if(x<y){cout << 2*c*maxi << endl;}
            else{cout << 2*c*mini + a * (maxi-mini);}
        }
    }
}

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

const int INF = 2e9;

int main(){
    int n;
    cin >> n;
    vector<map<char,int>> d(n);
    rep(i,n){
        string s;
        cin >> s;
        rep(j,s.size()){
            d[i][s[j]]++;
        }
    }
    map<char,int> m = d[0];
    for(auto x:m){
        char k = x.first;
        rep(i,n) m[k] = min(m[k],d[i][k]);
    }
    for(auto x:m){
        rep(i,x.second) cout << x.first;
    }
    cout << endl;
}

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

const int size = 1000001;
bool a[size],DP[size];
int n,x;
int m[30];

void eratos(){
	if(size>=1)
		a[0] = false;
	if(size>=2)
		a[1] = false;
	for(int i=2; i<size; i++)
		a[i] = true;
	for(int i=2; i*i<size; i++)
		if(a[i])
			for(int j=i*i; j<size; j+=i)
				a[j] = false;
}

int main(){
	eratos();
	while(true){
		cin >> n >> x;
		if(!n&&!x)
			return 0;
		for(int i=0; i<n; i++)
			cin >> m[i];
		DP[0] = true;
		for(int i=1; i<=x; i++)
			DP[i] = false;
		for(int i=0; i<n; i++)
			for(int k=0; k<=x; k++)
				if(DP[k]&&k+m[i]<=x)
					DP[k+m[i]] = true;
		bool flag = true;
		for(int i=x; i>2; i-=2){
			if(!(i%2))
				i--;
			if(DP[i] && a[i]){
				cout << i << endl;
				flag = false;
				break;
			}
		}
		if(flag)
			cout << "NA\n";
	}
}

Measured memory_bytes: 2820
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<double> V(N);
  for(int i = 0;i < N;i++)cin >> V[i];
  sort(V.begin(),V.end());
  double ans = 0;
  ans = (V[0] + V[1])/2;
  for(int i  =2;i<N;i++){
    ans = (ans+V[i])/2;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a1, a2, a3, a4, b1, b2, b3, b4 int
	for {
		i, _ := fmt.Scan(&a1, &a2, &a3, &a4)
		if i == 0 {
			break
		}
		fmt.Scan(&b1, &b2, &b3, &b4)
		a := [4]int{a1, a2, a3, a4}
		b := [4]int{b1, b2, b3, b4}
		var hit, blow int

		for j := 0; j < 4; j++ {
			for k := 0; k < 4; k++ {
				if a[j] == b[k] {
					if j == k {
						hit++
					} else {
						blow++
					}
				}
			}
		}
		fmt.Println(hit, blow)
	}
}



Measured memory_bytes: 1120
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		long n = nextLong();
		long m=1,sum=0;
		while(m*m<n) {
			if(n%m==0)if(n%m==0)if(n/m-1!=m)sum+=n/m-1;
			m++;
		}
		out.println(sum);
	}
	@SuppressWarnings("unused")
	private int min(int a, int b) {
		return Math.min(a, b);
	}
	@SuppressWarnings("unused")
	private int nextInt() {
		return Integer.parseInt(next());
	}
	@SuppressWarnings("unused")
	private long nextLong() {
		return Long.parseLong(next());
	}
	private String next() {
		return sc.next();
	}
}


Measured memory_bytes: 21972
// #pragma GCC optimize("O3")

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <random>
#include <cmath>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back

using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using ld = long double;


int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &i : a) {
        cin >> i;
    }
    vector<int> ans;
    while (!a.empty()) {
        int pos = -1;
        for (int i = a.size() - 1; i >= 0; i--) {
            if (a[i] == i + 1) {
                pos = i;
                break;
            }
        }
        if (pos == -1) {
            cout << "-1\n";
            return 0;
        }
        ans.push_back(a[pos]);
        a.erase(a.begin() + pos);
    }    
    for (auto it = ans.rbegin(); it != ans.rend(); it++) {
        cout << (*it) << '\n';
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

long solve(long a, const std::string& b)
{
  int x = b[0] - '0';
  int y = std::stoi(b.substr(2, 2));
  return a * x + a * y / 100;
}

int main()
{
  long a;
  std::string b;
  std::cin >> a >> b;

  std::cout << std::setprecision(20);
  std::cout << solve(a, b) << std::endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector< vector<ll> > dp(100001,vector<ll>(2,-1)); //0:not black ,1:black
vector<ll> node[100001];
vector<ll> node_true[100001];
vector<bool> HasCome(100001,false);

ll search(ll n){
  if(HasCome[n]) return 0;
  HasCome[n]=true;

  if(node[n].size()==1 && n!=1){
    dp[n][0]=1;
    dp[n][1]=1;

    return 1;
  }
  dp[n][0]=1;
  dp[n][1]=1;
  for(auto x:node[n]){
    if(search(x)==1LL){
    dp[n][0]*=(dp[x][0]+dp[x][1]);
    dp[n][0]%=mod;
    dp[n][1]*=(dp[x][0]);
    dp[n][1]%=mod;
    }
  }

  return 1;
}

int main(void){

  ll n;
  cin>>n;

  rep(i,n-1){
    ll x,y;
    cin>>x>>y;
    node[x].pb(y);
    node[y].pb(x);
  }


  search(1);

  cout << (dp[1][0]+dp[1][1])%mod << endl;
  return 0;

}


Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}

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


int main() {
  ll n; cin >> n;
  vector<mint> invsum(n+1);
  rep(i, n) invsum[i+1] += invsum[i] + mint(1)/(i+1);

  mint ans = 0;
  mint fac = 1;
  rep(i, n) {
    int a; cin >> a;
    ans += mint(a) * (invsum[i+1] + invsum[n-i] - 1);
    fac *= mint(i+1);
  }
  ans *= fac;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
m = [list(map(int,input().split())) for _ in range(M)]
ans = min(a)+min(b)
for x in m:
    kouho = a[x[0]-1]+b[x[1]-1]-x[2]
    ans = min(ans,kouho)
print(ans)

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

int main() {
	int m,f,r;
	while(1) {
		cin >> m >> f >> r;
		if (m==-1&&f==-1&&r==-1) break;
		if (m==-1||f==-1) {
			cout << "F" << endl;
		} else if (m+f>=80) {
			cout << "A" << endl;
		} else if (m+f>=65) {
			cout << "B" << endl;
		} else if (m+f>=50) {
			cout << "C" << endl;
		} else if (m+f<30) {
			cout << "F" << endl;
		} else if (r>=50) {
			cout << "C" << endl;
		} else {
			cout << "D" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<long>A(N+1);
  vector<long>B(N);
  for(int i=0;i<N+1;i++) cin>>A[i];
  for(int i=0;i<N;i++) cin>>B[i];
  long M=0;
  for(int i=0;i<N+1;i++)M+=A[i];
  long L=0;
  for(int i=N-1;i>=0;i--){
    if(A[i+1]>B[i]){
		L+=A[i+1]-B[i];
      B[i]=0;
    }else{
     
      if(A[i]>B[i]-A[i+1]) A[i]-=(B[i]-A[i+1]);
      
      else A[i]=0;
      A[i+1]=0;
    }
  }
  L+=A[0];
  cout<<M-L<<endl;
}
    

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N, M;
int s[5], c[5];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M;
    for(int i = 0; i < M; i++) cin >>  s[i] >> c[i];
    for(int i = 0; i < 1000; i++){
        bool flg = true;
        if(i < 10){
            if(N != 1) continue;
            for(int j = 0; j < M; j++){
                if(s[j] == 1 && c[j] == i) continue;
                flg = false;
            }
        }else if(i < 100){
            if(N != 2) continue;
            int d[2];
            d[1] = i%10;
            d[0] = (i-(d[1]))/10;
            for(int j = 0; j < M; j++){
                if(s[j] <= 2 && d[s[j]-1] == c[j]) continue;
                flg = false;
            }
        }else{
            if(N != 3) continue;
            int d[3];
            d[2] = i%10;
            d[1] = ((i-(d[2]))/10)%10;
            d[0] = (i-(d[2]+d[1]*10))/100;
            for(int j = 0; j < M; j++){
                if(s[j] <= 3 && d[s[j]-1] == c[j]) continue;
                flg = false;
            }
        }
        if(flg){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x;
        for(int i = 1;; i++){
            x = sc.nextInt();
            if(x != 0){
                System.out.printf("Case %d: %d\n", i, x);
            }else{
                break;
            }
        }
    }
}



Measured memory_bytes: 65288
'use strict';
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim();
var S = Number(inputs);
var h = Math.floor(S/3600);
var m = Math.floor(S % 3600 / 60);
var s = S % 60;

 console.log([h,m,s].join (':'));
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15540
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int N, K;
	cin >> N >> K;
	if(N % K == 0){
		cout << 0 << endl;
	}
	else{
		cout << 1 << endl;
	}
	return 0;
}

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

int main() {
  string  w;
  cin >> w;
 
  int s[30] ;
   for (int i = 0; i < 30; i++)
    s[i] = 0;
  
   
  int count, str ;
      for (int i = 0; i < w.size() ; i++) {
      
        s[w[i]-'a']++;}
        
      
  for (int i = 0; i < 30; i++){
    
       if (s[i] %2 != 0){
         cout << "No" <<endl;
      return  0; }
  }
      cout << "Yes" << endl;
         
    }

            
         

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

typedef long long ll;

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

// const int C ;
// const int M = 1000000007;

set<int> S;
int N;
int T[200010];

int main () {
  cin >> N;
  int tmp;
  for (auto i = 1; i <= N; i++) {
    cin >> tmp;
    T[tmp] = i;
  }
  S.insert(0);
  S.insert(N+1);
  ll cnt = 0;
  for (auto i = 1; i <= N; i++) {
    ll x = T[i];
    auto it = S.lower_bound(x);
    ll ub = *it;
    ll lb = *(--it);
    /*
    cerr << "i = " << i
         << ", x = " << x << ", lb = " << lb << ", ub = " << ub << endl;
    cerr << "point : " << x * (x - lb) * (ub - x) << endl;
    */
    cnt += i * (x - lb) * (ub - x);
    S.insert(x);
  }
  cout << cnt << endl;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,x,ans=0,anss,cnt;
  cin >> n >> x;
  long long a[2*n],MIN[n][n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    ans+=a[i];
    a[i+n]=a[i];
  }
  for(int i=0;i<n;i++){
    cnt=0;
    priority_queue<long long,vector<long long>,greater<long long> > pq;
    for(int j=i+n;j>=i;j--){
      pq.push(a[j]);
      MIN[i][cnt]=pq.top();
      cnt++;
    }
  }
  for(int i=1;i<n;i++){
    anss=i*x;
    for(int j=0;j<n;j++){
      anss+=MIN[j][i];
    }
    ans=min(ans,anss);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include "string.h"
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A,B,C,D;
	cin >> A >> B >> C >> D;
	if(B >= C && D >= A){
		if(A <= C){
			if(B >= D){
				cout << abs(D - C) << endl;
			}else{
				cout << abs(B - C) << endl;
			}
		}else{
			if(B >= D){
				cout << abs(D - A) << endl;
			}else{
				cout << abs(B - A) << endl;
			}
		}
	}else{
		cout << 0 << endl;
	}
	return 0;
}

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


vector<int>solve2(const vector<int>&v,int from){
	vector<int>que;
	map<int,int>mp;
	for(int x=from;x<v.size();++x){
		if(mp.find(v[x])==mp.end()){
			que.emplace_back(v[x]);
			mp[v[x]]=que.size()-1;
		}else{
			while(true){
				int aback=que.back();
				
				mp.erase(aback);
				que.pop_back();
				if(aback==v[x])break;
			}
		}
	}
	return que;
}
vector<int> solve(int N,long long int K,vector<int>v,int start){
	
	vector<int>rs(N);

	{
		map<int,int>mp;
		for(int i=N-1;i>=0;--i){
			mp[v[i]]=N+i;
		}
		for(int i=N-1;i>=0;--i){
			rs[i]=mp[v[i]];
			mp[v[i]]=i;
		}
	}
	

	long long int ny=0,nx=start;
	map<int,long long int>mp;
	mp[start]=0;
	while(true){
		//cout<<nx<<ny<<endl;
		auto next_x=rs[nx];
		long long next_y=ny;
		//cout<<next_x<<' '<<next_y<<endl;
		if(next_x>=N){
			next_y++;
			next_x-=N;
		}
		next_x++;
		if(next_x>=N){
			next_y++;
			next_x-=N;
		}
		if(next_y>=K){
			
			if(K-1==next_y){
				v.insert(v.end(),v.begin(),v.end());
			}
			return solve2(v,nx);
		}else{
			ny=next_y;
			nx=next_x;

			if(mp.find(nx)==mp.end()){
				mp[nx]=ny;
			}else{
				long long sa=-(mp[nx]-ny);
				long long int rest=K-ny;
				rest%=sa;
				//cout<<rest<<endl;
				if(rest==0)rest=sa;

				long long xx=K%sa;
				if(xx==0)xx=sa;
				assert(nx==0);
				return solve(N,xx,v,0);
			}
		}
	}
	assert(false);
	
}

int main() {

	int N;cin>>N;
	long long int K;cin>>K;
	vector<int>v;
	for(int i=0;i<N;++i){
		int a;cin>>a;
		v.push_back(a);
	}
	auto ans=solve(N,K,v,0);
	for(auto an:ans)cout<<an<<' ';
	cout<<endl;
	return 0;
}	

Measured memory_bytes: 28148