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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vi lnum;
typedef long double ld;

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define code first
#define index second

const ll MOD9 = 1e9+7;
const ll mod = 2 * (1000 * 1000 * 1000 + 7);
const int MOD91 = 1e9+9;
const ll MOD12 = 1e12+39LL;
const ll MOD15 = 1e15+37LL;
const ll INF = 1000 * 1000 * 1000;
const ll LINF = 1000LL*1000*1000*1000 * 1000 * 1000;
const int base = 1e9;
const int MAX = 2e5;
const double EPS = 1e-10;
const double EPS2 = 1e-9;
int n;
int sum(int x)
{
	int ans = 0;
	while(x)
	{
		ans += x % 10;
		x /= 10;
	}
	return ans;
}
int main()
{
	cin >> n;
	int digitSum = INF;
	for(int a = 1; a < n; a++)
	{
		digitSum = min(digitSum , sum(a) + sum(n - a));
	}
	cout << digitSum;
	return 0;
}





Measured memory_bytes: 256
using System;
 
namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' '); 
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
 
            Console.WriteLine(b % a == 0 ? a + b : b - a);
        }      
    }
}

Measured memory_bytes: 11092
import sys
import math

a,b,h,m= map(int,input().split())

kak1 = float(h * 30 + m * 0.5)
kak2 = m * 6

kaku = kak1 -kak2 if kak1 < kak2 else kak2 - kak1
result = a * a + b * b - 2 * a * b * math.cos(kaku * math.pi / 180)
print(math.sqrt(result))

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

[A,B] = inpl()
print((B-1)//(A-1)+((B-1)%(A-1)>0))

Measured memory_bytes: 12456
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  
  cin >> a >> b >> c >> d;
  
  int left = a + b;
  int right = c + d;
  if (left > right) {
  	cout << "Left" << endl;
  } else if (left < right) {
  	cout << "Right" << endl;
  } else {
  	cout << "Balanced" << endl;
  }
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N), F, B;
    rep(i, N) cin >> A[i];
    F.push_back(A.front());
    iter(i, A) F.push_back(__gcd(F.back(), i));
    reverse(A.begin(), A.end());
    B.push_back(A.front());
    iter(i, A) B.push_back(__gcd(B.back(), i));
    ll ans = 0;
    rep(i, N) {
        ll temp;
        if(i == 0) temp = B[N - 1];
        else if(i == N - 1) temp = F[N - 1];
        else temp = __gcd(F[i], B[N - i - 1]);
        ans = max(ans, temp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6348
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
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; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
ll n;
vector<ll> t;
vector<ll> a(20000), b(20000);
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        temp--;
        t.push_back(temp);
    }
    a[t[0]]=0;
    b[t[0]]=0;
    ll base=t[0];
    for(ll i=1;i<n;i++){
        ll now=t[i];
        a[now]=i+n*(now-base);
        b[now]=i+n*(base-now);
    }
    ll temp=a[0];
    for(int i=0;i<n;i++){
        a[i]-=temp;
        a[i]++;
    }
    temp=b[n-1];
    for(int i=0;i<n;i++){
        b[i]-=temp;
        b[i]++;
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
    for(int i=0;i<n;i++){
        cout<<b[i]<<" ";
    }
    cout<<"\n";
}



Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

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

  vector<int> bin;
  if (N == 0) {
    bin.pb(0);
  }
  while (N) {
    int temp = N % (-2);
    if (temp == -1) {
      bin.pb(1);
      N = N / (-2) + 1;
    } else {
      bin.pb(temp);
      N /= (-2);
    }
  }
  reverse(all(bin));
  rep(i, bin.size()) { cout << bin[i]; }

  cout << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    #h0,w0h1,w1 = map(int, input().split())
    s=input()
    ans=""
    for c in s:
        oc=ord(c)
        if c.isupper():
            ans+=c.lower()
        elif c.islower():
            ans+=c.upper()
        else:
            ans+=c
    print(ans)

main()



Measured memory_bytes: 5568
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
#pragma endregion

int main() {
  cin >> A >> B >> C;
  cout << C << " " << A << " " << B;
} 



Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        x: i64,
        aa: [i64; n],
    }

    let mut ans = 0;

    let mut x = x;
    let mut aa = aa;
    aa.sort();

    for a in aa.into_iter() {
        if x >= a {
            x -= a;
            ans += 1;
        }
    }

    if ans == n && x > 0 {
        ans -= 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
import sys
import re
import math
import collections

import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

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


# ===CODE===


def main():
    n = ni()
    l = 10 ** 5 + 1

    items = [1]
    for i in range(10 ** 3):
        tmp6 = 6 ** i
        if tmp6 < l:
            items.append(tmp6)

        tmp9 = 9 ** i
        if tmp9 < l:
            items.append(tmp9)

    s = {0}
    for i in range(l):
        next_s = set()
        for ts in s:
            for d in items:
                if ts+d <= n:
                    next_s.add(ts+d)
        if n in next_s:
            print(i+1)
            break
        s = next_s


if __name__ == '__main__':
    main()


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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



void func(std::string S, std::string T){

    lli cnt=0;
    REP(i,0,S.size()){
        if(S[i]!=T[i])cnt++;
    }

    cout<<cnt<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    func(S, T);
    return 0;
}


Measured memory_bytes: 4064
/*package whatever //do not write package name here */

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next(), t = sc.next();
		int n = s.length(), m = t.length();
		int[][] dp = new int[n+1][m+1];
		for(int i=1;i<=n;i++){
		    for(int j=1;j<=m;j++){
		        if(s.charAt(i-1)==t.charAt(j-1)){
		            dp[i][j] = dp[i-1][j-1] + 1;
		        }
		        else{
		            dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
		        }
		    }
		}
		StringBuilder s1 = new StringBuilder("");
		int len = dp[n][m];
		int i = n, j = m;
		while(i>0 && j>0){
		    if(s.charAt(i-1)==t.charAt(j-1)){
		        s1.append(s.charAt(i-1));
		        i--;
		        j--;
		    }
		    else if(dp[i-1][j]>dp[i][j-1]){
		        i--;
		    }
		    else{
		        j--;
		    }
		}
		System.out.println(s1.reverse());
	}
}

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

int n,m;
double x[1000],y[1000],z[1000];
double tx,ty,tz,ar;

double dot(double ax,double ay,double az,
           double bx,double by,double bz){
  return ax*bx+ay*by+az*bz;
}

int calc(double sx,double sy,double sz){
  double S=sqrt(sx*sx+sy*sy+sz*sz);
  double T=sqrt(tx*tx+ty*ty+tz*tz);
  double Cos = dot(tx,ty,tz,sx,sy,sz)/T/S;
  double ti=acos(Cos);

  if(ti < ar + 0.00000001 ){
    return 1;
  }else{
    return 0;
  }
}
bool flg[1000];
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      flg[i]=false;
      cin>>x[i]>>y[i]>>z[i];
    }
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>tx>>ty>>tz>>ar;
      for(int j=0;j<n;j++){
        if(calc(x[j],y[j],z[j]))flg[j]=true;
      }
    }
    int ans=0;
    for(int i=0;i<n;i++)ans+=flg[i];
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(){

	
	while(1){
	int n,i;
	double s[1001]={},m=0.0,a=0.0;
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%lf",&s[i]);
			m +=s[i];
		}
		m /=n;
		for(i=0;i<n;i++){
			a += pow(s[i]-m,2);
		}
		a = sqrt( a/(1.0*n));
		printf("%f\n",a);
	}
	return 0;
}

Measured memory_bytes: 664
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9+1;
const int MOD = 2e9 + 9;
const ll LINF = 1e18;
using namespace std;

int main(){
	int n, x;
	int ans = 0;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		if (x >= a.at(i)) {
			ans++;
			x -= a.at(i);
		}
		
	}
	if (x > 0&&ans==n)ans--;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
using System;

namespace ITP1_5_C {
    class Program {
        static void Main(string[] args) {
            while(true) {
                string[] s = Console.ReadLine().Split(' ');
                int H = int.Parse(s[0]), W = int.Parse(s[1]);
                if(H == 0 && W == 0) break;
                string a = "";
                for(int i = 0; i < H; i++) {
                    for(int j = 0; j < W; j++) {
                        if(i == 0 || i % 2 == 0) {
                            if(j == 0 || j % 2 == 0) {
                                a = a.Insert(a.Length, "#");
                            } else {
                                a = a.Insert(a.Length, ".");
                            }
                        } else {
                            if(j == 0 || j % 2 == 0) {
                                a = a.Insert(a.Length, ".");
                            } else {                               
                                a = a.Insert(a.Length, "#");
                            }
                        }                       
                    }
                    Console.WriteLine(a);
                    a = "";
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9192
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
    int n;
    cin>>n;
    int d=n-1,t=2,cnt=0;
    while(t<=d){
        cnt+=d/t;
        t*=2;
    }
    string s;
    cin>>s;
    V<int> a(n);
    bool c=false;
    for(int i=0;i<n;i++){
        a[i]=int(s[i]-'1');
        if(a[i]==1)c=true;
    }
    if(!c)for(int i=0;i<n;i++)a[i]/=2;
    int ans=0;
    for(int i=0;i<n;i++){
        if(a[i]!=1)continue;
        d=i;t=2;int cn=0;
        while(t<=d){
        cn+=d/t;
        t*=2;
    }
    d=(n-i-1);t=2;
    while(t<=d){
        cn+=d/t;
        t*=2;
    }
    if(cn==cnt)ans^=1;
    }
    if(!c)cout<<(ans?2:0)<<"\n";
    else cout<<ans<<"\n";
}


Measured memory_bytes: 5276
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  vector<int> dp(n, INT_MAX);
  dp[0] = 0;
  for (int i = 0; i < n - 1; ++i) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
    if (i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
  }

  cout << dp[n - 1] << endl;

  return 0;
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (ll& x : v) {
        cin >> x;
    }
    vector<ll> r1 = v;
    for (ll i = 1; i < n; i++) {
        r1[i] = r1[i-1] + r1[i];
        // printf("r1[%d] = %d + %d\n", i, r1[i-1], r1[i]);
    }
    vector<ll> r2 = v;
    for (ll i = n-2; i >= 0; i--) {
        r2[i] = r2[i+1] + r2[i];
    }

    // for (int i = 0; i < n; i++) {
    //     cout << r1[i] << " ";
    // } cout << endl;

    ll Min = abs(r1[0] - r2[1]);
    for (int i = 0; i < n-1; i++) {
        Min = min(Min, abs(r1[i] - r2[i+1]));
    }

    cout << Min << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main(void) {
	int w,n, a[30][2],i,c,no,rs[30];
	
	scanf("%d%d",&w,&n);
	for(i = 0; n > i; i++){
		scanf("%d",&a[i][0]);
		getchar();
		scanf("%d",&a[i][1]);
	}
	
	for(i = 1; w >= i; i++){
		no = i;
		for(c = 0; n > c; c++){
			if(a[c][0] == no) no = a[c][1];
			else if(a[c][1] == no) no = a[c][0];
		}
		rs[no-1] = i;
	}
	for(i = 0; w > i; i++){
		printf("%d\n",rs[i]);
	}
	
	return 0;
}

Measured memory_bytes: 1028
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

sum = 0
for i in range(N):
  if A[i] >= B[i]:
    sum += B[i]
  elif A[i] < B[i]:
    sum += A[i]
    C = B[i] - A[i]
    if A[i+1] >= C:
      sum += C
      A[i+1] = A[i+1] - C
    elif A[i+1] < C:
      sum += A[i+1]
      A[i+1] = 0

print(sum)

Measured memory_bytes: 18476
/*input
6
0 153 10 10 23
*/

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main() {
    ll n;
    cin >> n;
    vector<ll> b(n-1);
    for (int i = 0; i < n-1; i++) {
        cin >> b[i];
    }
    ll ans = b[0];
    for (int i = 1; i < n-1; i++) {
        ans += min(b[i], b[i-1]);
    }
    ans += b[n-2];
    cout << ans <<endl;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	int N, D; cin >> N >> D;
	int X[11][11];
	REP(i,N){
		REP(j,D){
			cin >> X[i][j];
		}
	}

	int ans = 0;
	REP(i,N-1){
		FOR(j, i+1, N){
			double x = 0.0;
			REP(k,D){
				x += pow(abs(X[i][k]-X[j][k]), 2);
			}
			x = sqrt(x);
			if(floor(x) == ceil(x)) ans++;
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
import itertools

n = int(input())
lst = list(map(int, input().split()))

accum_xor = [0]
s = 0
for i in lst:
    s = s ^ i
    accum_xor.append(s)

accum_lst = list(itertools.accumulate(lst))
accum_lst.insert(0, 0)

s = 0
e = 0
count = 0
while s <= n-1:
    flg = False
    if accum_xor[e+1] ^ accum_xor[s] == accum_lst[e+1] - accum_lst[s]:
        e += 1
        if e >= n:
            break
    else:
        flg = True
    if flg:
        count += (e-1) - s + 1
        s += 1
        
if e == n:
    for i in range(s, n):
        count += (n-1)-i+1

print(count)

Measured memory_bytes: 88136
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
vector<set<in> > cc;
map<in,in> cnt;
VI ttc;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n,m,x;
  cin>>n>>m;
  cc.resize(m);
  ttc.resize(m);
  forn(z,n){
    cin>>x;
    cc[x%m].insert(x);
    ++ttc[x%m];
    ++cnt[x];
  }
  VI bd={0};
  if(m%2==0)
    bd.PB(m/2);
  in sm=0;
  forv(i,bd){
    sm+=ttc[bd[i]]/2;
  }
  for(in i=1;i<(m-i);++i){
    auto a=cc[i].begin();
    auto b=cc[m-i].begin();
    while(a!=cc[i].end() && b!=cc[m-i].end()){
      if(cnt[*a]%2==0){
	++a;
	continue;
      }
      if(cnt[*b]%2==0){
	++b;
	continue;
      }
      ++sm;
      --cnt[*a];
      --cnt[*b];
    }
    in loa=0;
    in lob=0;
    while(a!=cc[i].end()){
      loa+=cnt[*a]%2;
      ++a;
    }
    while(b!=cc[m-i].end()){
      lob+=cnt[*b]%2;
      ++b;
    }
    in ttla=0;
    in ttlb=0;
    fors(it,cc[i])
      ttla+=(cnt[*it]-cnt[*it]%2);
    fors(it,cc[m-i])
      ttlb+=(cnt[*it]-cnt[*it]%2);
    loa-=loa%2;
    lob-=lob%2;
    in c=min(loa,ttlb);
    ttlb-=c;
    sm+=c;
    c=min(lob,ttla);
    ttla-=c;
    sm+=c;
    sm+=ttla/2;
    sm+=ttlb/2;
  }
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define en "\n"
#define ITER(i,a) for( typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define mod 1000000007
#define mpp make_pair
#define mes(a,b) memset((a),(b),sizeof((a))
typedef map<int,int> MI;
typedef pair<int,int>   PI;
typedef vector<int> VI;
typedef long long int LL;

int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long int n;
    cin>>n;
    long int a[n];
    for(long int i=0;i<n;i++)
    cin>>a[i];
    bool d=true;
    long int b[1000001]={0};
    for(long int i=0;i<n;i++)
    {
        for(long int j=2;j<=sqrt(a[i]);j++)
        {
            if(a[i]%j==0)
            {
               b[j]++;  
               if(j*j!=a[i])
               {
                 b[a[i]/j]++;
               }
            }
            
            if(b[j]>=2 || b[a[i]/j]>=2)
            {
                d=false;
                break;
            }
        }
        if(a[i]>1)
        b[a[i]]++;
        if(b[a[i]]>=2)
        {
            d=false;
            break;
        }
    }
    for(long int i=2;i<1000001;i++)
    {
        if(b[i]>=2)
        {
            d=false;
            break;
        }
    }
    if(d==true)
    cout<<"pairwise coprime"<<en;
    else
    {
        long  int g=a[0];
        for(long int i=1;i<n;i++)
        {
            g=__gcd(a[i],g);
           /// cout<<g<<en;
        }
        //cout<<g<<en;
        if(g==1)
        cout<<"setwise coprime"<<en;
        else
        cout<<"not coprime"<<en;
    }
	return 0;
}


Measured memory_bytes: 19280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define N 200010
int n,a[N],b[N],c[N],d[N];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
  cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n+1)c[i]=d[i]=0;
    rep(i,n)c[a[i]]++,d[b[i]]++;
    rep(i,n+1){
	if(c[i]+d[i]>n){
	    cout<<"No\n";
	    return 0;
	}
    }
    for(int i=1;i<=n;i++){
	c[i]+=c[i-1];
	d[i]+=d[i-1];
    }
    int x=0;
    for(int i=1;i<=n;i++)x=max(x,c[i]-d[i-1]);
    cout<<"Yes\n";
    rep(i,n){
	if(i)cout<<" ";
	cout<<b[(i+n-x)%n];
    }
    cout<<"\n";
}


Measured memory_bytes: 6776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n; cin>>n;
    vector<ll> l(n);
    rep(i,n) cin>>l[i];
    sort(l.begin(), l.end());
    ll res=0;
    for(ll i=0; i<n-1; i++){
        for(ll j=i+1; j<n; j++){
            ll tmp=0;
            auto itr = lower_bound(l.begin(), l.end(), l[i]+l[j]);
            tmp =itr-l.begin();
            res+=max(0ll, tmp-j-1);
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

struct UnionFind {
    vector<int> par;

    UnionFind(int n): par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    int issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);

        if (x == y) return false;

        // merge by size
        // force size of x to be bigger than that of y
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;

        return true;
    }

    ll size(int x) {
        return -par[root(x)];
    }
};

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

    int n, m;
    cin >> n >> m;

    vll a(n);
    REP(i, n) cin >> a[i];

    UnionFind uf(n);

    REP(i, m) {
        int x, y;
        cin >> x >> y;
        uf.merge(x, y);
    }

    vector<priority_queue<ll, vector<ll>, greater<>>> vq(n);
    REP(i, n) {
        vq[uf.root(i)].push(a[i]);
    }

    typedef pair<int, pair<ll, int>> P;
    priority_queue<P> q;

    REP(i, n) {
        if (vq[i].empty()) continue;
        q.push({vq[i].size(), {-vq[i].top(), i}});
        vq[i].pop();
    }

    ll ans = 0;
    while (q.size() > 1) {
        auto t1 = q.top(); q.pop();
        auto t2 = q.top(); q.pop();

        ans += -t1.se.fi - t2.se.fi;

        while (!vq[t2.se.se].empty()) {
            vq[t1.se.se].push(vq[t2.se.se].top());
            vq[t2.se.se].pop();
        }

        if (q.empty()) break;

        if (vq[t1.se.se].empty()) {
            print("Impossible");
            return 0;
        }

        q.push({vq[t1.se.se].size(), {-vq[t1.se.se].top(), t1.se.se}});
        vq[t1.se.se].pop();
    }

    print(ans);
}


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

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

  int ans = 1001, c, t;
  for (int i = 0; i < N; i++) {
    cin >> c >> t;
    if (t <= T && c < ans) {
      ans = c;
    }
  }

  if (ans == 1001) {
    cout << "TLE" << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
/*input

*/

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i < b;i++)
#define rrep(i,b,a) for(int i=b ; i > a ; i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define check1(a) cerr << a << endl
#define check2(a,b) cerr << a << "|" << b << endl
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
/*----------------------------------------------*/
int main()
{
	int n;
	cin >> n;
	map<int,int> ma;
	rep(i,0,n){
		int x;
		cin >> x;
		ma[x] ^= 1;
	}
	int s = 0;
	for(auto x:ma){
		s += x.S;
	}
	cout << s;
   return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define mod (int)(1e9 + 7)
#define pb push_back
#define ll long long int
using namespace std;
typedef pair<int,int> pii;

int main(){
  int n;
  cin>>n;
  vector<int> x(n),y(n);
  for(int i=0;i<n;i++) cin>>x[i];
  copy(x.begin(),x.end(),y.begin());
  sort(x.begin(),x.end());

  for(int i=0;i<n;i++){
    float mid=(x[n/2]+x[n/2-1])/2.0;
    if(mid==(float)y[i]){
      cout<<y[i]<<endl;
    }
    else if(mid>(float)y[i]){
      cout<<x[n/2]<<endl;
    }
    else{
      cout<<x[n/2-1]<<endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <map>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <algorithm>



using namespace std;

int A,B,C,a,b,c;
long long Ans=0;

int main()
{
	cin>>A>>B>>C;
	if(A%2||C%2||B%2)
	{
		cout<<0<<'\n';
		return 0;
	}
	if(A==B&&B==C)
	{
		cout<<"-1\n";
		return 0;
	}
	else
	while(A%2==0&&B%2==0&&C%2==0)
	{
		a=(B+C)/2;
		b=(A+C)/2;
		c=(A+C)/2;
		A=a;
		B=b;
		C=c;
		Ans++;
	}
	cout<<Ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> p;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
  int x, y;
  cin >> x >> y;
  int s = x + y;
  if(s % 3) {
    puts("0");
    return 0;
  }
  s /= 3;
  x -= s; y -= s;
  if(x < 0 || y < 0) {
    puts("0");
    return 0;
  }
  combination c(1000000);
  mint ans = c(x + y, x);
  cout << ans << endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
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 (a>b) { a=b; return true; } return false; }

int main(){
    string t;
    cin >> t;
    int n = 0, s = 0, w = 0, e = 0;
    rep(i,t.size()){
        if (t[i] == 'N') n++;
        else if (t[i] == 'S') s++;
        else if (t[i] == 'W') w++;
        else if (t[i] == 'E') e++;
    }   
    if (n != 0 && s == 0) cout << "No" << endl;
    else if (n == 0 &&s != 0) cout << "No" << endl;
    else if (w != 0 && e == 0) cout << "No" << endl;
    else if (w == 0 && e != 0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

const int INF = 1012345678;

int main()
{
	int k, s = 0;
	cin >> k >> s;
	int ans = 0;
	for (int x = 0; x <= k; x++)
	{
		for (int y = 0; y <= k; y++)
		{
			int z = s - x - y;
			if (0 <= z && z <= k)
			{
				if ((x + y + z) == s)
				{
					ans++;
				}
			}
		}
	}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
const int MAX = 1e5;
struct edge{int to, dist;};

vector<edge> graph[MAX];
vector<int> color(MAX, -1);
int dfs(int v, int p = -1)
{
	for(auto nv : graph[v])
	{
		if (nv.to == p) continue;
		if (color[nv.to] != -1) continue;
		if (nv.dist % 2 != 0)
			color[nv.to] = color[v] ^ 1;
		else
			color[nv.to] = color[v];
		dfs(nv.to, v);
	}
}
signed main(void)
{
	int n;
	cin >> n;
	rep(i, n - 1)
	{
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		graph[u].push_back({v, w});
		graph[v].push_back({u, w});
	}
	color[0] = 0;
	dfs(0);
	rep(i, n) cout << color[i] << endl;
	return 0;
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
	ll n;
	scanf("%ld", &n);
	std::vector<ll> a(n), b(n), c(n);
	for(ll i=0; i<n; i++) scanf("%ld", &a[i]);
	for(ll i=0; i<n; i++) scanf("%ld", &b[i]);
	for(ll i=0; i<n; i++) scanf("%ld", &c[i]);
	std::sort(a.begin(), a.end());
	std::sort(c.begin(), c.end());

	ll ans = 0;
	for(ll i=0; i<n; i++){
		ll tmp = std::lower_bound(a.begin(), a.end(), b[i]) - a.begin();
		tmp *= n - (std::upper_bound(c.begin(), c.end(), b[i]) - c.begin());
		ans += tmp;
	}
	
	printf("%ld\n", ans);
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}
ll myceil(ll x,ll y){//yがいくつ集まったらx以上になるか
	if(x<=y) return 1;
	else if(x%y==0) return x/y;
	else return x/y+1;
}

//a,b x
int main(){
	ll N,ans=0; cin>>N;
	string s; cin>>s;
	ll tmp=0;
	rep(i,s.sz){
		if(s[i]=='I') tmp++;
		else tmp--;
		ans=max(ans,tmp);
	}
	cout<<ans;
}

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

int main() {
	string s;
	cin >> s;
	int c=700;
	for(int i=0;i<3;i++)
		if(s[i]=='o')
			c=c+100;
	
	cout << c;
	
	
	
	
	
	
	
	
	
	
	
	// your code goes here
	return 0;
}

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

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
int64_t lcm(int64_t a, int64_t b) {
  return a * b / gcd(a, b);
}

int main(){
  string s;
  cin >> s;
  for (int i=0;i<s.size();i++){
    if (i==3){
      cout << 8;
    }else{
      cout << s.at(i);
    }
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;


int main(){
    std::ios_base::sync_with_stdio(false);

    int n; cin >> n;
    string s; cin >> s;

    std::vector<int> num_white(n+1);
    num_white[0] = 0;

    for(int i=1;i<=s.size(); ++i){
        if(s[i-1]=='.'){
            num_white[i] = num_white[i-1]+1;
        } else {
            num_white[i] = num_white[i-1];
        }
    }

    //rep(i,n+1) cout << num_white[i] << " ";
    //cout << '\n';

    int ans = INF;

    rep(i,n){
        //cout << i << " " << (i+1)-num_white[i+1] << " " << (num_white[n]-num_white[i+1]) << endl;
        ans = min(ans, (i+1)-num_white[i+1]+(num_white[n]-num_white[i+1]));
    }

    ans = min(ans, num_white[n]);
    ans = min(ans, n-num_white[n]);

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


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    int n;
    cin >> n;
    vector<int>d(100001,0);
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        d[a]++;
    }
    int ans=0;
    for(int i=1;i<100000;i++){
        int t=d[i-1]+d[i]+d[i+1];
        ans=max(ans,t);
    }
    cout << ans << endl;
}

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


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

int main(){
	int w, n, cnt = 1;
	char dum;
	vector< vector< int > > dp;
	vector< int > weight, value;
	
	while(cin >> w, w){
		cin >> n;
		
		weight.resize(n);
		value.resize(n);
		
		for(int i = 0; i < n; ++i){
			scanf("%d,%d", &(value[i]), &(weight[i]));
		}
		
		dp.resize(n + 1);
		for(int i = 0; i <= n; ++i){
			dp[i].resize(w + 1);
		}
		
		for(int i = 0; i <= w; ++i) dp[0][i] = 0;
		
		for(int i = 1; i <= n; ++i){
			for(int j = 0; j <= w; ++j){
				if(weight[i-1] > j){
					dp[i][j] = dp[i-1][j];
				}else{
					dp[i][j] = max(dp[i-1][j], dp[i-1][j-weight[i-1]] + value[i-1]);
				}
			}
		}
		
		cout << "Case " << cnt << ":" << endl;
		cout << dp[n][w] << endl;
		for(int i = 0; i <= w; ++i){
			if(dp[n][i] == dp[n][w]){
				cout << i << endl;
				break;
			}
		}
		
		++cnt;
	}
}

Measured memory_bytes: 4964
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int N, Q;
    string S;
    cin >> N >> Q >> S;
    vector<int> sums(N);
    REP(i, N - 1) {
        sums[i + 1] = sums[i];
        if (S[i + 1] == 'C' && S[i] == 'A') { sums[i + 1]++; }
    }

    vector<int> ans(Q);
    REP(i, Q) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        ans[i] = sums[r] - sums[l];
    }

    REP(i, Q) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

# define x first    
# define y second
# define mp make_pair
// everything go according to my plan      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector         
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

typedef pair <int, int> pii; 
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") { 
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}   
int n;

int m;

set<int> g[Sz];

int cnt[Sz][2];
      
int s[Sz];

int main()
{                                  
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  cin >> n >> m;
  
  for (int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    s[i] = c - 'A';
  }
  
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].insert (b);
    g[b].insert (a);
  }    
  for (int i = 1; i <= n; i++) {
    for (int j : g[i])
      cnt[i][s[j]]++;
  }    
  bool used[n + 1] = {0};

  queue <int> q;
  for (int i = 1; i <= n; i++) {
    if (!cnt[i][0] || !cnt[i][1]) {
      q.push (i);
      used[i] = 1;
    }
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int to : g[v]) {
      cnt[to][s[v]]--;
      g[to].erase (v);
      if (!used[to] && (!cnt[to][1] || !cnt[to][0])) {
        used[to] = 1;  
        q.push (to);
      }
    }
    g[v].clear();
  }
  for (int v = 1; v <= n; v++) {
    for (int to : g[v]) {
      if (to != v) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
       



  return 0;
}






// Coded by Z..



Measured memory_bytes: 74368
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  string t;
  int a;
  a = 0;
  cin >> s >> t;
  if (s.at(0) == t.at(0)) {
    a++;
  }
  if (s.at(1) == t.at(1)) {
    a++;
  }
  if (s.at(2) == t.at(2)) {
    a++;
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, T;
    std::cin >> N >> T;

    std::vector<int64_t> A;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }


    std::map<int64_t, int64_t> m;

    int64_t min = INT64_MAX;

    for (int64_t i = 0; i < N; ++i) {
        if (A[i] <= min) {
            min = A[i];
        }
        else {
            m[A[i]-min]++;
        }
    }

    std::cout << m.rbegin()->second << std::endl;


    return 0;
}


Measured memory_bytes: 7284