akhauriyash/Code-Regression huggingface dataset:
def main():
    from sys import stdin
    input = stdin.readline
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = [0]*(n-m)

    for use in range(m, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            q = max(-1, start-1-rest, bl(max_a, now_a[start-1]+1)-1)
            for i in range(start-1, q, -1):
                now_a[i] += 1
            if now_a[start-1] == 1:
                cnt += start-1-q
            rest -= start-1-q
            if start != m:
                nex = now_a[start]
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                end = min(end, bl(now_a, val+1), start+rest)
                for i in range(start, end):
                    now_a[i] -= 1
                if now_a[start] == 0:
                    cnt -= end-start
                rest -= end-start
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)


main()


Measured memory_bytes: 120548
from bisect import bisect_right
N = int(input())
X = list(map(int, input().split()))
L = int(input())

P = [[0] * N for i in range(30)]
for i in range(N):
    q = bisect_right(X, X[i] + L)
    P[0][i] = q - 1

for i in range(1, 30):
    for j in range(N):
        P[i][j] = P[i - 1][P[i - 1][j]]


Q = int(input())
for i in range(Q):
    a, b = map(int, input().split())
    if a > b:
        a, b = b, a
    a, b = a - 1, b - 1
    num = 0
    for j in range(29, -1, -1):
        if P[j][a] < b:
            a = P[j][a]
            num += 2 ** j
    print(num + 1)

Measured memory_bytes: 34532
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=1e5+4;

int main()
{
	int n; scn(n); string s; cin>>s;

	vector<int> w(n,0),r(n,0);

	rep(i,0,n)
	{
		if(s[i]=='W')
		w[i]++;
		else
		r[i]++;
	}

	rep(i,1,n)
	w[i]+=w[i-1];

	if(w[n-1]==0)
	{
		pri(0); return 0;
	}

	for(int i=n-2;i>=0;i--)
	r[i]+=r[i+1];

	int ans=0;

	rep(i,1,n)
	if(s[i]=='R')
	{
		if(i==n-1)
		ans++;
		else if(w[i-1]>r[i+1])
		ans++;
	}

	pri(ans);

	return 0;
}

Measured memory_bytes: 5256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,ans=0;
	cin>>n>>m;
	vector<int> a,b,c,d,bridge;
	int end[m]={};
	for(int i=0;i<m;i++){
		int A,B;
		cin>>A>>B;
		a.push_back(min(A,B));
		b.push_back(max(A,B));
		if(max(A,B)-min(A,B)==1){
			bridge.push_back(min(A,B));
			ans++;
		}
	}
	int br=bridge.size();
	for(int i=0;i<br;i++){
		for(int j=0;j<m;j++){
			if(a[j]<=bridge[i]&&b[j]>bridge[i]){
				end[j]=1;
			}
		}
	}
	int r=1;
	while(r){
		r=0;
		ans++;
		int max_a=0;
		for(int i=0;i<m;i++){
			if(end[i]==0){
				max_a=max(max_a,a[i]);
				r=1;
			}
		}
		for(int j=0;j<m;j++){
			if(a[j]<=max_a&&b[j]>max_a){
				end[j]=1;
			}
		}
	}
	cout<<ans-1<<endl;
	return 0;
}


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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!
unordered_set<ll> isL;

bool is_lunlun(ll x){
  if(isL.find(x/10)==isL.end()) return false;
  int p = x%10;
  int q = (x/10)%10;
  if(abs(p-q)>1) return false;
  isL.insert(x);
  return true;
}
//

void solve(long long K) {
  queue<ll> q;
  rep(i,1,10) { q.push(i); }
  ll x;
  rep(k,K){
    x = q.front(); q.pop();
    if(x%10!=0) { 
      ll val = x*10+(x%10)-1; 
      q.push(val);
    }
    q.push(x*10+(x%10));
    if(x%10!=9) {
      ll val = x*10+(x%10)+1;
      q.push(val);
    }
  }
  cout << x << endl;
}

// TLE
void solve_old(long long K) {
  if(K<10) { cout << K << endl; return; }
  rep(i,1,10) isL.insert(i);
  K -= 9;
  ll x = 0;
  while(K>0){
    x++;
    if(is_lunlun(x)) {
      //cerr << x << endl;
      K--;
    }
  }
  cout << x << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long K;
  std::cin >> K;
  solve(K);
  return 0;
}


Measured memory_bytes: 4732
import java.util.*;
public class Main {
	private static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			if (n==0) break;
			int ansa = 0;
			int ansb = 0;
			for (int i=0; i<n; i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				if (a>b) ansa += a+b;
				else if (b>a) ansb += a+b;
				else {
					ansa += a;
					ansb += b;
				}
			}
			System.out.println(ansa + " " + ansb);
		}
	}
}

Measured memory_bytes: 58504
#include <iostream>
//#include <fstream>

using namespace std;

int main(int argc, const char * argv[]) {
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());
    
    int r, D, x;
    cin >> r >> D >> x;
    
    for (int i=0; i < 10; i++)
    {
        x = r * x - D;
        cout << x << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
 
#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
 
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
 
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
 
  LL N, L;
  cin >> N >> L;
 
  vector<PLL> xs(N);
  REP(i,N){
	cin >> xs[i].FF;
	xs[i].SS = i;
  }
  RSORT(xs);
 
  VL ts(N);
  REP(i,N){
	int ix = xs[i].SS;
	ts[ix] = max((ix>0?ts[ix-1]:0ll), (ix+1<N?ts[ix+1]:0ll)) + L - xs[i].FF;
  }
  cout << *max_element(ALL(ts)) << endl;
 
  return 0;
}

Measured memory_bytes: 5212
"use strict";

const Main = (input) => {
  	input = input.split("\n");
    var five_h = parseInt(input[0]);
    var hundred = parseInt(input[1]);
    var fifty = parseInt(input[2]);
    var sum = parseInt(input[3]);
    var count = 0;

    for (let i = 0; i <= five_h; i++) {
        for (let j = 0; j <= hundred; j++) {
            for (let k = 0; k <= fifty; k++) {
                if(sum === k*50 + j * 100 + i * 500){
                    count++;
                }
            }
        }
    }

    console.log(count);



}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21192
import heapq
n,m=map(int,input().split())
item=list(map(lambda x: -int(x),input().split()))
heapq.heapify(item)
for i in range(m):
    top=-heapq.heappop(item)
    top //=2
    heapq.heappush(item,-top)

print(-sum(item))

Measured memory_bytes: 72216
a,b=map(int,input().split())
n=b-a
count=0
for i in range(n+1):
    t=a+i
    c=t%10#一桁目
    d=(t%100-c)//10#二桁目
    e=(t%1000-t%100)//100
    f=(t%10000-t%1000)//1000
    g=(t%100000-t%10000)//10000
    if(c==g and d==f):
        count+=1
    else:
        continue
print(count)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int k = int.Parse(input[0]);

		string s = Console.ReadLine();
		if(s.Length <= k) Console.WriteLine(s);
		else
		{
			string ret = s.Substring(0, k);
			ret += "...";
			Console.WriteLine(ret);
		}
		
	}

}

Measured memory_bytes: 27548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  string S;
  ll Q;
  cin >> S >> Q;
  vector<ll> T(Q, 0);
  vector<ll> F(Q, 0);
  vector<char> C(Q, 'X');
  rep(i, Q){
    cin >> T.at(i);
    if(T.at(i) == 2){
      cin >> F.at(i) >> C.at(i);
    }
  }
  bool rev = false;
  deque<char> ans;
  rep(i, sz(S)){
    ans.push_back(S.at(i));
  }
  rep(i, Q){
    if(T.at(i) == 1){
      rev = !rev;
    }
    else{
      if(!rev){
        if(F.at(i) == 1){
          ans.push_front(C.at(i));
        }
        else{
          ans.push_back(C.at(i));
        }
      }
      else{
        if(F.at(i) == 1){
          ans.push_back(C.at(i));
        }
        else{
          ans.push_front(C.at(i));
        }
      }
    }
  }
  ll s = sz(ans);
  if(!rev){
    rep(i, s){
      cout << ans.front();
      ans.pop_front();
    }
  }
  else{
    rep(i, s){
      cout << ans.back();
      ans.pop_back();
    }
  }
}

Measured memory_bytes: 4224
n, m = map(int, input().split())

left = 0
right = n

for i in range(m):
    l, r = map(int, input().split())
    if l > left:
        left = l
    if r < right:
        right = r

if right - left + 1 > 0:
    print(right - left + 1)
else:
    print("0")

Measured memory_bytes: 3060
n, k = [int(i) for i in input().split()]
woods = [int(i) for i in input().split()]


def k_cut_less_than(k, l, woods):
    kaisuu = 0
    for wood in woods:
        kaisuu += (wood-1) // l
    if kaisuu <= k:
        return False
    return True


# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math


def binary_research(start, end,  function):
    if start == end:
        return start
    middle = math.ceil((start + end) / 2)
    if function(k, middle, woods):
        start = middle
    else:
        end = middle - 1
    return binary_research(start, end, function)

start=0
end=10**9
print(binary_research(start,end,k_cut_less_than)+1)




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


int main() {
  string s;
  
  cin >> s;

  vector<string> day = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  
  int flag = 0;
  int i=0;
  
  for(;;){
    if(s == day.at(i)){
      cout << 7-flag;
      break;
    }
    flag++;
    i++;
  }
    
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run(){
		Scanner s = new Scanner(System.in);
		while(true){
		int f = s.nextInt();
		int m = s.nextInt();
		int r = s.nextInt();
		if(m == -1 && f == -1 && r == -1) break;
		if(m == -1 || f == -1){
			System.out.println("F");
			continue;
		}
		int sum = m + f; 
		if(sum >= 80) System.out.println("A");
		else if(sum >= 65 && sum < 80) System.out.println("B");
		else if(sum >= 50 && sum < 65) System.out.println("C");
		else if(sum >= 30 && sum < 50) {
			if(r >= 50) System.out.println("C");
			else System.out.println("D");
			}
		else if(sum < 30) System.out.println("F");
		}
	}

	public static void main(String[] args) {
	
		new Main().run();
		
	}
}

Measured memory_bytes: 26256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int flag = 0;
		
		Scanner sc = new Scanner(System.in);
		
		//intを受け取る
		int n = sc.nextInt();
		
		for(int i=1;i<=9;i++) {
			for(int j=1;j<=9;j++) {
				if(i*j == n) {
					flag = 1;
					break;
				}
			}
		}
		if(flag == 1) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


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

int main(void){
    int n;
    cin >> n;
    string s = "No";
    rep(i, 26){
        rep(j, 16){
            if(n == 4*i+7*j) s = "Yes";
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int H,W; cin >> H >>W ;
    int h,w; cin >> h >> w;
    int ans = H * W;
    ans -= h * W;
    ans -= w * H;
    ans += h*w;
    cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  
  if (N == 1) cout << "Hello World" << endl;
  else {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n, b, r = map(int, input().split())
a = 0
a += n//(r+b) * b
if n - n//(r+b) * (r+b)> b:
    a += b
else:
    a += n - n//(r+b) * (r+b)
print(a)



Measured memory_bytes: 2940
#include <stdio.h>

int main(void){
    int a;
    long i,min=10000000,max=-10000000,sum=0;
    int b;
    scanf("%d",&b);
    for(i=0;i<b;i++){
        scanf("%d",&a);
        sum = sum + a;
        if(a<min) {min=a;}
        if(a>max) {max=a;}
    }
    printf("%ld %ld %ld\n",min,max,sum);
     return 0;
}

Measured memory_bytes: 600
import qualified Data.Vector.Unboxed as V
import Data.Array.IArray (listArray, accumArray, (!))
import Data.Array.MArray
import Data.Array.ST (STUArray, runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.List (sortOn, sortBy, unfoldr, partition)
import Data.Char (isSpace)
import Control.Monad.ST (ST)
import Control.Monad.Trans.State (StateT(..))
import qualified Data.ByteString.Char8 as B

-- utility functions

--   Input functions
readInt = B.readInt . B.dropWhile isSpace

readInts :: Int -> B.ByteString -> [Int]
readInts n = take n . unfoldr readInt

readIntsV :: Int -> B.ByteString -> V.Vector Int
readIntsV n = V.unfoldrN n readInt

readIntsA :: Int -> B.ByteString -> UArray Int Int
readIntsA n bs = runSTUArray $ do
  arr <- newArray_ (0,n-1)
  go arr 0 bs
  return arr
  where
    go :: STUArray s Int Int -> Int -> B.ByteString -> ST s ()
    go arr i bs
      | i==n = return ()
      | otherwise = do
        let Just (x,bs') = readInt bs
        writeArray arr i x
        go arr (i+1) bs'

readTsV :: Int -> B.ByteString -> V.Vector (Int,Int)
readTsV n = V.unfoldrN n $ runStateT ((,) <$> StateT readInt <*> StateT readInt)

readTs :: Int -> B.ByteString -> [(Int,Int)]
readTs n = take n . unfoldr readT where
  readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)

-- main

yesno True = putStrLn "Yes"
yesno False = putStrLn "No"

main = do
  [a,b,c] <- map read . words <$> getLine :: IO [Int]
  if a<b then
    yesno $ a<=c && c<=b
  else
    yesno $ b<=c && c<=a


Measured memory_bytes: 508
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class Pair implements Comparable<Pair>{
		long a;
		long b;
		Pair(int a, int b){
			this.a=a;
			this.b=b;
		}
		@Override
		public int compareTo(Pair arg0) {
			return Long.compare(this.a, arg0.a);
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		ArrayList<Pair> ab = new ArrayList<Pair>();
		for(int i=0; i<n; i++) {
			ab.add(new Pair(sc.nextInt(), sc.nextInt()));
		}
		Collections.sort(ab);
		long ans = 0;
		for(int i=0; i<n; i++) {
			if(m<=0) {
				break;
			}
			Pair p = ab.get(i);
			long a = p.a;
			long b = Math.min(p.b, m);
			ans += a * b;
			m -= b;
		}
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 91716
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        long ans = 0;
        for (long i = k; i <= n + 1; i++) {
            long start = i * (i - 1) / 2;
            long end = i * (2 * n - i + 1) / 2;
            ans += end - start + 1;
        }
        System.out.println(ans%1_000_000_007);
    }
}


Measured memory_bytes: 35760
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define MX 100005
#define MOD 1000000007

using namespace std;

template <typename T> void read(T& x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

char str[MX];
int cnt[26];
int n;

int main()
{
	read(n);
	scanf("%s", str);
	for(int i=0; i<n; i++) cnt[str[i]-'a']++;
	int ans = 1;
	for(int i=0; i<26; i++) ans = 1ll * ans * (1 + cnt[i]) % MOD;
	printf("%d\n", (ans-1+MOD)%MOD);
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
// using System.Linq;

namespace easy_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // int[] NK = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // long K = long.Parse(Console.ReadLine());
            // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // string S = Console.ReadLine();
            // int a = int.Parse(Console.ReadLine());
            // int b = int.Parse(Console.ReadLine());
            // int h = int.Parse(Console.ReadLine());
            // float N = float.Parse(Console.ReadLine());
            // string c = Console.ReadLine();
            // string B = Console.ReadLine();
            // string[] AopB = Console.ReadLine().Split();
            // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), Console.ReadLine() }).Select(float.Parse);
            // float[] a = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // var X = Console.ReadLine();
            // int[,] abcd = new int[NMQ[2],4];
            // int[] A = new int[NMQ[0]];
            // int[] A_num = new int[NMQ[0]];
            long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            var hs=new Dictionary<long,long>();
            for(int i=0;i<s[0];i++){
                long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
                if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
                else{hs.Add(q[0],q[1]);}
            }
            List<long> kl=new List<long>(hs.Keys);
            kl.Sort();
            foreach(long k in kl){
                s[1]-=hs[k];
                if(s[1]<1){Console.WriteLine("{0}",k);break;}
            }
        }
        //最小公倍数
        static long Lcm(long a, long b)
        {
            return a/Gcd(a,b)*b;
        }

        //最大公約数
        static long Gcd(long m, long n)
        {
            if(n==0)return m;
            return Gcd(n,m%n);
        }
    }
}


Measured memory_bytes: 19656
from fractions import gcd

def lcm(a, b):
    return a // gcd(a, b) * b

def f(n, C, D):
    x = n // C
    y = n // D
    z = n // lcm(C, D)
    return n - x - y + z


A, B, C, D = map(int, input().split())
ans = f(B, C, D) - f(A-1, C, D)
print(ans)


Measured memory_bytes: 5076
n,m,X,Y=map(int,input().split())
x=sorted(list(map(int,input().split())))
y=sorted(list(map(int,input().split())))
ans='War'
for i in range(X+1,Y+1):
    if x[-1]<i and y[0]>=i:
        ans='No War'
        break
print(ans) 

Measured memory_bytes: 3060
N,C,K = gets.split.map(&:to_i)
T = Array.new(N){gets.to_i}.sort

Bus = Struct.new(:c, :t) do
  def inc
    self.c += 1
  end
  def valid(tt)
    tt <= t + K && c < C
  end
  def new(tt)
    self.t = tt
    self.c = 0
  end
end

bus = Bus.new(C, -K) # ダミーの満員バス、誰も乗れない
count = 0
T.each do |t|
  if bus.valid(t)
    bus.inc
  else
    bus = Bus.new(1, t)
    count += 1
  end
end
puts count

Measured memory_bytes: 4472
N = input()
num = int(N[-1])
if (num == 2) or (num == 4) or (num == 5) or (num == 7) or (num == 9):
    print('hon')
elif (num == 0) or (num == 1) or (num == 6) or (num == 8):
    print('pon')
else:
    print('bon')

Measured memory_bytes: 9136
#include<bits/stdc++.h>
#define int long long int
#define ull unsigned long long int
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD 1000000007
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define precise(i) cout<<fixed<<setprecision(i)
using namespace std;
const double PI = atan(1.0)*4;
const int64_t INF=100000000000000003;
const int32_t LOG=21;
const int BIG=pow(2,20);
const int N=100005;
 int32_t main(){
          getFaster;
          int n;
          cin>>n;
          int arr[n];
          int x[n],y[n];
          rep(i,0,n)arr[i]=i;
          rep(i,0,n)cin>>x[i]>>y[i];
          double ans=0.00000;
          int t=0;
          do{
              t++;

              rep(i,0,n-1)
              {
                  int i1=arr[i];
                  int i2=arr[i+1];
                  int d=(x[i1]-x[i2])*((x[i1]-x[i2]))+(y[i1]-y[i2])*(y[i1]-y[i2]);
                  double d1=d*1.00000;
                  double d2=sqrt(d1);
                  ans+=d2;
              }

          }while(next_permutation(arr,arr+n));
          double n1=t*1.00000;
          ans=ans/n1;
          precise(10)<<ans<<endl;
          return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int K = scanner.nextInt();
		String str = scanner.next();
		int y = scanner.nextInt();
		y -= 1;
		String[] X = new String[str.length()];

		for (int i = 0; i < str.length(); i++) {
			String str2 = String.valueOf(str.charAt(i));
			X[i] = str2;
		}

		for (int j = 0;j < K; j++) {
			if (X[j].equals(X[y])) {
				System.out.print(X[j]);
			} else {
				System.out.print("*");
			}
		}
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	ll ar[n+1];
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	ll an=1,mx=1;
	set< pair<ll,ll> > st;
	st.insert({ar[1],1});
	for(i=2;i<=n;i++){
		set<pair<ll,ll>>:: iterator it=st.upper_bound(make_pair(ar[i],0));
		if(it==st.begin()){
		//	cout<<ar[i]<<" 1 "<<(*it)<<endl;
			mx++;
			st.insert({ar[i],mx});
			continue;
		}
		it--;
		st.insert({ar[i],it->sc});
		set<pair<ll,ll>>:: iterator i2=it;
		st.erase(i2);
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 7296
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        long n = sc.nextLong(); int x = sc.nextInt(); int m = sc.nextInt();
        if (m == 1) {
            out.println(0);
            out.close();
            return;
        } else if (m == 2) {
            if (x % 2 == 0) out.println(0);
            else out.println(n);
            out.close();
            return;
        }
        long [] c = new long[m - 2]; long cur = x;
        for (int i = 0; i < m - 2; i++) {
            c[i] = cur;
            cur = (cur * cur) % m;
        }
        //n--;
        if (n <= m - 3) {
            long res = 0;
            for (int i = 0; i < n; i++) {
                res = (res + c[i]);
            }
            out.println(res);
        } else {
            Map<Long, Integer> map = new HashMap<>();
            long a = 0; int start = -1; int end = -1;
            for (int i = 0; i <= m - 3; i++) {
                a += c[i];
                if (!map.containsKey(c[i])) map.put(c[i], i);
                else {
                    start = map.get(c[i]);
                    end = i;
                    break;
                }
            }
            if (c[m - 3] == 0) {
                out.println(a);
            } else {
                if (start == -1) {
                    start = 0; end = m - 2;
                }
                int len = end - start;
                long before = 0;
                for (int i = 0; i < start; i++) before = before + c[i];
                long times = (n - start) / len;
                long cycle = 0;
                for (int i = start; i < end; i++) cycle += c[i];
                long ret = cycle * times;
                long rem = (n - start) % len;
                for (int i = start; i < start + rem; i++) ret += c[i];
                ret += before;
                out.println(ret );
            }
        }
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 41812
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N,K = map(int, input().split())

ans = (N//K)**3
if K%2 == 0:
    if N%K >= K//2:
        c = N//K+1
    else:
        c = N//K
    ans += c**3

print(ans)

Measured memory_bytes: 21728
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (sx, sy, tx, ty) = scan!(i64, i64, i64, i64);

    for _ in sx..tx {
        print!("R");
    }
    for _ in sy..ty {
        print!("U")
    }
    for _ in sx..tx {
        print!("L");
    }
    for _ in sy..ty {
        print!("D")
    }
    print!("D");
    for _ in sx..tx + 1 {
        print!("R");
    }
    for _ in sy..ty + 1 {
        print!("U")
    }
    print!("L");
    print!("U");
    for _ in sx..tx + 1 {
        print!("L");
    }
    for _ in sy..ty + 1 {
        print!("D")
    }
    println!("R");
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;string s;
  cin>>n;
  cin>>s;
  int x=0,ans=0;
  for(int i=0;i<n;i++)
  {
    if(s[i]=='I')x++;
    else x--;
    ans=max(ans,x);
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int i,j,k,l,A=0,n;
    while(scanf("%d",&n)!=EOF){
            A=0;
    for(i=0;i<=9;i++){
        for(j=0;j<=9;j++){
            for(k=0;k<=9;k++){
                for(l=0;l<=9;l++){
                    if(i+j+k+l==n){
                            A++;
                    }
                }
            }
        }
    }
    printf("%d\n",A);
    }
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define int long long 
using namespace std;

typedef pair<int,int> pii;

int32_t main(){

    int n;  cin >> n;
    vector<pair<int,int>> f1 , f2;
    for(int x=0;x<n;x++){
        pii p;
        cin >> p.first >> p.second;
        f1.push_back(p);
    }
    for(int x=0;x<n;x++){
        pii p;
        cin >> p.first >> p.second;
        f2.push_back(p);
    }

    sort(all(f1)); sort(all(f2));
    int ans = 0;

    int used[n] = {0};

    for(int x=0;x<n;x++){
        
        pii work = {-1,-1};

        for(int y=0;y<n;y++){
            if(f1[y].first  >= f2[x].first) continue;
            if(f1[y].second >= f2[x].second) continue;
            if(used[y]) continue;
            work = max(work , {f1[y].second,y});
        }

        if(work.first != -1){
            used[work.second] = 1;
            ans++;
        }

    }

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

Measured memory_bytes: 256
A,B,K = map(int,input().split())

if A >= K:
    A = A - K
    print(str(A)+ ' '+str(B))
else:
    B = B - (K - A)
    A = 0
    if B < 0:
        print('0 0')
    else:
        print(str(A)+ ' '+str(B))


Measured memory_bytes: 2940
from itertools import product
n, a, b, c = map(int, input().split())
l = [int(input()) for i in range(n)]

ans = float('inf')
for choice in product([0, 1, 2, 3], repeat=n):
    items = [0] * 3
    totals = [0] * 3
    temp = 0
    if min([choice.count(i) for i in range(3)]) == 0: continue
    for i, ch in enumerate(choice):
        if ch == 3: continue
        totals[ch] += l[i]
        items[ch] += 1
        if items[ch] > 1:
            temp += 10
    temp+=abs(a-totals[0])
    temp+=abs(b-totals[1])
    temp+=abs(c-totals[2])
    ans = min(ans, temp)
print(ans)

Measured memory_bytes: 9216
n = int(input())
A =list(map(int, input().split()))
 
A.sort(reverse=True)
 
ans = 0
if n % 2 == 0:
  for i in range(n//2):
    ans += 2* A[i]
  ans -= A[0]
  
else:
  for i in range((n-1)//2):
    ans += 2*A[i]
  ans -= A[0]
  ans += A[(n-1)//2]

print(ans)

Measured memory_bytes: 31572
#include "bits/stdc++.h"

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

#define rep(i,n) for (ll i = 0; i < (n); i++)
#define ru(a,b) (((a)+((b)-1)) / (b))   //切り上げ(a/b)
#define dump(x)  cout << #x << " = " << (x) << endl;

int main()
{
	ll n, k;
	cin >> n >> k;
	int digit = 0;

	while (n != 0) {
		n = n / k;
		++digit;
	}


	std::cout << digit << endl;

	return 0;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val soinsu = mutableMapOf<Int, Int>()
    for (i in 2..n) {
        var temp = i
        var j = 2
        while (j <= n) {
            if (temp % j == 0) {
                soinsu[j] = (soinsu[j] ?: 0) + 1
                temp /= j
            } else {
                j = if (j == 2) j + 1 else j + 2
            }
            if (temp == 1) break
        }
    }
    var answer = 1L
    for ((k, v) in soinsu) {
        answer *= v + 1
        answer %= 1000000007
    }
    println(answer)
}

Measured memory_bytes: 33788
use std::io::stdin;

fn main() {
    let mut ab = String::new();
    stdin().read_line(&mut ab).unwrap();
    let mut ab: Vec<isize> = ab.trim().split_whitespace().flat_map(str::parse).collect();
    ab.sort();
    let (a, b) = (ab[0], ab[1]);

    if (b - a) % 2 == 0 {
        println!("{}", a + (b - a) / 2);
    } else {
        println!("IMPOSSIBLE");
    }
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{


    public static void main(String[] args) throws IOException {
        MyScanner sc = new MyScanner();
        int n = sc.nextInt();


        int[] A = new int[n];
        int[] B = new int[n];
        int[] C = new int[10001];

        for (int i = 0; i < n; i++) {
            A[i] = sc.nextInt();
            C[A[i]]++;
        }

        for (int i = 1; i < C.length; i++)
            C[i] += C[i-1];


        for (int i = A.length-1; i >= 0; i--){
            B[C[A[i]]-1] = A[i];
            C[A[i]]--;
        }

        StringBuilder s = new StringBuilder().append(B[0]);
        for (int i = 1; i < n; i++)
            s.append(" ").append(B[i]);

        System.out.println(s);


    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}



Measured memory_bytes: 170636
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef complex<double> C;

typedef string::const_iterator State;
class ParseError {};
int expression(State& begin);
int term(State& begin);
int number(State& begin);
int factor(State& begin);

int expression(State& begin) {
    int ret = term(begin);
    for (;;) {
        if (*begin == '+') {
            begin++;
            ret += term(begin);
        } else if (*begin == '-') {
            begin++;
            ret -= term(begin);
        } else break;
    }
    return ret;
}

int term(State& begin) {
    int ret = factor(begin);
    for (;;) {
        if (*begin == '*') {
            begin++;
            ret *= factor(begin);
        } else if (*begin == '/') {
            begin++;
            ret /= factor(begin);
        } else break;
    }
    return ret;
}

int factor(State& begin) {
    if (*begin == '(') {
        begin++;
        int ret = expression(begin);
        begin++;
        return ret;
    } else {
        return number(begin);
    }
}

int number(State& begin) {
    int ret = 0;
    while (isdigit(*begin)) {
        ret = ret*10 + (*begin - '0');
        begin++;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cin.ignore();
    for (int i = 0; i < n; i++) {
        string s;
        getline(cin, s);

        State begin = s.begin();
        int ans = expression(begin);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1208
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[0]
for x in range(N):
 C.append(C[-1]+A[x])
D=[0]
for x in range(M):
 D.append(D[-1]+B[x])
count=0
y=M
for x in range(N+1):
 if C[x]>K:
    break
 while D[y]>K-C[x] and y>0:
   y-=1
 count=max(count,x+y)
print(count)

Measured memory_bytes: 47312
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long X = sc.nextLong();
    long ans = 0;
    while(X>=500){
      ans += 1000;
      X -= 500;
    }
    while(X>=5){
      ans += 5;
      X -= 5;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35760
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
int main(){
    int n,k;
    string s;
    cin >> n >> s >> k;
    rep(i,n){
        if(s[i] != s[k-1]){
            cout << '*';
        }
        else{
            cout << s[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
/*
R         R R R R        R        R R R      R      R    R    R      R    R R R R                                                     
R         R             R R       R    RR    R R    R    R    R R    R    R              
R         R            R   R      R R R      R  R   R    R    R  R   R    R   R R                 
R         R R R       R R R R     R R        R   R  R    R    R   R  R    R     R                       
R         R          R       R    R   RR     R    R R    R    R    R R    R     R           
R R R R   R R R R   R         R   R     RR   R      R    R    R      R    R R R R               

*/


#include<bits/stdc++.h>
using namespace std;
#define  bf            ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll            long long
#define  pb            push_back
#define  pr            10
#define  mx            100000 // 10^6
#define  md            1000000007
#define  result(a)     cout<<a<<endl;
#define  forr(a,x)     for(int i=a;i<=x;i++)
#define  input(n,a)    int a[n];for(int i=0;i<n;i++)cin>>a[i];
#define  print(a)      for(auto it:a)cout<<it<<' '; //0-based 
#define  printt(n,a)   for(i=0;i<n;i++)cout<<a[i]<<' '; //1-based 
#define  sz(a)         cout<<a.size()<<endl; 
#define  prefx(n,a)    for(i=1;i<n;i++)a[i]=a[i-1]+a[i]; //0-based
#define  sortt(v)      sort(v.begin(),v.end());
#define  srt(n,a)      sort(a,a+n);
#define  rev(n,a)      reverse(a,a+n);
#define  revr(a)       reverse(a.begin(),a.end());
#define  yes           cout<<"Yes\n";
#define  no            cout<<"No\n";

int main()
{
  int n,sum=0,r;
  cin>>n;
  r = n;
  while(r>0)
  {
    sum+=(r%10);
    r /=10;
  }
  if(n%sum==0){yes;}
  else {no;}
  
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int r, g, b, n;
    ll ans = 0;
    cin >> r >> g >> b >> n;
    rep(i, n + 1)
    {
        rep(j, n + 1)
        {
            if ((n >= r * i + g * j) && (n - r * i - g * j) % b == 0)
            {
                //     cerr << i << "," << j << "," << n - i - j << endl;
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define all(v) v.begin(),v.end()
#define INF 1e7
using namespace std;

bool check(string s){
	string alt="";
	rep(i,s.size())alt+=s[0];
	if(s==alt)return true;
	else return false;
}

int func(string s,char ch){
	int cnt=0;
	string t;
	while(!check(s)){
		t="";
		rep(i,s.size()-1){
			if(s[i]==ch || s[i+1]==ch){
				t+=ch;
			}else t+=s[i];
		}
		s=t;
		cnt++;
	}
	return cnt;
}

int main(){
	string s;
	cin>>s;
	int m=INF;
	rep(i,s.size()){
		char now=s[i];
		m=min(m,func(s,now));
	}
	cout<<m<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

const int Maxn = 1000;
const int Maxm = 2000;

vector<int> G[Maxn + 5];

int N, M;
bool vis[Maxn + 5];
int dep[Maxn + 5], ed;
vector<int> ans;

bool DFS(int u) {
	vector<int> tmp;
	int t = -1;
	for(int i = 0; i < (int)G[u].size(); i++) {
		int v = G[u][i];
		if(dep[v] != -1) {
			if(t == -1) t = v;
			else if(dep[v] > dep[t]) t = v;
		}
		if(!vis[v]) tmp.push_back(v);
		vis[v] = true;
	}
	if(t == -1) {
		for(int i = 0; i < (int)tmp.size(); i++) {
			int v = tmp[i];
			dep[v] = dep[u] + 1;
			if(DFS(v)) {
				if(dep[u] >= dep[ed])
					ans.push_back(u);
				return true;
			}
			dep[v] = -1;
		}
		for(int i = 0; i < (int)tmp.size(); i++)
			vis[tmp[i]] = false;
		return false;
	} else {
		ed = t;
		ans.push_back(u);
		return true;
	}
}

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%d %d", &N, &M);
	for(int i = 1; i <= M; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		G[u].push_back(v);
	}
	memset(dep, -1, sizeof dep);
	for(int i = 1; i <= N; i++) {
		memset(vis, false, sizeof vis);
		vis[i] = true, dep[i] = 0;
		if(DFS(i)) {
			printf("%d\n", ans.size());
			for(int i = (int)ans.size() - 1; i >= 0; i--)
				printf("%d\n", ans[i]);
			return 0;
		}
		dep[i] = -1;
	}
	puts("-1");
	return 0;
}


Measured memory_bytes: 3436
#!/usr/bin/env ruby
w = gets.chomp!.to_i
n = gets.chomp!.to_i

lots = (1..w).to_a
n.times do
  a, b = gets.chomp!.split(",").map(&:to_f)
  lots[a-1], lots[b-1] = lots[b-1], lots[a-1]
end

puts lots

Measured memory_bytes: 8580