akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BTreeBurning solver = new BTreeBurning();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTreeBurning {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            long l = in.longs();
            int n = in.ints();
            long[] x = new long[n + 1];
            for (int i = 1; i <= n; i++) {
                x[i] = in.longs();
            }
            long ans = 0;
            // 最初に左
            long t = 0;
            for (int i = 1; i <= n; i++) {
                if (i % 2 == 1) {
                    t += x[i / 2 + 1] - x[i / 2];
                    t += 2 * (x[i] - x[i / 2 + 1]);
                } else {
                    t += 2 * (x[i] - x[i / 2]);
                }
                long a = i * l - t;
                if (a > ans) {
                    //System.out.println("LEFT i="+i+" a="+a);
                    ans = a;
                }
            }

            for (int i = 1; i <= n; i++) {
                x[i] = l - x[i];
            }
            Arrays.sort(x);

            t = 0;
            for (int i = 1; i <= n; i++) {
                if (i % 2 == 1) {
                    t += x[i / 2 + 1] - x[i / 2];
                    t += 2 * (x[i] - x[i / 2 + 1]);
                } else {
                    t += 2 * (x[i] - x[i / 2]);
                }
                long a = i * l - t;
                if (a > ans) {
                    //System.out.println("RIGHT i="+i+" a="+a);
                    ans = a;
                }
            }


            out.println(ans);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

        public long longs() {
            return Long.parseLong(string());
        }

    }
}



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


public class Main {

	
	
	
	public static void main(String[] args) {
		
			FastScanner fs = new FastScanner();
			int t=fs.nextInt();
			while(t-->0)
			{
				System.out.print("ACL");
			}
			
		
	}
	static class FastScanner 
    { 
        BufferedReader br; 
        StringTokenizer st; 
        public FastScanner() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	
	

}


Measured memory_bytes: 32420
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    S = input()

    mods = [0] * 2019

    ttl = 0
    pows = 1

    for i in range(len(S)-1, -1, -1):
        ttl += (int(S[i]) * pows) % 2019
        ttl %= 2019
        pows *= 10
        pows %= 2019
        mods[ttl] += 1

    mods[0] += 1
    ans = 0
    for i in range(2019):
        ans += mods[i] * (mods[i] - 1) / 2

    print(int(ans))


main()


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

int main(){
  string s;
  cin >> s;
  int cnt = 1;
  char c = s[0];
  for(int i = 1; i < s.size(); i++){
  	if(c == s[i]) {
      cnt++;
      if(cnt == 3){
      	cout << "Yes" << endl;
        return 0;
      }
    }
    else{
      c = s[i];
      cnt = 1;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<queue>
#include<string.h>
#include<string>
#include<map>
#include<unordered_set>
#include<stack>
#include<vector>
#include<deque>
#define mod 1000000007
using namespace std;
struct str {
	long long node, cost, t;
};
struct str2 {
	long long node, cost;
	bool operator < (const str2&A)const {
		return cost > A.cost;
	}
};
int n, m, k, b, r;
long long cal(int a, int b) {
	long long sum_n = 1;
	long long sum_r = 1;
	long long sum_m = 1;
	long long t = a - b;
	while (a > 1) {
		sum_n = (sum_n* a) % mod;
		a--;
	}
	while (b > 1) {
		sum_r = (sum_r*b) % mod;
		b--;
	}
	while (t > 1) {
		sum_m = (sum_m*t) % mod;
		t--;
	}
	long long p = 1e9 + 5, val = (sum_r*sum_m) % mod, temp = 1;
	while (p) {
		if (p & 1)temp = (temp * val) % mod;
		val = (val*val) % mod;
		p >>= 1;
	}
	return (sum_n*temp) % mod;
}
int main() {
	scanf("%d %d", &n, &b);
	r = n - b;
	long long ans = 0, sum = 0;
	for (int i = 1; i <= b; i++) {
		long long temp_val = 0;
		if(r-i+1 >= 0)temp_val = (cal(r + 1, r - i + 1)) % mod;
		ans = (temp_val*cal(b - 1, i - 1)) % mod;
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 256
h, w= gets.split(" ").map{ |v|
	v.to_i
}

ans = 100000 * 10000

# 最初を縦に切る
w1 = w / 3

if ((w - w1) % 2 == 0 || h % 2 == 0) then
	tem = ((w-w1)*h/2 - w1 * h).abs
	ans = [tem, ans].min
else
	temarr = [w1*h, (w-w1)/2*h, ((w-w1)/2+1)*h ]
	tem = temarr.max - temarr.min
	ans = [tem, ans].min
	
	temarr = [w1*h, (w-w1)*(h/2), (w-w1)*(h/2+1) ]
	tem = temarr.max - temarr.min
	ans = [tem, ans].min
end

w1 = w / 3 + 1

if ((w - w1) % 2 == 0 || h % 2 == 0) then
	tem = ((w-w1)*h/2 - w1 * h).abs
	ans = [tem, ans].min
else
	temarr = [w1*h, (w-w1)/2*h, ((w-w1)/2+1)*h ]
	tem = temarr.max - temarr.min
	ans = [tem, ans].min
	
	temarr = [w1*h, (w-w1)*(h/2), (w-w1)*(h/2+1) ]
	tem = temarr.max - temarr.min
	ans = [tem, ans].min
end

#最初を横に切る
h1 = h / 3
if ((h - h1) % 2 == 0 || w % 2 == 0) then
	tem = ((h-h1)*w/2 - h1 * w).abs
	ans = [tem, ans].min
else
	temarr = [h1*w, (h-h1)/2*w, ((h-h1)/2+1)*w ]
	tem = temarr.max - temarr.min
	ans = [tem, ans].min
	
	temarr = [h1*w, (h-h1)*(w/2), (h-h1)*(w/2+1) ]
	tem = temarr.max - temarr.min
	ans = [tem, ans].min
end

h1 = h / 3 + 1
if ((h - h1) % 2 == 0 || w % 2 == 0) then
	tem = ((h-h1)*w/2 - h1 * w).abs
	ans = [tem, ans].min
else
	temarr = [h1*w, (h-h1)/2*w, ((h-h1)/2+1)*w ]
	tem = temarr.max - temarr.min
	ans = [tem, ans].min
	
	temarr = [h1*w, (h-h1)*(w/2), (h-h1)*(w/2+1) ]
	tem = temarr.max - temarr.min
	ans = [tem, ans].min
end

puts ans


Measured memory_bytes: 1788
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    int n, m;
    cin >> n >> m;
    int a[n], b[n];
    rep(i, n) { cin >> a[i] >> b[i]; }
    int c[m], d[m];
    rep(i, m) { cin >> c[i] >> d[i]; }

    rep(l0, n) {
        int distance = pow(10, 9);
        int ans = -1;
        for (ll l1 = m - 1; l1 >= 0; l1--) {
            int temp = abs(c[l1] - a[l0]) + abs(d[l1] - b[l0]);
            if (temp <= distance) {
                ans = l1;
                distance = temp;
            }
        }
        cout << ans + 1 << endl;
    }
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


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

int main() {
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  while(true){
    A-=D;
    C-=B;
    if(C<=0){
      cout<<"Yes";
        break;
    }
    if(A<=0){
      cout<<"No";
      break;
    }
  }
}
    

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define fastIO          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll              long long
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define mp              make_pair
#define in              insert
#define ff              first
#define ss              second
#define vv              vector
#define vll             vector <ll>
#define pll             pair <ll,ll>
#define vpll            vector <pll>
#define umap            unordered_map
#define uset            unordered_set
#define mset            multiset
#define pqueue          priority_queue
#define stk             stack<ll>
#define que             queue<ll>
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define gcd(a,b)        __gcd(a,b)
#define rev             reverse
#define Y               "YES"
#define N               "NO"
#define br              "\n"
#define sp              " "
#define debug(x)        cout << #x << " : " << x << endl;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ll inf = 1e18;
const ll MAX = 2e5 + 1;


// ====== int_1024t begins ======
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// ====== int_1024t ends ======

inline ll add(ll a, ll b) {return ((a % mod) + (b % mod)) % mod;}
inline ll sub(ll a, ll b) {return ((a % mod) - (b % mod) + mod) % mod;}
inline ll mul(ll a, ll b) {return ((a % mod) * (b % mod)) % mod;}
ll pwr(ll x, ll n) {
	x = x % mod;
	if (!n) return 1;
	if (n & 1) return mul(x, pwr(mul(x, x), (n - 1) / 2));
	else return pwr(mul(x, x), n / 2);
}
// O(nlogn) for [1,n]
ll modinv(ll n) {
	return pwr(n, mod - 2);
}
// O(logn) for[1,n]
ll inv(ll i) {
	if (i == 1) return 1;
	return (MOD - (MOD / i) * inv(MOD % i) % MOD) % MOD;
}
// =============================



void solve()
{
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	vector<bool> dp(k + 1, false);
	for (int i = 0; i <= k; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if ((i - a[j]) >= 0 && dp[i - a[j]] == false)
			{
				dp[i] = true;
			}
		}
	}

	if (dp[k])
	{
		cout << "First";
	}
	else
		cout << "Second";

}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;

	solve();


	return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;
public class Main {

    
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        if(n<1200){
            System.out.println("ABC");
        }
        else if(n<2800){
            System.out.println("ARC");
        }
        else
            System.out.println("AGC");
    }
    
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b-1); i>=(a); i--)
#define de(x) cout << #x << " => " << x << endl
using namespace std;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

typedef long long ll;
typedef long double ld;

///----------------------------------------------

int main() {

	///read
	int n; cin >> n;
	int has4 = 0;
	int has2 = 0;
	rep(i, 0, n) {
		int dig; scanf("%d", &dig);
		if (dig % 4 == 0) has4++; else
		if (dig % 2 == 0) has2++;
	}

	///
	int ned = n - has4 - has2;
	if (has2) ned++;
	if (has4 + 1 >= ned) puts("Yes");
		else puts("No");


}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;


int main()
{
	ll x;
	cin >> x;
	ll ans = (x / 11) * 2;
	x %= 11;
	if (x > 0 && x <= 6) ans++;
	if (x > 6) ans += 2; 
	cout << ans << endl;
}

Measured memory_bytes: 3600
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
Q = int(input())
px = [0]*(H*W+1)
py = [0]*(H*W+1)
for y in range(H):
    for x in range(W):
        n = A[y][x]
        px[n] = x + 1
        py[n] = y + 1
csum = [0]*(H*W+1)
for i in range(D+1,H*W+1):
    csum[i] = csum[i-D] + abs(px[i]-px[i-D]) + abs(py[i]-py[i-D])
for q in range(Q):
    L, R = map(int,input().split())
    print(csum[R]-csum[L])



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

int main() {
    int N;
    cin >> N;
    vector<int> A(N+1);
    for(int i=1;i<=N;i++) {
        cin >> A[i];
    }
    vector<int> rev(N+1);
    for(int i=1;i<=N;i++) {
        rev[A[i]] = i;
    }
    for(int i=1;i<=N;i++) {
        cout << rev[i] << " ";
    }
    return 0;
}


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

int main(){
	string S;
	cin >> S;
	rep(i, S.size())
	for (int j=i; j<=S.size(); j++){
		string T = S.substr(0,i) + S.substr(j,S.size()-j);
		if (T=="keyence") {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}


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

#define int long long
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; }


set<pair<int, char>> tate[1000010], yoko[1000010];

signed main(){
	int h, w, k;
	cin >> h >> w >> k;
	int sx, sy, gx, gy;
	cin >> sy >> sx >> gy >> gx;
	sx--;
	sy--;
	gx--;
	gy--;

	for(int i = 0;i < h;i++){
		string s;
		cin >> s;
		for(int j = 0;j < w;j++){
			tate[i].insert({j, s[j]});
			yoko[j].insert({i, s[j]});
		}
	}

	for(int i = 0;i < h;i++){
		tate[i].insert({-1, '@'});
		tate[i].insert({w, '@'});
	}
	for(int i = 0;i < w;i++){
		yoko[i].insert({-1, '@'});
		yoko[i].insert({h, '@'});
	}

	tate[sy].erase({sx, '.'});
	yoko[sx].erase({sy, '.'});

	queue<pair<int, pair<int, int>>> que;
	que.push({0, {sx, sy}});

	while(!que.empty()){
		int cost = que.front().first;
		int x = que.front().second.first;
		int y = que.front().second.second;
		que.pop();
		if(x == gx && y == gy){
			cout << cost << endl;
			return 0;
		}

		{
		auto p = tate[y].lower_bound({x, '.'});
		for(auto q = p;q->first <= x+k;){
			if(q->second == '@') break;
			int idx = q->first;
			auto tmp = q;
			que.push({cost+1, {idx, y}});
			q++;
			tate[y].erase(tmp);
			yoko[idx].erase({y, '.'});
		}
		}

		{	
		auto p = tate[y].lower_bound({x, '.'});
		for(auto q = p;q->first >= x-k;){
			if(q->first > min(w-1, x)){
				q--;
				continue;
			}
			if(q->second == '@') break;
			int idx = q->first;
			auto tmp = q;
			que.push({cost+1, {idx, y}});
			q--;
			tate[y].erase(tmp);
			yoko[idx].erase({y, '.'});
		}
		}

		{
		auto p = yoko[x].lower_bound({y, '.'});
		for(auto q = p;q->first <= y+k;){
			if(q->second == '@') break;
			int idx = q->first;
			auto tmp = q;
			que.push({cost+1, {x, idx}});
			q++;
			yoko[x].erase(tmp);
			tate[idx].erase({x, '.'});
		}
		}

		{
		auto p = yoko[x].lower_bound({y, '.'});
		for(auto q = p;q->first >= y-k;){
			if(q->first > min(h-1, y)){
				q--;
				continue;
			}
			if(q->second == '@') break;
			int idx = q->first;
			auto tmp = q;
			que.push({cost+1, {x, idx}});
			q--;
			yoko[x].erase(tmp);
			tate[idx].erase({x, '.'});
		}
		}
	}

	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 347384
x,n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    flag = False
    for i in range(100):
        for j in range(n):
            if p[j] == x - i:
                break
            if j == n-1:
                print(x - i)
                flag = True
                break
        if flag:
            break
        for h in range(n):
            if p[h] == x + i:
                break
            if h == n-1:
                print(x + i)
                flag = True
                break
        if flag:
            break
else:
    print(x)

Measured memory_bytes: 9148
def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    ex = [0 for _ in range(n)]
    for i in range(n):
        ex[i] = (p[i]+1)/2
    
    sumex = sum(ex[:k])
    tmp = sum(ex[:k])
    for i in range(n-k):
        tmp = tmp + (ex[i+k] - ex[i])
        sumex = max(sumex, tmp)
    print(sumex)
    
main()


Measured memory_bytes: 24812
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  int n;
  while(cin>>n,n){
    int ans = 0;
    while(n != 0){
      ans += n/5;
      n/=5;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

const int kN = 200000 + 5;
int n;
char s[kN];

int a[kN], b[kN], c[kN];

int main()
{
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++ i)
    a[i] = s[i] - '0';
  for (int i = 1; i <= n + 1; ++ i) {
    b[i] = a[i] ^ a[i - 1];
  }
  for (int i = 1; i <= n + 1; ++ i) {
    c[i] = c[i - 1] + b[i];
  }
  int result = 1;

  // for (int i = 1; i <= n + 1; ++ i)
    // printf("%d ", b[i]); puts("");

  for (int k = n; k > result; -- k) {
    int r = k;
    int l = n + 1 - k + 1;

    int x = c[n + 1], y = 0;

    if (l <= r) {
      y = c[r] - c[l - 1];
      x -= y;
    }
    if (y == 0 && x % 2 == 0) {
      //printf("l = %d, r = %d, k = %d, x = %d, y = %d\n", l, r, k, x, y);
      result = k;
    }
  }
  printf("%d\n", result);
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s(n+1);
  int m;
  for(int i = 0; i < n; i++){
    cin >> m;
    s.at(i+1) = s.at(i) + m+1;
  }
  
  int ans = 0;
  int tmp = 0;
  for(int i = 0; i + k <= n; i++){
    tmp = s.at(i+k) - s.at(i);
    if(ans < tmp) ans = tmp;
  }
  cout<<fixed<<setprecision(6);
  cout << ans / 2.0;
}



Measured memory_bytes: 1024
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

    a=int(input())

    print(a+a*a+a*a*a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27152
#include<bits/stdc++.h>
using namespace std;
typedef struct node
{
    int x,y;
    bool operator < (const struct node & n)const
    {
        return y>n.y;
    }
}NODE,*PNODE;
NODE a[100005];
int n,k,cnt=0;
int visited[100005];
stack<int>s;
int main()
{
	int i;
    long long ans=0,res=0,type=0;
    scanf("%d%d",&n,&k);
    for(i=1;i<=n;i++)
		scanf("%d%d",&a[i].x,&a[i].y);
    sort(a+1,a+1+n);
    for(i=1;i<=n;i++)
    {
        if(cnt<k)
        {
            if(!visited[a[i].x])
            {
                visited[a[i].x]=1;
                type++;
            }
            else
				s.push(a[i].y);
            res+=a[i].y;
            cnt++;
            ans=max(ans,res+type*type);
        }
        else
        {
            if(s.empty())
				break;
            if(visited[a[i].x])
				continue;
            visited[a[i].x]=1;
            type++;
            res+=a[i].y;
            res-=s.top();s.pop();
            ans=max(ans,res+type*type);
        }
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 1536
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import qualified Data.IntMap as IM
import Data.List

bsReadInts = map (fst . fromJust . B.readInt) . B.words

solve n m as = sum $ map g $ IM.toList im
  where
    g (_,c) = (c*(c-1)) `div` 2
    accs = scanl' op 0 as
      where op a1 a2 = (a1 + a2) `mod` m
    im = foldr (IM.alter f) IM.empty accs
      where f Nothing = Just 1
            f (Just a) = Just (a+1)

tmain cont =
  let n : m : as = bsReadInts cont
  in solve n m as

main = putStrLn . show . tmain =<< B.getContents


Measured memory_bytes: 13692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}


int main(){

  ll N;
  cin >> N;
  vector<P> A(N);

  FOR(i,0,N){
    cin >> A[i].first;
    A[i].second = i;
  }
  SORT(A);
  REV(A);
  
  ll dp[N+1][N+1] = {};

  FOR(i,0,N){
    FOR(j,0,N){
      ll k = i+j;
      if(k >= N)continue;

      dp[i+1][j] = max( dp[i+1][j]  ,  dp[i][j] + A[k].first*abs(i-A[k].second)  );
      dp[i][j+1] = max( dp[i][j+1]  ,  dp[i][j] + A[k].first*abs(N-j-1-A[k].second)  );

    }
  }

  ll ans = 0;
  FOR(i,0,N+1){
    ans = max(ans,dp[N-i][i]);
  }

  cout << ans << endl;

}


Measured memory_bytes: 34936
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
count_f = 0
count_b = 0
for i in range(len(a)):
    if a[i] < x:
        count_f += 1
    elif a[i] > x:
        count_b += 1
print(min(count_f, count_b))

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

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

    vector<string> moji(N);

    for(int i = 0;i < N;i++){
        cin >> moji.at(i);
    }

    sort(moji.begin(),moji.end());
    string hako = "";

    for(int i = 0;i < N;i++){
        hako += moji.at(i);
    }

    cout << hako << endl;


}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
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;}
// clang-format on

void solve(long long N, std::vector<long long> A) {
  vector<ll> a(N);
  rep1(i, N) { a[A[i - 1] - 1] = i; }
  rep(i, N) { cout << a[i] << (i != N - 1 ? " " : ""); }
  cout << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 2432
N=int(input())

p= list(map(int, input().split())) #ABCが数字の場合これで一発


a = sorted(p)

diff = 0

for i in range(N):
    if a[i]!=p[i]:
        diff += 1



ans = 'NO'
if diff==2 or diff == 0:
    ans = 'YES'



print(ans)
    



    


Measured memory_bytes: 38384
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <stack>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <sstream>
#include <random>
#include <functional>
#include<algorithm>
#include <array>
#include<random>
using namespace std;

int main() {
	uint64_t N;
	cin >> N;
	vector<uint64_t> a(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	uint64_t l = 0, r = 0;
	uint64_t sum_a = 0, xor_a = 0;
	uint64_t ans = 0;
	while (r < N) {
		sum_a += a[r];
		xor_a ^= a[r];
		while(sum_a != xor_a) {
			sum_a -= a[l];
			xor_a ^= a[l];
			++l;
		}
		++r;
		ans += r - l;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	int n, l = 0;
	cin >> n >> l;
	
	vector<int> tastes;

	int* apples = new int[n + 1];
	for (int i = 1; i <= n; i++)
	{
		tastes.push_back(l + i - 1);
	}


	//方針
	//味の絶対値が最も小さいリンゴを食べればよい

	//味をソート
	sort(tastes.begin(), tastes.end(), [](int l, int r) { return abs(l) < abs(r); });

	//2個目から集計
	int sum = 0;
	for (int i = 1; i < tastes.size(); i++)
	{
		sum += tastes[i];
	}

	cout << sum;

	return 0;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<functional>
#include<sstream>

using namespace std;
typedef long long ll;
int n;
string str[60];
vector<string> ss;
vector<ll> kk;

int main(void){
	scanf("%d",&n);
	priority_queue<int> que;
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		que.push(a);
		if(que.size()>=5)que.pop();
	}
	for(int i=min(3,n-1);i>=0;i--){
		int b=que.top();
		que.pop();
		stringstream sss;
		sss << b;
		sss >> str[i];
	}
	for(int i=0;i<=min(3,n-1);i++){
		for(int j=0;j<=min(3,n-1);j++){
			if(i==j)continue;
			string sss;
			sss=str[i];
			sss+=str[j];
			stringstream ssss;
			ssss << sss;
			ll co;
			ssss >> co;
			kk.push_back(co);
		}
	}
	sort(kk.begin(),kk.end());
	cout << kk[2] << endl;
	return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Multiplication3 | diff Multiplication3.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Multiplication3.cpp && ./a.out

/*

 5/31/2020

 5:05-5:07

 */

LL A;
string B;

void solve() {
  if(SZ(B)==1) B.push_back('.');
  while(SZ(B)<4) B.push_back('0');
  LL b=(B[0]-'0')*100+(B[2]-'0')*10+B[3]-'0';
  LL res=A*b/100;
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>A>>B;
  solve();

  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
typedef long long ll;
const int mod = 1e9+7;
struct matrix{
    ll m[maxn][maxn];
}M;
matrix operator*(matrix & a,matrix &b){
    matrix c;
    for (int i = 0; i < maxn;i++)
        for (int j = 0; j < maxn;j++){
                c.m[i][j] = 0;
            for (int k = 0; k < maxn;k++){
                c.m[i][j]+= (ll)a.m[i][k]*b.m[k][j] % mod;
                c.m[i][j]%= mod;
            }
        }
    return c;
}
matrix operator^(matrix & base,ll e){
    matrix c;
    for (int i = 0; i < maxn;i++)
        for (int j = 0; j < maxn;j++)
            c.m[i][j] = (i== j);
    while(e){
        if (e & 1)
            c = c*base;
        base = base*base;
        e >>= 1ll;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N;
    long long K;
    cin >> N >> K;
    for (int i = 1; i <= N;i++){
        for (int j = 1; j <= N;j++){
            cin >> M.m[i][j];
        }
    }
    int sol = 0;
    M= M^(K);
    for (int i = 1; i <= N;i++){
        for (int j = 1; j <= N;j++){
            sol+= M.m[i][j];
            sol%= mod;
        }
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 384
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 3e3 + 10;
vector<pair<int, int>> v[N];
LL dis[N];
LL dis1[N];
LL dis2[N];
int flag[N];
LL minINF;
void solve(int n)
{
	for (int i = 1; i <= n; i++)
	{
		if (dis[i] == minINF) continue;
		for (auto& p : v[i])
		{
			int y, w;
			tie(y, w) = p;
			dis[y] = max(dis[y], dis[i] + w);
		}
	}
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m, p;
	cin >> n >> m >> p;
	while (m--)
	{
		int x, y, w;
		cin >> x >> y >> w;
		v[x].emplace_back(y, w - p);
	}

	int cnt = 2 * n;
	MEM(dis, 0xef);
	minINF = dis[0];
	dis[1] = 0;
	while (cnt--)
		solve(n);
	LL ans1 = dis[n];
	memcpy(dis1, dis, sizeof(dis));

	cnt = 2 * n;
	while (cnt--)
		solve(n);
	LL ans2 = dis[n];
	memcpy(dis2, dis, sizeof(dis));
	queue<int> q;
	for (int i = 1; i <= n; i++)
	{
		if (dis1[i] != dis2[i])
		{
			flag[i] = 1;
			q.push(i);
		}
	}
	while (!q.empty())
	{
		int x = q.front();
		q.pop();
		for (auto& p : v[x])
		{
			int y = p.first;
			if (flag[y]) continue;
			flag[y] = 1;
			q.push(y);
		}
	}
	if (flag[n] == 0) cout << max(0LL, ans1) << endl;
	else cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  int n,totX;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i==0){
      totX=a[i];
    }else{
      totX^=a[i];
    }
  }
  for(int i=0;i<n;i++){
    cout<<(totX^a[i])<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3904
n=int(input())
h=list(map(int,input().split()))
dp = [0]*n
dp[1] = abs(h[1] - h[0])

for i in range(2,n):
    cost1 = abs(h[i] - h[i-2])
    cost2 = abs(h[i] - h[i-1])
    dp[i] = min(dp[i-2]+cost1, dp[i-1]+cost2)

print(dp[n-1])

Measured memory_bytes: 13928
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

int i,n;cin>>n;
vector<string> s(n);
unordered_map<string,int> h;
for(i=0;i<n;i++)
{
	cin>>s[i];h[s[i]]++;
}
int m=0;
for(auto x:h)
{
	m=max(m,x.second);
}
vector<string> t;
for(auto x:h)
{
	if(x.second==m) t.pb(x.first);
}
sort(t.begin(),t.end());
for(auto x:t) cout<<x<<endl;

return 0;
}

Measured memory_bytes: 26948
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    int n,a[110],sum;
    while(scanf("%d",&n)!=EOF)
    {
        sum = 0;
        for (int i = 0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        for (int i = 0;i<n-1;i++)
        {
            sum= sum+(a[i+1]-a[i]);
        }
        printf("%d\n",sum);
    }
    return 0;
}


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

const int INF = 10000000000000;
vector<vector<int>> cost(200, vector<int>(200,INF));
void warshall_floyd( int N ){
  for( int i = 0; i < N; i++ ){ //経由
    for( int j = 0; j < N; j++ ){ //始点
      for( int k = 0; k < N; k++ ){ //終点
        cost.at(j).at(k) = min(cost.at(j).at(k), cost.at(j).at(i)+cost.at(i).at(k));
      }
    }
  }
}

signed main(){
  int N, M, R;
  cin >> N >> M >> R;
  
  vector<int> r(R);
  for( int i = 0; i < R; i++ ){
    cin >> r.at(i);
    r.at(i)--;
  }
  sort( r.begin(), r.end() );
  
  for( int i = 0; i < M; i++ ){
    int A, B, C;
    cin >> A >> B >> C;
    A--;
    B--;
    cost.at(A).at(B) = C;
    cost.at(B).at(A) = C;
  }
  
  for( int i = 0; i < N; i++ ) cost.at(i).at(i) = 0;
  warshall_floyd(N);
  
  int ans = INF;
  do{
    int now = 0;
    for( int i = 0; i < R-1; i++ ){
      now += cost.at(r.at(i)).at(r.at(i+1));
    }
    ans = min(ans, now);
  }while( next_permutation(r.begin(), r.end()) );
  
  cout << ans << endl;
  
}


Measured memory_bytes: 640
# RMQ のパフォーマンステスト
class Rmq:
    # 平方分割
    # 値を変更すると元のリストの値も書き換わる
    # 検証: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3990681
    def __init__(self, a, sqrt_n=150, inf=(1<<31)-1):
        self.sqrt_n = sqrt_n
        if hasattr(a, "__iter__"):
            from itertools import zip_longest
            self.n = len(a)
            self.layer0 = [min(values) for values in zip_longest(*[iter(a)]*sqrt_n, fillvalue=inf)]
            self.layer1 = a
        elif isinstance(a, int):
            self.n = a
            self.layer0 = [inf] * ((a - 1) // sqrt_n + 1)
            self.layer1 = [inf] * a
        else:
            raise TypeError

    def get_min(self, l, r):
        sqrt_n = self.sqrt_n
        parent_l, parent_r = l//sqrt_n+1, (r-1)//sqrt_n
        if parent_l < parent_r:
            return min(min(self.layer0[parent_l:parent_r]),
                       min(self.layer1[l:parent_l*sqrt_n]),
                       min(self.layer1[parent_r*sqrt_n:r]))
        else:
            return min(self.layer1[l:r])

    def set_value(self, idx, val):
        self.layer1[idx] = val
        idx0 = idx // self.sqrt_n
        idx1 = idx0 * self.sqrt_n
        self.layer0[idx0] = min(self.layer1[idx1:idx1+self.sqrt_n])

    def chmin(self, idx, val):
        if self.layer1[idx] > val:
            self.layer1[idx] = val
            idx //= self.sqrt_n
            self.layer0[idx] = min(self.layer0[idx], val)

    def debug(self):
        print("layer0=", self.layer0)
        print("layer1=", self.layer1)

    def __getitem__(self, item):
        return self.layer1[item]

    def __setitem__(self, key, value):
        self.set_value(key, value)


from operator import itemgetter

N, M = map(int, input().split())
LRC = [list(map(int, input().split())) for _ in range(M)]
LRC.sort(key=itemgetter(0))

idx_LRC = 0
q = []

inf = 10**18
seg = Rmq(N+1, inf=inf)

seg.set_value(1, 0)
for v in range(1, N + 1):
    d = seg.get_min(v, N + 1)
    while idx_LRC < M:
        l, r, c = LRC[idx_LRC]
        if l <= v:
            seg.chmin(r, d+c)
            idx_LRC += 1
        else:
            break
ans = seg[N]
print(ans if ans != inf else -1)


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

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            Console.WriteLine(((((N / 1000) + 1) * 1000) - N) % 1000);
        }
    }
}


Measured memory_bytes: 27456
n = int(input())
s = input()


left_black = 0
right_white = s.count(".")
answer = left_black + right_white

for w in s:
    if w == "#":
        left_black += 1
    else:
        right_white -= 1
    answer = min(answer, left_black + right_white)

print(answer)





Measured memory_bytes: 3500
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int m,n;
	cin >> m;
	vector<int> p1;
	vector<int> p2;
	for (int i = 0;i < m;i++)
	{
		int num;
		cin >> num;
		p1.push_back(num);
	}
	cin >> n;
	for (int i= 0;i < n;i++)
	{
		int num;
		cin >> num;
		p2.push_back(num);
	}
	sort(p1.begin(), p1.end());
	sort(p2.begin(), p2.end());
	if (includes(p1.begin(), p1.end(), p2.begin(), p2.end()))cout << 1 << endl;//前面做大范围，后面做小范围
	else cout << 0 << endl;
}
//includes 函数的原理
/*template <class InputIterator1, class InputIterator2>
bool includes ( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2 )
{    while (first2!=last2)  
	{    if ( (first1==last1) || (*first2<*first1) ) 
			return false;    
     	     if (!(*first1<*first2))     //可以改为*first1==*first2，如果能执行到这一行一定是*first2>=*first1
     	                ++first2;    
     	     ++first1;  
     	}  
     	return true;
}
*/


Measured memory_bytes: 5244
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

typedef pair<int, int> P;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> cd;
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		if (a < n) {
			cd.push_back(n - a);
		}
	}
	sort(cd.begin(), cd.end());
	int ans = 0;
	for (int i = 0; i + 1 < cd.size(); i++) {
		ans += cd[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3136
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(i%2==1&&s[i]=='R'){
      cout <<"No\n";
      return 0;
    }
    if(i%2==0&&s[i]=='L'){
      cout <<"No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

struct Node {
	int key;
	Node* parent, * left, * right;
};

Node* root;

void root_init() {
	root = nullptr;
}

void insert(int k) {
	if (root == nullptr) {
		Node* ins_value = new Node;
		ins_value->key = k;
		ins_value->parent = nullptr;
		ins_value->left = nullptr;
		ins_value->right = nullptr;
		root = ins_value;
		return;
	}
	Node* npntr = nullptr;
	Node* now = root;
	Node* ins_value = new Node;

	ins_value->key = k;
	ins_value->left = nullptr;
	ins_value->right = nullptr;

	while (now != nullptr) {
		npntr = now;
		if ((ins_value->key) < (now->key)) now = now->left;
		else now = now->right;
	}
	ins_value->parent = npntr;
	if ((ins_value->key) < (npntr->key)) npntr->left = ins_value;
	else npntr->right = ins_value;
}

void inorder(Node* u) {
	if (u == nullptr) return;
	inorder(u->left);
	cout << " " << u->key;
	inorder(u->right);
}
void preorder(Node * u) {
	if (u == nullptr) return;
	cout << " " << u->key;
	preorder(u->left);
	preorder(u->right);
}

void all_delete_node(Node * now) {
	if (now == nullptr) return;
	all_delete_node(now->left);
	all_delete_node(now->right);
	delete now;
}

bool exist2Node(Node* now,int value){
  if(now==nullptr) return false;
  if(now->key==value) return true;
  return exist2Node(now->left,value)||exist2Node(now->right,value);
}

bool existNode(Node* now,int value){
  if(now==nullptr) return false;
  if(now->key==value) return true;
  if(value<(now->key)) return existNode(now->left,value);
  else return existNode(now->right,value);
}


int main() {
	int size, value;
	string cmd;
	cin >> size;

	for (int i = 0; i < size; i++) {
		cin >> cmd;
		if (cmd == "insert") {
			cin >> value;
			insert(value);
		}
    else if(cmd=="find"){
      cin>>value;
      if(existNode(root,value)) cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }
		else if (cmd == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	all_delete_node(root);

	return 0;
}



Measured memory_bytes: 21856
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}
int exp(int a, int b){
    LL res = 1;
    LL sum = a;
    while(b){
        if(b&1)res = (res * sum)%MOD;
        sum = (sum * sum) % MOD;
        b >>= 1;
    }
    return res;
}

int main(){
    int N;
    cin >> N;
    int M;
    cin >> M;
    vector<int> line(N + 1, 0);
    REP(i, M){
        int d;
        cin >> d;
        line[d] = -1;
    }
    line[0] = 1;
    REP(i, N){
        if(line[i]==-1)continue;
        if(i+1 >= line.size() || line[i+1]==-1);
        else{
            line[i+1] = (line[i+1] + line[i])%MOD;
        }
        if(i+2 >= line.size() || line[i+2]==-1);
        else{
            line[i+2] = (line[i+2] + line[i])%MOD;
        }
    }
    cout << line.back() << endl;
    return 0;
}


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

int main(){
	int n,k;
    cin >> n >> k;
    
    ll ans;
    if(k%2 == 0){
        ll l = 2*n/k;
        ll o = (l+1)/2;
        ll e = l/2;
        ans = o*o*o + e*e*e;
    }else{
        ll l = n/k;
        ans = l*l*l;
    }

    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256