akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <string>
#include <set>
#include <map>

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

ll gcd(ll x,ll y)
{
	if(x==0) return y;
	return gcd(y%x,x);
}
ll euler(ll N)
{
	ll ret=N;
	for(ll i=2;i*i<=N;i++)
	{
		if(N%i==0)
		{
			ret/=i;
			ret*=i-1;
			while(N%i==0) N/=i;
		}
	}
	if(N>1)
	{
		ret/=N;
		ret*=N-1;
	}
	return ret;
}
ll mpow(ll m,ll t,ll mod)
{
	if(t==0) return 1;
	ll ret=mpow(m,t/2,mod);
	ret=ret*ret%mod;
	if(t%2==1) ret=ret*(m%mod)%mod;
	return ret;
}
ll solve(ll A,ll m1,ll m2)
{
	if(m2==1) return 1;
	ll pm2=euler(m2);
	ll g=gcd(pm2,m2);
	ll ret=solve(A,m1,g);
	ll vt=mpow(A,m1*(ret%pm2)%pm2,m2)-m1*(ret%m2)%m2;
	if(vt<0) vt+=m2;
	ll z=m1*pm2%m2;
	z/=g,vt/=g;
	ll L=vt*mpow(z,pm2-1,m2)%m2;
	//printf("%lld %lld\n",m1,m2);
	//printf("%lld %lld : %lld %lld %lld\n",A,ret,vt,z,L);
	
	
	ll ans=ret+L*pm2;
	ans%=pm2*m2;
	
	//printf("%lld %lld %lld : %lld %lld\n",A,m1,m2,mpow(A,ans,m2),ans%m2);
	return ans;
}
int main()
{
	int Q;
	scanf("%d",&Q);
	while(Q--)
	{
		ll A,M;
		scanf("%lld %lld",&A,&M);
		if(A==0)
		{
			printf("%lld\n",M);
			continue;
		}
		ll now=M;
		ll m1=1,m2=1;
		for(ll i=2;i*i<=now;i++)
		{
			while(now%i==0)
			{
				if(A%i==0) m1*=i;
				else m2*=i;
				now/=i;
			}
		}
		if(now>1)
		{
			if(A%now==0) m1*=now;
			else m2*=now;
		}
		ll mod=euler(M)*M;
		ll ret=solve(A,m1,m2)*m1%mod;
		if(ret==0) ret+=mod;
		printf("%lld\n",ret);
		//printf("%lld %lld\n",mpow(A,ret,M),ret%M);
	}
	return 0;
}


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

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int A[10000005];
    memset(A, 0, sizeof(A));
    for(int i = 1; i <= 1e7; i++){
        for(int j = 1; j*i <= 1e7; j++){
            A[i*j]++;
        }
    }
    int n;
    cin >> n;
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        // ans += i * f(i);
        ans += i * (long long)A[i];
    }
    cout << ans << '\n';
}

Measured memory_bytes: 42712
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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++)
using namespace std;
typedef long long ll;

int a, b;

int main(){
  cin >> a >> b;
  if (a == b) cout << a + b << endl;
  else cout << 2 * max(a, b) - 1 << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define Maxn 307
int n,m;
int a[Maxn][Maxn],que[Maxn];
bool vis[Maxn];
vector<int> e[2*Maxn];
int l[Maxn];
void print()
{
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
            printf("%d ",a[i][j]);
        printf("\n");
    }
}
void insert(int x,int y)
{
    e[x].push_back(n+y);
    e[n+y].push_back(x);
}
int find(int u)
{
    for (int i=0;i<(int)e[u].size();i++)
    {
        int v=e[u][i];
        if (!vis[v])
        {
            vis[v]=true;
            if (l[v]==0||find(l[v]))
            {
                l[v]=u;
                return true;
            }
        }
    }
    return false;
}
int hungary()
{
    int ans=0;
    memset(l,0,sizeof(l));
    for (int i=n+1;i<=2*n;i++)
    {
        memset(vis,false,sizeof(vis));
        if (find(i)) ++ans;
    }
    return ans;
}
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            scanf("%d",&a[i][j]);
    for (int i=1;i<=m;i++)
    {
        memset(e,0,sizeof(e));
        for (int j=1;j<=n;j++)
        {
            memset(vis,false,sizeof(vis));
            for (int k=i;k<=m;k++)
            {
                int tmp=(a[j][k]+m-1)/m;
                if (!vis[tmp])
                {
                    vis[tmp]=true;
                    insert(j,tmp);
                }
            }
        }
        hungary();
        for (int j=1;j<=n;j++)
        {
            int pos=i;
            for (int k=i;k<=m;k++)
            {
                int tmp=(a[j][k]+m-1)/m;
                if (tmp==l[j]-n)
                {
                    pos=k;
                    break;
                }
            }
            if (pos!=i) swap(a[j][pos],a[j][i]);
        }
    }
    print();
    for (int i=1;i<=m;i++)
    {
        for (int j=1;j<=n;j++)
            que[j]=a[j][i];
        sort(que+1,que+n+1);
        for (int j=1;j<=n;j++)
            a[j][i]=que[j];
    }
    print();
    return 0;
}

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

typedef long long LL;
typedef pair<int, int> II;

const int N = (int) 1e5 + 10;
int n, a[N * 3];
LL L[N * 3], R[N * 3];

int main() {
#ifdef LOCAL
    freopen("inp", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n * 3; ++i) scanf("%d", &a[i]);

    map<int, int> freq;
    int cnt = 0;
    LL sum = 0;
    for (int i = 1; i <= n * 2; ++i) {
        freq[a[i]]++;
        cnt += 1;
        sum += a[i];
        while (cnt > n) {
            int x = freq.begin()->first;
            sum -= x;
            cnt -= 1;
            freq[x]--;
            if (freq[x] == 0) freq.erase(x);
        }
        L[i] = sum;
    }

    freq.clear();
    cnt = 0;
    sum = 0;
    for (int i = n * 3; i >= n + 1; --i) {
        freq[a[i]]++;
        cnt += 1;
        sum += a[i];
        while (cnt > n) {
            int x = freq.rbegin()->first;
            sum -= x;
            cnt -= 1;
            freq[x]--;
            if (freq[x] == 0) freq.erase(x);
        }
        R[i] = sum;
    }

    LL ans = -1e18;
    for (int i = n; i <= 2 * n; ++i) ans = max(ans, L[i] - R[i + 1]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 9472
object Main extends App {
	override def main(args: Array[String]) = {
		val sc = new java.util.Scanner(System.in)
		
		val a,b,c = sc.nextInt()	

		println(solve(a,b,c))
	}
	
	def solve(a:Int , b:Int, c:Int) : Int = {

		(a to b).count(c%_ == 0)
	}
}

Measured memory_bytes: 45296
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;




int main()
{
  int n, t; //かっている数//最大100
  cin >> n ;

  vector<long> x(n);
  vector<long> y(n);
  vector<long> h(n);

  vector<tuple<long, long, long>> val(n);


  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> h[i];
    get<0>(val[i]) = x[i];
    get<1>(val[i]) = y[i];
    get<2>(val[i]) = h[i];
  }

  sort(val.begin(), val.end(), [](tuple<long, long, long> & l, tuple<long, long, long> &r) {
    return get<2>(l) > get<2>(r);
  });

  long ax, ay, ah = -1;

  for (int px = 0; px <= 100; ++px) {
    for (int py = 0; py <= 100; py++) {
      long tmph = 0;
      bool isUnique = true;
      for (int i = 0; i < n; ++i) {
        if (i == 0) {
          tmph = get<2>(val[i]) + abs(get<0>(val[i]) - px) + abs(get<1>(val[i]) - py);
        } else {

          if (get<2>(val[i]) == 0 ){
            if (tmph > abs(get<0>(val[i]) - px) + abs(get<1>(val[i]) - py)  )isUnique = false;

          } else {
            if (tmph != get<2>(val[i]) + abs(get<0>(val[i]) - px) + abs(get<1>(val[i]) - py) ) {
              isUnique = false;
            }
          }

        }
      }

      if (isUnique) {
        ax = px;
        ay = py;
        ah = tmph;
        break;
      }

    }
    if (ah >= 0)break;
  }




  cout << ax << " " << ay << " " << ah;

  return 0;
}



























Measured memory_bytes: 256
#C
s = list(input())
#0101010101…
count1 = 0
#1010101010…
count2 = 0

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == "0":
            count1 += 1
        if s[i] == "1":
            count2 += 1
    if i % 2 == 1:
        if s[i] == "0":
            count2 += 1
        if s[i] == "1":
            count1 += 1

print(min(count1,count2))

Measured memory_bytes: 3956
from collections import defaultdict
n = int(input())
a = [int(i) for i in input().split()]
l_i = [a[i] + i + 1 for i in range(len(a))]
r_j = [i - a[i] + 1 for i in range(len(a))]
dl = defaultdict(int)
dr = defaultdict(int)
for i in range(n):
    dl[l_i[i]] += 1
    dr[r_j[i]] += 1

ans = 0
for i in dl.keys():
    ans += dl[i] * dr[i]

print(ans)

Measured memory_bytes: 75012
flag = True
sen = ""
ushi = ""
S = input()
Q = int(input())
for i in range(Q):
  T = input().split()
  if T[0] == "1" :
    flag = not flag
  else:
    if flag:
      if T[1] == "1":
        sen = T[2] + sen
      else:
        ushi = ushi + T[2]
    else:
      if T[1] == "1":
        ushi = ushi + T[2]
      else:
        sen = T[2] + sen
ans = sen + S + ushi
if flag == False:
  print(ans[::-1])
else:
  print(ans)
    
    
  

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

#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

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

int main()
{
    int N = 0;
    int W = 1;
    string s;
    while (cin >> s) {
        if (s == "#") break;
        vector<int> vec;
        loop(s.size(), i) {
            if (s[i] == 'n') {
                vec.push_back(N);
                i+=4;
            } else {
                vec.push_back(W);
                i+=3;
            }
        }
//        for(auto i : vec) cout << i;
//        cout << endl;
        vector<pair<int,int>> rs;
        if (vec.back()==N) { 
            rs.push_back({0,1});
        } else {
            rs.push_back({90,1});
        }
        if (vec.size() == 1) {
            cout << rs[0].first << endl;
            continue;
        }
        vec.pop_back();
        int den_max = 0;
        int exp = 1;
        while(vec.size()) {
            if (vec.back() == N) {
                rs.push_back({-90, pow(2,exp++)});
            } else {
                rs.push_back({90, pow(2,exp++)});
            }
            den_max = max(den_max, (int)pow(2,exp-1));
            vec.pop_back();
        }
        int ans_num=0;
        for(auto r:rs) {
            //cout << r.first << ',' << r.second << endl;
            int k = den_max/r.second;
            ans_num += r.first*k;
        }
        int f = gcd(ans_num, den_max);
        //cout << ans_num << ' ' << f << ' ' << den_max << endl;
        cout << ans_num/f;
        if (den_max == f) cout << endl;
        else cout << '/' << den_max/f << endl;
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;

int main() {
   ll k,a,b;cin>>k>>a>>b;
   ll ans=1;
   if(ans<a){
       ans+=min(a-1,k);
       k-=min(a-1,k);
   }
   if(b-a>2){
       ans+=(b-a)*(k/2);
       k%=2;
       ans+=k;
   }
   else {
       ans+=k;
   }
   cout <<ans <<endl;
}

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

int tile[22][22];
int sum;

void search(int w,int h)
{
  if(tile[w][h]){
    tile[w][h]=0; sum++;
    search(w,h-1);
    search(w-1,h);
    search(w+1,h);
    search(w,h+1);
  }
}

int main()
{
  int w,h,i,j,sx,sy;
  char c;
  
  for(;;){
    cin>>w>>h;
    if(!(w|h)) break;

    sum=0;
    for(i=0;i<22;i++)
      for(j=0;j<22;j++)
	tile[i][j]=0;
    for(i=1;i<h+1;i++){
      for(j=1;j<w+1;j++){
	cin>>c;
	if(c=='#') tile[j][i]=0;
	else if(c=='.') tile[j][i]=1;
	else if(c=='@'){
	  tile[j][i]=1; sx=j; sy=i;
	}
      }
    }
    search(sx,sy);
    cout<<sum<<endl;
  }
}


Measured memory_bytes: 1172
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

struct UnionFind
{
    vector<int> d;
    UnionFind(int n = 0) : d(n, -1) {}
    int find(int x)
    {
        if (d[x] < 0)
            return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return false;
        if (d[x] > d[y])
            swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    int size(int x)
    {
        return -d[find(x)];
    }
};
int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
    }
    int ans = -1;
    for (int i = 0; i < n; i++)
    {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4052
#include<stdio.h>

int main(){
  int n,i,F[50];

  scanf("%d",&n);

  F[0] = F[1] = 1;

  for(i = 2;i <= n;i++){
    F[i] = F[i - 1] + F[i - 2];
  }

  printf("%d\n",F[n]);

  return 0;
}



Measured memory_bytes: 2132
#include <iostream>
#include <string>

using namespace std;

void Replace(string& str, string from, string to)
{
	string::size_type pos;
	while(pos = str.find(from), pos != str.npos)
	{
		str.replace(pos, from.length(), to);
		pos += to.length();
	}
}

void solve()
{
	string str;
	getline(cin, str);
	Replace(str, "apple", "hogehoge");
	Replace(str, "peach", "apple");
	Replace(str, "hogehoge", "peach");
	cout << str << endl;
}

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

Measured memory_bytes: 1208
local n=io.read("n")
local a,b,c={},{},{}
for i=1,n do
    a[i]=io.read("n")
end
for i=1,n do
    b[i]=io.read("n")
end
for i=1,n-1 do
    c[i]=io.read("n")
end

local total=0
for i=1,n do
    if i>=2 then
        total=total+b[a[i]]+(a[i-1]+1==a[i] and c[a[i-1]] or 0)
    else
        total=total+b[a[i]]
    end
end
print(total)

Measured memory_bytes: 2780
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int x[n];
  int a=0;
  rep(i,n){
    cin>>x[i];
    a^=x[i];
  }
  rep(i,n){
    if(i) cout<<" ";
    cout<<(a^x[i]);
  }
  cout<<endl;
     

  return 0;
}


Measured memory_bytes: 5156
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    K=int(input())
    S=input()
    s=len(S)
    if s>K:
        a=S[:K]
        print(a+"...")
    else:print(S)
#%%submit!
resolve()


Measured memory_bytes: 61736
#include <string>
#include <iostream>
#include <set>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  set<string> str;
  str.insert(s);
  char prev = s[s.size()-1];
  rep(i,n-1){
    cin >> s;
    if(s[0] == prev){
      prev = s[s.size()-1];
      str.insert(s);
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  if(str.size() == n){
    cout << "Yes" << endl;
  }else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N = 0;
  cin>>N;
  
  if (N == 1){
     cout<<1<<endl;
  }
  else if (2<=N && N<=3){
    cout<<2<<endl;
  }
  else if (4<=N && N<=7){
    cout<<4<<endl;
  }
  else if (8<=N && N<=15){
    cout<<8<<endl;
  }
  else if (16<=N && N<=31){
    cout<<16<<endl;
  }
  else if (32<=N && N<=63){
    cout<<32<<endl;
  }
  else{
    cout<<64<<endl;
  }
}

Measured memory_bytes: 256
import static java.lang.System.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(in);

        String s = sc.next();
		
		long ans = 0;
		long bc = 0;
		for(char c: s.toCharArray()) {
			if(c == 'B') bc++;
			else ans += bc;
		}
        
        out.println(ans);
    }
}


Measured memory_bytes: 25868
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

mod = 1000000007

h, w, kk = na()
kk -= 1

dp = [0] * w
dp[0] = 1

vs = []
for j in range(1 << w - 1):
    ok = True
    for k in range(w):
        if (j & 3 << k) == 3 << k:
            ok = False
            break
    if ok:
        vs.append(j)

for i in range(h):
    ndp = [0] * w
    for j in range(w):
        for l in vs:
            if l>>j&1:
                ndp[j+1] += dp[j]
            elif j >= 1 and (l>>j-1&1) > 0:
                ndp[j-1] += dp[j]
            else:
                ndp[j] += dp[j]

    for j in range(w):
        ndp[j] %= mod
    dp = ndp

print(dp[kk])


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t A, B, C, K;
    std::cin >> A >> B >> C >> K;

    for (int64_t i = 0; i < K; ++i) {
        if (B <= A) {
            B *= 2;
        } else if (C <= B) {
            C *= 2;
        }
    }

    if (C > B && B > A) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl

using namespace std;

using ll = int64_t;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

template <class T>
ostream &operator<<(ostream &os, vector<T> const &vec) {
    if (vec.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr) {
    if (arr.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

namespace math {
ll gcd(ll u, ll v) {
    while (v != 0) {
        ll r = u % v;
        u = v;
        v = r;
    }
    return u;
}
ll lcm(ll m, ll n) {
    if ((0 == m) || (0 == n)) return 0;

    return ((m / math::gcd(m, n)) * n);
}
}  // namespace math

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) {}
    bool unionSet(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) { return root(x) == root(y); }
    ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    ll size(ll x) { return -data[root(x)]; }
};

template <class T, class U>
pair<T, U> operator+(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first + b.first, a.second + b.second);
}

template <class T, class U>
pair<T, U> operator-(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first - b.first, a.second - b.second);
}

ll bound(function<bool(ll)> f, ll ng, ll ok) {
    while (abs(ng - ok) > 1) {
        ll mid = (ng + ok) / 2;
        if (f(mid))
            ok = mid;
        else
            ng = mid;
    }

    return ok;
}

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

    string S;
    cin >> S;

    ll const w = count(S.begin(), S.end(), '.');
    ll const b = count(S.begin(), S.end(), '#');

    ll lw = 0, lb = 0;
    ll c = N + 1;
    rep(i, N) {
        c = min(c, (w - lw) + lb);
        if (S[i] == '.') lw++;
        if (S[i] == '#') lb++;
    }

    cout << min({ w, b, c }) << endl;

    return 0;
}


Measured memory_bytes: 832
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */

const int M = (1<<20)+5;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll ans[M],lv[M];
vector<ll> adj[M],ap[5];

void dfs(int u,int p)
{
	lv[u] = (lv[p]+1)%2;
	ap[lv[u]].pb(u);
	for(auto v:adj[u])
	{
		if(v == p)
			continue;
		dfs(v,u);
	}
}

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

	ll i,n,s,u,v,p,q,m;

	cin >> n;

	for(i=1;i<n;++i)
	{
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	if(n == 2)
	{
		cout << 1 << " " << 2 << "\n";
		return 0;
	}

	dfs(1,0);

	u = ap[0].size();
	v = ap[1].size();
	m = n/3;

	if(u < v)
	{
		p = 0;
		q = 1;
	}
	else
	{
		p = 1;
		q = 0;
	}

	if(min(u,v) <= m)
	{
		s = 3;
		for(auto v:ap[p])
		{
			ans[v] = s;
			s += 3;
			if(s > n && s%3 == 0)
				s = 1;
			else if(s > n && s%3 == 1)
				s = 2;
		}
	 
		for(auto v:ap[q])
		{
			ans[v] = s;
			s += 3;
			if(s > n && s%3 == 0)
				s = 1;
			else if(s > n && s%3 == 1)
				s = 2;
		}
	}
	else
	{
		s = 2;
		for(auto v:ap[p])
		{
			ans[v] = s;
			s += 3;
			if(s > n && s%3 == 2)
				s = 3;
			else if(s > n && s%3 == 0)
				s = 1;
		}
	 
		for(auto v:ap[q])
		{
			ans[v] = s;
			s += 3;
			if(s > n && s%3 == 2)
				s = 2;
			else if(s > n && s%3 == 0)
				s = 1;
		}
	}

	for(i=1;i<=n;++i)
		cout << ans[i] << " ";

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

Measured memory_bytes: 45676
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 

int main(void) {
  ll h,w;cin>>h>>w;
  if(h==1 ||w==1) cout << 1 << endl;
  else cout << ((h%2==0||w%2==0)? (h*w/2):(h*w/2+1)) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

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

  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  rep(i, n) cin >> a[i] >> b[i] >> c[i];

  vector<vector<ll>> dp(n, vector<ll>(3, 0));
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];

  for (int i = 0; i < n-1; i++) {
    chmax(dp[i+1][0], dp[i][1] + a[i+1]);
    chmax(dp[i+1][0], dp[i][2] + a[i+1]);
    chmax(dp[i+1][1], dp[i][0] + b[i+1]);
    chmax(dp[i+1][1], dp[i][2] + b[i+1]);
    chmax(dp[i+1][2], dp[i][0] + c[i+1]);
    chmax(dp[i+1][2], dp[i][1] + c[i+1]);
  }

  ll ans = 0;
  rep(i, 3) chmax(ans, dp[n-1][i]);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6912
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> M;
	if (N > M)
		swap(N, M);
	rep(i, M) cout << N;
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
// Aizu 1189: Prime Caves
// 2017.9.21 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX  1020000
#define N    1010
#define SQRT 1009     // sqrt(MAX)
#define max(a,b) ((a)>=(b)?(a):(b))

char prime[MAX + 5], *pmax = prime + MAX;

void mkprime()
{
	int k;
	register char *p, *q;
	prime[1] = 1, prime[2] = 0;
	for (p = prime + 4; p <= pmax; p += 2) *p = 1;
	for (k = 3, p = prime + 3; k <= SQRT; k += 2, p += 2)
		if (!*p) for (q = p + k; q <= pmax; q += k) *q = 1;
}

typedef struct { int r, c; } PP;
PP pp[MAX+3];
int map[N+5][N+5];
int dp[N+5][N+5];
int mv[4][2] = { {-1,0},{0,-1},{1,0},{0,1} };
int m, n;

void set()
{
	int i, k, w, r, c, d;

    k = 1, r = c = N/2, d = 3, w = 2;
	while (1) {
		for (i = 0; i < w/2; i++) {
			map[r][c] = k, pp[k].r = r, pp[k].c = c, k++;
			r += mv[d][0], c += mv[d][1];
			if (r < 0 || r >= N || c < 0 || c >= N) return;
		}
		if (++d == 4) d = 0;
		w++;
	}
}

int main()
{
	int r, c, ans, x;

	mkprime(); set();
	while (scanf("%d%d", &m, &n) && m) {
		memset(dp, -1, sizeof(dp));
		r = pp[n].r, c = pp[n].c;
		dp[r][c] = !prime[n];
		for (r = 0; r < N; r++) for (c = 0; c < N; c++) {
			if (dp[r][c] >= 0 && map[r][c] <= m) {
		        if (map[r+1][c-1] <= m)
					dp[r+1][c-1] = max(dp[r+1][c-1], dp[r][c] + !prime[map[r+1][c-1]]); 
		        if (map[r+1][c] <= m)
					dp[r+1][c]   = max(dp[r+1][c],   dp[r][c] + !prime[map[r+1][c]]); 
				if (map[r+1][c+1] <= m)
					dp[r+1][c+1] = max(dp[r+1][c+1], dp[r][c] + !prime[map[r+1][c+1]]); 
			}
		}
		ans = x = 0;
		for (r = 0; r < N; r++) for (c = 0; c < N; c++)
			if (map[r][c] <= m && !prime[map[r][c]])
				if (ans < dp[r][c]) ans = dp[r][c], x = map[r][c];
				else if (ans == dp[r][c] && x < map[r][c]) x = map[r][c];

		printf("%d %d\n", ans, x);
	}
	return 0;
}

Measured memory_bytes: 18768
#include<bits/stdc++.h>
using namespace std;
int x,dp[305][305][305];
int main()
{
	string s;cin>>s>>x;
	for(int i=0;i<s.size();i++)for(int j=0;j<s.size()-i;j++)
	{
		int fr=j,to=j+i;
		for(int k=0;k<=x;k++)
		{
			if(fr==to)dp[fr][to][k]=1;
			else dp[fr][to][k]=max(dp[fr][to][k],max(dp[fr][to-1][k],dp[fr+1][to][k])),dp[fr][to][k+(s[fr]!=s[to])]=max(dp[fr][to][k+(s[fr]!=s[to])],dp[fr+1][to-1][k]+2);
		}
	}
	printf("%d\n",dp[0][s.size()-1][x]);
	return 0;
}

Measured memory_bytes: 110848
#include<bits/stdc++.h>
     
    #define INF 1000000007
    #define LINF 1000000000000000007
     
    using namespace std;
     
    typedef long long Int;
    typedef pair<Int, Int> P;
     
    Int gcd(Int x, Int y){
    	if(y == 0)
    		return x;
    	return gcd(y, x % y);
    }
     
    Int lcm(Int x, Int y){
    	return x * y / gcd(x, y);
    }
     
    bool sosuu(int x){
    	bool b = 1;
    	if(x == 1) b = 0;
    	for(int i = 2; i * i <= x; i++){
    		if(x % i == 0) {
    			b = 0;
    			break;
    		}
    	}
    	return b;
    }
     
    int n, x[200000], a[200000];
     
    int main(){
    	cin >> n;
    	for(int i = 0; i < n; i++){
    		cin >> x[i];
    		a[i] = x[i];
    	}
    	sort(x, x+ n);
    	int l = x[n/2-1], r = x[n/2];
    	
    	for(int i = 0; i < n; i++){
    		if(a[i] <= l) cout << r << endl;
    		else cout << l << endl;
    	}
    	
    	return 0;
    }

Measured memory_bytes: 3712
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
//#pragma GCC target("popcnt")
//#pragma GCC target("sse4")
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;








#define int long long

vector<int> b;
int n, m, v, p;
bool go(int i){
    vector<int> a = b;
    int vv = v;
    vv -= i;
    vv--;
    int q = a[i] + m;
    for(int k = i + 1; k < n; k++){
        if (a[k] == a[i]) vv--;
        else break;
    }
    int j;
    for (j = n - 1; j >= 0; j--){
        if (a[j] <= q) break;
    }
    j++;
    if ((n - j) >= p) return false;
    vv -= (p - 1);
    //if (vv <= 0) return true;
    int ff = m * vv;
    for (int id = i + 1; id < min(j, n - p + 1); id++){
        ff -= (q - a[id]);
    }
    if (ff > 0) return false;
    return true;
}



signed main(){
    cin >> n >> m >> v >> p;
    b.resize(n);
    for (int i = 0; i < n; i++) cin >> b[i];
    sort(rng(b));
    int l = -1, r = n - 1;
    while(r - l > 1){
        int m = (l + r) / 2;
        if (go(m)) r = m;
        else l = m;
    //    cout << l << ' ' << r << ' ' << m << endl;
    }
    cout << n - r;



}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
const ll mod = 1000000007;
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; }

const long long INF = 1LL << 60;

int N;

long long dp[100010];

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

  rep(i, 100010) dp[i] = -1;
  dp[0] = 1;
  dp[1] = 1;

  rep(i, M){
    int a; cin >> a;
    dp[a] = 0;
  }

  REP(i, 2, N+1){
    if(dp[i] != 0){
      dp[i] = dp[i-1] + dp[i-2];
      dp[i] %= mod;
    }
  }

  cout << dp[N] << endl;

  return 0;
}


Measured memory_bytes: 1024
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)

monster_count = 0
next_saver = 0

for i in range(N+1):
    if A[i] > B[i] + next_saver:
        monster_count += B[i] + next_saver
        next_saver = 0
    else:
        monster_count += A[i]
        if A[i] <= next_saver:
            next_saver = B[i]
        else:
            next_saver = B[i] - (A[i]-next_saver)
print(monster_count)


Measured memory_bytes: 18624
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD = 1e9  +7;
 
int main() {
    int n;
    scanf("%d", &n);
 
    long long ten = 1;
    long long nine = 1;
    long long eight = 1;
 
    for (int i = 0; i < n; i++) {
        ten = ten * 10 % MOD;
        nine = nine * 9 % MOD;
        eight = eight * 8 % MOD;
    }
 
    ten = ten - nine * 2 + eight;
    ten %= MOD;
  	ten += MOD;
  	ten %= MOD;
 
    printf("%lld\n", ten);
}

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

int a,b,c,sr[500],ans,n,p[500];
string s;

int  main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>p[i];

    for(int i=1;i<n-1;i++){
        if(p[i]>p[i+1]&&p[i]<p[i-1])ans++;
        else if(p[i]<p[i+1]&&p[i]>p[i-1])ans++;
    }
    cout<<ans<<endl;
}




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

int main(){
	double limit;
	double t;
	double y;
	double n;
	while(cin >> limit){
		t = limit / 9.8;
		y = 4.9 * t * t;
		n = ceil(y/5.0+1.0);
		cout << n << endl;
	}
	return 0;
}

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

int N;
int A[210];         // 最大 200 個なので余裕を持って 210 に --- 200 以上ならなんでもよいです

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];

    int res = 0;

    // 操作が行える限り操作を繰り返す
    while (true) {
        bool exist_odd = false;  // A[i] がすべて偶数かどうかを判定するフラグ
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;  // 奇数があったらフラグを立てる
        }

        if (exist_odd) break;  // 奇数があったら break

        // 操作を行えるなら操作を実際に行う
        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res;  // 操作回数をインクリメント
    }

    cout << res << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <set>
using namespace std;
int main()
{
    int n,temp;
    cin >> n;
    set<int> a;
    for(int i = 0; i< n; i++){
        cin >> temp;
        if(a.find(temp) == a.end()){
            a.insert(temp);
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


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

#define ll long long

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
        int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i =0;i<n;i++)
		cin>>arr[i];
	vector<int>dp(n,INT_MAX);
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
	{
		for(int j= i-1,jump=0;j>=0 && jump<k;j--,jump++)
			dp[i]=min(dp[i],dp[j]+abs(arr[j]-arr[i]));

	}
	int cost=dp[n-1];
	cout<<cost<<'\n';
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
constexpr i64 MOD = 1e9 + 7;

i64 fact[101010];
i64 factinv[101010];

i64 modpow(i64 a, i64 n, i64 mod) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        i64 t = modpow(a, n / 2, mod);
        return t * t % mod;
    }
    return a * modpow(a, n - 1, mod) % mod;
}

void build() {
    fact[0] = 1;
    for (int i = 1; i < 101010; i++) {
        fact[i] = fact[i - 1] * i % MOD;
    }
    factinv[101010 - 1] = modpow(fact[101010 - 1], MOD - 2, MOD);
    for (int i = 101010 - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * (i + 1) % MOD;
    }
}

vi as;
vi sum;

int main() {
    build();
    int n;
    cin >> n;
    as = vi(n);
    sum = vi(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
        sum[i + 1] = sum[i] + as[i];
    }
 
    i64 ans = sum[n] % MOD * fact[n] % MOD;
    for (int i = 1; i < n; i++) {
        ans += ((sum[i] - sum[0]) + (sum[n] - sum[n - i])) % MOD * fact[n] % MOD * factinv[i + 1] % MOD * fact[i] % MOD;
        ans %= MOD;
        assert(ans >= 0);
    }
 
    i64 tmp = 0;
    for (int i = 1; i < n - 1; i++) {
        i64 cur = (sum[n - i] - sum[i]) % MOD; 
        ans += 2 * (tmp + cur) % MOD * fact[n] % MOD * factinv[i + 2] % MOD * fact[i] % MOD;
        ans %= MOD;
        tmp += cur;
        tmp %= MOD;
    }

    cout << (ans + MOD) % MOD << endl;
}

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

using namespace std;

int x[10],y[10];
double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

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

    int nn=1;
    int a=0;
    for (int i = 0; i < n; i++) {
        cin>>x[i]>>y[i];
        nn=nn*(i+1);
    }
    double ans=0;

    vector<int> v(n);
    iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
    do {
        for(int i=1;i<n;i++) ans+=dist(v[i]-1,v[i-1]-1);
    } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成


    cout<<fixed << setprecision(10) <<ans/nn<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

template <class T>
struct Union_find {
    /*
  T: integer(int, long longなど)
  n個の整数に対してunion find森を生成
  par: 親の配列 ex)par[x]はxの親
  rank: ランクの配列で、root以外は意味はない
  size_of: サイズの配列で、root以外は意味がない
  root(x): xの根を返す
  same(x, y): boolでxとyが連結かを返す
  size(x): xが含まれる木の要素数を返す
  unite(x, y): xが含まれる木とyが含まれる木を連結させる
  */
    vector<T> par;
    vector<T> rank;
    vector<T> size_of;

    Union_find(T n) : par(n), rank(n), size_of(n) {
        for (T i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            size_of[i] = 1;
        }
    }

    T root(T x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

    bool same(T x, T y) {
        return root(x) == root(y);
    }

    T size(T x) {
        return size_of[root(x)];
    }

    void unite(T x, T y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (rank[x] < rank[y]) {
            size_of[y] += size_of[x];
            par[x] = y;
        }
        else {
            size_of[x] += size_of[y];
            par[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
        return;
    }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<set<int>> cannot_make_friends_with(n);
    int a, b;
    Union_find<int> uf(n);
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
        cannot_make_friends_with[a].insert(b);
        cannot_make_friends_with[b].insert(a);
    }
    int c, d;
    rep(i, k) {
        cin >> c >> d;
        c--;
        d--;
        if (uf.same(c, d)) {
            cannot_make_friends_with[c].insert(d);
            cannot_make_friends_with[d].insert(c);
        }
    }
    rep(i, n) {
        cout << uf.size(i) - cannot_make_friends_with[i].size() - 1;
        if (i != n - 1)
            cout << " ";
        else
            cout << endl;
    }
    return 0;
}

Measured memory_bytes: 25472
import heapq

v, e = map(int, input().split())
edges = []
for i in range(e):
    s, t, w = map(int, input().split())
    heapq.heappush(edges, (w, (s, t)))


class Node():
    def __init__(self, id):
        self.id = id
        self.p = self
        self.rank = 0


class DisjointSet():
    def __init__(self, n):
        self.nodes = {}
        for i in range(n):
            self.makeSet(i)

    def makeSet(self, i):
        self.nodes[i] = Node(i)

    def findSet(self, x):
        if x.p is not x:
            x.p = self.findSet(x.p)
        return x.p

    def unite(self, x, y):
        # ランクの低い方を子にする
        px = self.findSet(x)
        py = self.findSet(y)
        if px.rank > py.rank:
            py.p = px
        else:
            px.p = py
        if x.rank == y.rank:
            py.rank += 1

    def bool(self, x, y):
        return self.findSet(x) == self.findSet(y)


def kruskal(v, edges):
    S = DisjointSet(v)
    K = []

    while len(edges):
        w, edge = heapq.heappop(edges)
        # sorceとtargetがdisjointなら追加
        x, y = S.nodes[edge[0]], S.nodes[edge[1]]
        if not S.bool(x, y):
            S.unite(x, y)
            K.append((edge, w))
    return K


K = kruskal(v, edges)
# print(K)
print(sum(map(lambda x: x[1], K)))



Measured memory_bytes: 30712
N, A = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(lambda n:n-A, x))

X = max(x)
dp = [[0 for i in range(2*X*N + 1)] for j in range(N + 1)]

for i in range(1, N + 1):
    dp[i][y[i - 1] + X*N] += 1
    for j in range(len(dp[0])):
        dp[i][j] += dp[i - 1][j]
        diff = j + y[i - 1]
        if 0 <= diff and diff <= 2*X*N:
            dp[i][diff] += dp[i - 1][j]

print(dp[N][X*N])

Measured memory_bytes: 5748
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>


using namespace std;
const int MOD = 1000000009; // check!!!
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

typedef vector<vector<int> > Graph;

bool visit(const Graph &g, int v, vector<int> &order, vector<int> &color) {
	color[v] = 1;
	FOR(i,sz(g[v])) {
		if (color[g[v][i]] == 2) continue; //vectorに追加済
		if (color[g[v][i]] == 1) return false; //DFSで既に訪れている -> loop検出
		if (!visit(g, g[v][i], order, color)) return false;
	}
	order.push_back(v); color[v] = 2;
	return true;
}
bool topological_sort(const Graph &g, vector<int> &order) {
	order.clear();
	int n = g.size();
	vector<int> color(n);
	FOR(u, n) if (!color[u] && !visit(g, u, order, color)) return false;
	reverse(order.begin(),order.end());
	return true;
}



int main(){

	int m,n; cin>>m>>n;
	Graph g(m);
	FOR(i,n){
		int x,y; cin>>x>>y;
		x--; y--;
		g[x].push_back(y);
	}

	vector<int> ans;
	topological_sort(g,ans);

	FOR(i,sz(ans)) cout << ans[i] + 1 << endl;

	return 0;
}

Measured memory_bytes: 1220
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
		int m = sc.nextInt();
    
		// 出力
		System.out.println((n - 1) * (m - 1));
	}
}


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

datas = [list(map(int, input().split())) for _ in range(n)]

for Cx in range(101):
  for Cy in range(101):
    flag = True
    H = 0
    for data in datas:
      if data[2] != 0:
        #高さをあるデータから適当に決める
        H = data[2] + abs(data[0] - Cx) + abs(data[1] - Cy)
        break
        
    #直前で適当に決めた高さがほかのデータにも適合すればOK
    for data in datas:
      if data[2] != 0:
        if H != data[2] + abs(data[0] - Cx) + abs(data[1] - Cy):
          flag = False
          break
      else:
        #hi = 0ならH-abs(data[0] - Cx)-abs(data[1] - Cy)<= 0であるあず
        if H - abs(data[0] - Cx) - abs(data[1] - Cy) > 0:
          flag = False
          break
          
    if flag:
      print(Cx, Cy, H)
          
    

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

int main(){
	string s; 
	cin >> s; 
	for(int i = 0 ; i < (int)s.size()-1 ; i++ ){
		if( s[i] == s[i+1] ){
			cout << "Bad" << endl; 
			return 0 ; 
		}
	}
	cout << "Good" << endl; 
}


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

typedef struct{
  double x;
  double y;
}vertex;

void kock(int,vertex,vertex);

int main()
{
  int n;
  vertex p1={0,0},p2={100,0};

  scanf("%d",&n);

  if(n > 6 || n < 0) return 0;

  printf("%.8lf %.8lf\n",p1.x,p1.y);

  kock(n,p1,p2);
  
  printf("%.8lf %.8lf\n",p2.x,p2.y);
  
  return 0;
}

void kock(int n,vertex p1,vertex p2)
{
  vertex s,u,t;
  if(n == 0) return;

  s.x = (2 * p1.x + p2.x) / 3;

  s.y = (2 * p1.y + p2.y) / 3;

  t.x = (p1.x + 2 * p2.x) / 3;

  t.y = (p1.y + 2 * p2.y) / 3;

  u.x = (t.x - s.x) * cos(60 * M_PI/180.0) - (t.y - s.y) * sin(60 * M_PI/180) + s.x;

  u.y = (t.x - s.x) * sin(60 * M_PI/180.0) + (t.y - s.y) * cos(60 * M_PI/180) + s.y;

  
  kock(n-1,p1,s);
  printf("%.8lf %.8lf\n",s.x,s.y);
  kock(n-1,s,u);
  printf("%.8lf %.8lf\n",u.x,u.y);
  kock(n-1,u,t);
  printf("%.8lf %.8lf\n",t.x,t.y);
  kock(n-1,t,p2);

}



Measured memory_bytes: 2104
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	int n;
	string s;
	cin >> n >> s;
	int count(0);
	int sum(0);
	rep(i, n) {
		if (s[i] == 'A') {
			count = 1;
		}
		else if (s[i] == 'B' && count == 1) {
			count = 2;
		}
		else if (s[i] == 'C' && count == 2) {
			count = 0;
			++sum;
		}
		else {
			count = 0;
		}
	}
	cout << sum;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    n %= 10;

         if(n == 3) cout << "bon" << endl;
    else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
}

Measured memory_bytes: 3616
N, M, K = gets.chomp.split.map(&:to_i)

AS = gets.chomp.split.map(&:to_i)
BS = gets.chomp.split.map(&:to_i)

a_sum = [0]
b_sum = [0]
AS.each { |a| a_sum << a_sum[-1] + a }
BS.each { |b| b_sum << b_sum[-1] + b }

b_index = BS.size

ans = 0

a_sum.size.times do |a_index|
  break if a_sum[a_index] > K
  b_index -= 1 while a_sum[a_index] + b_sum[b_index] > K
  ans = [ans, a_index + b_index].max
end

puts ans


Measured memory_bytes: 49428