akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String[] hiki = scan.nextLine().split(" ");
    int n = Integer.parseInt(hiki[0]);
    int k = Integer.parseInt(hiki[1]);
    int[] cost = new int[n];
    int[] dp = new int[n];
    hiki = scan.nextLine().split(" ");
    for(int i = 0;i < n;i++){
      cost[i] = Integer.parseInt(hiki[i]);
      dp[i]=Integer.MAX_VALUE;
    }
    dp[0]=0;
    for(int i = 1;i < n;i++){
      for(int j = 1;j < Math.min(i,k)+1;j ++){
        dp[i] = Math.min(dp[i],
        dp[i-j]+Math.abs(cost[i]-cost[i-j]));
      }
    }
    System.out.println(dp[n-1]);
  }
}


Measured memory_bytes: 46512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<int> a(N);
	rep(i,N)cin>>a[i];
	sort(all(a));
	int maxa = a[N-1];
	int mid = maxa/2;
	int d =  INF;
	int xx = 0;
	rep(i,N){
		if(abs(mid - abs(maxa-a[i]))<d){
			xx = a[i];
			d = abs(mid-abs(maxa-a[i]));
		}
	}
	cout<<maxa<<" "<<xx<<endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
  int a=0,b=0,i=0;
  char s[100001];
  
  scanf("%s",s);
  
  while(1){
        if(s[i]=='\0')
          break;
        if(s[i]=='0'&&i%2==0)
           a++;
        else if(s[i]=='1'&&i%2==1)
         a++;
         i++;
        if(s[i]=='\0')
          break;
  }
i=0;
    while(1){
          if(s[i]=='\0')
           break;
          if(s[i]=='1'&&i%2==0)
           b++;
          else if(s[i]=='0'&&i%2==1)
           b++;
           i++;
  }
  if(b<a)
    a=b;
  
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N; 
  cin >> N;
  int max = 0; 
  int count = 0;
  for(int i = 0; i < N; i++){
    int H;
    cin >> H;
    if(H >= max){
      max = H;
      count++;  
    } 
  }
  cout << count <<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_V = 100100;
const int MAX_N = 110;
ll wi[MAX_N];
ll vi[MAX_N];
ll dp[MAX_N][MAX_V];
const long long INF = 1LL<<60;

void solve() {
    int N; ll W;
    cin >> N >> W;
    for (ll i = 0; i < N; ++i) cin >> wi[i] >> vi[i];
    for (ll i = 0; i < MAX_N; ++i) for (ll j = 0; j < MAX_V; ++j) dp[i][j] = INF;

    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        ll v = vi[i];
        ll w = wi[i];
        for (ll vj = 0; vj < MAX_V; ++vj) {
            if (v <= vj) dp[i+1][vj] = min(dp[i+1][vj], dp[i][vj - v] + w);
            dp[i+1][vj] = min(dp[i+1][vj], dp[i][vj]);
        }
    }
    ll vmax = 0;
    for (int i = 0; i < MAX_V; ++i) {
        if (dp[N][i] <= W) {
            vmax = i;
        }
    }
    cout << vmax << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  string ans = "";
  while(n>=1){
    n--;
    ans += 'a'+(n%26);
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
k, n = map(int, input().split())
a = list(map(int, input().split()))
maxdis = 0
for i in range(1, n):
    maxdis = max(maxdis, a[i] - a[i - 1])
maxdis = max(maxdis, a[0] + k - a[-1])
print(k - maxdis)

Measured memory_bytes: 78540
import java.util.Scanner
import scala.util.control.Breaks

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt()
  val Y = sc.nextInt()

  var ans = ""
  val b = new Breaks

  b.breakable {
    for (i <- 0 to N; j <- 0 to N - i) {
      val k = N - i - j
      if (i * 10000 + j * 5000 + k * 1000 == Y && i + j + k == N) {
        ans = i + " " + j + " " + k
        b.break
      }
    }
  }
  if (ans == "") ans = "-1 -1 -1"
  println(ans)
}


Measured memory_bytes: 55480
import sys
if sys.version_info[0]>=3: raw_input=input
a=[1,1,2]
for i in range(3,31): a.append(a[i-1]+a[i-2]+a[i-3])
while True:
	n=int(raw_input())
	if n==0: break
	print((a[n]+3649)//3650)

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

using namespace std;

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

	int n;
	cin >> n;

	vector<string> s(n);

	for (auto &x : s) {
		cin >> x;
	}

	vector<vector<int>> a(26, vector<int>(s.size()));

	for (int j = 0; j < s.size(); j++){
		for (int i = 0; i < s[j].size(); i++) {
			a[s[j][i] - 'a'][j]++;
		}
	}

	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < *min_element(a[i].begin(),a[i].end()); j++) {
			cout << (char)('a' + i);
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;

#define MAX_N 101
#define INF 1 << 28

struct edge_t {
    int from, to, cost;
    edge_t(int from=0, int to=0, int cost=0) :
        from(from), to(to), cost(cost) {}
};

struct state_t {
    int city;   // 現在地
    int coupon; // 残り割引券枚数
    int cost;   // 現在地までにかかった金額
    state_t(int city=0, int coupon=0, int cost=0) :
        city(city), coupon(coupon), cost(cost) {}
    bool operator>(const state_t &o) const {
        return cost == o.cost ? coupon < o.coupon : cost > o.cost;
    }
    bool operator<(const state_t &o) const {
        return cost == o.cost ? coupon > o.coupon : cost < o.cost;
    }
};

int c, n, m, s, d;
vector<edge_t> graph[MAX_N];

int dijkstra() {
    int cost[n+1][c+1];
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= c; j++)
            cost[i][j] = INF;

    priority_queue<state_t, vector<state_t>, greater<state_t> > q;

    cost[s][c] = 0;

    q.push(state_t(s, c, 0));

    while (!q.empty()) {
        state_t p = q.top(); q.pop();

        for (int i = 0; i < graph[p.city].size(); i++) {
            edge_t e = graph[p.city][i];

            // クーポン券を使わないとき
            if (cost[e.to][p.coupon] > cost[e.from][p.coupon] + e.cost) {
                cost[e.to][p.coupon] = cost[e.from][p.coupon] + e.cost;
                q.push(state_t(e.to, p.coupon, cost[e.to][p.coupon]));
            }

            // クーポン券を使うとき
            if (p.coupon > 0) {
                if (cost[e.to][p.coupon-1] > cost[e.from][p.coupon] + e.cost / 2) {
                    cost[e.to][p.coupon-1] = cost[e.from][p.coupon] + e.cost / 2;
                    q.push(state_t(e.to, p.coupon-1, cost[e.to][p.coupon-1]));
                }
            }
        }
    }

    int min_cost = INF;
    for (int i = 0; i <= c; i++) 
        min_cost = min(min_cost, cost[d][i]);
    return min_cost;
}

int main() {
    while (cin >> c >> n >> m >> s >> d) {
        if (c == 0 && n == 0 && m == 0 && s == 0 && d == 0) break;
        for (int i = 0; i <= n; i++) graph[i].clear();
        for (int i = 0; i < m; i++) {
            int a, b, f; cin >> a >> b >> f;
            graph[a].push_back(edge_t(a, b, f));
            graph[b].push_back(edge_t(b, a, f));
        }
        cout << dijkstra() << endl;
    }
    return 0;
}
    

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d,g;
  cin >> d >> g;
  vector<int> p(d),c(d);
  for(int i=0;i<d;i++){
    cin >> p[i] >> c[i];
  }
  int ans=1e9;
  for(int i=0;i<(1<<d);i++){
    int sum=0,num=0,m=-1;
    for(int j=0;j<d;j++){
      if(i>>j&1){
        sum+=100*(j+1)*p[j]+c[j];
        num+=p[j];
      }
      else m=j;
    }
    if(sum<g){
      int r=100*(m+1);
      int need=(g-sum+r-1)/r;
      if(need>=p[m]){
        continue;
      }
      num+=need;
    }
    ans=min(ans,num);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#include <map>
using namespace std;

int main()
{
	vector<vector<int>> A(3, vector<int>(3));
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> A[i][j];
		}
	}

	int N;
	cin >> N;
	vector<int> b(N);

	for (int i = 0; i < N; i++)
	{
		cin >> b[i];
	}

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < N; k++)
			{
				if (A[i][j] == b[k]) {
					A[i][j] = 0;
				}
			}
			
		}
	}

	int count = 0;
	bool bingoFlag = false;
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (A[i][j] == 0) {
				count++;
			}
		}
		if (count == 3) {
			bingoFlag = true;
		}
		count = 0;
	}

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (A[j][i] == 0) {
				count++;
			}
		}
		if (count == 3) {
			bingoFlag = true;
		}
		count = 0;
	}

	if (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0) {
		bingoFlag = true;
	}
	
	if (A[0][2] == 0 && A[1][1] == 0 && A[2][0] == 0) {
		bingoFlag = true;
	}



	if (bingoFlag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}



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

int main() {
    int n,m;
    cin>>n>>m;
    int a[n],b[n],c[m],d[m];
    for (int i=0;i<n;i++)
        cin>>a[i]>>b[i];
    for (int i=0;i<m;i++)
        cin>>c[i]>>d[i];
    for (int i=0;i<n;i++) {
        int mn=1e9;
        int ans=0;
        for (int j=0;j<m;j++) {
            int dis=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if (dis<mn) {
                mn=dis;
                ans=j+1;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

int main(void){
    string taro, hana;
    int n, tarop = 0, hanap = 0;

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> taro >> hana;
        if(taro > hana) tarop += 3;
        else if(taro < hana) hanap += 3;
        else{
            tarop++;
            hanap++;
        }
    }
    cout << tarop << ' ' << hanap << endl;
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;

#define updmin(dp,x) (dp=(dp == 0 ? x : min(dp,x)))

int main(void){
    int n;
    while(cin>>n, n){
        vector<int> p(n);
        rep(i,n) cin>>p[i];
        // vector<map<int,int>> dp(n+1); // dp[get][coin] = pay
        vector<vector<int>> dp(n+1, vector<int>(500*n,INF));
        dp[0][0] = 0;
        int coin_max = 0;
        rep(i,n){
            for(int k = i; k >= 0; k--){
                // for(auto itr = dp[k].rbegin(); itr != dp[k].rend(); ++itr){
                for(int coin = 500*n-1; coin>=0; coin--){
                    if(dp[k][coin] == INF) continue;
                    // int coin = itr->first;
                    // coin_max = max(coin_max, coin);
                    int pay = dp[k][coin];
                    // int pay = itr->second;
                    int mod = p[i]%500;
                    if(p[i]%1000 == 0){
                        if(coin>=500) updmin(dp[k+1][coin-500], pay+p[i]);
                    }else if(p[i]%1000 == 500){
                        updmin(dp[k+1][coin], pay+p[i]);
                    }else if(p[i]%1000 <= 500){
                        // if(mod+500<=coin){
                        //     updmin(dp[k+1][coin-500-mod], pay+p[i]);
                        // }else{
                            updmin(dp[k+1][coin+500-mod], pay+p[i]);
                        // }
                    }else if(mod <= coin){
                        updmin(dp[k+1][coin-mod], pay+p[i]);
                    }else{
                        updmin(dp[k][coin+500-mod], pay+p[i]);
                    }
                }
            }
        }
        for(int i = n; i>=0; i--){
            // if(dp[i].size()){
                int res = INF;
                for(auto itr : dp[i]){
                    // res = min(res,itr.second);
                    res = min(res,itr);

                }
                if(res != INF){
                cout<<i<<" "<<res<<endl;
                break;
            }
            // }
        }
        // debug(coin_max);
    }
    return 0;
}



Measured memory_bytes: 22952
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc097_b.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int x;
  cin >> x;

  int MAX_I = sqrt(1000) + 1;
  int ans = 1;
  repi(i, 2, MAX_I) {
    int j = 2;
    while (pow(i, j) <= x) {
      // printf("%d, %d, %f\n", i, j, pow(i, j));
      ans = max((int)pow(i, j++), ans);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
//atcoder 20190824 B
#include <bits/stdc++.h>
#define N 2005

using namespace std;

const long long mod = 1e9+7;
long long n, k;
long long c[N];

long long a[N], b[N];
long long num[N];
long long ans;

long long calc(int x) {
	long long res = 0;
	for (int i = n; i > x; --i)
		if (a[i] < a[x]) ++res;
	return res;
}

int main() {
	ios::sync_with_stdio(false);

	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
		cin >> a[i], b[i] = a[i];

	sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; ++i)
		num[i] = lower_bound(b + 1, b + n + 1, a[i]) - b - 1;

	for (int i = n; i; --i) {
		(ans += calc(i) * k % mod) %= mod;
		(ans += k * (k - 1) / 2 % mod * num[i] % mod) %= mod;
	}

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

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

using namespace std;

int N;
vector < string > arr;

int main(){
    cin >> N;
    for(int i = 1; i <= N; ++i){
        string s; cin >> s;
        arr.push_back(s);
        sort(arr[i - 1].begin(), arr[i - 1].end());
    }
    sort(arr.begin(), arr.end());
    long long cnt = 0, ans = 0;
    for(int i = 0; i < N; ++i){
        if(i && arr[i] == arr[i - 1]){
            ++cnt;
        }
        else{
            ans += (long long)cnt * (cnt - 1) / 2;
            cnt = 1;
        }
    }
    ans += cnt * (cnt - 1) / 2;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 5748
#include <iostream>
#include <cmath>
using namespace std;
#define rep(i, a, b) for(int i = a; i<=b; ++i)

int main(){
    int N, D, X, Y, count = 0;
    cin >> N >> D;
    rep(i,0,N-1){
        cin >> X >> Y;
        if (sqrt(pow(X, 2) + pow(Y, 2)) <= D) count++;
    }
    cout << count << "\n";
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<int>A(N);
    rep(i, N)cin >> A[i];
    if (N % 2 == 0) {
        sort(A.begin(), A.end());
        rep(i, N-2) {
            if ((i % 2 == 1&&A[i]!=A[i-1])||A[i+2]-A[i]!=2) {
                cout << 0 << endl;
                return 0;
            }
        }
        int ans = 1;
        rep(i, N / 2) {
            ans *= 2;
            ans %= INF;
        }
        cout << ans << endl;
    }
    else {
        sort(A.begin(), A.end());
        rep(i, N-2) {
            if (i == 0)continue;
            if ((i % 2 == 0 && A[i] != A[i - 1]) || A[i + 2] - A[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
        }
        int ans = 1;
        rep(i, N / 2) {
            ans *= 2;
            ans %= INF;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3764
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int N,M,A[200020];

int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>M;
    for(long long int i = 0; i < M; i++){
        cin>>A[i];
        N-=A[i];
    }
    cout<<max(-1LL,N)<<endl;

}    


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using comd = complex<double>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,S;
  while(cin >> n >> S){
    if(n + S == 0) break;
    int ans = 0;
    vary(int,r,n,0);
    rep(i,n){
      cin >> r[i];
    }
    rep(i,n){
      REP(j,i+1,n){
        if(r[i]+r[j] > S){
          ++ans;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    string s;
    cin >> s;

    if(s[A] != '-') {
        cout << "No" << endl;
        return 0;
    }
    for(int i=0; i < A; i++ ) {
        if(s[i] < '0' || s[i] > '9') {
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=A+1; i<A+B+1; i++) {
        if(s[i] < '0' || s[i] > '9') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;


}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define ll          long long
#define pii         pair<int, int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int, int>
#define mii         map<pii, int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define lb          lower_bound
#define ub          upper_bound

#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)
 
#define track(x)                 cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
 
#define ed(i)       i.end()
#define mem(a)	    memset(a, 0, sizeof(a))

#define MOD         1000000007
int mult(int a,int b, int p=MOD){return ((a%p)*(b%p))%p;}
int add(int a, int b, int p=MOD){return (a + b + p)%p;}
int fpow(int n, int k, int p = MOD) {int r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int b) {a = max(a, b); }
void self_min(int &a, int b) {a = min(a, b); }
void self_add(int &a, int b, int p = MOD) { a += b; if(a >= p) a -= p;}
void self_sub(int &a, int b, int p = MOD) { a -= b; if(a < 0) a += p;}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
const int INF = 1e9 + 5;
#define N	    	400001

int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
void solve(){
    int n, m;
    cin>>n>>m;
    int a[m];
    rep(i, 0, m) {
        cin>>a[i];
    }
    if(n >= m) {
        cout<<0<<endl;
        return;
    }
    sort(a, a + m);
    vi v;
    rep(i, 1, m) {
        v.pb(a[i] - a[i-1]);
    }
    sort(all(v)); reverse(all(v));
    int dis = 0;
    rep(i, 0, n-1)
        dis += v[i];
    cout<<a[m-1] - a[0] - dis<<endl;
}
int main() {
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin>>t;
	while(t--){
		solve();
	}
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m; cin >> n >> m;
  int l_max = 0, r_min = 1e9;
  rep(i, m) {
    int x, y; cin >> x >> y;
    l_max = max(l_max, x);
    r_min = min(r_min, y);
  }
  cout << max(0, min(n, r_min-l_max+(l_max <= r_min)));
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define eb emplace_back
#define pb push_back
#define mk make_pair
#define mt make_tuple
#define graph vector<vector<int>>
#define INF 1e9+5
#define N 40001


bool sortbysec(const tuple<int, int, int>& a,  
               const tuple<int, int, int>& b) 
{ 
    return (get<1>(a) < get<1>(b)); 
}
void dfs(int s, graph &g, bool vis[]){
	vis[s] = true;
	for(int i=0;i<g[s].size();i++){
		if(!vis[g[s][i]]) dfs(g[s][i],g,vis);
	}
}

string common_prefix(vector<string>& strings){
	string prefix;
	for(string s : strings){
		for(int i=0;i<s.size() && s[i]!='*';++i){
			if(i<prefix.size()){
				if(s[i]!=prefix[i]) return "*";
			}
			else prefix+=s[i];
		}
	}
	return prefix;
}

void reverse(vector<string>& strings){
	for(string& s : strings){
		reverse(s.begin(),s.end());
	}
}


void solve(){
	int n; cin>>n;
	vector<int>h(n);
	for(int& x : h) cin>>x;

	vector<int>dp(n,INF);

	dp[0] = 0;


	for(int i=0;i<n;i++){
		for(int j : {i+1,i+2}){
			if(j<n) dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n-1]<<endl;

}

int main() {
IOS;
	int t=1; 
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
}

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

using namespace std;

int main()
{
    int n, m; cin >> n >> m;
    int b[m][2]; bool pos[n]; int num[n];
    pos[0] = true; num[0] = 1;

    for (int i = 0; i < m; i++)
        cin >> b[i][0] >> b[i][1];

    for (int i = 1; i < n; i++){
        pos[i] = false;
        num[i] = 1;
    }

    for (int i = 0; i < m; i++){
        if(pos[b[i][0] - 1]) {
            if(num[b[i][0] - 1] != 1) {
                num[b[i][0] - 1]--;
                num[b[i][1] - 1]++;
                pos[b[i][1] - 1] = true;
            }
            else {
                num[b[i][0] - 1] = 0;
                num[b[i][1] - 1]++;
                pos[b[i][1] - 1] = true;
                pos[b[i][0] - 1] = false;
            }
        }
        else {
            num[b[i][0] - 1]--;
            num[b[i][1] - 1]++;
        }
    }

    int sol = 0;
    for (int i = 0; i < n; i++)
        if (pos[i]) sol++;

    cout << sol << '\n';
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#define MAX 1000000000000000000

int main() {
    int n;
    std::cin >> n;
    long long a[n];
    long long sum = 1;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        if (sum > MAX / a[i]) {
            sum = -1;
            long long temp;
            for (i = i + 1; i < n; i++) {
                std::cin >> temp;
                if (temp == 0) {
                    sum = 0;

                    break;
                }
            }
            break;
        }
        sum *= a[i];
    }
    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 4320
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    string s; cin >> s;
    int pos = 15 - s.size();
    for(int i = 0; i < s.size(); i++) if(s[i] == 'o') pos++;
    if(pos >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int A, B, C, D, sum = 0;
  unused = scanf("%d", &A);
  unused = scanf("%d", &B);
  unused = scanf("%d", &C);
  unused = scanf("%d", &D);

  if(A<B) sum+=A;
  else sum+=B;
  if(C<D) sum+=C;
  else sum+=D;

  printf("%d", sum);
  return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int n, m, k;

int main() {
	
	FAST;
	
	cin >> n >> m >> k;
	vector <int> a(n + 1), b(m + 1);
	vector <intt> prefa(n + 1), prefb(m + 1);
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		prefa[i] = prefa[i - 1] + a[i];
	}
	for (int i = 1; i <= m; i ++) {
		cin >> b[i];
		prefb[i] = prefb[i - 1] + b[i];
	}
	int ans = 0;
	for (int i = 0; i <= n; i ++) {
		if (k - prefa[i] < 0) break;
		vector <intt> ::iterator itr;
		itr = upper_bound(prefb.begin(), prefb.end(), k - prefa[i]);
		itr --;
		int j = itr - prefb.begin();
		ans = max(ans, i + j);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 7924
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

template <typename T>
struct SegTree {
	T init_val;
	int n;
	vector<T> dat;
	
	SegTree() {}
	SegTree(int _n, T init_val) : init_val(init_val) {
		n = 1;
		while (n < _n) n *= 2;
		dat.resize(n * 2 - 1, init_val);
	}
	
	void update(int i, T x) {
		i += n - 1;
		dat[i] = min(dat[i], x);
		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
		}
	}
	
	void set(int i, T x) {
		dat[i + n - 1] = x;
		update(i, x);
	}
	
	// 探索範囲[a,b), 現在見ているkノード[l,r)
	T query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		
		if (r <= a || b <= l) return init_val;
		if (a <= l && r <= b) return dat[k];
		return min( query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r) );
	}
};

int N;
int p[212345], ans[212345];
SegTree<pii> segodd, segeven;
pii num[212345];
vector<pii> g[212345];
int cnt[212345];
priority_queue<pip, vector<pip>, greater<pip> > pq;

// [l, r)
void dfs(int l, int r, int prev) {
	if (l >= r) return;
	
	int miidx, nidx;
	if (l & 1) {
		miidx = segodd.query(l, r).se;
		nidx = segeven.query(miidx + 1, r).se;
	}
	else {
		miidx = segeven.query(l, r).se;
		nidx = segodd.query(miidx + 1, r).se;
	}
	
	chmax(cnt[miidx], 0);
	if (prev != -1) {
		g[prev].push_back(pii(miidx, nidx));
		cnt[miidx]++;
	}
	else {
		pq.push(pip(p[miidx], pii(p[nidx], miidx)));
	}
	
	dfs(l, miidx, miidx);
	dfs(miidx + 1, nidx, miidx);
	dfs(nidx + 1, r, miidx);
	
	return;
}

int main() {
	cin >> N;
	REP(i, N) scanf("%d", p + i);
	
	segodd = SegTree<pii>(N, pii(INF, -1));
	segeven = SegTree<pii>(N, pii(INF, -1));
	
	REP(i, N) {
		if (i & 1) segodd.update(i, pii(p[i], i));
		else segeven.update(i, pii(p[i], i));
	}
	
	memset(cnt, -1, sizeof(cnt));
	dfs(0, N, -1);
	
	vector<int> ans;
	
	while (!pq.empty()) {
		pip now = pq.top(); pq.pop();
		ans.push_back(now.fi);
		ans.push_back(now.se.fi);
		
		int idx = now.se.se;
		REP(i, g[idx].size()) {
			if (--cnt[g[idx][i].fi] == 0) {
				pq.push(pip(p[g[idx][i].fi], pii(p[g[idx][i].se], g[idx][i].fi)));
			}
		}
	}
	
	
	
	REP(i, N) printf("%d%c", ans[i], i == N - 1 ? '\n' : ' ');
	
	return 0;
}


Measured memory_bytes: 44532
def f(l):
    a, b, c = l
    return int(b)

def f2(l):
    a, b, c = l
    return a

N = int(input())
SP = [list(map(str, input().split())) for _ in range(N)] #N_length and M_times args

for _ in range(len(SP)):
    SP[_].append(_+1)

SP.sort(key=f, reverse=True)
SP.sort(key=f2)

for _ in SP:
    print(_[2])


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

int main() {
	long tmp=0, n,count=0;
  	cin >> n;
  	vector<int> a(n);
  	for(int i = 0; i<n;i++) {
    	cin >> a[i];
      	if(a[i] == 0) {
          	if(tmp != 0) {
            	count += tmp/2; 
            }
      		tmp = 0;
        } else {
        	tmp += a[i]; 
        }
    }
    count += tmp/2;
  	cout << count << endl;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
int main(){
	string s;
	int x;
	map<string,vector<int> > mp;
	while(cin>>s>>x)
		mp[s].push_back(x);
	typedef vector<pair<string,vector<int> > > P;
	P vp(mp.begin(),mp.end());
	sort(vp.begin(),vp.end());

	for(P::iterator it = vp.begin(); it != vp.end(); ++it){
		sort((*it).second.begin(),(*it).second.end());
		cout << (*it).first << endl;
		vector<int> &v = (*it).second;
		for(int i = 0; i < (int)v.size(); i++){
			printf("%d%c",v[i],i==(int)v.size()-1?'\n':' ');
		}
	}

    return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;
	public static final long HUGE_NUM = 99999999999999999L;
	public static final double EPS = 0.000000001;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);
		int table[] = new int[5];
		int ans[] = new int[5];
		int work[] = new int[4];
		int count,zero_type;

		while((table[0] = scanner.nextInt()) != 0){

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

				work[i] = 0;
			}

			work[table[0]] += 1;

			for(int i = 1; i < 5; i++){

				table[i] = scanner.nextInt();
				work[table[i]] += 1;
			}

			count = 0;
			zero_type = -1;

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

				if(work[i] > 0){
					count++;
				}else{

					zero_type = i;
				}
			}

			if(count != 2){

				for(int i = 0; i < 5; i++){

					ans[i] = 3;
				}
			}else{

				int win = -1,lose = -1;

				switch(zero_type){
				case 1:
					win = 2;
					lose = 3;
					break;
				case 2:
					win = 3;
					lose = 1;
					break;
				case 3:
					win = 1;
					lose = 2;
					break;
				}

				for(int i = 0; i < 5; i++){

					if(table[i] == win){

						ans[i] = 1;
					}else{

						ans[i] = 2;
					}
				}
			}

			for(int i = 0; i < 5; i++){

				System.out.println(ans[i]);
			}

		}

    }
}

class UTIL{

	//最大公約数
	public static long gcd(long x,long y){

		x = Math.abs(x);
		y = Math.abs(y);

		if(x < y){

			long tmp = y;
			y = x;
			x = tmp;
		}

		if(y == 0){

			return x;
		}else{

			return gcd(y,x%y);
		}
	}

	//最小公倍数
	public static long lcm(long x,long y){

		return (x*y)/gcd(x,y);
	}

	//String→intへ変換
    public static int getNUM(String tmp_str){

        return Integer.parseInt(tmp_str);
    }

    //文字が半角数字か判定する関数
    public static boolean isNumber(String tmp_str){

        if(tmp_str == null || tmp_str.length() == 0){

            return false;
        }

        Pattern pattern = Pattern.compile("\\A[0-9]+\\z");
        Matcher matcher = pattern.matcher(tmp_str);
        return matcher.matches();
    }
}


Measured memory_bytes: 28796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int n, k, x, y; cin >> n >> k >> x >> y;

    if(n <= k) cout << n*x << endl;
    else cout << k*x + (n-k)*y << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  string s;cin >> s;
  rep(i,3){
    if(s[i]=='1')s[i]='9';
    else if(s[i]=='9')s[i]='1';
  }
  cout << s << endl;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,M = inpl()
aa = [False]*(N+1)
for _ in range(M):
    a = int(input())
    aa[a] = True

dp = [1]*(N+1)
if aa[1]:
    dp[1] = 0

for i in range(2,N+1):
    if aa[i]:
        dp[i] = 0
    else:
        dp[i] = (dp[i-1]+dp[i-2]) %mod

print(dp[-1]%mod)


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

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        long N = in.l();
        double root = Math.sqrt(N+1);
        long a = 1;
        for(int i = 2; i < root; i++){
            if(N%i == 0){
                a = i;
            }
        }
        out.println(a+N/a-2);
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 23124
N = int(input())
k =[]
for i in range(N):
    k.append([x for x in input().split()])
X = input()
counter = 0
iscounter=False
for i in range(N):
    if iscounter == False:
       if k[i][0] == X:
         iscounter = True
    else:
      counter += int(k[i][1])
print(counter)

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

const ll INF = 1LL << 60;

ll N, K;
vector<ll> A;

int main() {
    cin >> N >> K;
    A.resize(N);
    rep(i, N) {
        cin >> A[i];
        A[i]--;
    }

    vector<ll> sum(N + 1);
    sum[0] = 0;

    rep(i, N) {
        sum[i + 1] = (sum[i] + A[i]) % K;
    }

    // 長さがKであること
    queue<ll> que;
    map<ll, ll> mp;
    ll ans = 0;
    rep(i, N + 1) {
        ans += mp[sum[i]];
        mp[sum[i]]++;
        que.push(sum[i]);

        while (que.size() >= K) {
            mp[que.front()]--;
            que.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 20644
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main(){
  int a, b, c;
  int k;
  cin >> a >> b >> c >> k;
  int mx = max({a, b, c});
  int ans = mx;
  rep(i,k) ans *= 2;
  ans += (a+b+c) - mx;
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
void trace(int A[], int N) {
    int i;
    for( i = 0; i < N; i++){
        if( i>0 ) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

void insertionSort(int A[], int N){
    int j, i, v;
    for( i = 1; i < N; i++ ){
        v = A[i];
        j = i -1;
        while ( j >= 0 && A[j] > v ){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        trace(A,N);
    }
}

int main() {
    int N, i, j;
    int A[100];
    
    scanf("%d", &N);
    for( i = 0; i < N ; i++ ) scanf("%d", &A[i]);
    
    trace(A,N);
    insertionSort(A,N);
    
    return 0;
}


Measured memory_bytes: 2092
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n = int(input())
    a = list(map(int,input().split()))
    r = 0
    pinf = 0
    ans = 0
    for l in range(n):
        while (r<n)and pinf ^ a[r] == pinf + a[r]:
            pinf += a[r]
            r += 1
        ans += r-l
        if l == r:
            r += 1
        else:
            pinf -= a[l]
    
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================
    

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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N;
    cin >> N;
    vector<int> list(N);
    vector<bool> baisu(10000001);
    map<int, int> hist;

    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        list[i] = tmp;
        hist[tmp]++;
    }

    for (auto x : hist)
    {
        int p = x.first, q = 2;
        if(!baisu[p])
        {
            while (p * q <= 1000000)
            {
                baisu[p * q] = true;
                q++;
            }
        }
        
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        int tmp = list[i];
        if (hist[tmp] == 1 && baisu[tmp] == false)
            ans++;
    }
    cout << ans;
}


Measured memory_bytes: 14444
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}

ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  ll n;
  cin>>n;
  ll ans;
  set<int>st;
  st.emplace(n);
  for(ll i=2;i*i<=n;++i){
    ll nn=n;
    while(nn>=i){
      if(nn%i==0)nn/=i;
      else nn%=i;
    }
    if(nn==1)st.emplace(i);
  }
  for(ll i=2;i*i<=n-1;++i){
    if((n-1)%i==0)st.emplace((n-1)/i);
  }
  if(n-1>1)st.emplace(n-1);
  ans=st.size();
  cout<<ans;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 256
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

def main():
  A,B= map(int,input().split())
  print(lcm(A,B))


if __name__=='__main__':
  main()

Measured memory_bytes: 38256