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

using namespace std;

typedef long long ui;

char d[5005][5005];
int vv[5005][5005];
int tp[5005];

int main() {
	int h, w, KK;
	scanf("%d%d%d", &h, &w, &KK);
	for (int i = 0; i < h; i++)
		scanf("%s", d[i]);
	int S = 1 << (h - 1);
	int ans = 19260817;
	for (int i = 0; i < S; i++) {
		for (int p = 0; p < w; p++)
			for (int q = 0; q < h; q++)
				vv[p][q] = 0;
		int cnt = 0, rig = 0;
		for (int j = 0; j < h - 1; j++)
			if ((1 << j) & i)
				rig++;
		cnt = rig;
		bool cant = false;
		for (int j = 0; j < w; j++) {
			int f = 0;
			for (int k = 0; k < h; k++) {
				vv[j][f] += (d[k][j] == '1');
				if (vv[j][f] > KK) {
					cant = true;
					break;
				}
				if ((1 << k) & i)
					f++;
			}
			if (cant)
				break;
		}
		if (cant)
			continue;
		for (int j = 0; j <= rig; j++)
			tp[j] = 0;
		for (int j = 0; j < w; j++) {
			for (int k = 0; k <= rig; k++) {
				tp[k] += vv[j][k];
				if (tp[k] > KK) {
					for (int p = 0; p <= rig; p++)
						tp[p] = vv[j][p];
					cnt++;
					break;
				}
			}
		}
		ans = min(ans, cnt);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 21120
#include <iostream>
#include <map>
#include <cmath>

using ll = long long;
using namespace std;

int main() {
    int n; cin >> n;
    map<pair<int, int>, int> cnt;
    for (int j = 0; j < n; ++j) {
        double d; cin >> d;
        ll i = llround(d*1e9);
        int two, five;
        two = five = 0;
        while (i % 2 == 0)
            i /= 2, ++two;
        while (i % 5 == 0)
            i /= 5, ++five;
        ++cnt[{two, five}];
        // cout << two << " " << five << "\n";
    }
    
    ll ans = 0;
    for (auto [p1, c1] : cnt) {
        for (auto [p2, c2] : cnt) {
            if (p1.first + p2.first >= 18 and p1.second + p2.second >= 18) {
                if (p1 < p2) {
                    ans += (ll) c1 * c2;
                } else if (p1 == p2) {
                    ans += (ll) (c1 - 1) * c1 / 2;
                }
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3148
#include <stdio.h>
#include <string.h>
 
int stricmp(char* ch1,char* ch2){
    int ch1_length = 0,ch2_length = 0,div;
    for(int i = 0; ch1[i] != '\0';i++) ch1_length++;
    for(int i = 0; ch2[i] != '\0';i++) ch2_length++;
    if(ch1_length != ch2_length) return -1;
    for(int i = 0; ch1[i] != '\0';i++)
    {
        div = ch1[i] -ch2[i];
        if(div != 0 && div != 32 && div != -32)
            return -1;
    }
    return 0;
}
 
int main(){
    char W[11],T[1001];
    int count = 0;
    scanf("%s",W);
    while(true){
        scanf("%s",T);
        if(strcmp("END_OF_TEXT",T) == 0) break;
        if(stricmp(T, W) == 0) count++;
    }
    printf("%d\n",count);
}


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

int bubbleSort(int A[],int N){
  int sw=0;
  bool flag=1;
  for(int i=0;flag;i++){
    flag=0;
    for(int j=N-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
        swap(A[j],A[j-1]);
        flag=1;
        sw++;
      }
    }
  }
  return sw;
}

int main(){
  int A[100],N,sw;

  cin>>N;
  for(int i=0;i<N;i++)cin>>A[i];

  sw=bubbleSort(A,N);

  for(int i=0;i<N;i++){
    if(i)cout<<" ";
    cout<<A[i];
  }
  cout<<endl;
  cout<<sw<<endl;

  return 0;
}

Measured memory_bytes: 3120
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (A, B) = Slice2<long>();
            if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
                WriteLine("Possible");
            else
                WriteLine("Impossible");
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27468
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main(){

    int A,B,C,x,y;
    cin >> A>>B>>C;

    if(A>B){
        if(A>C){
            x=A;
            y=B+C;
        }else{
            x=C;
            y=A+B;
        }
    }else{
        if(B>C){
            x=B;
            y=A+C;
        }else{
            x=C;
            y=A+B;
        }
    }

    if(x==y){
        cout << "Yes"<<endl;
    }else{
        cout << "No"<<endl;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#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() {

  int a,b;
  cin >> a >> b;
  for (int n = 0; n < 10000; n++) {
    int za = n * 8/100;
    int zb = n * 10/100;
    if (a == za && b == zb) {
      cout << n << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
  
}

    


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

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<int> A;
map<int, int> values;
int res;
int main()
{
    cin >> N;
    A.resize(N);
    for (auto &val : A)
    {
        cin >> val;
    }
    for (int i = 0; i < N; i++)
    {
        int val = A[i];
        values[val] = values[val - 1] + 1;
        res = max(res, values[val]);
    }
    cout << N - res << endl;
    return 0;
}


Measured memory_bytes: 11000
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=500010, inf=1e9;
int n, N;
int a[maxn], b[maxn], tr[maxn];

template<typename T>
inline void read(T &k)
{
	int f=1; k=0; char c=getchar();
	while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
	while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
	k*=f;
}

inline void add(int x){for(;x<=2*n+1;x+=x&-x) tr[x]++;}

inline int query(int x){int sum=0; for(;x;x-=x&-x) sum+=tr[x]; return sum;}

inline ll check(int mid)
{
	int sum=0; ll ans=0;
	for(int i=1;i<=2*n+1;i++) tr[i]=0;
	add(n+1);
	for(int i=1;i<=n;i++)
	{
		sum+=(a[i]<mid)?1:(-1);
		ans+=query(sum+n);
		add(sum+n+1);
	}
	return ans;
}

int main()
{
	read(n);
	for(int i=1;i<=n;i++) read(a[i]), b[i]=a[i];
	sort(b+1, b+1+n); N=unique(b+1, b+1+n)-b-1;
	for(int i=1;i<=n;i++) a[i]=lower_bound(b+1, b+1+N, a[i])-b;
	int l=1, r=N;
	while(l<r)
	{
		int mid=(l+r+1)>>1;
		if(check(mid)*2<=(1ll*n*(n+1)>>1)) l=mid;
		else r=mid-1;
	}
	printf("%d\n", b[l]);
}

Measured memory_bytes: 3328
#include <stdio.h>
int main(){
	int i,n, a[10000],min,max;
	long long int sum = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	min = a[0];
	max = a[0];
	for (i = 0; i < n; i++)
	{

		if (min>a[i])
		{
			min = a[i];
		}
		if (max < a[i])
		{
			max = a[i];
		}

		sum +=a[i];

	}
	printf("%d %d %lld\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#define INF 100000000
using namespace std;

int n;
int a[101],e[101],r[101];
int dp[101][20001];
int ans,cnt ;
int maxr;
void saiki(int d,int ex,int kai) {
  cnt++;
  if(d <= 0 ) dp[0][ex] = 0;
  if(d > 0) {
    for(int i=0;i<n;i++) {
      if(r[i] <= ex) {
	int da  =  d-a[i];
	if(da < 0) da = 0;
	if(maxr <=ex && a[i] == 0) continue;
	if(a[i] == 0 && e[i] == 0) continue;
	if(dp[da][ex+e[i]] < INF) {
	  dp[d][ex] =min(dp[d][ex],dp[da][ex+e[i]]+1);
	  continue;
	}
        saiki(da,ex+e[i],kai+1);
	dp[d][ex] =min(dp[d][ex],dp[da][ex+e[i]]+1);
      }
    }
  }
}

int main() {

  while(1) {
    int d;
    cin >> d >> n;
    if(d==0 && n ==0) break;

    maxr = 0;
    for(int i=0;i<n;i++) {
      cin >> a[i] >> e[i] >> r[i];
      maxr = max(maxr,r[i]);
    }
    
    for(int i=0;i<=d;i++) 
      for(int j=0;j<=20000;j++)
	dp[i][j] = INF;
    
    saiki(d,0,0);

    if(dp[d][0] == INF) cout << "NA" <<endl;
    else cout << dp[d][0] <<endl;
    // cout << cnt <<endl;
  }

  return 0;
}

Measured memory_bytes: 9068
#include<bits/stdc++.h>
#define Abra_Ka_Dabra ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    Abra_Ka_Dabra
    string n;
    cin>>n;
    for(int i=0; i<n.size(); i++){
        if(n[i]=='7'){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3536
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, A, B, C = MAP()
l = [INT() for _ in range(N)]

def dfs(cur, a, b, c):
    if cur == N: # 最初の1つを入れた分の10*3を引く
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur+1, a, b, c)  # 使わない
    ret1 = dfs(cur+1, a+l[cur], b, c) + 10  # Aに加える
    ret2 = dfs(cur+1, a, b+l[cur], c) + 10  # Bに加える
    ret3 = dfs(cur+1, a, b, c+l[cur]) + 10  # Cに加える
    return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3920
#include <bits/stdc++.h>
    #define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    #define ll long long
    //pair<int, int> *p=new pair<int, int>[n];
    //std::vector<pair<int,int>> vp;
    //v.push_back(make_pair(x,y))
    //pair<int, int> p[1001];
    //string *s=new string [n];
     
    //int freq[e];
    //freq[a[i]-'a']++; freq[a[i]]++;
    using namespace std;  
        ll t,n,c1,c2,c3,sum,m,mn,k;
        set<int>v,v2,v3;

    int main(void)
    {
        SpeeD;  
        cin>>n;
        ll temp=n;
while (n--){
    int a;
    cin>>a;
    v.insert(a);
    
}
//cout<<v.size();
if (v.size()==temp)cout<<"YES";
else cout<<"NO";
}


Measured memory_bytes: 9600
object Main {
  def main(args: Array[String]): Unit = {
    val tiles = io.StdIn.readLine().split("").filter(_ != "").map{_.toInt}

    var tiles01_change_num = 0
    var tiles10_change_num = 0

    (0 until tiles.length).foreach { i =>
      if(tiles(i) != i%2)            tiles01_change_num += 1
      else if(tiles(i) != (i + 1)%2) tiles10_change_num += 1
    }

    if(tiles01_change_num < tiles10_change_num) {
      println(tiles01_change_num)
    }
    else {
      println(tiles10_change_num)
    }
  }
}

Measured memory_bytes: 42136
#include <stdio.h>

int main (void) {
	char str[16][16];
	int i , j;
	
	for ( i = 0; i < 8; i++ ) {
		scanf("%s",str[i]);
	}
	
	printf("90\n");
	for ( j = 0; j < 8; j++ ) {
		for ( i = 7; i >= 0; i-- ) {
			printf("%c",str[i][j]);
		}
		printf("\n");
	}
	
	printf("180\n");
	for ( i = 7; i >= 0; i-- ) {
		for ( j = 7; j >= 0; j-- ) {
			printf("%c",str[i][j]);
		}
		printf("\n");
	}
	
	printf("270\n");
	for ( j = 7; j >= 0; j-- ) {
		for ( i = 0; i < 8; i++ ) {
			printf("%c",str[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
#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() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a*c <= b){ 
        cout << c << endl;
    }
    else{
        cout << b/a << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

const long long kMaxV = 5010;
const long long kInf = 0x3F3F3F3F;

using namespace std;

struct Edge {
  long long from;
  long long to;
  long long dist;

  Edge(long long from, long long to, long long dist): from(from), to(to), dist(dist) {}
};

struct BellmanFord {
  long long v, e;
  vector<Edge> edges;
  vector<long long> g[kMaxV];
  long long dist[kMaxV];
  long long parent[kMaxV];
  bool has_negative_cycle;

  BellmanFord(long long v): v(v) {}

  void AddEdge(long long from, long long to, long long dist) {
    edges.emplace_back(from, to, dist);
    g[from].push_back(edges.size() - 1);
  }

  void Solve(long long source) {
    queue<long long> q;
    for (long long i = 0; i < v; ++i) {
      dist[i] = kInf;
      q.push(i);
    }
    dist[source] = 0;
    for (long long i = 0; i < v; ++i) {
      for (auto e: edges) {
        if (dist[e.to] > dist[e.from] + e.dist && dist[e.from] != kInf) {
          dist[e.to] = dist[e.from] + e.dist;
          parent[e.to] = e.from;
        }
      }
    }
    // has_negative_cycle = false;
    // for (auto e: edges) {
    //   if (dist[e.to] > dist[e.from] + e.dist && dist[e.from] != kInf) {
    //     has_negative_cycle = true;
    //   }
    // }
  }
};

int main() {
  long long n, m, p;
  cin >> n >> m >> p;
  auto solver = new BellmanFord(kMaxV);
  for (long long i = 0; i < m; ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    solver->AddEdge(a, b, - c + p);
  }
  solver->Solve(1);

  auto dist_origin = solver->dist[n];
  for (long long i = 0; i < kMaxV; ++i) {
    for (auto e: solver->edges) {
      if (solver->dist[e.to] > solver->dist[e.from] + e.dist && solver->dist[e.from] != kInf) {
        solver->dist[e.to] = solver->dist[e.from] + e.dist;
        solver->parent[e.to] = e.from;
      }
    }
  }
  if (-solver->dist[n] > -dist_origin) {
    cout << -1 << "\n";
  } else if (dist_origin < 0) {
    cout << -dist_origin << "\n";
  } else {
    cout << 0 << "\n";
  }
}


Measured memory_bytes: 768
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

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

int n;
char s[55];
int a[33];
int c[33];

int main(){
	scanf("%d" , &n);
	fill(a,a+33,111);
	repp(i,0,n){
		scanf(" %s" , s);
		fill(c,c+33,0);
		for(int j = 0 ; s[j] != 0 ; ++j){
			++c[s[j]-'a'];
		}
		repp(j,0,33){
			a[j] = min(a[j] , c[j]);
		}
	}
	repp(i,0,33){
		repp(j,0,a[i]){
			printf("%c" , 'a' + i);
		}
	}
	printf("\n");
	return 0;
}


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

int main(void){
    int n;
    cin >> n;
    
    char input;
    int i;
    for(i = 1; i <= n; i++){
        cin >> input;
        if(input == 'Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    
    cout << "Three" << endl;
    
    return 0;
}


Measured memory_bytes: 256
def count_2chr(li):
    ans = [0 for _ in range(10)]
    s = li.copy()
    while len(s) >= 2:
        i = s.pop(0)
        if ans[i] == 0:
            ans[i] = len(set(s))
    
    return sum(ans)

n = int(input())
s = list(map(int, list(input())))

count = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

while len(s) >= 3:
    i = s.pop(0)
    if count[i] == 0:
        count[i] = count_2chr(s)

print(sum(count))


Measured memory_bytes: 3700
from fractions import gcd


N, M = map(int, input().split(" "))
S = input()
T = input()
a, b = M // gcd(N, M), N // gcd(N, M)
GCD = gcd(N, M)

flag = True
for n in range(0, GCD):
    flag &= S[b * n] == T[a * n]

if flag:
    print(N * M // GCD)
else:
    print(-1)

Measured memory_bytes: 5436
# 20200612_yorukatsu_c.py
N, K = map(int,input().split())
M = [int(input()) for i in range(N)]
M.sort()
lis = [0]*(N-K+1)
for i in range(N-K+1):
    lis[i] = abs(M[i]-M[i+K-1])
print(min(lis))


Measured memory_bytes: 11036
# check
def is_prime(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    else:
        for p in range(2, n):
            if n % p == 0:
                return False
        else:
            return True


# input
X = int(input())

while is_prime(X) is False:
    X += 1

print(X)

Measured memory_bytes: 2940
n, a, b = map(int, input().split())
mod = 10**9+7

def cmb2(n, r, mod):
    res = 1
    temp = 1
    for k in range(1, r+1):
        res *= (n-k+1)
        temp *= k
        res %= mod
        temp %= mod
    res *= pow(temp,(mod-2),mod)
    res %= mod
    return res

def power(a, n, mod):
    bi=str(format(n,"b")) #2進数
    res=1
    for i in range(len(bi)):
        res=(res*res) %mod
        if bi[i]=="1":
            res=(res*a) %mod
    return res

ans = power(2, n, mod) - cmb2(n, a, mod) - cmb2(n, b, mod) -1
ans %= mod
print(ans)


Measured memory_bytes: 63212
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl;
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main()
{
    ll k,x;
    cin >> k >> x;
    if(k * 500 >= x)cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>

using namespace std;
using int64 = long long;

int main() {
    string s;
    cin >> s;
    int n = s.size() + 1;
    vector<int64> v(n,0);
    int64 now = 0;
    for (int i=1; i<n; i++) {
        if (s[i-1] == '>') continue;
        now = 0;
        while(i<n && s[i-1]=='<') v[i++] = ++now;
    }

    // for (auto c : s)cerr<<" "<<c;cerr<<endl;
    // for (auto vi : v)cerr<<vi<<" ";cerr<<endl;
    reverse(s.begin(), s.end());
    reverse(v.begin(), v.end());
    for (int i=1; i<n; i++) {
        if (s[i-1] == '<') continue;
        now = 0;
        while(i<n && s[i-1]=='>') {
            v[i] = max(v[i], ++now);
            i++;
        }
    }

    // reverse(s.begin(), s.end());
    // reverse(v.begin(), v.end());

    // for (auto c : s)cerr<<" "<<c;cerr<<endl;
    // for (auto vi : v)cerr<<vi<<" ";cerr<<endl;

    int64 ans = accumulate(v.begin(), v.end(), 0LL);
    cout << ans << endl;
}


Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    map<int,int> A;
    rep(i,N) {
        int n; cin >> n;
        A[n]++;
    }
    bool success = false;
    if (A.size() == 1 && A[0] == N) success = true;
    else if (N % 3 == 0) {
        if (A.size() == 2 && A[0] == N / 3) success = true;
        else if (A.size() == 3) {
            vector<int> keys;
            for (auto [k,v] : A) {
                keys.push_back(k);
                if (v != N/3) goto END;
            }
            if (keys[0] == (keys[1] ^ keys[2]) ||
                keys[1] == (keys[2] ^ keys[0]) ||
                keys[2] == (keys[0] ^ keys[1]))
                success = true;
        }
    }
END:
    if (success) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 7212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int n;cin>>n;
    vector<ll> v(n),sum(n);
    for(int i=0;i<n;i++)cin>>v[i];
    sort(v.begin(),v.end());
    if(n&1){cout<<0;return 0;}
    cout<<v[n/2]-v[n/2-1];
    
    
}

Measured memory_bytes: 1792
#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)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const int MAX = 200005;
const int mod = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
 
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

vector<pair<ll, ll>> prime_factorize(ll n){
    vector<pair<ll, ll>> res;
    for(ll i=2; i*i<=n; i++){
        if(n%i != 0) continue;
        int num = 0;
        while(n%i == 0){
            num++;
            n/=i;
        }
        res.push_back(make_pair(i, num));
    }
    if(n > 1) res.push_back(make_pair(n, 1));
    return res;
}

int main(){
    int N, M; cin >> N >> M;

    ll ans = 1;
    vector<pair<ll, ll>> v = prime_factorize(M);
    COMinit();

    for(auto e:v){
        ans *= COM(e.second+N-1, N-1);
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4992
n = int(input())
userIn = input().split()
a = [0 for i in range(2*n+1)]
deleteCounter = 0

for j in userIn:
    if int(j) > n:
        deleteCounter += 1
    else:
        a[int(j)] += 1

for j in range(n+1):
    if a[j] != 0:
        if a[j] >= j:
            deleteCounter += a[j] - j
        else:
            deleteCounter += a[j]

print(deleteCounter)


Measured memory_bytes: 12408
from math import log2


def action(n):
    count = 0
    while n % 2 == 0:
        n //= 2
        count += 1
    else:
        return count

def main():
    _n = int(input())
    nums = [int(x) for x in input().split()]

    print(sum([int(action(e)) for e in nums if e % 2 == 0]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 4148
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000007
# define INF 2000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
int main() {
	ll ans = 0, counter = 0, maxi = -1, mini = INF, pass = 0;
	//new
	ll n, k;
	cin >> n >> k;
	if (n == 1 && k == 1) {
		cout << 1000000<< endl;
		return 0;
	}
	else {
		if (n <= 3)ans += (4 - n) * 100000;
		if (k <= 3)ans += (4 - k) * 100000;
		cout << ans << endl;
	}

}

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    ll a,b;
    cin >> a >> b;
    if(a%2==b%2){
        cout << (a+b)/2 - a << endl;
    }else {
        ll x=INF+8;
        x = min(x,(a+(n-b+1)+n)/2-(a+(n-b+1))+(n-b+1));
        x = min(x,(1+b-a)/2-1+a);
        cout << x << endl;
    }
    return 0;
}

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

using namespace std;

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

  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  vector<long long> y(n + 1);
  int j = 0;
  for (int i = 0; i < n; i++) {
    while (j < n && b[i] >= c[j]) {
      j++;
    }
    y[i] = n - j;
  }
  for (int i = n - 1; i >= 0; i--) {
    y[i] += y[i + 1];
  }

  j = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    while (j < n && a[i] >= b[j]) {
      j++;
    }
    ans += y[j];
  }

  cout << ans << endl;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    /*
    int n;
    cin >> n;
    vector<int> count(2*n),perm;
    rep(i,1,n*2) perm.push_back(i);
    do{
        vector<int> prev=perm,next(2*n-1);
        rep(i,1,n){
            rep(j,i,2*n-i-1){
                vector<int> temp;
                temp.push_back(prev[j-1]);
                temp.push_back(prev[j]);
                temp.push_back(prev[j+1]);
                sort(temp.begin(),temp.end());
                next[j]=temp[1];
            }
            swap(prev,next);
        }
        ++count[prev[n-1]];
        cout << prev[n-1] << endl;
        cout << perm << endl;
    }while(next_permutation(perm.begin(),perm.end()));
    rep(i,1,2*n){
        cout << i << ": " << count[i] << endl;
    }
    */

    int n,x;
    cin >> n >> x;
    int mini=1,maxi=2*n-1;
    if(x==mini or x==maxi){
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
    if(n==2){
        cout << 1 << endl << 2 << endl << 3 << endl;
        return;
    }
    vector<int> ans(2*n-1);
    vector<bool> used(2*n);
    ans[n-1]=x;
    used[x]=true;
    if(x-2==0){
        ans[n-2]=x+1;
        ans[n]=x-1;
        ans[n+1]=x+2;
        used[x+1]=used[x-1]=used[x+2]=true;
    }else{
        ans[n-2]=x-1;
        ans[n]=x+1;
        ans[n+1]=x-2;
        used[x-1]=used[x+1]=used[x-2]=true;
    }
    int k=1;
    rep(i,0,2*n-1){
        if(ans[i]!=0) continue;
        while(used[k]){
            ++k;
        }
        ans[i]=k;
        used[k]=true;
    }
    rep(i,0,2*n-1){
        cout << ans[i] << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cerr << #x " = " << (x) << endl;
#define P(x) cerr << #x << endl;    
typedef long long ll;
//#define int long long
const int mod = 1000000007;
 
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    
    int a, b;
    cin >> a >> b;
    int count = 0;
    while(b > a)
    {
        b -= (a - 1);
        ++ count;
    }
    
    ++ count;
    if(b == 1) count = 0;
    cout << count << endl;
    
    return 0;
}
 
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

signed main()
{
  ios::sync_with_stdio(false);
  ll sum = 0;
  int n;
  cin >> n;
  REP(i, n){
    ll m;
    cin >> m;
    sum += m;
  }
  print(sum / n);

  return (0);
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ll N;
    cin >> N;
    set<ll> A;
    for(ll i=1;i<=N/i;i++)if(N%i==0)A.insert(max(to_string(i).size(),to_string(N/i).size()));
    cout << *A.begin() << endl;
}


Measured memory_bytes: 3652
a, b, c, x, y = map(int, input().split())
if c > (a + b) / 2:
    print(a * x + b * y)
else:
    price = c * min(x, y) * 2
    if x > y:
        price += (x - y) * min(a, 2 * c)
    else:
        price += (y - x) * min(b, 2 * c)
    print(price)


Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
using psi = pair<string, int>;

ld coin(ld i, ld K) {
    ld count = 0;
    while (true) {
        if (K <= i) {
            break;
        }
        count++;
        i *= 2;
    }
    ld ans = 1;
    for (ld d = 0; d < count; d++) {
        ans /= 2;
    }
    return ans;
}

int main() {
    ld N, K;
    cin >> N >> K;
    ld ans = 0;
    for (ld i = 1; i < N + 1; i++) {
        ans += coin(i, K) / N;
    }
    cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 3716
using System;

namespace _20190324
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            int count = 0;
            int tmpCount = 0;
            for (int i = 0; i < str.Length; i++)
            {
                if (count > str.Length - i) { break; }
                for (int j = 0; j < str.Length - i; j++)
                {
                    if (str[i + j] == 'A' || str[i + j] == 'C' || str[i + j] == 'G' || str[i + j] == 'T')
                    {
                        tmpCount++;
                    }
                    else
                    {
                        break;
                    }                     
                }
                count = count > tmpCount ? count : tmpCount;
                tmpCount = 0;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define SIZE(a) (int)((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}


signed main()
{
  int N, Z, W;
  cin >> N >> Z >> W;
  vector<int> a(N);
  rep(i, 0, N) {
    cin >> a[i];
  }

  cout << max(abs(a[max((int)0, N-2)] - a[N-1]), abs(a[N-1] - W)) << endl;

  return 0;
}


Measured memory_bytes: 256
function checkRegularFlights(i, ns, N, cnt) {
    if (cnt <= 2) {
        var dests = (i in ns) ? ns[i] : [];
        for (var i = 0; i < dests.length; i++) {
            var dest = dests[i];
            if (dest == N)
                return true;
            if (checkRegularFlights(dest, ns, N, cnt + 1))
                return true;
        }
    }
    return false;
}
function Main(input) {
    var lines = input.split("\n");
    var ns = [];
    var N = -1;
    for (var i = 0; i < lines.length; i++) {
        var line = lines[i];
        var mc = lines[i].match(/(\d+) (\d+)/);
        if (mc) {
            var n = parseInt(mc[1]);
            var m = parseInt(mc[2]);
            if (!(n in ns))
                ns[n] = [];
            ns[n].push(m);
            if (n > N)
                N = n;
        }
    }
    var result = checkRegularFlights(1, ns, N, 1)
        ? "POSSIBLE"
        : "IMPOSSIBLE";
    console.log(result);
}

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 73664
ans = 0
N = int(input())
A = list(map(int, input().split()))
ans = []
M = -float('inf')
m = float('inf')
for i in range(N):
  if A[i]>M:
    M_ind = i+1
    M = A[i]
  if A[i]<m:
    m_ind = i+1
    m = A[i]
if M*m<0:
  for i in range(N):
    if M>=abs(m):
      if i+1!= M_ind:
        ans.append([M_ind,i+1])
        A[i] += M
    else:
      if i+1!= m_ind:
        ans.append([m_ind,i+1])
        A[i] += m
if max(A)>0:
  for i in range(1,N):
    ans.append([i,i+1])
else:
  for i in range(N,1,-1):
    ans.append([i,i-1])
print(len(ans))
for a in ans:
  print(*a)

Measured memory_bytes: 62564
#include <iostream>
#include <vector>

using namespace std;

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

int main()
{
	int N;
	vector<int> A;

	//
	cin >> N;
	rep(i, N)
	{
		int x;
		cin >> x;
		A.push_back(x);
	}
	//

	//
	int Min = 0x7fffffff;
	for(int sum = -100; sum <= 100; ++sum)
	{
		int cost = 0;
		rep(i, N)
		{
			cost += (A[i] - sum)*(A[i] - sum);
		}

		if (cost < Min) Min = cost;
	}
	//

	cout << Min << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
 
int main(){
	int N, K; cin >> N >> K;
	long double ans = 0;
	long double bunsu = 0, bunsi = 0;
	int p1 = 0;
 
	for(int i = 1; i <= N; ++i){
		int p = 1, tmp = i*2;
		for(int j = 0; j < 20; ++j){
			if(tmp >= K) break;
			tmp *= 2;
			p++;
		}
 
		if(i > K-1) p = 0;
		if(i ==1) p1 = p;
		
		// cout << p << endl;
 
		bunsu += (long double)pow(10, 13) / pow(2, p);
		bunsi += pow(2, p1-p);
	}
 
	// cout << bunsi << endl;
 
	bunsi /= (long double)pow(2, p1);
	bunsi /= (long double)N;
 
	// bunsu /= (long double)N;
	// ans = (long double)bunsu / pow(10, 13);
 
	cout << fixed << setprecision(10) << bunsi << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%d%c", arr[i], i == n ? '\n' : ' ');}}
void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%lld%c", arr[i], i == n ? '\n' : ' ');}}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
#define DEBUG_Switch 0
int n;
int cnt[10];
int main()
{
#if DEBUG_Switch
    freopen("C:\\code\\input.txt", "r", stdin);
#endif
    //freopen("C:\\code\\output.txt","w",stdout);
    cin >> n;
    string str;
    while (n--)
    {
        cin >> str;
        if (str[0] == 'A')
        {
            cnt[0]++;
        } else if (str[0] == 'W')
        {
            cnt[1]++;
        } else if (str[0] == 'T')
        {
            cnt[2]++;
        } else
        {
            cnt[3]++;
        }
    }
    cout << "AC x " << cnt[0] << "\nWA x " << cnt[1] << "\nTLE x " << cnt[2] << "\nRE x " << cnt[3] << endl;
    return 0;
}




Measured memory_bytes: 3632
import java.util.Scanner;

 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n= in.nextInt();
        int m=in.nextInt();
        int min=1, max=n;
        boolean flag=false;
        for(int i=0;i<m;i++){
            int lb=in.nextInt();
            int ub=in.nextInt();

            if(lb>=min)
                min=lb;
            if(ub<=max)
                max=ub;

            if(ub<min || lb >max){
                flag=true;
            }

        }
        if(flag)
            System.out.println(0);
        else {
            int ans = max - min + 1;
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 63000
#include<stdio.h>

int main(){

        int input;
        scanf("%d",&input);

        int i;

        int num = input / 500;
        int amari = input % 500;

        int num2 = amari / 5;

        num = num *1000;
        num2 = num2 *5;

        int sum = num + num2;

        printf("%d",sum);

        return 0;

}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemD
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var N = read[0];
            var M = read[1];
            var As = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            As.Sort();
            var dictKeyCValueB = new List<KeyValuePair<int, int>>();
            for (int i = 0; i < M; i++)
            {
                read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                dictKeyCValueB.Add(new KeyValuePair<int, int>(read[1], read[0]));
            }
            var decendingDict = dictKeyCValueB.OrderByDescending(kv => kv.Key).ToArray();
            var Ds = new List<int>();
            var L = decendingDict.Count();
            for (int i = 0; i < decendingDict.Count(); i++)
            {
                Ds.AddRange(Enumerable.Repeat(decendingDict[i].Key, 
                    (int)decendingDict[i].Value));
                if (Ds.Count() >= N)
                    break;
            }
            long ret = 0;
            for (int i = 0; i < N; i++)
            {
                if (i < Ds.Count() && As[i] < Ds[i])
                    ret += (long)Ds[i];
                else
                    ret += (long)As[i];
            }
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 33968
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
 
using namespace std;
 
typedef unsigned long long ull;
 
 
int main(void)
{
    constexpr int N_MAX = 1000;
    constexpr int K_MAX = 1000;
 
    // Stirling numbers of the second kind
    ull s[N_MAX + 1][K_MAX + 1];
    REP(i, N_MAX + 1) s[i][i] = 1;
    FOR(n, 1, N_MAX + 1) s[n][0] = 0;
    FOR(n, 1, N_MAX + 1) FOR(k, 1, n) s[n][k] = ((k * s[n - 1][k]) % MOD + s[n - 1][k - 1]) % MOD;
 
    int n, k;
    cin >> n >> k;
    if (n >= k) {
        cout << s[n][k] << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 9996
#include<bits/stdc++.h>
using namespace std;
void S(int N,vector<int> V){
  int sum=0;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(V.at(i)>a)
      sum+=V.at(i)-a;
  }
  cout<<sum<<endl;
}
int main(){
  int N,sum=0;
  cin>>N;
  vector<int> V(N);
  for(int i=0;i<N;i++)
    cin>>V.at(i);
  S(N,V);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

int main(){
    int n,k;
    cin>>n>>k;
    vector<ll> H(n);
    rep(i,n) cin>>H[i];

    sort(H.begin(), H.end());
    unsigned long long sum=0;
    rep(i,n-k){
        sum+=H[i];
    }
    cout<<sum<<endl;
    
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		long x = Long.parseLong(sc.next());
		for (int i = 0; i < 10; i++) {
			x = r * x - d;
			System.out.println(x);
		}

	}

}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define MAXN 200005
#define INT_SIZE 32
#define debug cout<<"we are debugging"<<endl;
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main(){
	int n;
	cin>>n;
	ll a[n];
	map<ll,ll> mp;
	ll s=0;
	for(int i=0;i<n;i++)
     {
          cin>>a[i];
          s+=a[i];
          mp[a[i]]++;
     }
     ll x,y;
     int q;
     cin>>q;
     while(q--)
     {
          cin>>x>>y;
          int p=mp[x];
          s-=p*x;
          s+=p*y;
          mp.erase(x);
          mp[y]+=p;
          cout<<s<<'\n';
     }
}


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

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// ========== debug ==========
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// ===========================

int main() {
  string S, T;
  cin >> S >> T;

  int ans = 0;
  rep(i, S.size()) {
    if (S[i] != T[i])
      ++ans;
  }
  cout << ans << endl;

  return 0;
}


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

int main(void)
{
  int64_t a, b, k;
  cin >> a >> b >> k;
  if(a >= k)
  {
    a = a - k;
    cout<< a << " " << b << endl;
  }else if(a + b >= k)
  {
    b = b - (k - a);
    a = 0;
    cout<< a << " " << b << endl;
  }
  else
  {
    cout<< 0 << " " << 0 << endl;
  }
}

Measured memory_bytes: 256
class Tree:
    def __init__(self, num, count, zeroflag, accum):
        self.num = num
        self.count = count
        self.zeroflag = zeroflag
        self.accum = accum.copy()
        self.accum.append(self.num)

        if self.num != 0:
            self.zeroflag = False

        if self.zeroflag == True:
            self.list = list(range(0,10))
        elif self.zeroflag == True and self.count == 10:
            self.list = list(range(0,3))
        else:
            self.list = list(filter(lambda x: 0<=x and x<=9, [num-1,num,num+1]))

        if(count > 0):
            self.nodes = [Tree(elem, count-1,self.zeroflag,self.accum.copy()) for elem in self.list]

    def __repr__(self):
        if(self.count == 0):
            return "Tree: {}".format(self.num)
        else:
            return "Tree: {}<".format(self.num) + str(list(self.nodes))

    def print_accum(self, a):
        if(self.count == 0):
            #print(self.accum)
            a.append(self.accum)
        else:
            for elem in self.nodes:
                elem.print_accum(a)



if __name__ == '__main__':
    #print(Tree(0,2,True,[]))
    K = int(input())
    a = []
    t = Tree(0,9,True,[])
    t.print_accum(a)
    t = Tree(1,9,True,[])
    t.print_accum(a)
    t = Tree(2,9,True,[])
    t.print_accum(a)
    t = Tree(3,9,True,[])
    t.print_accum(a)
    lst = a[K]
    flag = True;
    for i in lst:
        if i != 0:
            flag = False                
        if i == 0 and flag == True:
            print("", end="")
        else:
            print(i, end="")

    print("")


Measured memory_bytes: 85316