akhauriyash/Code-Regression huggingface dataset:
import math

def combinations_count(n):
    return math.floor(n*(n-1)/2)

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    hist = [0] * 2*pow(10, 5)
    for a in A:
        hist[a-1] += 1

    all = 0
    for h in hist:
        if h >= 2:
            all += combinations_count(h)

    for a in A:
        h = hist[a-1]
        if h >= 2:
            diff = h-1
            print(all - diff)
        else:
            print(all)
    
if __name__ == "__main__":
    resolve()

Measured memory_bytes: 26140
#include <iostream>
#include<cmath>
#include <algorithm>
#include<string>
using namespace std;
int main()
{
	int N;
	int ans=0;
	string a, b, c;
	cin >> N;
	cin >> a >> b >> c;
	if (a == b && b == c) {
		cout << ans << endl;
	}
	else {
		for (int i = 0; i < N; i++) {
			if (a[i] == b[i] && b[i] != c[i]) {
				c[i] = a[i];
				ans++;
			}
			else if (a[i] != b[i] && b[i] == c[i]) {
				a[i] = b[i];
				ans++;
			}
			else if (a[i] != b[i] && a[i] == c[i]) {
				b[i] = a[i];
				ans++;
			}
			else if (a[i] != b[i] && b[i] != c[i]) {
				a[i] = b[i];
				c[i] = b[i];
				ans += 2;

}
		}
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int s;
  cin>>s;
  map<Int, Int> m;
  Int i=1;
  while(!m.count(s)){
    m[s]=i++;
    if(s&1) s=s*3+1;
    else s/=2;
  }
  cout<<i<<endl;
  return 0;
}


Measured memory_bytes: 256
// atc.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <string>
#include    <algorithm>
using namespace std;

//int n, m, x;
//
//vector<int> c(12,0);
//vector<vector<int>> A(12, vector<int>(12, 0));



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

    vector<double> H(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> H[i];
    }

    vector<int> flag(n, 1);
    vector<int> best(n, 0);
    int a, b, count = 0;

    for (int i = 0; i < n; i++) {
        best[i] = i;
    }

    vector<int> A(m, 0), B(m, 0);
    for (int i = 0; i < m; i++) {
        cin >> A[i] >> B[i];
    }

    
    for (int i = 0; i < m; i++) {
        a = A[i] - 1;
        b = B[i] - 1;

        if (H[a] > H[b]) {
            flag[b] = 0;
        }
        else if (H[a] < H[b]) {
            flag[a] = 0;
        }
        else {
            flag[a] = 0;
            flag[b] = 0;
        }
    }




    for (int i = 0; i < n; i++) {
        if (flag[i] == 1) {
            count++;
        }
    }


    printf("%d", count);


    return 0;

}


Measured memory_bytes: 5688
elements = gets.chomp.split(" ")
stack = []
elements.each do |e|
  case e
    when "+"
      a, b = stack.pop(2)
      stack.push(a + b)
    when "*"
      a, b = stack.pop(2)
      stack.push(a * b)
    when "-"
      a, b = stack.pop(2)
      stack.push(a - b)
    else
      stack.push(e.to_i)
  end
end
puts stack

Measured memory_bytes: 8688
def main():
    s = input()
    pa = [0]
    pb = [0]
    pc = [0]
    pd = [0]

    n = len(s)
    for i in range(n):
        pa.append(pa[-1])
        pb.append(pb[-1])
        pc.append(pc[-1])
        pd.append(pd[-1])

        if s[i] == 'A':
            pa[-1] += 1
        elif s[i] == 'B':
            pb[-1] += 1
        elif s[i] == 'C':
            pc[-1] += 1
        elif s[i] == '?':
            pd[-1] += 1

    totq = pd[n]

    MOD = 1000000007
    ans = 0
    for i in range(1, n + 1):
        if s[i - 1] == 'A' or s[i - 1] == 'C':
            continue

        if s[i - 1] == 'B':
            buf = 0
        else:
            buf = 1

        # ABC ?BC AB? ?B?
        a_bef = pa[i - 1]
        d_bef = pd[i - 1]
        c_aft = pc[n] - pc[i]
        d_aft = pd[n] - pd[i]

        if a_bef * c_aft > 0:
            ans += (a_bef * c_aft % MOD) * pow(3, totq - buf, MOD) % MOD
            ans %= MOD

        if d_bef * c_aft > 0:
            ans += (d_bef * c_aft % MOD) * pow(3, totq - buf - 1, MOD) % MOD
            ans %= MOD

        if a_bef * d_aft > 0:
            ans += (a_bef * d_aft % MOD) * pow(3, totq - buf - 1, MOD) % MOD
            ans %= MOD
        
        if d_bef * d_aft > 0:
            ans += (d_bef * d_aft % MOD) * pow(3, totq - buf - 2, MOD) % MOD
            ans %= MOD

    print(ans)

main()


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

#define N (1000 + 10)

#define max(a, b) (a < b ? b : a) 



int dp[N][N];
char a[N], b[N];

int LCS(void)
{
  const int a_size = strlen(a) - 1;
  const int b_size = strlen(b) - 1;
  int i,j,MAX;

  memset(dp,0,sizeof(dp));

  for(i=1;i<a_size+1;++i){
    for(j=1;j<b_size+1;++j){
      MAX = max(dp[i][j - 1],dp[i - 1][j]);
      if(a[i - 1] == b[j - 1]){
	MAX = max(MAX,dp[i - 1][j - 1]+1);
      }
      
      dp[i][j] = MAX;
    }
  }

  return dp[a_size][b_size];

}

int main(){
  
  int i,n;
  
  scanf("%d\n",&n);
  
  for(i=0;i<n;i++){
    
    fgets(a,N,stdin);
    fgets(b,N,stdin);
    printf("%d\n",LCS());
  }
  
  return 0;

}



Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
ll a[N];
int main()
{
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%lld", a+i);
	sort(a+1, a+1+n);
	ll ans = 0;
	if (n == 2 || n == 3) {
		if (n == 2) ans = a[2];
		else ans = a[1]+a[2];
		printf("%lld\n", ans);
		return 0; 
	}
	ans = a[n];
	int cnt = 1;
	for (int i = n-1; i > 0; i--) {
		ans += 2*a[i];
		cnt += 2;
		if (cnt >= n-1) {
			if (n & 1) ans -= a[i];
			break;
		}
	}
	printf("%lld\n", ans); 
	return 0;
}

Measured memory_bytes: 5392
s = input()
m = 0
l = 0
for c in s:
    if not (c == 'A' or c == 'C' or c == 'G' or c == 'T'):
        m = max(m, l)
        l = 0
        continue

    l += 1

m = max(m, l)
print(m)

Measured memory_bytes: 2940
# input
N = int(input())
S = input()

# check

# 参考：https://qiita.com/IGMML/items/5aa36f7fa03746ed6e6c
# 累積和で求める
int_s = [0] * N
cum_sum_w = [0] * (N + 1)
cum_sum_e = [0] * (N + 1)
answers = [0] * N

for i in range(N):
    if S[i] == 'W':
        int_s[i] = 1
    else:
        int_s[i] = 0
    cum_sum_w[i + 1] = cum_sum_w[i] + int_s[i]

for i in range(N):
    if S[i] == 'E':
        int_s[i] = 1
    else:
        int_s[i] = 0
    cum_sum_e[i + 1] = cum_sum_e[i] + int_s[i]

for i in range(N):
    answers[i] = cum_sum_w[i] + (cum_sum_e[N] - cum_sum_e[i + 1])
    
print(min(answers))

Measured memory_bytes: 41332
using System;
using System.Linq;

namespace A
{
    class Calc
    {
        public void MST(int[,] gragh, int n)
        {
            int[] d = new int[n];
            int[] pi = new int[n];
            string[] color = new string[n];
            int i;
            for (i = 0; i < n; i++)
            {
                d[i] = int.MaxValue;
                pi[i] = -1;
                color[i] = "WHITE";
            }
            d[0] = 0;

            int u=0;
            while (true)
            {
                int min = int.MaxValue;
                for (i = 0; i < n; i++)
                {
                    if (color[i] != "BLACK" && d[i] < min)
                    {
                        min = d[i];
                        u = i;
                    }
                }
                if (min == int.MaxValue)
                {
                    break;
                }
                color[u] = "BLACK";

                for (int v = 0; v < n; v++)
                {
                    if (color[v] != "BLACK" && gragh[u, v] != -1 &&gragh[u, v] < d[v])
                    {
                        pi[v] = u;
                        d[v] =gragh[u,v];
                    }
                }
            }

            Console.WriteLine(d.Sum());
        }
    }

    class A
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            int n = int.Parse(input1), i, j;
            int[,] gragh = new int[n, n];
            string[] input2 = new string[n+1];
            for (i = 0; i < n; i++)
            {
                input2 = Console.ReadLine().Split(' ');
                for (j = 0; j < n; j++)
                {
                    gragh[i, j] = int.Parse(input2[j + 1]);  
                }
            }
            Calc check = new Calc();
            check.MST(gragh, n);
        }
    }
}



Measured memory_bytes: 16180
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=LONG_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
ll a,b,c,d,n,ans,mn=llinf;
int main()
{
	//freopen("sol.in","r",stdin);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>a>>b>>c>>d>>n;
	mn=min(2LL*a,b);
	mn=min(2LL*mn,c);
	if(mn*2LL<=d)ans=n*mn;
	else
	{
		ans=(n/(2LL))*d;
		ans+=(n%(2LL))*mn;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    sort(a.begin(), a.end());
  
    int pair;
    double dist = a[N-1];
    for (int i = 0; i < N-1; i++) {
        double tmp = abs(double(a[i]) - double(a[N-1])/2);
        if (tmp < dist) {
            pair = i;
            dist = tmp;
        }
    }
    cout << a[N-1] << " " << a[pair] << endl;

}

signed main() {
    solve();
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=1e6+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,len,p[3],q[3],cnt[3];
char s[N];

bool cmp(int x,int y) {
	return cnt[x]<cnt[y];
}

int main() {
	scanf("%s",s+1);len=strlen(s+1);
	for(int i=1;i<=len;i++)
		if(s[i]!=s[i-1]) s[++n]=s[i];
	for(int i=1;i<=n;i++) s[i]-='A',++cnt[s[i]];
	for(int i=0;i<3;i++) p[i]=i;
	//cerr<<p[0]<<' '<<p[1]<<' '<<p[2]<<'\n';
	sort(p,p+3,cmp);sort(cnt,cnt+3);
	//for(int i=0;i<3;i++) cerr<<cnt[i]<<' ';
	for(int i=0;i<3;i++) q[p[i]]=i;
	for(int i=1;i<=n;i++) s[i]=q[s[i]];
	int x=0,y=0;
	for(int i=1,j;i<=n;i=j+1) {
		j=i;
		if(s[i]) {
			while(j<n&&s[j+1]) ++j;
			if(i==j&&i!=1&&j!=n&&s[i]==2) ++y;
			else {
				if(i!=j||s[i]==1) ++x;
				if(s[i]==2&&cnt[2]>cnt[1]) --cnt[2],s[i]=3;
				if(s[j]==2&&cnt[2]>cnt[1]) --cnt[2],s[j]=3;
			}
		}
	}
	//cerr<<cnt[0]<<' '<<cnt[1]<<' '<<cnt[2]<<'\n';
	int tmp=max(y-x,0);
	//cerr<<x<<' '<<y<<' '<<tmp<<'\n';
	for(int i=2;i<n&&tmp;i++)
		if(!s[i-1]&&!s[i+1]&&s[i]==2) --tmp,--cnt[2],--cnt[0],s[i-1]=s[i]=3;
	len=0;
	for(int i=1;i<=n;i++)
		if(s[i]!=3) s[++len]=s[i];
	n=len;
	//cerr<<cnt[0]<<' '<<cnt[1]<<' '<<cnt[2]<<'\n';
	for(int i=1,j;i<=n;i=j+1) {
		j=i;
		if(s[i]) {
			while(j<n&&s[j+1]) ++j;
			int tmp;
			if(i==1||j==n) tmp=(j-i+1)/2;
			else tmp=(j-i)/2;
			for(int k=i;cnt[1]>cnt[0]&&tmp;k+=2) s[k]=s[k+1]=3,--cnt[1],--tmp;
		}
	}
	for(int i=1;i<=n;i++) if(s[i]<3) putchar(p[s[i]]+'A');
	return 0;
}


Measured memory_bytes: 2176
import sys

line = sys.stdin.readline().strip()
# print(line)

def check(line):
    ns = line.count("a"), line.count("b"), line.count("c")
    ns = sorted(ns)
    m = min(ns)
    ns = ns[0] - m, ns[1] - m, ns[2] - m
    # print(ns, m)
    return ns[2] < 2

if check(line):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3188
// https://atcoder.jp/contests/abc165/tasks/abc165_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename F>
class
#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
    [[nodiscard]]
#elif defined(__GNUC__) && \
    (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
    __attribute__((warn_unused_result))
#endif
    FixPoint : private F {
 public:
  explicit constexpr FixPoint(F && f) noexcept : F(std::forward<F>(f)) {}

  template <typename... Args>
  constexpr decltype(auto) operator()(Args&&... args) const
#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
      noexcept(noexcept(
          F::operator()(std::declval<FixPoint>(), std::declval<Args>()...)))
#endif
  {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <typename F>
static inline constexpr decltype(auto) makeFixPoint(F&& f) noexcept {
  return FixPoint<F>{std::forward<F>(f)};
}

void solve() {
  ll N, M, Q;
  cin >> N >> M >> Q;

  struct Const {
    ll a, b, c, d;
  };

  V<Const> cs(Q);

  rep(i, Q) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    --a, --b;
    cs[i] = {a, b, c, d};
  }

  ll res = 0;

  auto dfs = makeFixPoint([&](auto f, VL& arr) -> void {
    if (len(arr) == N) {
      ll sum = 0;

      for (auto c : cs) {
        if (arr[c.b] - arr[c.a] == c.c) sum += c.d;
      }

      chmax(res, sum);
      return;
    }

    ll last_value = len(arr) == 0 ? 1 : arr.back();

    for (ll v = last_value; v <= M; ++v) {
      arr.push_back(v);
      f(arr);
      arr.pop_back();
    }
  });

  VL arr(0);
  dfs(arr);

  cout << res << "\n";
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c) 
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;

const int max_h=100,max_w=100;
int h,w;
char a[max_h+1][max_w+1];

void solve(){
    priority_queue<int,vector<int>,greater<int>> H,W;
    queue<int> que;
    bool flag=false;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]=='#') break;
            else if(j==w-1 && a[i][j]!='#')
            H.push(i);
        }
    }
    for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
            if(a[j][i]=='#') break;
            else if(j==h-1 && a[j][i]!='#')
            W.push(i);
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(!H.empty() || !W.empty()){
                if(i==H.top()){
                    H.pop();
                    flag=true;
                    break;
                }else if(j==W.top()){
                    que.push(W.top());
                    W.pop();
                }else cout << a[i][j];
            }else cout << a[i][j];
        }
        while(!que.empty()){
            W.push(que.front());
            que.pop();
        }
        if(!flag) cout << endl;
        else flag=false;
    }
}



int main(){
    cin >> h >> w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
        }
    }
    solve();
}

Measured memory_bytes: 256
N,K = map(int,input().split(' '))

max_num = (N-2)*(N-2+1)/2
M = 0
if max_num >=K:
    base_graph = [[] for _ in range(N+1)]
    base_graph[1].append(2)
    base_graph[2].append(1)
    for i in range(3,N+1):
        base_graph[1].append(i)
        base_graph[i].append(1)
    #print(base_graph)
    M = N- 1

    idx = N
    diff = max_num-K
    while diff != 0:
        if len(base_graph[idx]) == N-1:
            idx -= 1
        else:
            insert_val = len(base_graph[idx]) + 1 - (N-idx)
            base_graph[idx].append(insert_val)
            base_graph[insert_val].append(idx)
            diff -=1
            M +=1
    print(M)
    for idx,node in enumerate(base_graph): 
        for i in node:
            if idx < i:
                print(idx,i)
        
else:
    print(-1)

Measured memory_bytes: 3740
#include <stdio.h>

int main(){
	int i;
	int n;
	scanf("%d", &n);
	int R[n];
	for(i=0;i<n;i++)
		scanf("%d",&R[i]);

	int minv = R[0], maxv=R[1]-R[0];
	for(i=1;i<n;i++){
		maxv = maxv < R[i] - minv ? R[i] - minv : maxv;
		minv = minv > R[i] ? R[i] : minv;
	}
	printf("%d\n",maxv);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int r=0;
void dfs(int n,int s){
  if(s==1){
    r++;
    return;
  }
  for(int i=0;i*s*s<=n;i++) dfs(n-i*s*s,s-1);
}
 
int main(){
  for(int n;cin>>n,n;r=0){
  dfs(n,17);
  cout<<r<<endl;
  }
  return 0;
}

Measured memory_bytes: 3076
#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;

int main(void){
  int s, w;
  cin >> s >> w;
  if(w >= s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  return 0;
}

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

cnt = 0

for i in range(N):
    c = min(A[i]+A[i+1], B[i])
    cnt += c
    A[i+1] = A[i+1] - max(c-A[i], 0)

print(cnt)

Measured memory_bytes: 24040
while(1):
    [n, m, h, k ] = [int(x) for x in input().split()]
    if n==0:
        break
    A=[]
    B=[ [] for x in range(h)]
    C=list(range(n))
    S=[0 for i in range(n)]
    X=[]
    for i in range(n):
        A.append(int(input()))
    for i in range(m):
        [a, b] = [int(x) for x in input().split()]
        B[b].append(a)
    for y in range(h):
        for a in B[y]:
            C[a-1:a+1]=[C[a], C[a-1]]
            X.append( sorted( C[a-1:a+1] ))
    for i in range(n):
        S[C[i]]=A[i]
    #print(S)
    ans=sum( S[:k ] )
    tmpdif=0
    for xx in X:
        if xx[0]<k and xx[1]>=k:
            tmpdif = min (tmpdif, S[xx[1]] - S[xx[0]] )
    print(ans + tmpdif)


Measured memory_bytes: 20208
import java.util.Scanner;

public class Main{
    public static void main(String[] aaa){
        Scanner s = new Scanner(System.in);
        int[] count = new int[27];
        String st;
        char m;
        int i,j;
        while(s.hasNext()){
            st = s.next();
            for(i=0;i<st.length();i++){
                j=st.charAt(i);
                if(j-'a'>=0&&j-'a'<26)count[st.charAt(i)-'a']++;
                else if(j-'A'<26&&j-'A'>=0)count[st.charAt(i)-'A']++;
            }
        }
        for(i=0;i<26;i++){
            m = (char)('a'+i);
            System.out.println(m+" : "+count[i]);
        }
    }
}


Measured memory_bytes: 26088
($N, $M ,$C) = split / /,<>;
@B = split / /,<>;
for (my$i=0;$i<$N;$i++){
    @A= split / /,<>;
    $sum=$C;
    $sum+=$A[$_]*$B[$_] for(0..$M);
    $x++ if($sum>0);
}
$x//=0;
print "$x";

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int gcd2(int x, int y) {
	if (y == 0) {
		return x;
	}
	return gcd2(y, x % y);
}
int gcd3(int x, int y, int z) {
	int s;
	return gcd2(gcd2(x, y), z);
}
int main() {
	long long int K, ans;
	cin >> K;
	ans = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int k = 1; k <= K; k++) {
				ans = ans + gcd3(i, j, k);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  int n;

  while(1) {
    cin >> n;
    if(!n) break;

    int ans = 0;
    REP(i, n) {
      int tmp = i+1;
      while(tmp%5 == 0) {
	ans++;
	tmp /= 5;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

/*

ゲーム 
区間DP

------------

左をi個、右をj個とった状態からの先手(＝次の人)の得点 x[i][j]

i + j == n のとき
	x[i][j] = 0

i + j + 1 == n のとき　※実はこれも下に吸収される
	x[i][j] = a[i]

その他のとき
	x[i][j] = max(a[i] - x[i + 1][j], a[n - j - 1] - x[i][j + 1])

------------

上記だと添字が上からになるのでやりづらい。添字をつけ直す


残りがi個で、左からj個とった状態の先手(＝次の人)の得点 x[i][j]

※上のn - i - jがこちらのi、上のiがこちらのj


i == 0 のとき
	x[i][j] = 0

i == 1 のとき
	x[i][j] = a[j]

その他のとき
	x[i][j] = max(a[j] - x[i - 1][j + 1], a[i + j - 1] - x[i - 1][j])

求めるものは
	x[n][0]

------------

オンメモリでできる


*/

void main(){
	int n = read.to!int;
	
	long[] as = readln.chomp.split.map!(to!long).array;
	
	long[] xs;
	foreach(j; 0 .. n + 1) xs ~= 0;
	
	debug writeln("i:0, xs:", xs);
	foreach(i; 1 .. n + 1){
		foreach(j; 0 .. n - i + 1){
			if(j + 1 < n + 1) xs[j] = max(as[j] - xs[j + 1], as[i + j - 1] - xs[j]);
			else xs[j] = as[i + j - 1] - xs[j];
		}
		debug writeln("i:", i, " xs:", xs);
	}
	
	xs[0].writeln;
}



Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i=j; i<k; i+=step)
#define loop(i, j, k) for (int i=j; i<k; i++) 
#define rloop1(i, j, k, step) for (int i=j; i>=k; i-=step)
#define rloop(i, j, k) for(int i=j; i>=k; i--)
#define rep(i, k) for(int i = (0); i < (k); i++ )
#define rrep(i, k) for(int i = k-1; i >= 0; i-- )

#define forall(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define endl "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;


void solve()
{
	int n,i,j,k,l;
	cin>>i>>j;
	cout<<i*j<<endl;
}
int  main() 
{
	
	fast_io;
    int t=1;
    //cin>>t;
    while(t--)
    	solve();
	return 0; 
}

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

int i,x,p;
int main() {
    // insert code here...
    cin>>i>>x;
    if (i>=13) {
        cout<<x<<endl;
    }else if (i>=6){
        cout<<x/2<<endl;
    }else{
        cout<<0<<endl;
    }
}


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


int main(){
    int n;
    cin >> n;
    string j = "ACL";
    for(int i = 0; i < n - 1; i++){
        j += "ACL";
    }

    cout << j << endl;
}

Measured memory_bytes: 3596
N = gets.to_i
A = $<.map &:to_i
A.sort!

def f(_a)
  a = _a.dup
  res = [a.pop]
  while !a.empty?
    res.unshift a.shift
    res << a.shift

    res.unshift a.pop
    res << a.pop
  end
  res.compact
end

def f2(_a)
  a = _a.dup
  res = [a.pop]
  while !a.empty?
    res << a.shift
    res.unshift a.shift

    res << a.pop
    res.unshift a.pop
  end
  res.compact!
end

def g(a)
  a.each_cons(2).inject(0){|r, (a, b)|
    r + (a - b).abs
  }
end

p [g(f(A)), g(f(A.reverse))].max


Measured memory_bytes: 7124
fn main() {
    proconio::input! {
        n: usize,
        mut a: [u64; n],
    }

    a.sort();

    let mut r = 0;
    for i in 1..n {
        r += a[n - 1 - (i / 2)];
    }
    println!("{}", r);

//    a.reverse();
//    println!("{}", calc1(n, a));
}

fn _calc1(n: usize, a: Vec<u64>) -> u64 {
    let mut dic = vec![(a[0], 0u64)];
    let mut pre = 0;
    for i in 0..n-1 {
        if dic[pre].0 == a[i] {
            dic[pre].1 += 1;
        } else {
            dic.push((a[i], 1));
            pre += 1;
        }
    }

    let mut r = 0;
    for dici in dic {
        let n = if dici.1 >= 1 { dici.1 } else { 1 };
        r += dici.0 * n;
    }
    r
}


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

int main() {
    int n, m; cin >> n >> m;
    char imgA[n][n], imgB[m][m];
    for (int i = 0; i < n; i++) {
        string a; cin >> a;
        for (int j = 0; j < n; j++) {
            imgA[i][j] = a[j];
        }
    }
    for (int i = 0; i < m; i++) {
        string b; cin >> b;
        for (int j = 0; j < m; j++) {
            imgB[i][j] = b[j];
        }
    }

    for (int iA = 0; iA + m - 1 < n; iA++) {
        for (int jA = 0; jA + m - 1 < n; jA++) {
            bool matched = true;

            for (int iB = 0; iB < m; iB++) {
                for (int jB = 0; jB < m; jB++) {
                    matched &= imgA[iA + iB][jA + jB] == imgB[iB][jB];
                }
            }

            if (matched) {
                cout << "Yes" << endl; 
                return 0;
            }
        }
    }

    cout << "No" << endl;
}


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

#include <iomanip>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;
const double PI = 3.141592653589793238;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    double a,b,x;cin>>a>>b>>x;
    if(x<a*a*b/2){
        cout<< std::setprecision(8)<<atan(a*b*b/2/x)/PI*180;
    }
    else{
        x=a*a*b-x;
        cout<< std::setprecision(8)<<atan(2*x/a/a/a)/PI*180;
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	vector<bool> ls(101,true);
	int x,n;cin>>x>>n;
	while(n--){int a;cin>>a;ls[a]=false;}
	int a=x,b=x;
	while(!ls[x]){
		a++;b--;
		if(ls[a]) x=a;
		if(ls[b]) x=b;}
	cout<<x;
}


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

int main() {

    int n, m; cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; i++) {
        int a; cin >> a;
        sum += a;
    }
    if (n < sum) cout << -1 << endl;
    else cout << n - sum << endl;
    return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

string str;
int expr(int &idx);
int factor(int &idx);
int primary(int &idx);
int inum(int &idx);

// expr ::= factor | expr '+' factor | expr '-' factor
int expr(int &idx){
	auto ret = factor(idx);
	while(str[idx] != ')' && str[idx] != '='){
		auto op = str[idx];
		auto rest = factor(++idx);
		if(op == '+'){
			ret += rest;
		}
		else if(op == '-'){
			ret -= rest;
		}
		else{
//			cerr << op << endl;
			assert(0);
		}
	}
	return ret;
}


// factor ::= primary | factor '*' primary | factor '/' primary
int factor(int &idx){
	auto ret = primary(idx);
	while(str[idx] == '*' || str[idx] == '/'){
		auto op = str[idx];
		auto rest = primary(++idx);
		if(op == '*') ret *= rest;
		else if(op == '/') ret /= rest;
		else{
//			cerr << op << endl;
			assert(0);
		}
	}
	return ret;
}

// primary ::= '(' expr ')' | num
int primary(int &idx){
	int ret;
//	cerr << idx << ":" << str[idx] << endl;
	if(str[idx] == '('){
		ret = expr(++idx);
		assert(str[idx] == ')');
		idx++;
		return ret;
	}
	if(isdigit(str[idx])){
		return inum(idx);
	}
	assert(0);
	return -1;
}

int inum(int &idx){
	assert(isdigit(str[idx]));
	int i = idx;
	while(isdigit(str[idx]))idx++;
	return stoi(str.substr(i,idx-i));
}

signed main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		cin >> str;
		int idx =0 ;
		cout << expr(idx) << endl;
	}

	return 0;
}




Measured memory_bytes: 3152
import sys
sys.setrecursionlimit(10**8)
#普通にinputするよりstdin.readlineのほうがはやい
input = sys.stdin.readline 
n,q=map(int,input().split())
Graph=[[] for _ in range(n+1)]
ans=[0 for _ in range(n+1)]


for _ in range(n-1):
    a,b=map(int,input().split())
    Graph[a].append(b)
    Graph[b].append(a)

for _ in range(q):
    p,x=map(int,input().split())
    ans[p]+=x

def dfs(v,par):
    for nv in Graph[v]:
        if nv==par:
            continue
        else:
            ans[nv]+=ans[v]
            dfs(nv,v)

dfs(1,-1)
print(*ans[1:])

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

int main(){

  int N,ans=0;
  cin >> N;

  for(int i=1; i<=N; i++){
    if(i<10 || (i>99 && i<1000) || (i>9999 && i<100000)) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right, insort_left

q = int(input())
S = []
D = {}
a = []
c = 0
for i in range(q):
    a.append(list(map(int,input().split())))

for i in range(q):
    if a[i][0] == 0:
        if not a[i][1] in D:
            insort_left(S,a[i][1])
            D[a[i][1]] = 1
            c += 1
        else:
            if not D[a[i][1]] == 1:
                D[a[i][1]] = 1
                c += 1
        print(c)
    elif a[i][0] == 1:
        if a[i][1] in D:
            if D[a[i][1]] == 1:
                print(1)
            else:
                print(0)
        else:
            print(0)
    elif a[i][0] == 2:
        if a[i][1] in D:
            if D[a[i][1]] == 1:
                D[a[i][1]] = 0
                c -= 1
    else:
        L = bisect_left(S,a[i][1])
        R = bisect_right(S,a[i][2])
        for j in range(L,R):
            if D[S[j]] == 1:
                print(S[j])


Measured memory_bytes: 51120
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
#define P pair<ll,ll>
#define fs first
#define sc second
using namespace std;


#define N_MAX 200000
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n),b(n),c(n);
  ll ans = 0;

  rep(i,0,n) cin >> a[i];
  rep(i,0,n) cin >> b[i];
  rep(i,0,n) cin >> c[i];

  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());

  rep(i,0,n){
    ll temp1 = lower_bound(a.begin(),a.end(),b[i]) - a.begin();
    ll temp2 = c.end() - upper_bound(c.begin(),c.end(),b[i]);
    
    ans += temp1*temp2;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
    #include <stdio.h>
    #include <vector>
    #include <list>
    #include <queue>
    #include <cmath>
    #include <cstring>
    #include <string.h>
    #include <map>
    #include <set>
    #include <utility>
    #include <stdlib.h>
    #include <algorithm>
    #define mp make_pair
    #define pb push_back
    #define ff first
    #define ss second 
    #define NUM 1000000007
    using namespace std;
    typedef pair<int, int> iPair;
    typedef pair <long long, long long> lPair;
    typedef long long int ll;
    typedef long double ld;
     
     
    int min(int x, int y) {
        return (x > y ? y : x);
    }
     
    int max (int x, int y) {
        return (x > y ? x : y);
    }
     
    int a[305][305];
     
    int main () {
        int n, flag;
        bool b;
        ll res = 0;
        scanf("%d", &n);
        for (int i=0; i<n; i++)
            for (int j=0; j<n; j++)
                scanf("%d", &a[i][j]);
        flag = 0;
        for (int i=0; i<n-1; i++) {
            for (int j=i+1; j<n; j++) {
                b = 1;
                for (int k=0; k<n; k++) {
                    if (k == i || k == j)
                        continue;
                    else if (a[i][j] > a[i][k] + a[k][j]) {
                        flag = 1;
                        break;
                    }
                    else if (a[i][j] == a[i][k] + a[k][j])
                        b = 0;
                }
                if (flag == 1)
                    break;
                res += b*a[i][j];
            }
            if (flag == 1)
                break;
        }
        if (flag == 1)
            cout<<-1<<endl;
        else
            cout<<res<<endl;
        return 0;
    } 

Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        i: usize
    }
    println!("{}", n + 1 - i);
}


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

using namespace std;

int a[200001];
int number_count[200002];
set<int> numbers_left;


int main(){
  int n, k;
  scanf("%d %d", &n, &k);
  memset(number_count, 0, sizeof number_count);
  for(int i = 0; i < n; ++i){
    scanf("%d", a + i);
    if(numbers_left.count(a[i]) == 0){
      numbers_left.insert(a[i]);
    }
    number_count[a[i]]++;
  }
  if(numbers_left.size() <= k){
    return 0 * puts("0");
  }
  vector<int> v;
  for(int i = 0; i < 200001; ++i){
    if(number_count[i] > 0){
      v.push_back(number_count[i]);
    }
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  int ans = n;
  for(int i = 0; i < k; ++i){
    ans -= v[i];
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 12284
#include <bits/stdc++.h>
#define ll long long
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e5+5, M=5e5+5, oo=0x3f3f3f3f, mod = 1e9+7;

int n, a[N], b[N], c[N], mem[N][6];
int solve(int ind, int last){
    if(ind == n) return 0;
    if(mem[ind][last] != -1) return mem[ind][last];
    int op1 = (last == 1) ? -oo : (solve(ind+1, 1)+a[ind]);
    int op2 = (last == 2) ? -oo : (solve(ind+1, 2)+b[ind]);
    int op3 = (last == 3) ? -oo : (solve(ind+1, 3)+c[ind]);
    return mem[ind][last] = max(op1, max(op2, op3));
}
int main()
{
    _69e27
    memset(mem, -1, sizeof mem);
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> a[i] >> b[i] >> c[i];
    cout << solve(0, 0);
    return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         998244353 
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
void solve(){   
    int n,k;
    cin >> n >> k;
    vector<int>v(n+5);
    FOR(i,1,n+1)cin >> v[i];
    sort(v.begin()+1,v.begin()+n+1);
    int tot = 0;
    FOR(i,1,k+1)tot += v[i];
    cout << tot << "\n";
}

signed main()
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){   
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


Measured memory_bytes: 3624
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val ((x, y), (x2, y2)) = (sc.nextInt() -> sc.nextInt(), sc.nextInt() -> sc.nextInt())
  val (diffX, diffY) = (x2 - x, y2 - y)
  println(s"${x2 - diffY} ${y2 + diffX} ${x - diffY} ${y + diffX}")
}


Measured memory_bytes: 55352
#include<stdio.h>

int main(){
	int i, j;
	for(i = 1; i <= 9; i++)
	{
		for(j = 1; j <= 9; j++)
		{
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}
	
    return 0;
}

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


int main() {
  int a,b;
  cin >> a >> b;
  int n = b-a;
  int sum = 0;
  for(int i = 1; i <= n; i++){
    sum+=i;
  }
  cout << sum - b << endl;
 } 

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define ull unsigned long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define flush fflush(stdout)
using namespace std;

#define N 100*57

int n, p, a;

ll dp[N];

ll res;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	dp[0] = 1;

	cin >> n >> p;

	for(int i = 1; i <= n; ++i)
	{
		cin >> a;

		for(int j = N-1-a; j >= 0; --j)
		{
			dp[j+a] += dp[j];
		}
	}

	for(int i = 0; i < N; ++i)
	{
		if(i%2==p)
			res += dp[i];
	}

	cout << res;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
using namespace std;

int N;

int main(){
	while(cin >> N && N>0){
		vector<int> A(N+10,0);
		vector< pair<int,int> > ans;
		for(int i=1;i<N+1;i++){
			cin >> A[i];
		}
		int min = A[1],max = A[1],minid = 1,maxid = 1;
		for(int i=1;i<N+1;i++){
			if(min > A[i]){
				min = A[i];
				minid = i;
			}
			if(max < A[i]){
				max = A[i];
				maxid = i;
			}
		}
		if(abs(min)<=abs(max)){
			for(int i=1;i<N+1;i++){
				A[i] += abs(max);
				ans.push_back(make_pair(maxid,i));
			}
			for(int i=1;i<N;i++){
				ans.push_back(make_pair(i,i+1));
			}
		}else if(abs(min)>abs(max)){
			for(int i=1;i<N+1;i++){
				A[i] += abs(min);
				ans.push_back(make_pair(minid,i));
			}
			for(int i=1;i<N;i++){
				ans.push_back(make_pair(N-(i-1),N-i));
			}
		}
		cout << ans.size() << endl;
		for(int i=0;i<ans.size();i++){
			cout << ans[i].first << " " << ans[i].second << endl;
		}
	}
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    int n, i;
    cin >> n >> i;
    print(n - i + 1);

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;

Int GCD(Int a, Int b){
if(b==0) return a;
if(a < b) return GCD(b, a);
unsigned r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}

int main() {
    Int N,M, ans;
    vector<pair<Int,Int>> stocks;
    cin >> N >> M;
    ans = 0;

    int count = 0;
    rep(i,N){
        Int A;
        cin >> A;
        Int B;
        cin >> B;
        pair<Int,Int> p;
        p.first = A;
        p.second = B;
        stocks.push_back(p);
    }

    sort(stocks.begin(), stocks.end());

    rep(i,N){
        pair<Int,Int> p= stocks[i];
        ans += p.first*p.second;
        count += p.second;
        if(count>M){
            ans -= (count-M)*p.first;
            break;
        }
    }



    cout << ans;
    return 0;
}

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

int main() {
	
    int n[3] ;
    cin >> n[0] ;
    cin >> n[1] ;
    cin >> n[2] ;

    sort(n,n+3) ;

    cout << n[0]+n[1] << endl;
    
	return 0;
}


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

long long n;
vector<long long>a;

long long solve();

int main() {
    cin >> n;
    a.resize(n);
    for(int i = 0;i < n;++i)cin >> a[i];
    cout << solve() << endl;
    return 0;
}

long long solve(){
    long long ans = 0,cnt = 0,x = abs(a[0]);
    bool existzero = 0;
    for(int i = 0;i < n;++i){
        if(a[i] < 0){
            ++cnt;
            a[i] *= -1;
        }
        else if(a[i] == 0)existzero = 1;
        ans += a[i];
        x = min(a[i],x);
    }
    if(existzero || cnt % 2 == 0)return ans;
    return ans - 2 * x;
}

Measured memory_bytes: 1024
def counter(x):
        if x == 0:
                return 0
        return counter(x >> 1) + (x & 1)

N = int(input())
A = []
x = [0] * N 
for i in range(N):
        A.append(int(input()))
        x[i] = [list(map(int, input().split())) for j in range(A[i])]

ans = 0 
for bits in range(1, 1 << N): 
        flag = 1 
        for i in range(N):
                if not bits & (1 << i): 
                        continue
                for j in range(A[i]):
                        if (bits >> (x[i][j][0] - 1) & 1) ^ x[i][j][1]:
                                flag = 0 
        if flag:
                ans = max(ans, counter(bits))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
string a[1009];
long long dp[1009][1009];
long long mod=1000000007;
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<m;i++){
		if(a[0][i]=='#') break;
		dp[0][i]=1;
	} 
	for(int i=0;i<n;i++){
		if(a[i][0]=='#') break;
		dp[i][0]=1;
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if(a[i][j]=='#'){
	//			cout<<dp[i][j]<<" ";
				continue;
			}
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
/*	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}*/
	cout<<dp[n-1][m-1]<<endl;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  // (a - 1) * x + a = b
  int x = (b - a) / (a - 1);
  if ((a - 1) * x + a < b)
    ++x;
  cout << x + 1 << '\n';   
  return 0;
}

Measured memory_bytes: 3620