akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long N, long long M, std::vector<long long> s, std::vector<long long> c){
    set<ll> ans;
    ll num = 1;
    REP(i, N) num *= 10;
    REP(i, num){
        string tmp = to_string(i);
        if(tmp.length()!=N) continue;
        bool isGood = true;
        REP(j, M){
            if(tmp[s[j]-1] - '0' != c[j]){
                isGood = false;
                break;
            }
        }
        if(isGood) ans.insert(i);
    }
    if(ans.empty()) cout<<-1<<endl;
    else
        cout<<*(ans.begin())<<endl;
}

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


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int A[3010];
int memo[3010][3010];

int DP(int l,int r)
{
	if(r<l)return 0;
	if(memo[l][r]!=INF)return memo[l][r];

	int p=(N^(r-l+1))&1;
	int res=0;
	if(p==0)
	{
		res=-INF;
		chmax(res,DP(l+1,r)+A[l]);
		chmax(res,DP(l,r-1)+A[r]);
	}
	else 
	{
		res=INF-1;
		chmin(res,DP(l+1,r)-A[l]);
		chmin(res,DP(l,r-1)-A[r]);
	}

	memo[l][r]=res;
	return memo[l][r];
}

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

	cin>>N;
	rep(i,0,N)cin>>A[i];
	rep(i,0,3010)rep(j,0,3010)memo[i][j]=INF;

	cout<<DP(0,N-1)<<endl;
	
	return 0;
}

Measured memory_bytes: 71168
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9



int main() {
	int n;
	cin >> n;
	ll tot1, tot2, ans1, ans2;
	tot1 = 0;
	tot2 = 0;
	ans1 = ans2 = 0;

	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		tot1 += tmp;
		tot2 += tmp;

		if (i % 2 == 0) { // 偶数番目
			if (tot1 <= 0) {
				ans1 += (1 - tot1); // 合計を1にする
				tot1 = 1;
			}
			if (tot2 >= 0) {
				ans2 += (tot2 + 1); // 合計を-1にする
				tot2 = -1;
			}
		}

		if (i % 2 == 1) { // 奇数番目
			if (tot1 >= 0) {
				ans1 += (tot1 + 1); // 合計を-1にする
				tot1 = -1;
			}
			if (tot2 <= 0) {
				ans2 += (1 - tot2); // 合計を1にする
				tot2 = 1;
			}
		}
	}
	cout << min(ans1, ans2) << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().rstrip().split())
    X = list(map(int, readline().rstrip().split()))
    len_m = len([x for x in X if x < 0])
    ans = 10**10
    for i in range(max(0, len_m-K), min(len_m+K, N-K+1)):
        l = X[i]
        r = X[i+K-1]
        if l < 0 and r > 0:
            c = min(abs(l) * 2 + r, abs(l) + r * 2)
        else:
            c = max(abs(l), abs(r))
        ans = min(ans, c)

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14844
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long;

int main()
{

    int a,b;
    cin >> a >> b;

    int sum = 1;
    int cnt = 0;
    while(sum < b){
        sum+= a - 1;
        cnt++;
    }
    cout << cnt<< endl;
    return 0;
}


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

int main() {
  
  int N,a;
  cin>>N>>a;
  int count=0;
  
  for(int i=0;i<N;i++){
    int b;
    cin>>b;
    
    if(b>a-b)
      count+=(a-b);
    else
      count+=(b);
  }
  cout<<2*count;
  
    
    
  }


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n, m, i, l, r, ans;
    int max = 0; int min = 100001;
    scanf("%d %d", &n, &m);

    for (i = 0; i < m; i++) {
        scanf("%d %d", &l, &r);
        if (max < l) max = l;
        if (min > r) min = r;
    }

    ans = min - max + 1;

    printf("%d\n", ans < 0 ? 0:ans);
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int repeat = 1;
    int sub = 0;
    int[] a = new int[n];
    for(int i = 0; i < n; i++) {
      a[i] =  sc.nextInt();
    }
    Arrays.sort(a);

    sub = a[0];
    for(int i = 1; i < n; i++) {
      sub = a[i];
      if(sub == a[i-1]) {
        repeat++;
      }else {
        if(repeat % 2 == 1) {
          count++;
          repeat = 1;
        }else {
          repeat = 1;
        }
      }
    }
    if(repeat % 2 == 1) {
      count++;
      repeat = 1;
    }else {
      repeat = 1;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 50772
#include <bits/stdc++.h>
using namespace std;
static constexpr int N = 1000 + 5;
static constexpr int MOD = 1000000007;

int ro[ N ], co[ N ];

int main() {
	ios_base::sync_with_stdio( false );
	cin.tie( nullptr );
	int n, m; cin >> n >> m;
	for ( int i = 0 ; i < n ; ++ i )
		cin >> ro[ i ];
	for ( int j = 0 ; j < m ; ++ j )
		cin >> co[ j ];
		
	sort( ro, ro + n ); sort( co, co + m ); 
	if ( unique( ro, ro + n ) != ro + n ) {
		cout << 0 << '\n';
		return 0;
	}
	if ( unique( co, co + m ) != co + m ) {
		cout << 0 << '\n';
		return 0;
	}
	reverse( ro, ro + n ); reverse( co, co + m ); 

	int64_t ans = 1;
	int p1 = 0, p2 = 0;
	for ( int i = n * m ; i >= 1 ; -- i ) {
		bool rf = p1 < n and ro[ p1 ] == i;
		bool cf = p2 < m and co[ p2 ] == i;
		if ( rf and cf ) {
			p1++, p2++;
		} else if ( rf ) {
			ans *= p2; p1++;
			ans %= MOD;
		} else if ( cf ) {
			ans *= p1; p2++;
			ans %= MOD;
		} else {
			if ( p1 * p2 - n * m + i <= 0 ) {
				cout << 0 << '\n';
				return 0;
			}
			ans *= ( p1 * p2 - n * m + i );
			ans %= MOD;
		}
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int s;
    int cunt=1;

    cin >> s;

    if(s==1||s==2){
        cout << 4 << endl;
        return 0;
    }
    while(s!=1){
        cunt++;

        if(s%2==0) s /= 2;
        else s = 3*s+1;
    }

    cout << cunt+1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
       ll n,k,sum=0;
       cin>>n>>k;
       ll A[n];
       for(ll i=0;i<n;i++)
       {
           cin>>A[i];
           if(abs(k-A[i])>=A[i])
           {
               sum=sum+(2*A[i]);
           }
           else
           {
               sum=sum+(2*(abs(k-A[i])));
           }
       }
       cout<<sum;
    } 
    return 0;
}


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

const long long INF = 1LL << 30;

int main() {
  int n;
  cin >> n;
  
  vector<int> h(n);
  for(int i=0; i<n; i++){
    cin >> h.at(i);
  }
  
  vector<long long> dp(n);
  for(int i=0; i<n; i++){
    dp.at(i) = INF;
  }
  
  dp.at(0) = 0;

  for(int i=1; i<n; i++){
    dp.at(i) = min(dp.at(i), dp.at(i-1)+abs(h.at(i) - h.at(i-1)));
    if(i>1) dp.at(i) = min(dp.at(i), dp.at(i-2)+abs(h.at(i) - h.at(i-2)));
  }
  
  cout << dp.at(n-1) << endl;
  
  return 0;
}


Measured memory_bytes: 1408
fun main(args: Array<String>) {
    val A = readInputLine().toCharArray()

    val dp = LongArray(A.size)
    dp[0] = 1L

    val charCnt = LongArray('z' - 'a' + 1)
    charCnt[A[0] - 'a']++

    for (i in 1 until A.size) {
        dp[i] = dp[i - 1]
        for (j in 'a'..'z') {
            if (j == A[i]) {
                continue
            }
            dp[i] += charCnt[j - 'a']
        }
        charCnt[A[i] - 'a']++
    }

    println(dp[A.size - 1])
}

fun readInputLine(): String {
    return readLine()!!
}


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

int main() {
  string s, t, r;
  int a, b;
  cin>>s>>t;
  map<string, int> cnt;
  cin>>a>>b;
  cnt[s] = a, cnt[t] = b;
  cin>>r;
  cnt[r]--;
  cout<<cnt[s]<<' '<<cnt[t];
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin>>S>>T;
  int N=S.size();
  vector<vector<int>> A(26),B(26);
  for(int i=0;i<N;i++){
    A[S[i]-'a'].push_back(i);
    B[T[i]-'a'].push_back(i);
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  if(A==B)puts("Yes");
  else puts("No");
}

Measured memory_bytes: 5952
n, m, x = list(map(int, input().split()))
a_m = list(map(int, input().split()))

ryokins = [0] * (n + 1)
res_left = 0
res_right = 0

for a in a_m:
    ryokins[a] = 1
for i in range(x, n, 1):
    res_left = res_left + ryokins[i]
for i in range(0, x, 1):
    res_right = res_right + ryokins[i]

print(min(res_left, res_right))


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    x, y = map(int, input().split())
    group_a = [1,3,5,7,8,10,12]
    group_b = [4,6,9,11]
    group_c = [2]
    if x in group_a and y in group_a:
        print('Yes')
        return
    if x in group_b and y in group_b:
        print('Yes')
        return
    if x in group_c and y in group_c:
        print('Yes')
        return
    print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 10;
int n, p[11];
int main(){
    scanf("%d", &n);
    int sum = 0;
    int big = 0;
    for(int i = 0; i < n; i++){
        scanf("%d", &p[i]);
        sum += p[i];
        big = max(big, p[i]);
    }
    sum -= big / 2;
    printf("%d", sum);
return 0;
}


Measured memory_bytes: 256
from math import log2, ceil
N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    if i < K:
        n = ceil(log2(K/i))
        ans += (1/N) * (1/2)**n
    else:
        ans += 1/N
print(ans)


Measured memory_bytes: 2940
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}


void func(void)
{
//DEBUG_OUT("----\n");
    uint32 N;
    cin >> N;
    const uint32 N_MAX = 100000 + 5;

    vector<uint32> hist(N_MAX, 0);
    for(uint32 i=0; i<N; i++){
        uint32 a;
        cin >> a;
        hist[a]++;
    }

    uint32 x = 0;
    for(uint32 i=0; i<N_MAX-1; i++){
        uint32 tmp = 0;
        if(i==0){
            tmp = hist[i] + hist[i+1];
        }else{
            tmp = hist[i-1] + hist[i] + hist[i+1];
        }
        x = max(x, tmp);
    }

    cout << x << endl;
    
    return;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int a[200] = {};
int main()
{
    cin >> n >> s;
    int c = 0;
    for(int i = 0; i < n-1; i++)
    {
        for(int t = 0; t < 26; t++)
        {
            int k = 0;
            for(int j = 0; j < i+1; j++)
            {
                if(s[j] == 'a'+t)
                {
                    k = 1;
                }
            }
            int l = 0;
            if(k == 1)
            {
                for(int m = 0; m < n-i-1; m++)
                {
                    if(s[m+i+1] == 'a'+t)
                    {
                        l = 1;
                    }
                }
            }
            a[i] = a[i] + l;
            
        }
    }
    
    sort(a, a+n);
    cout << a[n-1] << endl;


}



Measured memory_bytes: 256
// A. 

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(int argc, char *argv[])
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	bool ans = false;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (a[i] == k) {
			ans = true;
		}
	}
	sort(a.begin(), a.end());
	if (n == 1) {
		ans = a[0] == k;
	} else if (!ans) {
		int g = a[1] - a[0];
		for (int i = 2; i < n; ++i) {
			g = gcd(g, a[i] - a[i-1]);
		}
		for (int i = 0; i < n; ++i) {
			if (a[i] > g && a[i] > k && ((a[i] - k) % g) == 0) {
				ans = true;
				break;
			}
		}
	}
	cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
	return 0;
}


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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector <int> a(n);
	for (int i=0; i<n; i++) {
		cin >> a[i];
	}
	for (int q=0; q<=30; q++) {
		int cnt = 0;
		for (int i=0; i<n; i++) {
			if (!((a[i]>>q)&1)) {
				cnt ++;
			}
		}
		if (cnt == n) continue;
		bool flag = 0;
		for (int i=0; i<=2; i++) {
			if ((n+2-i)/3 != cnt) continue;
			flag = 1;
		}
		if (!flag) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    int ans = 1e9;
    for(int A = 1; A < (1<<n); ++A){
        int la = 0, costA = 0;
        rep(i,n){
            if(A>>i & 1){
                la += l[i];
                ++costA;
            }
        }
        for(int B = 1; B < (1<<n); ++B){
            bool okB = true;
            int lb = 0, costB = 0;
            rep(i,n){
                if((A>>i & 1) && (B>>i & 1)) okB = false;
                if(B>>i & 1){
                    lb += l[i];
                    ++costB;
                }
            }
            if(!okB) continue;
            for(int C = 1; C < (1<<n); ++C){
                bool okC = true;
                int lc = 0, costC = 0;
                rep(i,n){
                    if(C>>i & 1){
                        if((A>>i & 1) || (B>>i & 1)) okC = false;
                        lc += l[i];
                        ++costC;
                    }
                }
                if(!okC) continue;
                int cost = (costA + costB + costC - 3) * 10;
                cost += abs(la - a) + abs(lb - b) + abs(lc - c);
                chmin(ans, cost);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            //var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            string s = Console.ReadLine();

            Console.WriteLine(s.Count(x=>x=='1'));
            //Console.Out.Flush();

        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}


Measured memory_bytes: 11220
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	repi(i, 1, b + 1) {
		if ((a*i) % b == c) {
			wrln("YES");
			return 0;
		}
	}
	wrln("NO");
	return 0;
}


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

long long int n, arr[3001], dp[3001][3001][2];

long long int recursive(int l, int r, int tur){
	if(dp[l][r][tur]!=-1)return dp[l][r][tur];
	if(l==r&&tur==1)return arr[l];
	if(l==r&&tur==2)return -arr[l];
	if(tur==1)dp[l][r][tur]=max(recursive(l+1, r, 2)+ arr[l], recursive(l, r-1, 2)+arr[r]);
	if(tur==2)dp[l][r][tur]=min(recursive(l+1, r, 1)-arr[l] , recursive(l, r-1, 1)-arr[r]);
	return dp[l][r][tur];
}


int main(void){
	cin>>n;
	memset(dp, -1, sizeof(dp));
	for(int i=0;i<n;i++)cin>>arr[i];
	cout<<recursive(0, n-1, 1);

	return 0;
}

Measured memory_bytes: 141184
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		String[] Ws = W.split(" ");
		long N = Long.parseLong(Ws[0]);
		long K = Long.parseLong(Ws[1]);

		W = in.readLine();
		Ws = W.split(" ");
		long[] l = new long[Ws.length];
		for (int i = 0; i < Ws.length; i++) {
			l[i] = Long.parseLong(Ws[i]);
		}
		Arrays.sort(l);

		long ans = 0;
		for(int i=0;i<K;i++){
			ans+=l[(int)N-1-i];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21460
#include <stdio.h>
int main(void)
{
	char alfa[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	char c;
	int n = 0;
	
	scanf("%c", &c);
	while(alfa[n] != c){
		n++;
	}
	
	printf("%c", alfa[n + 1]);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t N, M, K;
  cin >> N >> M >> K;
  vector<int64_t> A(N + 1), B(M + 1);
  A.at(0) = 0;
  for (int i = 1; i <= N; i++) {
    int64_t a;
    cin >> a;
    A.at(i) = A.at(i - 1) + a;
  }
  B.at(0) = 0;
  for (int i = 1; i <= M; i++) {
    int64_t b;
    cin >> b;
    B.at(i) = B.at(i - 1) + b;
  }
  int64_t ans = 0;
  int64_t best = M;
  for (int64_t i = 0; i <= N; i++) {
    if (A.at(i) > K) {
      break;
    }
    for (int64_t j = best; j >= 0; j--) {
      if (A.at(i) + B.at(j) <= K) {
        ans = max(ans, i + j);
        best = j;
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 6380
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

ll f(ll a, ll b) {
    if (a == 0) {
        if (b == 0) return 0;
        
        if (b % 2 == 1) return (b + 1) / 2 % 2;
        return f(0, b - 1) ^ b;
    }
  
    return f(0, a - 1) ^ f(0, b);
}

int main() {
    ll a, b;
    cin >> a >> b;
    cout << f(a, b) << endl;
}

Measured memory_bytes: 256
n = gets
a = gets.chomp.split.map(&:to_i)
cnt = a.count{|item| 0 > item}
i = 0
z = 0
if cnt % 2 == 0 then
    a.each do |hoge|
        i += hoge.abs
    end
    puts i
else
    a.each do |hoge|
        i += hoge.abs
        if i == hoge.abs then
            z = hoge.abs
        elsif i != hoge.abs and z > hoge.abs then
            z = hoge.abs
        end
    end
    puts i - (z * 2)
end

Measured memory_bytes: 9732
import itertools
n=int(input())
l=[i for i in range(1,101)]
x=list(itertools.product(l,l,l))
d={i:0 for i in range(1,n+1)}
for i in range(len(x)):
	r=x[i][0]**2+x[i][1]**2+x[i][2]**2+(x[i][0]*x[i][1])+(x[i][1]*x[i][2])+(x[i][0]*x[i][2])
	if r>n:
		continue
	d[r]+=1

for u,v in d.items():
	print(v)




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

int n, m;
string a[50], b[50];

int main() {
	bool isYes = 0;

	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++)
		cin >> b[i];
	for (int i = 0; i < n - m + 1; i++)
		for (int j = 0; j < n - m + 1; j++) {
			bool flag = 1;
			for (int k = 0; k < m; k++)
				for (int l = 0; l < m; l++)
					if (a[k + i][l + j] != b[k][l])
						flag = 0;
			if (flag)
				isYes = 1;
		}

	cout << (isYes ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld; 
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << ", ";
	err(++it, args...);
	cout<<"\n";
}

#define vmax(type)   std::numeric_limits<type>::max()
#define vmin(type)   std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'

ll powm(ll a, ll b, ll mod) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

const ll mod = 1e9 + 7;
const ll N = 1000005;
const ll inf = 1e9;

void solve()
{
	int n;
	cin>>n;
	cinal(a, n);
	ll sum = 0;
	rep(i, n)
		sum += a[i];
	sum %= mod;
	ll ans = 0;
	rep(i, n){
		ans += ((sum - a[i] + mod) % mod) * a[i];
		ans %= mod;
	}
	ans *= (mod+1)/2;
	ans %= mod;
	cout<<ans<<endl;
}

// #define _DEBUG 
// #define testCases
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);
	
	int tc = 1;
#ifdef testCases
	cin>>tc;
#endif
	while(tc--)
	{
#ifdef _DEBUG
	int tt = clock();
#endif
		solve();
		
#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
#endif
	}
	return 0;
}




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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;
typedef pair<pi,pi> P;

const int INF=12345678;

int w,h;
int d[50][50][50][50];

inline bool in(int x, int y)
{
    return (0<=x&&x<w && 0<=y&&y<h);
}

int main()
{
    int dx[]={1,-1,0,0}, dy[]={0,0,1,-1};

    while(cin >>w >>h,w|h)
    {
        vector<string> l(h),r(h);
        rep(i,h) cin >>l[i] >>r[i];

        pi len,rin;
        pi gl,gr;
        rep(i,h)rep(j,w)
        {
            if(l[i][j]=='L') len=pi(j,i);
            if(r[i][j]=='R') rin=pi(j,i);
            if(l[i][j]=='%') gl=pi(j,i);
            if(r[i][j]=='%') gr=pi(j,i);
        }

        //len(x,y),rin(x,y)
        rep(a1,50)rep(a2,50)rep(a3,50)rep(a4,50) d[a1][a2][a3][a4]=INF;
        d[len.fi][len.se][rin.fi][rin.se]=0;

        queue<P> que;
        que.push(P(len,rin));
        while(!que.empty())
        {
            P now=que.front();
            que.pop();

            pi nl=now.fi, nr=now.se;

            rep(i,4)
            {
                int nlx=nl.fi+dx[i], nly=nl.se+dy[i];
                int nrx=nr.fi-dx[i], nry=nr.se+dy[i];

                if(!in(nlx,nly) || (in(nlx,nly)&&l[nly][nlx]=='#'))
                {
                    //not move
                    nlx=nl.fi;
                    nly=nl.se;
                }

                if(!in(nrx,nry) || (in(nrx,nry)&&r[nry][nrx]=='#'))
                {
                    //not move
                    nrx=nr.fi;
                    nry=nr.se;
                }

                if(l[nly][nlx]=='%' && r[nry][nrx]!='%') continue;
                if(l[nly][nlx]!='%' && r[nry][nrx]=='%') continue;

                if(d[nlx][nly][nrx][nry]>d[nl.fi][nl.se][nr.fi][nr.se]+1)
                {
                    d[nlx][nly][nrx][nry]=d[nl.fi][nl.se][nr.fi][nr.se]+1;
                    que.push(P(pi(nlx,nly),pi(nrx,nry)));
                }
            }
        }

        puts((d[gl.fi][gl.se][gr.fi][gr.se]<INF)?"Yes":"No");
    }
    return 0;
}

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

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

  ll ans = 0;
  rep(i, n - 1) {
    if (a[i] + a[i + 1] > x) {
      ll tmp = a[i] + a[i + 1] - x;
      ans += tmp;
      a[i + 1] = max((ll)0, a[i + 1] - tmp);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4028
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Q;
    cin >> Q;
    vector<vector<int>> qs(Q, vector<int>(3, 0));
    REP(i, Q) {
        cin >> qs[i][0];
        if (qs[i][0] == 1) {
            cin >> qs[i][1] >> qs[i][2];
        }
    }

    priority_queue<int> ls;
    priority_queue<int, vector<int>, greater<int>> rs;
    ll lsum = 0, rsum = 0, B = 0;
    REP(i, Q) {
        if (qs[i][0] == 2) {
            int m = ls.top();
            ll res = rsum - lsum + B;
            if (ls.size() != rs.size()) {
                res += m;
            }
            cout << m << " " << res << endl;
            continue;
        }
        int a = qs[i][1];
        B += qs[i][2];
        if (ls.empty() || a < ls.top()) {
            ls.push(a);
            lsum += a;
        } else {
            rs.push(a);
            rsum += a;
        }
        if (ls.size() > rs.size() + 1) {
            int t = ls.top();
            ls.pop();
            rs.push(t);
            lsum -= t;
            rsum += t;
        } else if (ls.size() < rs.size()) {
            int t = rs.top();
            rs.pop();
            ls.push(t);
            lsum += t;
            rsum -= t;
        }
    }
    return 0;
}


Measured memory_bytes: 14460
#!/usr/bin/env python3

# from typing import Optional
# from typing import List
# from typing import Dict
# from typing import Tuple
# from typing import Sequence


def main():
    N = int(input())
    A = list(map(lambda x: int(x), input().split()))

    sum = 0
    mod = 1000000000 + 7

    sumJ = 0
    for j in range(N):
        sumJ += A[j]

    for i in range(N - 1):
        sumJ -= A[i]
        sum += A[i] * sumJ
        sum = sum % mod

    print(sum)


if __name__ == "__main__":
    main()


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	ll n;
	cin >> n;

	ll h[n+1];
	for (ll i = 1; i <= n; i++)
		cin >> h[i];

	ll c = 0;
	map<ll, ll> iAi;
	for (ll i = 1; i <= n; i++) {
		c += iAi[i-h[i]];
		iAi[i+h[i]]++;
	}

	cout << c << endl;

	return 0;
}

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

int main() {
  string s;
  ll n;
  cin >> s;
  n = s.size();
  vector<ll>cnt(26);
  rep(i,0,n) cnt[s[i]-'a']++;
  ll ans = 1+n*(n-1)/2;
  rep(i,0,26) ans -= cnt[i]*(cnt[i]-1)/2;
  cout << ans << endl;
}

Measured memory_bytes: 3744
def lunlun(n):
	nums = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
	while len(nums) < n:
		old_nums = list(nums)
		for num in old_nums:
			num = str(num)
			if num[-1] == '0':
				adds = num + '0'
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + '1'
				if int(adds) not in nums:
					nums.add(int(adds))
			elif num[-1] == '9':
				adds = num + '9'
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + '8'
				if int(adds) not in nums:
					nums.add(int(adds))
			else:
				adds = num + str(int(num[-1]) - 1)
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + str(int(num[-1]))
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + str(int(num[-1]) + 1)
				if int(adds) not in nums:
					nums.add(int(adds))
			# if num[0] == '1':
			# 	adds = '1' + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# 	adds = '2' + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# elif num[0] == '9':
			# 	adds = '8' + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# 	adds = '9' + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# else:
			# 	adds = str(int(num[0]) - 1) + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# 	adds = str(int(num[0])) + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# 	adds = str(int(num[0]) + 1) + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))

	nums = list(nums)
	nums = sorted(nums)
	return nums[n - 1]

n = int(input())
print(lunlun(n))

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n,m,k;
int d[111];
int vs[111][111];
int dp[1<<17];
int idx[111];

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>m>>k;
  memset(idx,-1,sizeof(idx));
  rep(i,m){
    cin>>d[i];
    d[i]--;
    idx[d[i]]=i;
  }
  rep(i,n)rep(j,k){
    cin>>vs[i][j];
    vs[i][j]--;
  }
  memset(dp,-1,sizeof(dp));
  queue<P> que;
  que.push(P((1<<m)-1,0));
  while(que.size()){
    int S=que.front().fi; int nd=que.front().se; que.pop();
    if(dp[S]!=-1)continue;
    dp[S]=nd;
    rep(i,k){
      int T=0;
      rep(j,m){
        if(((S>>j)&1)==0)continue;
        int nv=vs[d[j]][i];
        if(idx[nv]!=-1){
          T|=(1<<idx[nv]);
        }
      }
      que.push(P(T,nd+1));
    }
  }
  cout<<dp[0]<<endl;
  return 0;
}

Measured memory_bytes: 62336
#include<stdio.h>

int main(void){
    int i,n,p[32] = {1,1,2};
    for(i=3;i<=30;i++)p[i]=p[i-1]+p[i-2]+p[i-3];
    while(scanf("%d",&n),n!=0)printf("%d\n",p[n]/3650+1);
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

int le[1 << 18], ri[1 << 18];
void solve() {
	int n; string s;
	cin >> n >> s;
	rep(i, n) {
		if (s[i] == '#') {
			le[i + 1] = le[i] + 1;
		}
		else le[i + 1] = le[i];
	}
	rep(i, n) {
		if (s[n-1-i] == '.') {
			ri[i + 1] = ri[i] + 1;
		}
		else ri[i + 1] = ri[i];
	}
	int ans = mod;
	rep(i, n+1) {
		int sum = le[i] + ri[n - i];
		ans = min(ans, sum);
	}
	cout << ans << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}

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


bool func(vector<int>& v)
{


    int mx = *max_element(v.begin(),v.end());
    int mn = *min_element(v.begin(),v.end());
    int n;

    if(mx==v.size()-1 && mx==mn) return true;
    else n = mx;

    int u=0;
    for(auto x:v) if(x==n-1) u++;

    if(u>=n) return false;
    else if((n-u)*2+u<=v.size()) return true;
    return false;
}


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

    int N;
    cin >> N;
    vector<int> v(N);
    for(int i=0;i<N;i++) cin >> v[i];
    bool flag = func(v);

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
//
//    vector<int> v = {3,3,3,3,3};
//    cout << func(v,0) << endl;

    return 0;
}


Measured memory_bytes: 640
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

constexpr auto dogs = 1'000'000'000'000'001LL;

int main() {
    auto n = large{};
    cin >> n;

    auto name_len = 0;
    auto index = n - 1;
    auto same_length_count = 26LL;
    for (auto len = 1LL; len <= 14; ++len) {
        if (index < same_length_count) {
            name_len = len;
            break;
        }
        index -= same_length_count;
        same_length_count *= 26LL;
    }

    assert(name_len >= 1);

    auto s = string{};
    for (auto i = 0; i < name_len; ++i) {
        s.push_back('a' + index % 26);
        index /= 26;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, a, b) for(int i = (a); i >= (b); --i)
#define debug(x) cerr << #x << ' ' << x << endl;
using namespace std;

typedef long long ll;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;
const double EPS=1e-8;
inline int sign(double a){return a<-EPS?-1:a>EPS;}
inline int cmp(double a,double b){return sign(a-b);}
//点
struct P{
    double x,y;
    P(){}
    P(double _x,double _y):x(_x),y(_y){}
    P operator + (P p){return P(x+p.x,y+p.y);}
    P operator - (P p){return P(x-p.x,y-p.y);}
    P operator * (double k){return P(x*k,y*k);}
    P operator / (double k){return P(x/k,y/k);}
    double dot(P p){return x*p.x+y*p.y;}
    double det(P p){return x*p.y-y*p.x;}
    double distTo(P p){return (*this-p).abs();}
    double alpha(){return atan2(y,x);}
    void read(){scanf("%lf%lf", &x, &y);}
    void write(){printf("%.10lf %.10lf\n", x, y);}
    double abs(){return sqrt(abs2());}
    double abs2(){return x*x+y*y;}
    P rot90(){return P(-y,x);}
    P unit(){return *this/abs();}
    int quad(){return sign(y)==1||(sign(y)==0&&sign(x)>=0);}
    P rot(double an){return P(x*cos(an)-y*sin(an),x*sin(an)+y*cos(an));}
    bool operator < (P p)const{int c=cmp(x,p.x);if(c)return c==-1;return cmp(y,p.y)==-1;}
    bool operator == (P o)const{return cmp(x,o.x)==0&&cmp(y,o.y)==0;}
};

int main(int argc, char const *argv[])
{
    int q;
    scanf("%d", &q);
    P p0, p1, p2, p3, a, b, u;
    while (q--) {
        p0.read(); p1.read(); p2.read(); p3.read();
        a = p1 - p0; b = p3 - p2; u = p3 - p1;
        (p1 + a*(u.det(b)/a.det(b))).write();
    }
    return 0;
}



Measured memory_bytes: 3240
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s-1);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int n,m; cin>>n>>m;
    vector<ii> v(m);
    REP(i, m) {
        int a,b; cin>>a>>b; a--; b--;
        v[i] = make_pair(a,b);
    }

    sort(ALL(v), [](const ii& a, const ii&b) {
        return a.second == b.second ? a.first < b.first : a.second < b.second;
    });

    vector<int> rm(0);

    REP(i, m) {
        if (rm.empty() || rm.back() < v[i].first) {
            rm.push_back(v[i].second - 1);
        }
    }

    cout << rm.size() << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

const int N = 5e5+5;
int A[N];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	bool r=0;
	int a = N/2;
	int n;
	cin >> n;
	int f=a+1,e=a;
	for(int i = 0; i < n; ++i) {
		if(i&1) cin >> A[--f];
		else cin >> A[++e];
	}
	if(n%2==0) {
		for(int i = f; i <= e; ++i)
			cout << A[i] << " ";
	} else {
		for(int i = e; i >= f; --i)
			cout << A[i] << " ";
	}
	

	cout << "\n";
	
}

Measured memory_bytes: 3072
/*
author: Apoorv Singh
*/

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

typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
#define FORR(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"

int modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

int fpow(int a, int n)
{
    int ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int r,g,b,n; cin >> r >> g >> b >> n;
    int ans = 0;
    FOR(i,0,n+1)
    {
        FOR(j,0,n+1)
        {
            if (r*i+g*j > n)
                continue;
            int x = r*i+g*j;
            if ((n-x)%b)
                continue;
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
int main(){
  std::string s, sub;
  std::cin >> s;
  int num;
  int cnt = 0;
  int ans = 0;
  int tmp = 0;
  num = s.length();
  for(int i=0; i<num; ++i){
    sub = s.substr(i, 1);
    if(sub == "A" || sub == "C" || sub == "G" || sub == "T"){
      cnt++;
      tmp = cnt;
    }else{
      if(ans < cnt){
        ans = cnt;
      }
      cnt = 0;
    }
  }
  if(tmp > ans){
    ans = tmp;
  }
  std::cout << ans << std::endl;
  return 0;
}

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

int dfs(int n,vector<vector<int> >& matrix,vector<int> & dp)
{
	if(matrix[n].size()==0)
		return 0;
	
	if(dp[n]!=-1)
		return dp[n];

	dp[n]=0;
	int maxi=0;
	for(int i=0;i<matrix[n].size();i++)
	{
		maxi=max(maxi,1+dfs(matrix[n][i],matrix,dp));
	}
	dp[n]=maxi;
	return maxi;
}



int main()

{

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

	vector<vector<int> > matrix(n+1);

	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;

		matrix[x].push_back(y);
	}

	vector<int> dp(n+1,-1);
	for(int i=1;i<=n;i++)
	{
		if(matrix[i].size()==0)
			dp[i]=0;
	}

	int maxi=0;

	for(int i=1;i<=n;i++)
	{
		if(dp[i]==-1)
			dp[i]=dfs(i,matrix,dp);

		maxi=max(maxi,dp[i]);
	}
	// cout<<endl<<endl;
	// for(int i=1;i<=n;i++)
	// {
	// 	maxi=max(maxi,dp[i]);

	// }

	cout<<maxi;

	


	return 0;





}

Measured memory_bytes: 8832