akhauriyash/Code-Regression huggingface dataset:
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(void) {
  int D;
  cin >> D;
  vector<int> c(26);  // しばらく開催されないときの満足度の下がりやすさ
  rep(i, 26) {
    cin >> c[i];
  }
  vector<vector<int>> s(D, vector<int>(26)); // d日目にタイプjを開催すると得られる満足度
  rep(i, D) {
    rep(j, 26) {
      cin >> s[i][j];
    }
  }

  vector<int> t(D);
  rep(i, D) {
    cin >> t[i];
  }

  int v = 0;
  vector<int> last(26, 0);
  rep(i, D) {
    int type = t[i] - 1;
    int day = i + 1;
    // コンテスト開催で満足度アップ
    v += s[i][type];
    last[type] = day;
    // 一日の終わりに満足度低下
    rep(j, 26) {
      v -= c[j] * (day - last[j]);
    }

    cout << v << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3640
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val xs = (0 until n).map {
        val (x, u) = readLine()!!.split(' ')
        if (u == "JPY") {
            return@map x.toDouble()
        } else {
            return@map x.toDouble() * 380000
        }
    }
    println(xs.sum())
}

Measured memory_bytes: 38124
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main(){
	int N, L;
	cin >> N >> L;
	int sum = 0;
	int ans = 1000000000000;
	for (int i = L; i <= L + N - 1; i++) {
		if (abs(i) < abs(ans)) {
			ans = i;
		}
		sum += i;
	}
	print(sum-ans);



	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

#define MAX 2000

using namespace std;


int M,N,now,mx=0;
char S[MAX+1],T[MAX+1];
int s[MAX+1],t[MAX+1];
int dp[MAX+1][MAX+1][2];

int main(){
	scanf("%d %d",&M,&N);
	scanf("%s",S);
	scanf("%s",T);
	s[M]=-1;
	t[N]=-1;
	//cin>>st1;
	for(int i=0;i<M;i++){
		s[i]=(S[i]=='I' ? 1:0);
	}
	//cin>>st2;
	for(int i=0;i<N;i++){
		t[i]=(T[i]=='I' ? 1:0);
	}
	for(int i=M;i>=0;i--){
		for(int j=N;j>=0;j--){
			if(s[i]==0&&t[j]==0)
			now=max(dp[i+1][j][1]+1,dp[i][j+1][1]+1);
			else if(s[i]==0)
			now=dp[i+1][j][1]+1;
			else if(t[j]==0)
			now=dp[i][j+1][1]+1;
			else
			now=0;
			dp[i][j][0]=now;
			//
			if(s[i]==1&&t[j]==1)
			now=max(dp[i+1][j][0]+1,dp[i][j+1][0]+1);
			else if(s[i]==1)
			now=dp[i+1][j][0]+1;
			else if(t[j]==1)
			now=dp[i][j+1][0]+1;
			else
			now=0;
			dp[i][j][1]=now;
		}
	}
	for(int i=0;i<M;i++){
		for(int j=0;j<N;j++){
			if(dp[i][j][1]%2!=0)
			mx=max(dp[i][j][1],mx);
			else
			mx=max(dp[i][j][1]-1,mx);
		}
	}
	printf("%d\n",mx);
}

Measured memory_bytes: 34524
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int n,k;
int a[200001];
set<int> st;
vector<int> num(200001,0);

int main(){
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        st.insert(a[i]);
        num[a[i]]++;
    }

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

    int len = st.size();

    if(len < k){
        cout << 0 << endl;
        return 0;
    }
    else{
        int ans = 0;
        int tmp = len - k;

        for(int i = 0; i < 200001; i++){
            if(tmp == 0) break;
            if(num[i] > 0){
                ans += num[i];
                tmp--;
            }
        }

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


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

using ll = long long;
using namespace std;
using P = pair<int,int>;
ll mod=1e9+7;

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; } //最大公倍数

int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if (abs(x-a) - abs(x-b) > 0){
    cout << 'B' << endl;
  }else{
    cout << 'A' << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int main(){
	int N;

	scanf("%d",&N);
	bool table[10000];
	for(int i = 0; i <= 9999; i++)table[i] = false;

	int num[N];

	for(int i = 0; i < N; i++)scanf("%d",&num[i]);

	for(int i = 0; i < N; i++){
		table[num[i]] = true;
	}

	if(N > 1){
		for(int i = 0; i < N-1; i++){
			table[10*num[i]+num[i+1]] = true;
		}
	}

	if(N > 2){
		for(int i = 0; i < N-2; i++){
			table[100*num[i]+10*num[i+1]+num[i+2]] = true;
		}
	}

	if(N > 3){
		for(int i = 0; i < N-3; i++){
			table[1000*num[i]+100*num[i+1]+10*num[i+2]+num[i+3]] = true;
		}
	}

	for(int i = 0; i <= 9999; i++){
		if(table[i] == false){
			printf("%d\n",i);
			break;
		}
	}
}

Measured memory_bytes: 2776
import java.util.Scanner;
public class Main{
    public void solve(){
    Scanner sc = new Scanner(System.in);
    int t,n;
        for(int i=0;i<=3;i++){
        t = sc.nextInt();
        n = sc.nextInt();
        if(t==1){
            int kei = 6000*n;
            System.out.println(kei);
        }else{
            if(t==2){
                int kei = 4000*n;
                System.out.println(kei);
                }else{
                    if(t==3){
                        int kei = 3000*n;
                        System.out.println(kei);
                        }else{
                        int kei = 2000*n;
                        System.out.println(kei);
                    }
            }
        }
    }
    }
        public static void main(String[]args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17352
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  bool flag = true;
  int n;
  cin >> n;
	string s[n];
  r(i,n) cin >> s[i];
  r(i,n-1) {
    if(s[i][s[i].length()-1]!=s[i+1][0])  flag = false; 
  }
  r(i,n-1){
    for(int j = i+1; j<n;j++){
      if(s[i]==s[j]) flag = false;
    }
  }
  if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N, K;
    cin >> N >> K;
    vector<int> v(N);
    for(int i = 0; i < N; ++i) cin >> v[i];
    sort(all(v));

    int s = 0;
    for(int i = 0; i < K; ++i) {
        s += v[i];

    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
const ll MOD = 998244353;
const ll INF = 10000000000000000;

#define fr first
#define sc second

int main(){
	static ll n,m;
	static ll l[100010],r[100010],c[100010];
	scanf("%lld%lld",&n,&m);
	for(int i = 1 ; i <= m ; i ++){
		scanf("%lld%lld%lld",&l[i],&r[i],&c[i]);
	}
	
	static vector<P> G[100010];
	for(int i = 1 ; i+1 <= n ; i ++){
		G[i+1].push_back(P(i,0));
	}
	for(int i = 1 ; i <= m ; i ++){
		G[l[i]].push_back(P(r[i],c[i]));
	}
	
	/*for(int i = 1 ; i <= n ; i ++){
		puts("=====");
		cout << i << ":" << endl;
		for(int j = 0 ; j < G[i].size() ; j ++){
			cout << G[i][j].fr << " " << G[i][j].sc << endl;
		}
	}*/
	
	static ll dist[100010];
	static bool used[100010];
	static priority_queue<P,vector<P>,greater<P>> que;
	for(int i = 0 ; i < 100010 ; i ++){
		dist[i] = INF;
		used[i] = false;
	}
	que.push(P(0,1));
	dist[1] = 0;
	while(!que.empty()){
		P p = que.top(); que.pop();
		//cout << p.fr << " " << p.sc << endl;
		if(used[p.sc])continue;
		used[p.sc] = true;
		for(int i = 0 ; i < G[p.sc].size() ; i ++){
			P ed = G[p.sc][i];
			if(dist[ed.fr] > dist[p.sc]+ed.sc){
				dist[ed.fr] = dist[p.sc]+ed.sc;
				que.push(P(dist[ed.fr],ed.fr));
			}
		}
	}
	if(dist[n] == INF)cout << -1 << endl;
	else cout << dist[n] << endl;
}


Measured memory_bytes: 12664
#include<cstdio>
int main(){
	int n,i,a,maxn=0,ans=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		ans+=a;
		if(a>maxn)maxn=a;
	}
	printf("%d\n",ans-maxn/2);
	return 0;
}

Measured memory_bytes: 128
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
          
            //????????°????????????
            var read = Console.ReadLine();
            var temp_string = read.Split(' ');
            int n = int.Parse(temp_string[0]), m = int.Parse(temp_string[1]), l = int.Parse(temp_string[2]);
            

            //?????¨?????°??????
            var A_list = new int[n, m];
            var B_list = new int[m, l];
            var C_list = new long[n,l];

            //A???????????????
            for(int i=0;i<n;i++)
            {
                read = Console.ReadLine();
                temp_string = read.Split(' ');

                for (int j = 0; j < m;j++ )
                {
                    A_list[i, j] = int.Parse(temp_string[j]);
                }
                    
            }

            //B???????????????
            for (int i = 0; i < m; i++)
            {
                read = Console.ReadLine();
                temp_string = read.Split(' ');

                for (int j = 0; j < l; j++)
                {
                    B_list[i, j] = int.Parse(temp_string[j]);
                }

            }

            //?¨????
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    for(int k=0;k<l;k++)
                    {
                        C_list[i,k] += A_list[i, j] * B_list[j, k];
                    }
                }
            }


            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    Console.Write(C_list[i, j]);
                    if(j<l-1)
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }

           
        }
    }
}

Measured memory_bytes: 9552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn for(int i=0;i<n;i++)
int main()
{
   string s;
   cin>>s;
   int n=s.size();
   int red=0; int blue=0;
   forn 
   {
       if(s[i]=='1') blue++;
       else red++;
   }
   cout<<n-abs(red-blue);
   return 0;
}


Measured memory_bytes: 512
def win_score(hand):
  global R,S,P,my
  if hand=="r":
    my+="P"
    return P
  elif hand=="s":
    my+="R"
    return R
  elif hand=="p":
    my+="S"
    return S
  return 0

nk=input().split(" ")
N,K=int(nk[0]),int(nk[1])
nk=input().split(" ")
R,S,P=int(nk[0]),int(nk[1]),int(nk[2])
T=input()
my=""

score=0
for i in range(N):
  if i<K:
    score+=win_score(T[i])
  elif T[i]!=T[i-K] or my[i-K]=="-":
    score+=win_score(T[i])
  else:
    my+="-"

#print(my)
print(score)


Measured memory_bytes: 3548
#include<iostream>
  using namespace std;
  int main()
  {
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int ans = 0;
    for(int i = 0; i <= a; i++) {
      for(int j = 0; j <= b; j++) {
        for(int k = 0; k <= c; k++) {
          if (i * 500 + j * 100 + k * 50 == x) {
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
    return 0;
  }

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







int main () {
    
    long long n;
    cin >> n;
    string ans = "";

    while (n > 0) {

        int temp = n % 26;
        n /= 26;

        if (temp == 0) {

            ans += 'z';
            n--;
        }
        else
            ans += (temp + 'a' - 1);
    }

    reverse(ans.begin(), ans.end());

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int x,y,point;
    cin >> x >> y >> point;

    if(x <= point && point <= y)
    {
        cout << "Yes" << endl;
    }
    else if(x >= point && point >= y)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import math
import fractions

n = int(stdin.readline().rstrip())
b = [int(x) for x in stdin.readline().rstrip().split()]


result = 0
for i in range(len(b)):
    if i == 0:
        result += b[i]
        continue
    result += min(b[i-1], b[i])

result += b[i]

print(result)

Measured memory_bytes: 5048
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 300005
#define mod 1000000007
#define pi 3.14159265358979323846

using namespace std;




int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    ll sum = 0;
    ll a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(i&&a[i]<a[i-1]){
            sum+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<sum<<endl;


}


Measured memory_bytes: 5172
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

from operator import itemgetter
N = ii()
ABs = sorted([tuple(mi()) for _ in range(N)], key=itemgetter(1))

timesum = 0
for a, b in ABs:
  timesum += a
  if timesum>b:
    print('No')
    exit()

print('Yes')



Measured memory_bytes: 79324
import java.util.*;

public class Main {
    static int modP = 1000000007;
    static long inf = 1 << 61;
    static int[] x4 = {-1, 0, 0, 1};
    static int[] y4 = {0, -1, 1, 0};
    static int[] x8 = {-1, -1, 0, 1, 1, 1, 0, -1};
    static int[] y8 = {0, -1, -1, -1, 0, 1, 1, 1};

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long x = in.nextLong();
        long y = in.nextLong();
        long q = y/x;
        long div = 1;
        long len = 0;
        while(div <= q) {
            div *= 2;
            len++;
        }

        System.out.println(len);
    }

    static public void printArray2D(char[][] map) {
        for(int i = 0; i < map.length; i++) {
            for(int j = 0; j < map[i].length; j++) {
                System.out.format("%c\t", map[i][j]);
            }
            System.out.print("\n");
        }
    }

    static public void printArray2D(int[][] map) {
        for(int i = 0; i < map.length; i++) {
            for(int j = 0; j < map[i].length; j++) {
                System.out.format("%d\t", map[i][j]);
            }
            System.out.print("\n");
        }
    }
}

Measured memory_bytes: 23636
n,m,x,y=map(int,input().split())
xx=list(map(int,input().split()))
yy=list(map(int,input().split()))
mx=max(xx)
my=min(yy)
if mx>=my:
  print("War")
elif mx>=y or x>=my:
  print("War")
else:
  print("No War")

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define NB 100001
#define MOD 1000000007
ll DP[2][1001];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n,m;
	cin>>n>>m;
	int cur_x = 1;
	char c;
	DP[1][0] = 1;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < m; ++j) {
			cin>>c;
			if(c == '#'){DP[cur_x^1][j] = 0;}
			else {
				
				DP[cur_x^1][j] = (DP[cur_x][j] 
							+ ((j!=0)?DP[cur_x^1][j-1]:0))%MOD;
			}
		}
		cur_x^=1;
	}
	//cout<<DP[cur_x^1][i ]<<"\n";
	cout<<DP[cur_x][m-1]<<"\n";
	return 0;
}


Measured memory_bytes: 3604
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>京都
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

signed main()
{
	int A, B;
	cin >> A >> B;

	if (A == B)
	{
		cout << 0 << endl;
	}
	else if ((A + B) % 2 == 1)
	{
		cout << "IMPOSSIBLE" << endl;
	}
	else
	{
		cout << ((A + B) / 2) << endl;
	}
}











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

int main(){
  int k,t;
  cin >> k >> t;
  vector<int> a(t);
  for(int i=0;i<t;i++) cin >> a[i];
  int h = 0;
  for(int i=0;i<t;i++) h = max(h, a[i]);
  cout << max(0, h - (k - h) - 1) << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++)
			A[i] = sc.nextInt();
		int count = 0;
		for (int k = 0; k < 1000; k++) {
			boolean b = false;
			;

			for (int i = 0; i < N; i++) {
				if (A[i] % 2 != 0)
					b = true;
			}

			if (b == false) {
				for (int i = 0; i < N; i++)
					A[i] /= 2;
				count++;
			} else {
				System.out.println(count);
				return;
			}
		}

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 21332
#include<iostream>

int main(){

    int N,M;
    std::cin>>N >>M;

    int minnum,maxnum;
    std::cin >> minnum>>maxnum;

    for(int i=0;i<M-1;i++){
        int tempmin,tempmax;
        std::cin >> tempmin>>tempmax;
        if(minnum < tempmin){
            minnum = tempmin;
        }
        if(maxnum > tempmax){
            maxnum = tempmax;
        }
    }

    int result = maxnum -minnum +1;

    if(result <= 0){
        result =0;
    }
    std::cout<<result <<std::endl;    
}


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

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

	if(s.at(0) == s.at(1) && s.at(1) == s.at(2))
		cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n) cin >> a[i] >> b[i];

    ll cnt = 0;
    for(int i = n-1; 0 <= i; i--){
        a[i] += cnt;
        ll d = b[i] - (a[i] % b[i]);
        if(d == b[i]) continue;
        a[i] += d;
        cnt += d;        
    }

    cout << cnt << endl;


    return 0;
}



Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{

	String S, T;

	public static void main(String[] args) {
		Main a = new Main();
		a.read();
		a.solve();
	}

	public void read() {
		Scanner sc = new Scanner(System.in);
		S = sc.next();
		T = sc.next();
	}

	public void solve() {
		StringBuilder sb = new StringBuilder();
		sb.append(S);
		int tlen = T.length();
		int slen = S.length();
		boolean restorable = false;
		String key = "";

		outer: for(int i = slen - tlen; i >= 0; i--){
			inner: for(int j = 0; j < tlen; j++){
				if((S.charAt(i + j) != T.charAt(j)) && (S.charAt(i + j) != '?')) {
					continue outer;
				}

			}
		sb.replace(i, i + tlen, T);
		restorable = true;
		break;
		}
		if(restorable == true) {
			key = sb.toString().replaceAll("\\?", "a");
		}
		else {
			key = "UNRESTORABLE";
		}
		System.out.println(key);
	}
}


Measured memory_bytes: 23764
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var n = Read();   
           
            long ans = 0;
            long res = 1;
            for (int i = 1; i <= n; i++)
            {
                var s = i;
                var count = 0;
                while (s%2==0)
                {
                    s /= 2;
                    count++;
                }
                if (ans < count) res = i;
                ans = Math.Max(count, ans);
            }

            Console.WriteLine(res);



            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 13140
n = gets
as = gets.split.map(&:to_i)
classes = {gray: 0, brown: 0, green: 0, aqua: 0, blue: 0, yellow: 0, orange: 0, red: 0}
gorilla = 0
as.each do |a|
  if 400 > a
    classes[:gray] += 1
  elsif 800 > a
    classes[:brown] += 1
  elsif 1200 > a
    classes[:green] += 1
  elsif 1600 > a
    classes[:aqua] += 1
  elsif 2000 > a
    classes[:blue] += 1
  elsif 2400 > a
    classes[:yellow] += 1
  elsif 2800 > a
    classes[:orange] += 1
  elsif 3200 > a
    classes[:red] += 1
  else
    gorilla += 1
  end
end

count = 0
classes.each do |key, value|
  if value > 0
    count += 1
  end
end

max = count + gorilla
count = 1 if gorilla > 0 && count == 0 # ゴリラしかいない場合の最小色数は0ではなく1

puts "#{count} #{max}"


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

int main() {
  int A, B, sum = 0;
  cin >> A >> B;
  
  for (int i = A; i <= B; i++){
   string s = std::to_string(i);
   if (s[0] == s[4] && s[1] == s[3]){
     sum++;
   }
 }
  cout << sum << endl;
}

Measured memory_bytes: 256
main(n,a,b,i,ans){
  scanf("%d%d%d",&n,&a,&b);
  int p[n];
  int groupA=0,groupB=0,groupC=0;
  for(i=0;i++<n;){
    scanf("%d",&p[i]);
    if(p[i]<=a)groupA+=1;
  	else if((p[i]>a)&&(p[i]<=b))groupB+=1;
  	else groupC+=1;
  }
  ans=fmin(groupA,fmin(groupB,groupC));
  printf("%d\n",ans);
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
                Scanner s = new Scanner(System.in);
                int a = s.nextInt();
                int sum = 0;
                for(int i = 0; i < a; i++){
                    for(int j = 0; j < a; j++){
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    }
                }
                System.out.println(sum);
    }
    public static int gcd(int a, int b){
        int tmp;
        while ((tmp = a % b) != 0) {
            a = b;
            b = tmp;
        }
        return b;
    }
}

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

int main(){
    int64_t K, len, i, j, chan = 0, memo1 = 0, memo2 = 0, tale;
    string S;

    cin >> S;
    cin >> K;
    len = S.size();
    for(i = 0; i < len; i++){
        if(S[i] != S[0])break;
    }
    if(i == len)cout << len * K / 2 << endl;
    else{
        for(j = 1; j < len; j++){
            if(S[j] == S[j-1]){
                chan++;
                j++;
            }
        }
        if(S[0] == S[len-1]){
            while(S[memo1] == S[0])memo1++;
            tale = len-1;
            while(S[tale] == S[len-1]){
                memo2++;
                tale--;
            }
            if(memo1 % 2 == 1 && memo2 % 2 == 1)cout << (chan + 1) * K - 1 << endl; 
            else cout << chan * K << endl;
        }
        else cout << chan * K << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
    #include <vector>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <string>
    #include <cmath>
    using namespace std;
    #define MAX 100
    int is[MAX];
    int h, w;
    string s[8];
    
    int searchRowEnd(int start, int row) {
        int endCol = -1;
        bool onLoad = false;
        for (int col = 0; col < w; col++) {
            if (endCol == -1) {
                onLoad = col >= start;
            }
            if (!onLoad && s[row][col] == '#' || col == start && s[row][col] != '#') {
                return -1;
            }
            if (onLoad && s[row][col] == '#') {
                endCol = col;
            } else {
                onLoad = false;
            }
        }
        return endCol;
    }
    
    bool judge() {
        int start = 0;
    	for (int row = 0; row < h; ++row) {
    	    start = searchRowEnd(start, row);
    	    if (start == -1) {
    	        return false;
    	    }
    	}
    	return start == w - 1;
    }
    
    int main(void) {
    	cin >> h >> w;
    	for (int i = 0; i < h; ++i) {
    		cin >> s[i];
    	}
    	bool f = judge();
    	cout << (f ? "Possible" : "Impossible") << endl;
    	return 0;
    }

Measured memory_bytes: 256
NK = input().split()
N = int(NK[0])
K = int(NK[1])
H = input().split()
H_int = []

for i in range(N):
  H_int.append(int(H[i]))

H_int_sorted = sorted(H_int)

if N <= K:
  print(0)
else:
  print(sum(H_int_sorted[:N-K]))

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

int main(){
    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N), r(N), l(N), ans(N);
    for(auto& i : A)cin >> i;
    partial_sum(A.begin(), A.end() - 1, r.begin() + 1, __gcd<unsigned long>);
    partial_sum(A.rbegin(), A.rend() - 1, l.rbegin() + 1, __gcd<unsigned long>);
    transform(r.begin(), r.end(), l.begin(), ans.begin(), __gcd<unsigned long>);
    cout << *max_element(ans.begin(), ans.end()) << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N,M;
    cin>>N>>M;
    vector<pii> e(M);
    REP(i,M) {
        int a,b;
        cin>>a>>b;
        a--,b--;
        e[i]={a,b};
    }
    
    int ans=0;
    REP(i,M) {
        vector<vector<int>> g(N);
        REP(j,M) {
            if(i==j) continue;
            g[e[j].first].push_back(e[j].second);
            g[e[j].second].push_back(e[j].first);
        }
        vector<bool> vis(N,false);
        function<void(int)> dfs=[&](int v) {
            vis[v]=1;
            FORE(x,g[v]) {
                if(vis[x]) continue;
                dfs(x);
            }
        };
        dfs(0);
        REP(j,N) {
            if(!vis[j]) {
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
H = int(input())
A = list(map(int, input().split()))

def left(i):
  return 2 * i + 1

def right(i):
  return 2 * i + 2

def max_heapify(h, i):
  l = left(i)
  r = right(i)
  largest = i
  if l < H and h[l] > h[largest]:
    largest = l
  if r < H and h[r] > h[largest]:
    largest = r

  if largest != i:
    h[i], h[largest] = h[largest], h[i]
    max_heapify(h, largest)

def build_max_heap(h):
  for i in range(H//2, -1, -1):
    max_heapify(h, i)

build_max_heap(A)
print(" " + " ".join(list(map(str, A))))



Measured memory_bytes: 63700
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char x[200002];
int n,sums,sumt,ans;
int main()
{
	scanf("%s",x);
	ans=n=strlen(x);
	for(int i=0;i<n;i++)
	{
		if(x[i]=='S')sums++;
		else	if(sums)sumt++;
		if(sums>=sumt)
		{
			ans-=sumt*2;
			sums-=sumt;
			sumt=0;
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
 
 
 
int main() {
   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
     
    unsigned long long int n,q,sum=0,cnt=0,num1=0,num2=0;
    cin>>n;
     unsigned long long int a[n],i,b,c;
     unsigned long long int h[100005]={0};
  
     for(i=0;i<n;++i)
       { cin>>a[i];
         sum+=a[i];
         h[a[i]]++;
       }
        
   sort(a,a+n);
    
   cin>>q;
   while(q--)
   {
       cin>>b>>c;
       cnt=h[b];
       sum-=cnt*b;
       sum+=cnt*c;
       cout<<sum<<endl;
       h[c]+=h[b];
       h[b]=0;
   }
        
        
	return 0;
	
}

Measured memory_bytes: 5176
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
       x: [usize; 5],
    }
    for (i, xi) in x.into_iter().enumerate() {
        if xi == 0 {
            println!("{}", i + 1);
            break;
        }
    }
}


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

int main()
{
		int a, b;
		int t, h, k;

		cin >> a >> b;
		t = a + b;
		h = a - b;
		k = a * b;
		if (t <= h)
		{
			if (h <= k)
			{
				cout << k << endl;
			}
			else
			{
				cout << h << endl;
			}
		}
		else
		{
			if (t <= k)
			{
				cout << k << endl;
			}
			else
			{
				cout << t << endl;
			}
		}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
template <typename T>
vector<T> dijkstra(vector<vector<pair<ll, T>>> &G, ll start){
    using P = pair<T, ll>;
    const T inf = numeric_limits<T>::max();
    ll N = G.size();
    vector<T> dist(N, inf);
    vector<ll> route(N, -1);
    priority_queue<P, vector<P>, greater<P>> pq;
    dist[start] = 0;

    pq.emplace(dist[start], start);
    while(!pq.empty()){
        P p = pq.top();
        pq.pop();
        T c;ll from;
        tie(c, from) = p;
        if (dist[from] < c) continue;
        for(auto& e:G[from]){
            ll to;T cost;
            tie(to,cost) = e;
            if(dist[to]>dist[from]+cost){
                dist[to] = dist[from] + cost;
                route[to] = from;
                pq.emplace(dist[to], to);
            }
        }
    }
    // 各頂点までの最小コスト
    return dist;
    // 始点から各頂点へのルート
    // return route;
}
int main() {
    init();
    ll N, X, Y;
    cin >> N >> X >> Y;
    vvc<pair<ll, ll>> G(N);
    rep(i,N-1){
        G[i].eb(i + 1, 1);
        G[i + 1].eb(i, 1);
    }
    G[X - 1].eb(Y - 1, 1), G[Y - 1].eb(X - 1, 1);

    vl cnt(N);
    rep(i,N-1){
        vl dist = dijkstra(G, i);
        repe(j, i + 1, N) cnt[dist[j]]++;
    }

    repe(i, 1, N) cout << cnt[i] << "\n";
}

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

int main() {
  LL N;
  cin >> N;
  //vector<LL> a(N);
  unordered_map<LL, LL> m;
  for (int i=0; i<N; i++) {
    LL a;
    cin >> a;
    m[a]++;
  }
  
  bool flag = true;
  if (m.size() > 3) {
    flag = false;
  } else if (m.size() == 3) {
    LL t = 0;
    for (auto a : m) {
      t ^= a.first;
      if (a.second != N / 3) {
        flag = false;
      }
    }
    if (t != 0) {
      flag = false;
    }
  } else if (m.size() == 2) {
    for (auto a : m) {
      if (a.first == 0) {
        if (a.second != N / 3) {
          flag = false;
        }
      } else {
        if (a.second != 2 * N / 3) {
          flag = false;
        }
      }
    }
  } else {
    for (auto a : m) {
      if (a.first != 0) flag = false;
    }
  }
  
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
int main()
{
    int a,b,c;
    scanf("%d%d",&a,&b);
    if((a==1&&b==2)||(a==2&&b==1))
    {
        printf("3");
    }
    else if((a==2&&b==3)||(a==3&&b==2))
    {
        printf("1");
    }
    else
    {
        printf("2");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n,a,b,c,d,flag1=1,flag2=1;
	string s;
	cin>>n>>a>>b>>c>>d>>s;
	a--,b--,c--,d--;
	if(d>c)
	{
		for(int i=min(a,b);i<max(c,d);i++)
		{
			if(s[i]=='#'&&s[i+1]=='#')
			{
				puts("No");
				return 0;
			}
		}
		puts("Yes");
	}
	else
	{
		for(int i=a;i<c;i++)
		{
			if(s[i]=='#'&&s[i+1]=='#')
			{
				puts("No");
				return 0;
			}
		}
		for(int i=b-1;i<=d-1;i++)
		{
			if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.')
			{
				puts("Yes");
				return 0;
			}
		}
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 592
#include <stdio.h>

int main(void){
  int n,k,l,i,ans=0;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++){
  	scanf("%d",&l);
  	if(l>=k){
  		ans++;
  	}
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
vector<tuple<int, int, int>> vertexs[200];
int dp[200][200];
void solve(){
	while (true) {
		int n, m, l;
		cin >> n >> m >> l;
		if (n == 0) return;
		REP(i, n) {
			vertexs[i].clear();
		}
		REP(i, m) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			a--; b--;
			vertexs[a].push_back(make_tuple(b, c, d));
			vertexs[b].push_back(make_tuple(a, c, d));
		}
		REP(i, 200) {
			REP(q, 200) {
				dp[i][q] = 1e9;
			}
		}
		priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> next;
		
		REP(i, l + 1) {
			dp[0][i] = 0;
			next.push(make_tuple(0, 0, i));
		}

		while (next.empty() == false) {
			tuple<int, int, int> now = next.top();
			next.pop();
			if (get<0>(now) != dp[get<1>(now)][get<2>(now)]) continue;
			for (auto x : vertexs[get<1>(now)]) {
				//first we think of nothing
				if (dp[get<0>(x)][get<2>(now)] > get<0>(now) + get<2>(x)) {
					dp[get<0>(x)][get<2>(now)] = get<0>(now) + get<2>(x);
					next.push(make_tuple(get<0>(now) + get<2>(x), get<0>(x), get<2>(now)));
				}
				if (get<2>(now) - get<1>(x) < 0) continue;
				if (dp[get<0>(x)][get<2>(now) - get<1>(x)] > get<0>(now)) {
					dp[get<0>(x)][get<2>(now) - get<1>(x)] = get<0>(now);
					next.push(make_tuple(get<0>(now), get<0>(x), get<2>(now) - get<1>(x)));
				}
			}
		}
		cout << dp[n - 1][0] << endl;
	}
}

#undef int

int main() {
	init();
	solve();
}


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

#define ran 32032

int lim, n;
int MAGIC, lim_pre, lim_suf;
int f[111][ran], sf[111][ran];
int g[111][ran], sg[111][ran], tmp[111][ran];

struct modular_arithmetic{
	int mod;

	modular_arithmetic(){
		mod = 1000000007;
	}
	//No specific settings.
	int add(int x,int y){return (x+=y)<mod?x:x-mod;}
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
};
modular_arithmetic ma;

int get_s(int id, int x) {
	if(x<=lim_pre) return sf[id][x];
	
	int res = sf[id][lim_pre];
	int it = lim/x;
	res = ma.add(res, sg[id][it+1]);
	int rem = x - (lim/(it+1));
	res = ma.add(res, ma.mul(rem, tmp[id][it]));
	
	// printf("- %d %d\n", rem, res);
	return res;
}

int main() {
	scanf("%d%d", &lim, &n);
	if(lim==1) {
		puts("1");
		return 0;
	}
	
	MAGIC = sqrt(lim);
	
	lim_pre = lim/(MAGIC+1);
	lim_suf = MAGIC;
	
	memset(f, 0, sizeof f);
	memset(sf, 0, sizeof sf);
	memset(g, 0, sizeof g);
	memset(tmp, 0, sizeof tmp);
	memset(sg, 0, sizeof sg);
	
	f[0][1] = 1;
	for(int i=1;i<=lim_pre;i++)
		sf[0][i] = 1;
	
	for(int id=1; id<=n; id++) {
		for(int i=1;i<=lim_pre;i++) {
			f[id][i] = get_s(id-1, lim/i);
			sf[id][i] = ma.add(sf[id][i-1], f[id][i]);
		}
		for(int i=lim_suf;i>0;i--) {
			int l = lim/(i+1)+1;
			int r = lim/i;
			tmp[id][i] = get_s(id-1, i);
			g[id][i] = ma.mul((r-l+1), tmp[id][i]);
			sg[id][i] = ma.add(sg[id][i+1], g[id][i]);
		}
	}
	
	printf("%d\n", get_s(n, lim));
	
	return 0;
}

Measured memory_bytes: 69632
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define DEBUG 0

typedef struct {
	int head;
	int tail;
} Class;

typedef struct {
	int sub;
	int num;
} Sub;

int compare(const void *a,const void *b)
{
	return ((Class *)a)->head - ((Class *)b)->head;
}

int compareSub(const void *a,const void *b)
{
	return ((Sub *)a)->sub - ((Sub *)b)->sub;
}

void combine(Class class[],int comNum,int cN,int m)
{
	int i=comNum+1;
	while (1) {
		if (class[comNum].head > -1E6) break;
		comNum--;
	}
	while (1) {
		if (class[i].head > -1E6 || i>=m-1) break;
		i++;
	}

	class[comNum].tail = class[i].tail;
	class[i].head = -1E6;
	class[i].tail = -1E6;
	return;
}

int main(void)
{
	int n,m,i,j;
	long tmp,sum;
	int *x;
	int classNum;
	Class *class;
	Sub *sub;
	scanf("%d %d",&n,&m);
	x = (int *)malloc(sizeof(int) * m);
	class = (Class *)malloc(sizeof(Class) * m);
	sub = (Sub *)malloc(sizeof(Sub) * (m-1));
	for (i=0;i<m;i++) {
		scanf("%d",&x[i]);
		class[i].head = x[i];
		class[i].tail = x[i];
	}
	classNum = m;

	qsort(class,m,sizeof(Class),compare);
	
	sum = 0;
	for (i=0;i<(m-1);i++) {
		sub[i].sub = class[i+1].head - class[i].tail;
		sub[i].num = i;
		sum += sub[i].sub;
	}
	qsort(sub,m-1,sizeof(Sub),compareSub);
	if (DEBUG) {
		printf("===\n");
		for (i=0;i<m-1;i++) printf("[%d]%d ",sub[i].num,sub[i].sub);
		printf("\n");
	}

/*
	for (i=0;classNum>n;i++) {
		combine(class,sub[i].num,classNum,m);
		classNum--;
		if (DEBUG) printf("!!! [%d]%d-%d\n",sub[i].num,class[sub[i].num].head,class[sub[i].num].tail);
	}

	tmp = 0;
	for (i=0;i<m;i++) {
		if (DEBUG) printf("[%d]%d-%d \n",i,class[i].head,class[i].tail);
		if (class[i].head <= -1E6) continue;
		
		tmp += class[i].tail - class[i].head;
		
		if (DEBUG) printf("tmp = %ld\n",tmp);
	}
*/

	for (i=m-2,j=1;i>=0 && j<n;i--,j++) {
		sum -= sub[i].sub;
	}

	// printf("%ld\n",tmp);
	printf("%ld\n",sum);
	free(x);
	free(class);
	free(sub);
	return 0;
}


Measured memory_bytes: 2924
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+7
#define MOD 1000000007
using namespace std;



int main(){
    string S;
    cin >> S;
    for(int i=0; i<S.length(); i++){
        if(S[i]=='1'){
            cout<<9;
        }else if(S[i]=='9'){
            cout<<1;
        }else{
            cout<<S[i];
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
ans = 0
for a in range(1, n+1):
    ans += (n-1)//a
print(ans)


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

struct Point {
	int x;
	int y;
	int z;
};
struct Pip {
	int n;
	struct Point p;
};
struct Dice {
	struct Pip pip[6];
};

const struct Point top    = { 0,  0,  1};
const struct Point front  = { 0, -1,  0};
const struct Point right  = { 1,  0,  0};
const struct Point left   = {-1,  0,  0};
const struct Point back   = { 0,  1,  0};
const struct Point bottom = { 0,  0, -1};
const char *d = "NEWSRL";
const int r[6][3][3] = {
	{{ 1,  0,  0}, { 0,  0,  1}, { 0, -1,  0}}, // N
	{{ 0,  0,  1}, { 0,  1,  0}, {-1,  0,  0}}, // E
	{{ 0,  0, -1}, { 0,  1,  0}, { 1,  0,  0}}, // W
	{{ 1,  0,  0}, { 0,  0, -1}, { 0,  1,  0}}, // S
	{{ 0,  1,  0}, {-1,  0,  0}, { 0,  0,  1}}, // R
	{{ 0, -1,  0}, { 1,  0,  0}, { 0,  0,  1}}, // L
};

int comparePoints(struct Point p0, struct Point p1)
{
	if (p0.x == p1.x && p0.y == p1.y && p0.z == p1.z) {
		return 1;
	}
	return 0;
}

void roll(struct Dice *dice, char c)
{
	char *p = strchr(d, c);
	int n = p - d;
	for (int i = 0; i < 6; i++) {
		struct Point *p = &dice->pip[i].p;
		int x = p->x;
		int y = p->y;
		int z = p->z;
		p->x = x * r[n][0][0] + y * r[n][0][1] + z * r[n][0][2];
		p->y = x * r[n][1][0] + y * r[n][1][1] + z * r[n][1][2];
		p->z = x * r[n][2][0] + y * r[n][2][1] + z * r[n][2][2];
	}
}

void getPip(struct Dice *dice, int n, struct Pip *pip)
{
	for (int i = 0; i < 6; i++) {
		if (dice->pip[i].n == n) {
			pip->p = dice->pip[i].p;
			pip->n = dice->pip[i].n;
			break;
		}
	}
}

void turnTop(struct Dice *dice, int n)
{
	struct Pip pip;
	getPip(dice, n, &pip);
	if (comparePoints(pip.p, front)) {
		roll(dice, 'N');
	} else if (comparePoints(pip.p, right)) {
		roll(dice, 'W');
	} else if (comparePoints(pip.p, left)) {
		roll(dice, 'E');
	} else if (comparePoints(pip.p, back)) {
		roll(dice, 'S');
	} else if (comparePoints(pip.p, bottom)) {
		roll(dice, 'N');
		roll(dice, 'N');
	}
}

void turnFront(struct Dice *dice, int n)
{
	struct Pip pip;
	getPip(dice, n, &pip);
	if (comparePoints(pip.p, right)) {
		roll(dice, 'R');
	} else if (comparePoints(pip.p, left)) {
		roll(dice, 'L');
	} else if (comparePoints(pip.p, back)) {
		roll(dice, 'R');
		roll(dice, 'R');
	}
}

int getNumber(struct Dice *dice, struct Point p)
{
	int num = 0;
	for (int i = 0; i < 6; i++) {
		struct Pip pip = dice->pip[i];
		if (comparePoints(pip.p, p)) {
			num = pip.n;
			break;
		}
	}
	return num;
}

int main(void)
{
	struct Dice dice = {
		{{1, top}, {2, front}, {3, right},
		{4, left}, {5, back}, {6, bottom}}
	};
	for (int i = 0; i < 6; i++) {
		scanf("%d", &dice.pip[i].n);
	}
	int q, t, f;
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d %d", &t, &f);
		turnTop(&dice, t);
		turnFront(&dice, f);
		printf("%d\n", getNumber(&dice, right));
	}
	return 0;
}



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

int main() {
  int n;
  double sum = 0;
  double tmp,kekka;
  
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> tmp;
    sum += 1 / tmp;
  }
  
  kekka = 1 / sum;
  cout << kekka;
}


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

int main() {
  int N;
  cin >> N;
  bool ans = false;
  for (int i = 0; i <= N / 4; i++) {
    for (int j = 0; j <= N / 7; j++) {
      if (i * 4 + j * 7 == N) {
        ans = true;
      }
    }
  }
  if (ans) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 384