akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;

    while(scanf("%d",&n)==1){
        long long prefix[n+1], value;
        prefix[0] = 0;

        for(int i=0; i<n; i++){
            scanf("%lld",&value);
            prefix[i+1] = prefix[i] + value;
        }

        sort(prefix, prefix+n+1);

        long long ans = 0;

        for(int i=1; i<=n; i++){
            long long cnt=1;
            while(prefix[i]==prefix[i-1])
                cnt++, i++;
            ans += (cnt*(cnt-1))/2;
        }

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

    return 0;
}


Measured memory_bytes: 1792
/*************************************************************************
	> File Name: bac120_c.cpp
	> Author: 
	> Mail: 
	> Created Time: 2019年03月03日 星期日 20时23分30秒
 ************************************************************************/

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;int num=0;int num1=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='0')
        num++;
        else num1++;
    }
    cout<<2*min(num,num1)<<endl;
    
}


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

using namespace std;
const int MAX = 105;
string A[MAX];
map<string, int> M;
int main (){
	bool ok = true;
	char aux = '`';
	int n;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		string str;
		cin >> str;
		A[i] = str;
		if (i == 0)
			aux = str[str.size() - 1];
		else{
			if(aux != str[0] && i > 0){
				ok = false;
				break;
			}
			else
				aux = str[str.size() - 1];
		}
		M[str]++;
	}
	for(int i = 0; i < n; i++){
		if(M[A[i]] > 1){
			printf("No\n");
			return 0;
		}
	}
	if(ok)
		printf("Yes\n");
	else
		printf("No\n");


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N, M, X;
  cin >> N >> M >> X;
  vector<bool> is_gates(N + 1, false);
  rep(i, M)
  {
    int A;
    cin >> A;
    is_gates[A] = true;
  }
  int ans = 0;
  FOR(i, 0, X)
  {
    if (is_gates[i])
      ans++;
  }
  ans = min(ans, M - ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  dp=[inf]*100010
  dp[0]=0
  dp[1]=abs(l[0]-l[1])

  for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(l[i-2]-l[i]),dp[i-1]+abs(l[i-1]-l[i]))

  return dp[n-1]

print(main())


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

long long n;

void solve(){
    for(long long i = - 121; ; i++){
        bool sw = false;
        for(long long j = -121; j < 121 ; j++){
            if(i * i * i * i * i - j * j * j * j * j == n){
                cout << i << " " << j << endl;
                sw = true;
                break;
            }
        }
        if(sw) break;
    }
}

int main(){
    cin >> n;
    solve();
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	string s;
	int n;
	cin >> n >> s;
	int left = 0, right = n - 1;
	while(left < n and s[left] != 'W')left++;
	while(right > 0 and s[right] != 'R')right--;
	int ans =  0;
	while(left < right)
	{
		if(s[left] == 'W' and s[right] == 'R')
			ans++;
		left++,right--;
		while(left < n and s[left] != 'W')left++;
		while(right > 0 and s[right] != 'R')right--;
	}
	cout << ans;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100005
#define INF 1000000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 998244353;
int main(){
    int n;
    cin>>n;
    vector<ll>a(n);
    REP(i,n)cin>>a[i];
    sort(ALL(a));
    ll cnt=0;
    while(n<=a[n-1]){
        ll tmp=a[n-1]/n;
        a[n-1]-=(ll)tmp*n;
        REP(i,n-1)a[i]+=tmp;
        for(int i=n-1;i>=1;i--){
            if(a[i-1]>a[i])swap(a[i-1],a[i]);
        }
        cnt+=tmp;
    }
    OUT(cnt);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll n,q;
    cin>>n;
    ll a[n];
    vector<ll> cnt(100005,0);
    ll sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
        cnt[a[i]]++;
    }
    cin>>q;
    while(q--){
        ll b,c;
        cin>>b>>c;
        sum-=cnt[b]*b;
        sum+=(cnt[b])*c;
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair


void solve() {
  string s;
  cin >> s;
  int cnt = 0;
  REP(i,sz(s)) {
    cnt += s[i] == 'o';
  }
  int add = 15 - sz(s);
  cnt += add;
  cout << (cnt >= 8?"YES":"NO") << endl;
}

int main(int argc, char *argv[]){

  /*Regular*/
  int case_num = 1;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  REP(case_no, case_num) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }

  // /*ICPC*/
  // while (cin >> t >> d >> l, t) {
  //   solve();
  // }

  //solve();
  return 0;
}

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

int n;
int x[102][102], y[102][102];
int t[102][102];

void solve(){
  memset(t, -1, sizeof(t));

  int now = 0;
  int res = 0;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(t[i][j] != -1) continue;

      int now_x = j;
      int now_y = i;

      while(t[now_y][now_x] == -1){
        t[now_y][now_x] = now;
        int nx = x[now_y][now_x];
        int ny = y[now_y][now_x];
        now_x = nx;
        now_y = ny;
      }

      if(t[now_y][now_x] == now){
        res++;
      }

      now++;
    }
  }

  cout << res << endl;
}

int main(){
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        cin >> x[i][j] >> y[i][j];
      }
    }
    solve();
  }
}

Measured memory_bytes: 1288
import itertools
import math
from sys import stdin


def primes(x):
    if x < 2:
        return []

    primes = [i for i in range(x)]
    primes[1] = 0

    for prime in primes:
        if prime > math.sqrt(x):
            break
        if prime == 0:
            continue
        for non_prime in range(2 * prime, x, prime):
            primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]


def main():
    N = int(stdin.readline().rstrip())
    tmp = {x: [] for x in range(5)}
    for x in primes(1000000):
        tmp[x % 5].append(x)
        if len(tmp[x % 5]) == N:
            print(*tmp[x % 5])
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 43320
import Foundation
let N = Int(String(readLine()!))!
let nums = readLine()!.componentsSeparatedByString(" ").map { Int($0)! }
var table: [Int: Int] = [:]
var sum = 0
for n in nums {
  table[n] = (table[n] ?? 0) + 1
}
for (key, value) in table {
  sum += value * (value - 1) / 2
}
for n in nums {
  print(sum - table[n]! + 1)
}

Measured memory_bytes: 16340
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
N = inp.shift() * 1
l = inp.shift().split(" ")
a = new Array(N)
for (i=0; i<N; i++) {
    a[i] = 0
    a[l[i] - 1] = a[l[i] - 1] + 1
}
console.log(a.join("\n"))

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

int main(){
  int x,y;
  std::cin >> x>>y;
  for (int i = 0; i <= x ; i++) {
    for (int j = 0; j <= x ; j++) {
      if(i+j>x)break;
      if(2*i+4*j==y && i+j==x){
        std::cout << "Yes" << '\n';
        return 0;
      }
    }
  }

  std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 3636
using System;

class Atcoder61
{
    public static void Main()
    {
        string input = Console.ReadLine();
        char ten = input[0];
        char one = input[1];

        string strten = ten.ToString();
        string strone = one.ToString();

        if (strten == "9" || strone == "9")
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD_Q 1e9 + 7
#define MOD_A 998244353

long long powM(long long a, long long b){
	if(a==0)return 0;
	else if(b==0)return 1;
	else if(b==1)return a%MOD_A;
 
	if(b%2==0){
		return powM((a*a)%MOD_A, b/2)%MOD_A;
	}else{
		return (a*powM(a,b-1) )%MOD_A;
	}
}
 
void solve()
{
 
  int N;
  cin>>N;
 
  vector<lint> vec(N,0);
  lint MAX = 0;
 
  for (int i = 0; i < N; i++)
  {
    lint A;
    cin>>A;
    vec[A]++;
    MAX = max(MAX,A);
    if((i==0)&&(A!=0))
    {
      cout<<0<<endl;
      return;
    }
  }
  
  lint count = 1;
  if(vec[0] != 1)
  {
    cout<<0<<endl;
    return;
  }
  for (int i = 0; i < MAX; i++)
  {
   if((vec[i] ==0)&&(vec[i+1]!=0))
   {
     cout<<0<<endl;
     return;
   }
    lint A;
    A = (lint)(powM(vec[i],vec[i+1])) % (MOD_A);
    // cout<<A<<endl;
 
    count = (count * A)%(MOD_A);
  }
 
  cout<<count%(MOD_A)<<endl;
  
 
  return;
}
 
int main(int argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int H,W,K;
  cin>>H>>W>>K;
  ll mod=1e9+7;
  ll dp[H+1][W]={};
  dp[0][0]=1;
  ll L[W]={};
  ll M[W]={};
  ll R[W]={};
  if(W>1) rep(i,(1<<(W-1))){
    int F=1;
    rep(j,W-2) if((i&(1<<j))&&(i&(1<<(j+1)))) F=0;
    if(F) rep(j,W-1){
      if(i&(1<<j)){
        R[j]++;
        L[j+1]++;
      }
    }
    if(F) rep(j,W){
      if(j==0){
        if((i&(1<<j))==0) M[j]++;
      }else if(j==W-1){
        if((i&(1<<(j-1)))==0) M[j]++;
      }else{
        if((i&(1<<(j-1)))==0&&(i&(1<<j))==0) M[j]++;
      }
    }
  }
  rep(i,H){
    rep(j,W){
      if(j==0) dp[i+1][j]=(dp[i][j]*M[j]+dp[i][j+1]*R[j])%mod;
      else if(j==W-1) dp[i+1][j]=(dp[i][j]*M[j]+dp[i][j-1]*L[j])%mod;
      else dp[i+1][j]=(dp[i][j]*M[j]+dp[i][j+1]*R[j]+dp[i][j-1]*L[j])%mod;
    }
  }
  if(W==1) cout<<1<<endl;
  else cout<<dp[H][K-1]<<endl;
}

Measured memory_bytes: 256
_, _, m = map(int, input().split())

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

ans = min(a) + min(b)

for _ in range(m):
    x, y, c = map(int, input().split())
    kaikei = a[x-1] + b[y-1] - c
    if kaikei < ans:
        ans = kaikei

print(ans)

Measured memory_bytes: 18736
from itertools import permutations

n = int(input())
s = input()

r = [0] * n
g = [0] * n
b = [0] * n

for i in range(n):
    if s[i] == "R":
        r[i] = 1
    if s[i] == "G":
        g[i] = 1
    if s[i] == "B":
        b[i] = 1

ans = sum(r) * sum(g) * sum(b)

lst = [r, g, b]
for i in range(n - 1):
    for j in range(i + 1, n):
        k = 2 * j - i
        if k >= n:
            continue
        for x, y, z in permutations(lst):
            if x[i] and y[j] and z[k]:
                ans -= 1
print(ans)

Measured memory_bytes: 68596
#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <stdio.h>
#define INF 100000000
typedef long long int ll;
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, x;
    cin >> n >> x;
    int ans = n + 1;
    int sum = 0;
    rep(i, n){
        int a;
        cin >> a;
        sum += a;
        if (sum > x){
            ans = i + 1;
            break;
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,a,b;
	cin >> n >> a >> b;
	cout << min(n*a,b);
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1e+15;


void solve(istream &cin) {
    string s;
    cin >> s;
    if(!cin) return;

    for (int i = 1; i < s.size() ; ++i) {
        if(s[i] == s[i-1]){
            cout << i << ' ' << i+1 << '\n';
            return;
        }
        if(i >= 2 and s[i] == s[i-2]){
            cout << i-1 << ' ' << i+1 << '\n';
            return;
        }
    } // end i


    cout << "-1 -1\n";
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        solve(fs);
    }
#else
    solve(cin);
#endif
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0; i<(n); i++)
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;

const ll INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int n;cin>>n;
    
    vi ans(n+1,0);
    
    for(int i=1; i<=100; i++){
        for(int j=1; j<=100; j++){
            for(int k=1; k<=100; k++){
                int out = i*i + j*j + k*k + i*j + j*k + k*i;
                if(out<=n)ans[out]++;
            }
        }
    }
    
    for(int i=1; i<=n; i++){
        cout << ans[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3532
//BAGHER
//hame chi sefid o siah e engar ye omre shabe
#include <bits/stdc++.h>
using namespace std;

const int maxn = 4e5 + 12;
int n, a[maxn], b[maxn], cnt[maxn];
vector <int> cmp, ad[maxn];
int val, ans = -1;
bool ch[maxn];

void dfs(int root) {
	ch[root] = 1;
	for (int i : ad[root])
		if (!ch[i])
			dfs(i);
	return;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		val = (val ^ a[i]);
		cmp.push_back(a[i]);
	}
	cmp.push_back(val);
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		cmp.push_back(b[i]);
	}
	sort(cmp.begin(), cmp.end());
	cmp.resize(unique(cmp.begin(), cmp.end()) - cmp.begin());

	for (int i = 0; i < n; i++) {
		a[i] = lower_bound(cmp.begin(), cmp.end(), a[i]) - cmp.begin();
		cnt[a[i]]++;
		b[i] = lower_bound(cmp.begin(), cmp.end(), b[i]) - cmp.begin();
	}
	val = lower_bound(cmp.begin(), cmp.end(), val) - cmp.begin();
	cnt[val]++;
	for (int i = 0; i < n; i++) {
		cnt[b[i]]--;
		if (cnt[b[i]] < 0)
			return cout << -1, 0;
		if (a[i] == b[i])
			continue;
		ad[a[i]].push_back(b[i]);
		ad[b[i]].push_back(a[i]);
		ans++;
	}
	for (int i = 0; i <= n; i++) {
		if (!ch[i]) {
			if (ad[i].size() || i == val) {
				dfs(i); ans++;
			}
		}
	}
	cout << ans;

	return 0;
}



Measured memory_bytes: 20848
ans :: [Int] -> String
ans (0:y:_)
  | y <= 1911 = "M" ++ show(y-1867)
  | y <= 1925 = "T" ++ show(y-1911)
  | y <= 1988 = "S" ++ show(y-1925)
  | otherwise = "H" ++ show(y-1988)

ans (1:y:_) = show(y + 1867)
ans (2:y:_) = show(y + 1911)
ans (3:y:_) = show(y + 1925)
ans (4:y:_) = show(y + 1988)

main = do
  c <- getLine
  let i = map read $ words c :: [Int]
      o = ans i
  putStrLn o
  

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
static const int MAX=100000;
int H,W,ans,A;
int c[10][10];

void solve(){
    for(int k=0;k<9;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){  
                if(j==1||j==i)continue;
                if(c[i][1]>c[i][j]+c[j][1])
                    c[i][1]=c[i][j]+c[j][1];
            }

        }
    }
}

int main(){
    cin>>H>>W;
    for(int i=0;i<10;i++){
        for(int j=0 ;j<10;j++){
            cin>>c[i][j];
        }
    }
    solve();
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin>>A;
            if(A==-1||A==1)continue;
            ans+=c[A][1];
        }
    }
    cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 256
import numpy as np
N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
A = np.array([list(map(int, input().split())) for _ in range(N)])
count = 0
for a in A:
    if sum(a*B)+C > 0:
        count += 1
print(count)

Measured memory_bytes: 12424
import java.util.*;
public class Main {
    public static void main(String args []){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int N = n;
        int sum=0;
        while(true){
            if(n-10>=0){
                sum+=n%10;
                n/=10;
            }
            else{
                sum+=n;
                break;
            }
        }
        if(N%sum==0) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 22996
def max(a,b); a > b ? a : b; end
  
N,K = gets.split.map(&:to_i)
V = gets.split.map(&:to_i)
L = Array.new(N + 1, 0)
R = Array.new(N + 1, 0)

V.each.with_index(1){|v,i| L[i] = L[i - 1] + v }
V.reverse_each.with_index(1){|v,i| R[i] = R[i - 1] + v }

ans = 0
(0 .. N).each do |l|
  (0 .. N).each do |r|
    break if l + r > K || l + r > N
    b = K - (l + r)
    u0 = V.select.with_index{|v,i| v < 0 && (i < l || i >= N - r) }.min(b)
    ans = max(ans, L[l] + R[r] - u0.inject(0,&:+))
  end
end
puts ans

Measured memory_bytes: 3196
N = int(input())
A,B = map(int,input().split())
P = sorted(list(map(int,input().split())))

a,b,c = [],[],[]
for p in P:
    if p<=A: a.append(p)
    elif p<=B: b.append(p)
    else: c.append(p)
    
print(min([len(a),len(b),len(c)]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

ll dp[105][100005];

int main(void){
  ll N, W;
  cin >> N >> W;
  vector<ll> w(N), v(N);
  REP(i, N) cin >> w[i] >> v[i];
  REP(i, N){
    REP(j, W+1){
      chmax(dp[i+1][j], dp[i][j]);
      if(j+w[i] <= W)chmax(dp[i+1][j+w[i]], dp[i][j]+v[i]);
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}

Measured memory_bytes: 81640
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <iomanip> //cout << fixed << setprecision(12) << ans << endl;
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define rloop(i, l, r) for(int i = l; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vec_i;

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e9;
const int MOD = 1e9+7;

int main()
{
	int r,d,x;
	cin >> r >> d >> x;
	for(int i=0;i<10;i++){
		x = r*x - d;
		cout << x << endl;
	}
}

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

public class Program
{
    public static void Main(string[] args)
    {
        var s = Console.ReadLine();
        if (s.Length % 2 == 0)
            Console.WriteLine("No");
        var s1 = s.Substring(0, (s.Length - 1) / 2);
        var s2 = s.Substring((s.Length + 3) / 2 - 1, (s.Length - 1) / 2);
        Console.WriteLine(s1 == s2 ? "Yes" : "No");
    }
}

Measured memory_bytes: 13140
import java.util.Scanner;
import java.util.ArrayDeque;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner (System.in);
	int n = Integer.parseInt(scan.nextLine());
	int[][] graph = new int[n+1][n+1];
	int u, k, v;
	String[] input;
	for (int i = 0; i < n; i++) {
	    input = scan.nextLine().split(" ");
	    u = Integer.parseInt(input[0]);
	    k = Integer.parseInt(input[1]);
	    for (int j = 0; j < k; j++) {
		v = Integer.parseInt(input[2+j]);
		graph[u][v] = 1;
	    }
	}

	ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
	int[] dist = new int[n+1];
	for (int i = 2; i <=n; i++) {
	    dist[i] = Integer.MAX_VALUE;
	}
	queue.add(1);
	while (!queue.isEmpty()) {
	    int city = queue.poll();
	    for (int i = 0; i <= n; i++) {
		if (graph[city][i] != 0 && dist[i] > dist[city] + 1) {
		    dist[i] = dist[city] + 1;
		    queue.add(i);
		}
	    }
	}

	for (int i = 1; i <=n; i++) {
	    System.out.print(i + " ");
	    if (dist[i] == Integer.MAX_VALUE) {
		System.out.println(-1);
	    } else {
		System.out.println(dist[i]);
	    }
	}
    }
}

Measured memory_bytes: 26696
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int[] data = {a+b,b+c,c+a};
    int min = data[0];

    for (int i = 0; i < 3; i++) {
      min = Math.min(data[i],min);
    }

    System.out.println(min);
  }

}


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

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++){
    cin >> p.at(i);
  }
  vector<int> vec(0);
  for (int i = 0; i < N; i++){
    vec.push_back(p.at(i));
  }
  sort(vec.begin(), vec.end());
  
  int dif = 0;
  for (int i = 0; i < N; i++){
    if (p.at(i) != vec.at(i)){
      dif++;
    }
  }
  
  if (dif <= 2){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}





Measured memory_bytes: 3564
import java.util.*

class Position(val x: Int, val y: Int, val times: Int)
val delta = arrayOf(
        Pair(1, 0),
        Pair(-1, 0),
        Pair(0, 1),
        Pair(0, -1)
)

fun main(args : Array<String>) {
    val (H, W) = readLine()!!.split(" ").map { it.toInt() }
    val map = Array(H, { Array(W, { false })})

    val queue: Queue<Position> = ArrayDeque()
    (0..(H-1)).forEach { h ->
        readLine()!!.forEachIndexed { w, c ->
            if (c == '#') {
                map[h][w] = true
                queue.offer(Position(h, w, 0))
            } else {
            }
        }
    }
    var times = 0
    while (queue.isNotEmpty()) {
        val position = queue.poll()
        times = position.times
        delta.forEach { d ->
            val dx = d.first
            val dy = d.second
            val x = position.x + dx
            val y = position.y + dy
            val isValid = 0 <= x && x < H && 0 <= y && y < W
            if (isValid && !map[x][y]) {
                map[x][y] = true
                queue.offer(Position(x, y, position.times + 1))
            }
        }
    }

    println(times)
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    int s; cin >> s;
    vector<int> v;
    int a = s;
    v.push_back(a);
    REP(i, 1000001) {
        if (a%2==0) {
            a = a/2;
        } else {
            a = 3*a + 1;
        }
        if (find(v.begin(), v.end(), a) != v.end()) {
            cout << i+2 << endl;
            break;
        }
        v.push_back(a);
    }
    
    return 0;
}

Measured memory_bytes: 888
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define fi first
#define se second
#define pi pair<LL,LL>
#define LL long long
using namespace std;
const LL inf=2e9;
const LL mod=1e9+7;
LL n,h[110];
LL pow(LL a,LL b)
{
	LL ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;b>>=1;
	}
	return ans;
}
pi solve(LL l,LL r,LL k)//l r区间大于k的部分
{
	LL Min=inf,cnt=0;pi ans;
	for(LL i=l;i<=r;i++)
	{
		if(h[i]<Min) Min=h[i],cnt=1;
		else if(h[i]==Min) cnt++;
	}
	if(cnt==(r-l+1))//矩形随便算 
	{
		ans.fi=(pow(2,r-l+1)+mod-2)%mod;
		ans.se=pow(2,Min-k-1);
		return ans;
	}
	LL re=r-l+1,s0=1,s1=1,last=0;//s0 s1是first second 
	for(LL i=l;i<=r+1;i++) if(!last&&h[i]>Min) last=i;
	else if(last&&(h[i]<=Min||i>r))
	{
		re-=i-last;
		pi tmp=solve(last,i-1,Min);
		s0=s0*(tmp.fi+4*tmp.se%mod)%mod;//*4是因为上一行可以取反，当前行亦然，2*2
		s1=s1*(2*tmp.se%mod)%mod;
		last=0;
	}
	s0=(s0+mod-s1)%mod;
	ans.fi=s0*pow(2,re)%mod;
	(ans.fi+=(s1*(pow(2,re)-2+mod)%mod)%mod)%=mod; 
	ans.se=s1*pow(2,Min-k-1)%mod;
	//因为fi可以从两种情况转移过来，se只能从s1转移过来 
	return ans;
} 
int main()
{
	scanf("%lld",&n);
	for(LL i=1;i<=n;i++) scanf("%lld",&h[i]);
	if(n==1)
	{
		printf("%lld",pow(2,h[1]));
		return 0;
	}
	LL tot=1;
	for(LL i=1;i<=n;i++) if(h[i]>h[i-1]&&h[i]>h[i+1])
	{
		(tot*=pow(2,h[i]-max(h[i-1],h[i+1])))%=mod;
		h[i]=max(h[i-1],h[i+1]);
	}
	pi ans=solve(1,n,0);
	printf("%lld",tot*((ans.fi+ans.se*2)%mod)%mod);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define F first
#define S second
#define pb push_back
using namespace std;
string s[1000000];
int p[1000000];
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    multiset<pair<pair<string,int>,int > >ms;
    for(int i=1;i<=n;i++){
        cin>>s[i]>>p[i];
        ms.insert({{s[i],-1*p[i]},i});
    }
    for(auto it=ms.begin();it!=ms.end();it++){
            auto k=(*it);
            cout<<k.S<<endl;
    }
    return 0;
}


Measured memory_bytes: 9728
#ifndef ___Class_RSQ
#define ___Class_RSQ

#include <limits>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

template <typename Type> class RSQ
{
private:

	int size;

	vector<Type> sumvalue;

	Type _query(int a, int b, int k, int l, int r)
	{
		if (r <= a || b <= l) { return 0; }
		if (a <= l && r <= b) { return sumvalue[k]; }

		Type vl = _query(a, b, 2 * k, l, (l + r) / 2);
		Type vr = _query(a, b, 2 * k + 1, (l + r) / 2, r);

		return vl + vr;
	}

public:

	RSQ(int size_)
	{
		for (size = 1; size < size_;) { size <<= 1; }

		sumvalue = vector<Type>(size * 2, 0);
	}

	void update(int i, const Type& x)
	{
		i += size;

		sumvalue[i] += x;

		while (i > 1)
		{
			i = i / 2;

			sumvalue[i] = sumvalue[i * 2] + sumvalue[i * 2 + 1];
		}
	}

	Type query(int s, int t)
	{
		return _query(s, t, 1, 0, size);
	}
};

#endif


// ------ main ------ //

#include <cstdio>

#pragma warning(disable: 4996)

using namespace std;

int n, q, com, x, y;

int main()
{
	scanf("%d", &n);
	scanf("%d", &q);

	RSQ<long long> r(n);

	for (int i = 0; i < q; i++)
	{
		scanf("%d", &com);
		scanf("%d", &x);
		scanf("%d", &y);

		if (com == 0)
		{
			r.update(x - 1, y);
		}
		if (com == 1)
		{
			printf("%lld\n", r.query(x - 1, y));
		}
	}

	return 0;
}

Measured memory_bytes: 4508
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int N,M,A,B;
  cin>>N>>M>>A>>B;
  if(N*M<(A+B)*2){
    cout<<"NO"<<endl;
    return 0;
  }
  Int n=N,m=M,a=A,b=B;
  
  vector<string> s(N,string(M,'.'));
  if(m&1){
    Int x=min(b,n/2);
    for(Int i=0;i<x;i++){
      s[i*2][m-1]='^';
      s[i*2+1][m-1]='v';
    }
    b-=x;
    m--;
  }
  
  if(n&1){
    Int x=min(a,m/2);
    for(Int i=0;i<x;i++){
      s[n-1][(M&1)+i*2]='<';
      s[n-1][(M&1)+i*2+1]='>';
    }
    a-=x;
    n--;
  }
  for(Int i=0;i<n;i+=2){
    for(Int j=m-2;j>=0;j-=2){
      if(i+2==n&&j==0&&(N&1)&&(M&1)){
	if(a&&b){
	  s[i][j]='<';
	  s[i][j+1]='>';
	  s[i+1][j]='^';
	  s[i+2][j]='v';       
	  a--;b--;
	  continue;
	}
      }
      if(a>=2){
	s[i][j]='<';
	s[i][j+1]='>';
	a--;
	s[i+1][j]='<';
	s[i+1][j+1]='>';
	a--;
      }else if(b>=2){
	s[i][j]='^';
	s[i+1][j]='v';
	b--;
	s[i][j+1]='^';
	s[i+1][j+1]='v';
	b--;
      }else if(a){
	s[i][j]='<';
	s[i][j+1]='>';
	a--;
      }else if(b){
	s[i][j]='^';
	s[i+1][j]='v';
	b--;
      }
    }
  }
  if(0){
    cout<<a<<" "<<b<<endl;
    for(Int i=0;i<N;i++) cout<<s[i]<<endl;
  }
  
  if(a==0&&b==0){
    cout<<"YES"<<endl;
    for(Int i=0;i<N;i++) cout<<s[i]<<endl;
    return 0;
  }
  cout<<"NO"<<endl;
  return 0;
}


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

int main() {
int V, L;
cin >> V;
int MAX = 9999999;
int kunto = 0;
for (int i = 0; i < V; i++){
cin >>L;
kunto= 0;
while (L % 2 == 0){
L /= 2;
kunto += 1;
}
if (MAX > kunto){
 MAX = kunto;
}
}
cout << MAX << endl;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)



int main(){
	int N; cin >> N;	
	vector<int> a(N);
	int s = 0;
	repp(i,0,N){
		cin >> a[i];
		s += a[i];
	}
	int ans = N, m = 1e9;
	repp(i,0,N){
		if(abs(s-a[i]*N) < m){
			ans = i;
			m = abs(s-a[i]*N);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 768
n, d = map(int, input().split())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
ans = 0
d = d ** 2

for i in range(n):
    if ( x[i] ** 2 + y[i] ** 2 ) <= d:
        ans += 1

print(ans)

Measured memory_bytes: 116644
#include <bits/stdc++.h>
#define ll long long
#define arena ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main() 
{
   ll n;
   cin>>n;
   string s[n];
   map<string,ll> m;
   for(ll i=0;i<n;i++)
   {
       cin>>s[i];
       m[s[i]]++;
   }
   ll x=LONG_MIN;
   for(auto it:m)
   {
       x=max(x,it.second);
   }
   
   vector<string> v;
   for(auto it:m)
   {
       if(it.second==x)
       v.push_back(it.first);
   }
   sort(v.begin(),v.end());
   
   for(ll i=0;i<v.size();i++)
   {
       cout<<v[i]<<'\n';
   }
}

Measured memory_bytes: 28404
#include<stdio.h>
#include<string.h>

void trace( char A[][3], int n )
{
	int i=0;
	while( i<n ) {
		printf( "%s", A[i++] );
		if( i != n ) { printf( " " ); }
	}
	printf( "\n" );
	
	return;
}

void BubbleSort( char A[][3], int n ) 
{
	int i,j;
	char tmp[3];

	for( i=0; i<n; i++ ) {
		for( j=n-1; i<j; j-- ) {
			if( A[j][1]-'0' < A[j-1][1]-'0' ) {
				strncpy( tmp, A[j-1], 3 );
				strncpy( A[j-1], A[j], 3 );
				strncpy( A[j], tmp, 3 );
			}
		}
	}
	
	trace( A, n );
	
	return;
}

void SelectionSort( char A[][3], int n ) 
{
	int i,j;
	char tmp[3];
	int mini;
	
	for( i=0; i<n; i++ ) {
		mini=i;
		for( j=i; j<n; j++ ) {
			if( A[j][1]-'0' < A[mini][1]-'0' ) {
				mini=j;
			}
		}
		if( mini != i ) {
			strncpy( tmp, A[i], 3 );
			strncpy( A[i], A[mini], 3 );
			strncpy( A[mini], tmp, 3 );
		}
	}
	
	trace( A, n );
	
	return;
}

int main( void ) 
{
	int n;
	char cards[37][3];
	char cards2[37][3];	
	int i;

	scanf( "%d", &n );
	for( i=0; i<n; i++ ) {
		scanf( "%s", cards[i] );
		strncpy( cards2[i], cards[i], 3 );
	}
	
	BubbleSort( cards, n );
	printf( "Stable\n" );

	SelectionSort( cards2, n );
	for( i=0; i<n; i++ ) {
		if( cards[i][0] != cards2[i][0] ) {
			break;
		}
	}
	if( n != i ) {
		printf( "Not stable\n" );
	} else {
		printf( "Stable\n" );
	}
	
	return 0;
}

Measured memory_bytes: 620
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val L = nextIntList().sorted()
    val longest = L.last()
    val others = L.dropLast(1).sum()
    println(if (longest < others) "Yes" else "No")
}

Measured memory_bytes: 37800
package main
 
import(
  "fmt"
  "bufio"
  "os"
  "strings"
  "strconv"
  "log"
)
 

func main(){
  a,b := uint64(0),uint64(0)
  fmt.Scan(&a)
  fmt.Scan(&b)
  d := int64(a/b)
  r := int64(a%b)
  f := float64(a)/float64(b)
  fmt.Printf("%d %d %f\n",d,r,f)
}


var sc = bufio.NewScanner(os.Stdin)

func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}



//入力関係ライブラリ(Atcoder:yamanobori_oldさんのもの)
func make_liner(maxByte int) *bufio.Scanner {
  liner := bufio.NewScanner(os.Stdin)
  liner.Buffer(make([]uint8, 0, 8192), maxByte)
  return liner
}
func word_spliter() *bufio.Scanner {
  words := make_liner(8192) 
  words.Split(bufio.ScanWords)
  return words
}

func eGetLine(r *bufio.Scanner) string {
  if r.Scan() {
    return r.Text()
  }
  err := r.Err()
  if err != nil {
    log.Fatal(err)
  }
  // EOF
  return ""
}

func eGetInt(r *bufio.Scanner) int {
  line := eGetLine(r)
  return eAtoi(line)
}

func eAtoi(s string) int {
  n, err := strconv.Atoi(s)
  if err != nil {
    log.Fatal(err)
  }
  return n
}


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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

int n;
vector<vector<int> > F;
vector<vector<int> > P;

int cost(vector<int> v, int shop){
    vector<int> tmpv(10);
    for (int i = 0; i < 10; i++) {
        tmpv[i] = (v[i] & F[shop][i]);
    }

    return P[shop][accumulate(tmpv.begin(), tmpv.end(), 0)];
}

int main(int argc, char const* argv[])
{
    // int n;
    cin >> n;
    // vector<vector<int> > F(n);
    F.resize(n);
    for (int i = 0; i < n; i++) {
        F[i].resize(10);
        for (int j = 0; j < 10; j++) {
            cin >> F[i][j];
        }
    }

    // vector<vector<int> > P(n);
    P.resize(n);
    for (int i = 0; i < n; i++) {
        P[i].resize(11);
        for (int j = 0; j < 11; j++) {
            cin >> P[i][j];
        }
    }

    int ans=INT_MIN;
    // for (int i = 0; i < (int)pow(3,5); i++) {
    for (int i = 1; i < (int)pow(2,10); i++){
        vector<int> v(10);
        int t=i;
        // for (int j = 0; j < 10; j+=2) {
        //     if (t % 3 == 0) {
        //         v[j] = 0;
        //         v[j+1] = 1;
        //     }else if (t % 3 == 1){
        //         v[j] = 1;
        //         v[j+1] = 0;
        //     }else{
        //         v[j] = 1;
        //         v[j+1] = 1;
        //     }
        //     t /= 3;
        // }
        for (int j = 0; j < 10; j++) {
            if (t % 2 == 0) {
                v[j] = 0;
            }else {
                v[j] = 1;
            }
            t /= 2;
        }


        // cout << "i=" << i << " ";
        // for (int j = 0; j < 10; j++) {
        //     cout << v[j];
        // }
        // cout << endl;

        int tmpcost=0;
        for (int shop = 0; shop < n; shop++) {
           tmpcost += cost(v, shop);
        }
        ans = max(ans, tmpcost);
        // cout << tmpcost << " ";
        // // if (tmpcost == -4) {
        //     for (int k = 0; k < 10; k++) {
        //         cout << v[k];
        //     }
        //     cout << endl;
        // // }

    }

    // cout << cost(F[0], 0) << endl;
    // printmatrix(F); 
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// int main(int argc, char const *argv[]) {
//   cout << 1000000000;
//   for(long long i=1;i<1000000000;i++){
//     cout << i << endl;
//   }
//   return 0;
// }
int main(){
  int n, k;
  long long h[100000];
  long long hs[100000];
  long long minimum=10000000000;
  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  sort(h,h+n);
  for(int i=0;i<n-(k-1);i++){
    minimum=min(minimum,h[i+(k-1)]-h[i]);
  }
  cout << minimum << endl;

}

Measured memory_bytes: 1024
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N = 1e7 + 5;
int a[N];

void solve(int test) {
	for(int i = 1; i < N ; ++i) {
		for(int j = i ; j < N ; j += i) {
			a[j]++;
		}
	}

	int n; cin >> n ;

	int ans = 0 ;

	for(int i = 1 ; i <= n ; ++i) ans += i * a[i] ;

	cout << ans ; 
}
 
int32_t main() {
 
 
    fast;
	int t=1;
	// cin>>t;
	rep(i,0,t) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] price = new int[n];
		int ans=0;

		for(int i=0;i<n;i++) {
			price[i]=sc.nextInt();
		}
		Arrays.sort(price);
		for(int i=0;i<n;i++) {
			if(i==n-1) {
				ans+=price[i]/2;
			}else {
				ans+=price[i];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21588
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CWelcomeToAtCoder {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, M;
        cin >> N >> M;
        vector<int> p(M);
        vector<string> S(M);
        REP(i, M) {
            cin >> p[i] >> S[i];
            p[i]--;
        }

        vector<int> AC(N), WA(N);
        REP(i, M) {
            int no = p[i];
            auto& res = S[i];

            if (res == "AC") {
                AC[no]++;
            }
            if (res == "WA") {
                if (AC[no] == 0) {
                    WA[no]++;
                }
            }
        }

        int ac, wa;
        ac = 0;
        wa = 0;
        REP(i, N) {
            if (AC[i] > 0) ac++;
            if (AC[i] > 0) wa += WA[i];
        }
        cout << ac << " " << wa << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CWelcomeToAtCoder solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };

signed main() {
  int n,m;
  cin >> n >> m;
  vector<vector<int>> s(m);
  int ans = 0;
  bool flag;
  rep(i,m) {
    int k; cin >> k;
    rep(j,k) {
      int a; cin >> a;
      s[i].push_back(a);
    }
  }
  int p[m];
  for (int i = 0; i < m; i++) cin >> p[i];

  for (int bit = 0; bit < (1<<n); ++bit) {
    vector<int> B(n+1,0);
    for (int i = 0; i < n; ++i) {
      if (bit & (1<<i)) {
        B[i+1] = 1;
        // cout << B[i+1] << ' ';
      }
    }
    // cout << endl;
    flag = true;
    rep(j,m) {
      int cnt = 0;
      for (int swi : s[j]) {
        if (B[swi]==1) cnt++;
      }
      cnt %= 2;
      if (cnt != p[j]) flag = false;
    }
    if (flag) ans++;
  }
  cout << ans << endl;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    int a, b;
    std::cin >> a >> b;
    int mul = a * b;
    if(mul % 2 == 0){
        std::cout << "Even";
    }
    else{
        std::cout << "Odd";
    }
    return 0;
}

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

const int MAXS = 1e5 + 5;
int winner[MAXS];

int main() {
    memset(winner, -1, sizeof(winner));
    int n, k;
    cin >> n >> k;
    vector<int> st(n);
    for(int i =0; i < n; i++)
        cin >> st[i];
    for(int p = 1; p <= k; p++) {
        for(int i = 0; i < n; i++) {
            if(p - st[i] >= 0 && winner[p - st[i]] == -1)
                winner[p] = 1;
        }
    }
    cout << (winner[k] == 1 ? "First" : "Second") << endl;
}

Measured memory_bytes: 640