akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void){
    string input;
    
    while(getline(cin, input), !cin.eof()){
        int x, y;
        sscanf(input.c_str(), "%d %d\n", &x, &y);
        
        if(x == 0 && y == 0) break;
        if(x < y){
            printf("%d %d\n", x, y);
        }
        else{
            printf("%d %d\n", y, x);
        }
    }
    return(0);
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)

                    
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main()
{
    string S, T;
    cin >> S >> T;
    if(S.substr(0, S.size()) == T.substr(0, S.size()))
        cout << "Yes" << endl;
    else cout << "No" << endl; 
}


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

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

const long long MOD = 1000000007;

vector<int> s(1001);
vector<double> e(1001);

void ex(int i){
  s.at(i) = s.at(i-1) + i;
  e.at(i) = (double)s.at(i) / i;
  if(i<1000) ex(i+1);
}

int main(){
  ex(1);
  int n,k;
  double x=0,me=0;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p.at(i);
  
  rep(i,k){
    x += e.at(p.at(i));
  }
  me = x;
  
  for(int i=1;i<n-k+1;i++){
    x = x - e.at(p.at(i-1)) + e.at(p.at(i+k-1));
    if(x>me) me = x;
  }
  cout << fixed << setprecision(10);
  cout << me <<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>
 
std::vector<std::vector<std::pair<int, int>>> path;

std::vector<int> color;

void draw(int vertex, int old, int c){
	color[vertex] = c;
	for(const auto& p : path[vertex]){
		if(p.first == old)continue;
		draw(p.first, vertex, p.second ^ c);
	}
}
int main(void){
	int n;
	std::cin >> n;
	path.resize(n);
	color.resize(n);
	for(int i=0;i<n-1;i++){
		int a, b, c;
		std::cin >> a >> b >> c;
		c = c % 2;
		path[a-1].push_back(std::make_pair(b-1, c));
		path[b-1].push_back(std::make_pair(a-1, c));
	}
	for(int i=0;i<n;i++)color[i]=-1;
	draw(0, -1, 0);
	for(int i=0;i<n;i++){
		if(color[i] == -1)std::exit(-1);
		std::cout << color[i] << std::endl;
	}
}

Measured memory_bytes: 8192
// ------------------------------------
// Date:2018/ 3/ 4
// Problem:ABC 089 _ c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef unsigned long long ll;

static const int MOD = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  string str;
  //vector< pair< ll, bool > > cnt(5, {0ll, false});
  
  vector< ll > cnt(5, 0ll);
  //bool state[5];
  REP(i, N) {
    cin >> str;
    switch(str[0]) {
      case 'M':
        cnt[0] += 1;
        break;
      case 'A':
        cnt[1] += 1;
        break;
      case 'R':
        cnt[2] += 1;
        break;
      case 'C':
        cnt[3] += 1;
        break;
      case 'H':
        cnt[4] += 1;
        break;
    }
  }
  
  // 大きい順にソート
  sort(cnt.begin(), cnt.end(), [](ll x, ll y) {
    return x >= y;
  });
  
  ll ans = 0, sum, tmp;
  REP(i, 5) {
    sum = 0;
    if (cnt[i] == 0) continue;
    FOR(j, i + 1, 5) {
      tmp = 0;
      if (cnt[j] == 0) continue;
      // state[j] == trueのとき
      FOR(k, j + 1, 5) {
        if (cnt[k] == 0) continue;
        tmp += cnt[k];
        //debug(i);
        //debug(j);
        //debug(k);
      }
      sum += tmp * cnt[j];
    }
    if (cnt[i] != 0) ans += sum * cnt[i];
  }
  
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

ll k;


ll solve() {
    int s = 7;
    for (int i = 1; i < 10000000; i++) {
        s %= k;
        if (s == 0) return i;
        s = 10 * s + 7;
    }
    return -1;
}

void input() {
    cin >> k;
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3152
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<int>>
constexpr auto mod = 1000000007;


//2のn乗を求めるよ！！！
int ni(int n) {
	if (n == 0)return 1;
	int x = ni(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
}

//フィボナッチ数列のx番目を求めるよ！
int f(int x,vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1,s) + f(x - 2,s);
	return s[x];
}

//aとｂの最大公約数を求めるよ！
llint gcd(llint a, llint b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b,ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//m進数のn桁を全列挙やで
void dfs(int m, int n) {

	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			cout << now << endl;
		}
		else {
			for (int i = m-1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}



int main() {
	int n;
	llint X;
	cin >> n>>X;
	llint x;
	hei(llint) s(n);
	rep(i, 0, n) {
		cin >> x;
		s[i] = abs(X - x);
	}
	llint ans = 0;
	if (n == 1)ans = s[0];
	else {
		ans = gcd(s[0], s[1]);
		if (n >= 3) {
			rep(i, 2, n)ans = gcd(ans, s[i]);
		}
	}
	cout << ans << endl;
}


  


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

using namespace std;

int main(){
	int n,k,mn=INT_MAX,pp;
	cin>>n>>k;
	long long sum(0);
	for(int i=1; i<=n; ++i){
		sum += k+i-1;
		if(abs(0-k-i+1)<mn)
			mn=abs(0-k-i+1),pp=0-k-i+1;
	}	
	cout<<sum+pp<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
ll n;
ll dp[100005][13]; // 先頭i文字として考えられるもののうち,13で割った余りがjであるものの数

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // input
    string s;
    cin >> s;
    // output
    n = s.size();
    ll res = 0;
    dp[0][0] = 1;
    // sの文字目に関して
    rep(i, n)
    {
        int c;
        if (s[i] == '?') {
            c = -1;
        } else {
            c = s[i] - '0';
        }
        rep(j, 10) {
            // s[i]が'?'のときはjが全てのときでdp
            // s[i]が数字の時はjが数字のときのみdp
            if (c != -1 && c != j) {
                continue;
            }
            // 次の文字に関して
            rep(k, 13) {
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
            }
        }
        // MODを取る
        rep(j, 13) {
            dp[i + 1][j] %= MOD;
        }
    }
    // あまりが5となる,最後の文字の位置が答え
    res = dp[n][5];

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 10704
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    rep(i,n){
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    int64_t sum=0;
    if(n-k>=0){
    rep(i,n-k){
        sum += h[i];
    }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		param.set(0, param.get(0).substring(0,param.get(0).length()-1));
		int count = 0;
		int maxi = 0;
		int memo = 0;
		int memoJ = 99999999;
		boolean memoF = false;


		for(int i = 0; i < param.get(0).length(); i++){
			for(int j = i+1; j < param.get(0).length(); j++){
				//System.out.println(i +" " + param.get(0).charAt(i) + " " + j + " " +param.get(0).charAt(j));
				if(param.get(0).charAt(i) == param.get(0).charAt(j) && i < memoJ){
					if(!memoF){
						memo = i;
						memoJ = j;
						memoF = true;
					}
					i++;
					count++;
				} else {
					if(maxi < count && j - count == i) maxi = count;
					count = 0;
					if(memoF){
						i = memo;
						j = memoJ;
					}
					memoF = false;
				}
				if(i == param.get(0).length()-1 && memoF){
					i = memo;
					j = memoJ;
					memoF = false;
				}
			}
		}
		System.out.println(maxi*2);
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(){
	int map[10][10],ink,x,y,max=0,count=0;
	int dx[] = { 0, 0,-1, 1,-1,-1, 1, 1, 0, 0,-2, 2};
	int dy[] = {-1, 1, 0, 0,-1, 1,-1, 1,-2, 2, 0, 0};

	for(int i=0 ; i<10 ; i++){
		for(int j=0 ; j<10 ; j++){
			map[i][j] = 0;
		}
	}
	while( scanf("%d,%d,%d", &x, &y, &ink) != EOF ){
		map[y][x]++;
		for(int i=0 ; i<ink*4 ; i++){
			int mx = x + dx[i];
			int my = y + dy[i];
			if(mx>=0 && mx<10 && my>=0 && my<10){
				map[my][mx]++;
			}
		}
	}
	for(int y=0 ; y<10 ; y++){
		for(int x=0 ; x<10 ; x++){
			if(map[y][x]==0){
				count++;
			}
			if(map[y][x]>max){
				max = map[y][x];
			}
		}
	}
	printf("%d\n%d\n", count , max);
}

Measured memory_bytes: 1028
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,a,M=0,b[100010]={0};
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a;
    b[a]++;
  }
  for(int i=1; i<=100000; i++) {
    M=max(M,b[i-1]+b[i]+b[i+1]);
  }
  cout << M << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define min(a, b) (a > b ? b : a)
#define max(a, b) (a > b ? a : b)

int main(){
  int N,K;
  cin >> N >> K;
  long long int res = 0;

  for(int b = K + 1;b <= N;b++){
    int alpha = N / b;
    res += alpha * (b - K) + max(0,N - alpha * b - K + 1);
  }
  if(K == 0){
    res -= N;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    ld N; cin >> N ;
    vector<ld>v(N);
    for(auto& e : v) cin >> e;
    priority_queue<ld,vector<ld>,greater<>>que;
    for(auto e : v) que.push(e);
    while(que.size() > 1){
        auto b = que.top(); que.pop();
        auto c = que.top(); que.pop();
        que.push((b + c) /2);
        
    }
    cout << que.top() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int INF = 1000000000;

//int h[200005][2] = { 0 };

int main(){
	long long a,b;

	cin>> a>>b;

	if (abs(b - a) % 2 == 1)cout << "IMPOSSIBLE" << endl;
	else cout << (a + b) / 2 << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int SQRT_N = 317;
const int MAX_N = SQRT_N*SQRT_N;
int dat[MAX_N] = {};
int bucket_min[SQRT_N] = {};
int lazy_bucket_update[SQRT_N] = {};
bool lazy_flag_update[SQRT_N] = {};

void init() {
	rep(i, 0, MAX_N) {
		dat[i] = INT_MAX;
	}
	rep(k, 0, SQRT_N) {
		bucket_min[k] = INT_MAX;
	}
}

void update(int l, int r, int val) {
	for (int k = 0; k < SQRT_N; k++) {
		int bl = k * SQRT_N, br = (k + 1) * SQRT_N;
		if (r <= bl || br <= l)
			continue;
		if (l <= bl && br <= r) {
			lazy_bucket_update[k] = val;
			lazy_flag_update[k] = true;
			bucket_min[k] = val;
		}
		else {
			if (lazy_flag_update[k]) {
				for (int i = bl; i < br; i++) {
					dat[i] = lazy_bucket_update[k];
				}
				lazy_flag_update[k] = false;
			}
			for (int i = max(l, bl); i < min(r, br); i++) {
				dat[i] = val;
			}
			int mini = dat[bl];
			for (int i = bl; i < br; i++) {
				chmin(mini, dat[i]);
			}
			bucket_min[k] = mini;
		}
	}
}

int find(int l, int r) {
	int mini = INT_MAX;
	for (int k = 0; k < SQRT_N; k++) {
		int bl = k * SQRT_N, br = (k + 1) * SQRT_N;
		if (r <= bl || br <= l)
			continue;
		if (l <= bl && br <= r) {
			chmin(mini, bucket_min[k]);
		}
		else {
			if (lazy_flag_update[k]) {
				for (int i = bl; i < br; i++) {
					dat[i] = lazy_bucket_update[k];
				}
				lazy_flag_update[k] = false;
			}
			for (int i = max(l, bl); i < min(r, br); i++) {
				chmin(mini, dat[i]);
			}
		}
	}
	return mini;
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	init();
	rep(i, 0, q) {
		int c; cin >> c;
		if (c == 0) {
			int s, t, x; cin >> s >> t >> x;
			update(s, t + 1, x);
		}
		else {
			int s, t; cin >> s >> t;
			cout << find(s, t + 1) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var a = new long[N];
            var b = new long[N];
            var c = new long[N];
            for (int i = 0; i < N; i++)
            {
                (a[i], b[i], c[i]) = Read3Longs();
            }

            var dpA = new long[N]; dpA[0] = a[0];
            var dpB = new long[N]; dpB[0] = b[0];
            var dpC = new long[N]; dpC[0] = c[0];
            for (int i = 1; i < N; i++)
            {
                dpA[i] = Math.Max(dpB[i - 1] + a[i], dpC[i - 1] + a[i]);
                dpB[i] = Math.Max(dpC[i - 1] + b[i], dpA[i - 1] + b[i]);
                dpC[i] = Math.Max(dpA[i - 1] + c[i], dpB[i - 1] + c[i]);
            }

            return Math.Max(Math.Max(dpA[N - 1], dpB[N - 1]), dpC[N - 1]);
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 51540
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

N,M,*A = map(int,read().split())

def f(x,y,k):
    if x > y:
        y += M
    if k <= x:
        k += M
    if k <= y:
        return (y-k) + 1
    return y-x

add_X = 0
add_DX = 0
DDX = [0] * M
for x,y in zip(A,A[1:]):
    x -= 1
    y -= 1
    a = f(x,y,M-2)
    b = f(x,y,M-1)
    add_X += b
    add_DX += b-a
    d = y - x
    if d < 0:
        d += M
    DDX[(y+1)%M] += d
    DDX[(y+2)%M] -= (d-1)
    DDX[(x+2)%M] -= 1

DX = [add_DX + y for y in itertools.accumulate(DDX)]
X = [add_X + y for y in itertools.accumulate(DX)]

answer = min(X)
print(answer)

Measured memory_bytes: 17616
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

x = ni()

t = 1
i = 1
while t < x:
    i += 1
    t += i

print(i)

Measured memory_bytes: 3064
from decimal import *

class UnionFind():
    # 初めは全ての頂点が別々の木の根
    def __init__(self, n):  # n要素で初期化
        self.parent = list(range(n)) # 親
        self.rank = [0] * n   # 木の深さ
        self._nsets = n  # 集合の数

    def root_of(self, x):
        children = [x]
        while self.parent[x] != x:
            x = self.parent[x]
            children.append(x)

        for ch in children:
            self.parent[ch] = x
        return x

    # xとyの属する集合を併合
    def union(self, x, y):
        rx = self.root_of(x)
        ry = self.root_of(y)
        if rx == ry:
            return
        if self.rank[rx] < self.rank[ry]: # ランクの小さい木から大きい木の根に辺を張る
            self.parent[rx] = ry  # rxをryの子とする
        else:
            self.parent[ry] = rx
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1
        self._nsets -= 1

    # 同じ集合に属するかどうか
    def same(self, x, y):
        return self.root_of(x) == self.root_of(y)

    # 集合の数
    def get_nsets(self):
        return self._nsets

while True:
    N = int(input())
    if N == 0: break
    x = [None] * N;  y = [None] * N;  z = [None] * N
    r = [None] * N
    for i in range(N):
        x[i], y[i], z[i], r[i] = [Decimal(a) for a in input().split()]

    E = []
    uf = UnionFind(N)
    for i in range(N):
        for j in range(i + 1, N):
            dsq = pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2) + pow(z[i] - z[j], 2)
            rsq = pow(r[i] + r[j], 2)
            if dsq <= rsq:
                uf.union(i, j)
            else:
                E.append((dsq.sqrt() - r[i] - r[j], (i, j)))

    E.sort()
    ans = Decimal('0')
    for d, (i, j) in E:
        if uf.get_nsets() == 1:  break
        if uf.same(i, j): continue
        uf.union(i, j)
        ans += d

    ans = ans.quantize(Decimal('0.001'), rounding = ROUND_HALF_UP)
    print(ans)


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


int main(void){
	long L,R;
	cin>>L>>R;

	if(R - L >= 2019){
		cout<<0<<endl;
		return 0;
	}

	vector<long> nums;


	long mini = 2020;
	for(long i=L;i<= R;i++){
		for(long j=i + 1;j<= R;j++){
			long tmp = ( i * j ) % 2019;
			if(tmp < mini){
				mini = tmp;
			}

			if(mini == 0){
				cout<<0<<endl;
				return 0;
			}

		}
	}

	cout<<mini<<endl;	

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

bool is_contain(vector<int> &a, map<int, bool> &b)
{
    for (auto x : a)
    {
        if (b[x] == false)
        {
            return false;
        }
    }
    return true;
}

int main(int argc, char const *argv[])
{
    while (true)
    {
        int n;
        cin >> n;
        if (n == 0)
            break;
        map<int, bool> info[n];
        rep(i, n)
        {
            map<int, bool> mp;
            int t;
            cin >> t;
            rep(j, t)
            {
                int p;
                cin >> p;
                mp[p] = true;
            }
            info[i] = mp;
        }

        int t;
        cin >> t;
        vector<int> leak(t, 0);
        rep(i, t)
        {
            cin >> leak[i];
        }
        int ans = -1;
        rep(i, n)
        {
            if (is_contain(leak, info[i]))
            {
                if (ans == -1)
                {
                    ans = i + 1;
                }
                else
                {
                    ans = -1;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3488
from bisect import bisect_right

s = list(input())
t = list(input())

#s上で各アルファベットがどの位置にあるか
pos_in_s = {}
for i in range(len(s)):
  c = s[i]
  if c not in pos_in_s:
    pos_in_s[c] = []
  pos_in_s[c].append(i)

#t上でどの文字が何回使われているか
pos = -1
rep = 0
#count_on_t = {}
for c in t:
  #文字がなければ終わり
  if c not in pos_in_s:
    pos = -1
    break
    
  #bin search
  right = bisect_right(pos_in_s[c], pos)
  if right == len(pos_in_s[c]):
    pos = pos_in_s[c][0]
    rep += 1
  else:
    pos = pos_in_s[c][right]
    
#print(rep, pos, rep * len(s) + pos + 1)
if pos == -1:
   print(-1)
else:
  print(rep * len(s) + pos + 1)

Measured memory_bytes: 8928
#pragma GCC optimize "O3"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define POP pop_back
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define F first
#define S second
#define X real()
#define Y imag()
#ifndef LOCAL
    #define endl "\n"
#endif

using namespace std;
using namespace chrono;
using namespace __gnu_pbds;

typedef pair<int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef long long C;
typedef complex<C> P;

const int INF = 1e9;
const long long LLINF = 1e18;
const double PI = 3.14159265358979323;
const long long PRIME = (1ll << 31) - 1;
const long long PRIME2 = 269;
const long long MOD = 1e9 + 7;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T, class U> using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> using hash_set = gp_hash_table<T, null_type>;
template <class T, class U> using hash_map = gp_hash_table<T, U>;
template <class T, class U> ostream& operator<< (ostream &out, pair<T, U> p) { return out << "(" << p.F << ", " << p.S << ")"; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T, class U> ostream& operator<< (ostream &out, map<T, U> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, ordered_set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T, class U> ostream& operator<< (ostream &out, ordered_map<T, U> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, hash_set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T, class U> ostream& operator<< (ostream &out, hash_map<T, U> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> int sign (T x) { return (x > 0) - (x < 0); }
inline ll mod (ll a, ll b) { return a%b + (a < 0) * b; }
inline ll mod (ll a) { return mod(a, MOD); }
C dot (P a, P b) { return a.X * b.X + a.Y * b.Y; }
C cross (P a, P b) { return a.X * b.Y - b.X * a.Y; }

double startTime;
double currTime() { return duration_cast<nanoseconds>(system_clock::now().time_since_epoch()).count() / 1e9; }
double execTime() { return currTime() - startTime; }

int main() {
#ifndef LOCAL
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#endif
    srand(time(0));
    startTime = currTime();

    int n;
    cin >> n;
    cout << n*n << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

long a, b, n;

int main(){
    scanf("%ld %ld %ld", &a, &b, &n);

    long x, ans;
    if (n>=b){
        x = b-1;
    }
    else{
        x = n;
    }
    
    ans = floor(a*x/b) - a*floor(x/b);
    printf("%ld\n", ans);

    return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#define l(u) (u<<1)
#define r(u) (u<<1|1)
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define root 1, n, 1
#define BUG puts("I am bug")
#define XY(x, y) printf("(%d %d)\n", x, y)
typedef long long ll;
using namespace std;

int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
const int MAXN = 1010;


int main() {
    ios_base::sync_with_stdio(0);
    ll a, b;
    while (cin >> a >> b)
    {
        ll ans1 = __gcd(a, b);
        ll ans2 = a * b / ans1;
        cout << ans1 << ' ' << ans2 << '\n';
    }
    return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
        cout << "Possible";
    else
        cout << "Impossible";

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
using ll = long long;
#define max(a,b) ((a)>(b) ? (a):(b))
#define min(a,b) ((a)<=(b) ? (a):(b))
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

int main(){
  ll N,K,S;
  cin >> N >> K >> S;
  vector<ll> A(N);
  ll i;
  rep(i,K){
    A[i] = S;
  }
  rep(i,N-K){
    if(S > pow(10,5))
      A[K+i] = 1;
    else
      A[K+i] = S+1;
  }
  cout << A[0];
  rep(i,N-1) cout << " " << A[i+1];
  return 0;
}


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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define fill(a,p) memset(a,p,sizeof(a))
#define pb push_back
#define mod 1000000007
#define N 200005
#define all(a) a.begin(),a.end()
#define point pair<ll,ll>
#define endl "\n"

const int inf = 1000000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM =2005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll minim(ll a, ll b){return a<b?a:b;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

ll power(ll x, ll y,ll p) 
{ 
    ll res = 1;      
     x = x % p;    
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
            y = y>>1;  
            x = (x*x) % p;   
    } 
    return res; 
}

ll modInverse(ll n,ll p) 
{ 
    return power(n, p-2, p); 
} 


ll lcm(ll a,ll b){
  return (a*b)/__gcd(a,b);
}

bool comp(const point &p1,const point &p2){
	if(p1.first!=p2.first)return p1.first<p2.first;
	else return p1.second<p2.second;
}

int main()
{
	fio;
	ll n;cin>>n;
	vl a(n);
	f(n)cin>>a[i];
	vl dp(n+1);
	dp[0]=0;dp[1]=abs(a[1]-a[0]);
	for(ll i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
<?php
  $n = trim(fgets(STDIN));
  $h = explode(" ",trim(fgets(STDIN)));
  $total_move=0;
  $move = 0;
  for($i=0; $i<$n-1; $i++){
    if($h[$i] >= $h[$i+1]){
      $move++;
    }else{
      $move = 0;
    }
    $total_move = max($move,$total_move);
  }
  echo $total_move."\n";

Measured memory_bytes: 14840
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (size_t i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
#define vec2d(T, v, m, n) vector<vector<T>> (v)(m, vector<T>(n))
#define nvec2d(T, v, m, n) vec2d(T, v, m, n); REP(j, m){REP(i, n) {cin>>(v[j])[i];}}

#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))
#define P 1000000007
long powP (long a, long b) {
  if (b == 1) return a;
  else if (b == 0) return 1;
  else if (b < 0) return powP(a, P + b - 1);
  else return (powP(a, b/2) * powP(a, b/2 + b%2)) % P;
}

#define GCD(v) gcd(ALL(v), 0l)

/*template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}*/

template <typename T>
using vec = vector<T>;

template <typename T>
using vvec = vector<vector<T>>;


int main() {
  long long n; int x,m; cin>>n>>x>>m;
  vec<long> a(1,x);
  a.reserve(m);
  while (find(ALL(a),a.back())==a.end()-1) {
    a.push_back( (a.back()*a.back())%m );
  }
  int mae_len=find(ALL(a),a.back())-a.begin();
  long long loop_len=a.size()-mae_len-1;
  long long mae_sum=acm(a.begin(),a.begin()+mae_len,0l);
  long long loop_sum=acm(a.begin()+mae_len,a.end()-1,0l);
  if(n<=mae_len){
    cout<<acm(a.begin(), a.begin()+n, 0l);
  } else {
    n-=mae_len;
    long long ans = mae_sum;
    ans += loop_sum*(n/loop_len);
    ans += acm(a.begin()+mae_len,a.begin()+mae_len+n%loop_len,0l);
    cout<<ans;
  }
  
  
}


/* きょむ〜 */


Measured memory_bytes: 3788
n = int(input())

rgb = input()

r = rgb.count("R")
g = rgb.count("G")
b = rgb.count("B")

ans = r * g * b

for i in range(n):
    for k in range(n):
        a = i + k
        b = a + k
        if b >= n:break
        if rgb[i] != rgb[a] and rgb[i] != rgb[b] and rgb[a] != rgb[b]:
            ans -= 1 
print(ans)

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n,a,b;
    cin >> n >> a >> b;
    cout << min(n*a,b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
struct Graph{
  Graph(int n):E(n),d(n){}
  vector<vector<P>>E;
  vector<int>d;
  void add_edge(int a,int b,int c){
    E[a].push_back({b,c});
  }
  void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>>q;
    fill(d.begin(),d.end(),1e9);
    q.push({d[s]=0,s});
    while(q.size()){
      P p=q.top();q.pop();
      if(p.first>d[p.second])continue;
      for(P& a:E[p.second]){
        int x=a.first,y=a.second+p.first;
        if(y<d[x])d[x]=y,q.push({y,x});
      }
    }
  }
};
main(){
  int n,a,b,c,x=0,y,z=1e9,g;
  while(cin>>n,n){
    Graph E(10);
    x=0,z=1e9;
    for(int i=0;i++<n;x=max(x,max(a,b)),E.add_edge(a,b,c),E.add_edge(b,a,c))cin>>a>>b>>c;
    for(int i=0;i<=x;++i){
      E.dijkstra(i);
      y=0;
      for(int j=0;j<=x;++j)y+=E.d[j];
      if(y<z)z=y,g=i;
    }
    cout<<g<<' '<<z<<endl;
  }
}

Measured memory_bytes: 2976
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n;i>0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
//namespace mp = boost::multiprecision;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    int a[26]={0};
    string s,ans="Yes";
    cin>>s;
    for(char c:s) a[c-'a']++;
    for(int i:a) if(i%2) ans="No";
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
N=int(input())
s=list(map(int,input().split()))
s.insert(0,0)
s.append(0)
ans=0
for k in range(N+1):
    ans+=abs(s[k]-s[k+1])
for i in range(N):
    a,b,c=s[i]-s[i+1],s[i+1]-s[i+2],s[i]-s[i+2]
    if a*b>=0:
        print(ans)
    else:
        print(ans-abs(a)-abs(b)+abs(c))
        
    

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

using namespace std;

int main()
{
    set <int> m;
    int q;
    cin>>q;
    while(q--)
    {
        int a;
        cin>>a;
        if(a==0)
        {
            int x;
            cin>>x;
            m.emplace(x);
            cout<<m.size()<<endl;
        }
        else if(a==1)
        {
            int x;
            cin>>x;
            cout<<m.count(x)<<endl;
        }
        else
        {
            int x;
            cin>>x;
            m.erase(x);
        }
    }
    return 0;
}



Measured memory_bytes: 12456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/*Atcoder用
 * 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int a = Integer.parseInt(tmp[0]);
		int b = Integer.parseInt(tmp[1]);
		int c = Integer.parseInt(tmp[2]);


		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String get = br.readLine();
		char[] s = get.toCharArray();
		for(char c:s)System.out.println(c);

		List<Integer> ls = new ArrayList<Integer>();
		String[] tmp = br.readLine().split(" ");
		for (int n = 0; n < N; n++) {
			ls.add(Integer.parseInt(tmp[n]));
		}
 */

public class Main {

	public static void main(String[] args) throws IOException {
 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String num = br.readLine();
		int N = Integer.parseInt(num);
		String get = br.readLine();
		char[] S = get.toCharArray();

		List<Integer> whiteNum = new ArrayList<Integer>();
		List<Integer> blackNum = new ArrayList<Integer>();

		//TODO: testCase 1 # でバグ
		//		おそらくマスの目まで計算している

		int count = 0;
		for(int i = 0;i<S.length;i++){
			if(S[i] == '.')count++;
			whiteNum.add(count);

		}
		count = 0;
		int memory = 0;
		for(int i = 0;i<S.length;i++){
			if(S[i] == '#')memory++;
			blackNum.add(count);
			count = memory;
		}

		int min = (int) Math.pow(10,10);
		for(int j = 0;j<S.length;j++){
			count = blackNum.get(j) + (whiteNum.get(S.length-1) - whiteNum.get(j));
			min = Math.min(min, count);
		}

		System.out.println(min);

	}

}


Measured memory_bytes: 40860
#include<stdio.h>
int main() {
	int n,m,pi,xi,i,j,sum;
	int a1[110];
	scanf("%d",&n);
	for(i=1;i<=n;i++) {
		scanf("%d",&a1[i]);
	}
	scanf("%d",&m);
	for(i=1;i<=m;i++) {
		sum=0;
		scanf("%d%d",&pi,&xi);
		for(j=1;j<=n;j++) {
			if(j!=pi) sum+=a1[j];
		}
		sum+=xi;
		printf("%d\n",sum);
	}
}

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

int main() {
    long long N,M;
    cin >> N >> M;
    if(N==1 || M==1){
        if(N==M) cout << 1 << endl;
        else cout << max(N*M-2,(long long)0) << endl;
    }else if(N==2 || M==2){
        cout << 0 << endl;
    }else{
        cout << (N-2)*(M-2) << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
const int N = 1010;
char M[N][N];
bool mark[N][N];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sx, sy;
int total = 1;

void clear(queue<pair<int, int> > &q) {
    queue<pair<int, int> > empty;
    swap(empty, q);
}

void solve(int row, int col, int n) {
    memset(mark, 0, sizeof(mark));
    queue<pair<int, int> > que;
    que.push(pair<int, int>(sx, sy));
    int count = 1;
    while(que.size()) {
        int size = que.size();
        for(int k = 0; k < size; k++) {
            int nx = que.front().first;
            int ny = que.front().second;
            que.pop();
            for(int i = 0;i < 4; i++) {
                int x = nx + dx[i];
                int y = ny + dy[i];
                if(0 <= x && x < row && 0 <= y && y < col && M[x][y] != 'X' && !mark[x][y]) {
                    que.push(pair<int, int>(x, y));
                    mark[x][y] = true;
                    if(M[x][y] != '.' && M[x][y] - '0' == count) {
                        memset(mark, 0, sizeof(mark));
                        M[x][y] = '.';
                        count += 1;
                        if(count > n) {
                            printf("%d\n", total);
                            return ;
                        }
                        k = size;
                        clear(que);
                        que.push(pair<int, int>(x, y));
                        break;
                    }
                }
            }    
        }
        total += 1;
    }
    
}

int main() {
    int row, col, n;
    scanf("%d%d%d", &row, &col, &n);
    for(int i = 0; i < row; i++) {
        scanf("%s", M[i]);
        for(int j = 0; j < col; j++) {
            if(M[i][j] == 'S') {
                sx = i;
                sy = j;
            }
        }
    }
    solve(row, col, n);
}


Measured memory_bytes: 4700
{-# LANGUAGE BangPatterns #-}

import           Control.Monad
import           Data.Array.ST
import           Data.Array.Unboxed    (UArray)
import qualified Data.Array.Unboxed    as U
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List

getAsInt :: IO [Int]
getAsInt =  unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getAsIntLine :: Int -> IO [[Int]]
getAsIntLine n = replicateM n getAsInt

getAsIntArray2D :: Int -> Int -> IO (UArray (Int,Int) Int)
getAsIntArray2D n m = U.listArray ((1,1),(n,m)) . concat <$> getAsIntLine n


main :: IO ()
main = main2

main1 :: IO ()
main1 = do
  [n,w] <- getAsInt
  wvs <- getAsIntArray2D n 2
  let result = solve1 wvs n w
  print $ maximum $ map (\x -> result U.! (n,x)) [0..w]

main2 :: IO ()
main2 = do
  [n,w] <- getAsInt
  wvs <- map (\[x,y] -> (x, y)) <$> getAsIntLine n
  let solve = solve3
      result = solve w wvs
  print $ maximum $ map (\x -> result U.! x) [0..w]

solve1 :: UArray (Int,Int) Int -> Int -> Int -> UArray (Int,Int) Int
solve1 wvs n' w' = runSTUArray $ do
  dp <- newArray ((0,0),(n',w')) 0
  forM_ [(n_,w_) | n_ <- [1..n'], w_ <- [0..w']] $ \(n,w) -> do
    let wtmp = wvs U.! (n,1)
        vtmp = wvs U.! (n,2)
    if w - wtmp < 0
      then readArray dp (n-1,w) >>= writeArray dp (n,w)
      else do
        a <- readArray dp (n-1,w)
        b <- readArray dp (n-1,w-wtmp)
        writeArray dp (n,w) $ max a (b+vtmp)
  return dp

solve2 :: Int -> [(Int,Int)] -> UArray Int Int
solve2 w' [] = U.listArray (0,w') $ repeat 0
solve2 w' ((wtmp,vtmp):xs) = let a = solve2 w' xs
                                 f w = if w - wtmp >= 0
                                       then max (a U.! w) (a U.! (w - wtmp) + vtmp)
                                       else a U.! w
                             in U.array (0,w') [(w, f w) | w <- [0..w']]

solve3 :: Int -> [(Int,Int)] -> UArray Int Int
solve3 !w' = foldr f (U.listArray (0,w') $ repeat 0)
  where f (!wtmp,!vtmp) !a = let g !w = if w - wtmp >= 0
                                        then max (a U.! w) (a U.! (w - wtmp) + vtmp)
                                        else a U.! w
                          in U.array (0,w') [(w, g w) | !w <- [0..w']]


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


void print_sharp(){
    cout<<"####################"<<endl;
}

void print(ll building[3][10]){
    rep(i,3){
        rep(j,10) cout<<" "<<building[i][j];
        cout<<endl;
    }
}

int main(){
    cout<<fixed<<setprecision(10);

    ll n;cin>>n;
    
    ll cnt[4][3][10];
    rep(i,4)rep(j,3)rep(k,10)cnt[i][j][k] = 0;
    
    while(n){
        ll b,f,r,v;
        cin>>b>>f>>r>>v;
        b--;f--;r--;
        
        cnt[b][f][r] += v;
        
        
        --n;
    }
    
    rep(i,3){
        print(cnt[i]);
        print_sharp();
    }
    
    print(cnt[3]);

    

    return 0;
}







Measured memory_bytes: 3080
h,w=map(int,input().split())
s=[list("."*(w+2))]
for _ in range(h):
    s+=[list("."+input()+".")]
s+=[list("."*(w+2))]
ans=[list("#"*w) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i+1][j+1]!="#":
            c=0
            for k in range(3):
                for l in range(3):
                    if s[i+k][j+l]=="#":
                        c+=1
            ans[i][j]=str(c)
for m in range(h):
    answer=""
    answer=''.join(ans[m])
    print(answer)

Measured memory_bytes: 3188
from collections import deque

n, q = map(int, input().split())
nt = [list(input().split()) for _ in range(n)];
que = deque(nt)
time = 0

while len(que)>0:
  a = que.popleft()
  if int(a[1]) > q:
    que.append([a[0], int(a[1])-q])
    time += q
  else:
    time += int(a[1])
    print(a[0], time)


Measured memory_bytes: 16268
#include<iostream>
using namespace std;
int main()
{
	int n,s=0,a;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		if(a!=i)
		s++;
	}
	if(s<=2) cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 256