akhauriyash/Code-Regression huggingface dataset:
//code by lynmisakura.wish to be accepted!
/****************************/
#include<bits/stdc++.h>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;
 
//const long long INF = 1LL << 55;
 
#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int n,m;
const int MAX_N = 1010;
const int INF = 1 << 30;
vector<int> to[MAX_N];
//最小サイクルの検出
vector<int> bfs(int x){
   
   queue<int> q;
   vector<int> dist(n+1,INF);//xからの最小距離
   vector<int> prev(n+1,-1);
   pair<int,int> best(INF,n+1);//最小サイクルの
   
   q.push(x);
   dist[x] = 0;
   while(!q.empty()){
      int y = q.front();q.pop();
      for(auto v : to[y]){
         if(dist[v] != INF)continue;
         else{
            prev[v] = y;
            dist[v] = dist[y] + 1;
            q.push(v);
         }
      }
   }
   // for(auto i : dist)printf("%d ",i);
   //cout << endl;
   rep(v,n){
      for(auto i : to[v]){
         if(i == x){
            if(best.first > dist[v]){
               best = make_pair(dist[v],v);
            }
         }
      }
   }
   
   // cout << best.first << " " << best.second << endl;
   if(best.first == INF)return vector<int>(n+1);
   else{
      vector<int> res;
      
      int j = best.second;
      res.pb(j);
      while(j != x){
         j = prev[j];
         res.pb(j);
      }
      return res;
   }
}
int main(void){
   cin >> n >> m;
   rep(i,m){
      int a,b;cin >> a >> b;
      to[--a].pb(--b);
   }
   
   vector<int> ans(n+1,INF);
   rep(i,n){
      auto res = bfs(i);
      if(res.size() < ans.size()) ans = res;
   }
   if(ans.size() == n + 1){
      cout << -1 << endl;
   }else{
      cout << ans.size() << endl;
      for(auto i : ans)cout << i + 1 << endl;
   }
   return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n),c(n);
    for (int i = 0; i < n; i++){
        cin >> v.at(i);
    }
    for (int i = 0; i < n; i++){
        cin >> c.at(i);
    }
    int sum = 0;
    for (int i = 0; i < n; i++){
        if (v[i] - c[i] > 0){
            sum += v[i] - c[i];
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vsort(x) sort(x.begin(),x.end())

using int64 = ll;

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vint a(m);
	rep(i, 0, m)
		cin >> a[i];
	int c[200][2] = {};
	rep(i, 0, 2 * n)
		c[i][1] = i + 1;
	rep(i, 0, m){
		if (!a[i]){
			rep(j, 0, 2 * n){
				if (j&1){
					c[j][i & 1] = c[n + j / 2][1 ^ (i & 1)];
				}
				else{
					c[j][i & 1] = c[j / 2][1 ^ (i & 1)];
				}
			}
		}
		else{
			rep(j, 0, 2 * n){
				if (j < 2 * n - a[i]){
					c[j][i & 1] = c[j + a[i]][1 ^ (i & 1)];
				}
				else{
					c[j][i & 1] = c[j - 2 * n + a[i]][1 ^ (i & 1)];
				}
			}
		}
	}
	rep(i, 0, 2 * n)
		cout << c[i][1 ^ (m & 1)] << endl;
	return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
	char s1,s2,s3;
	int i=0;
	cin>>s1>>s2>>s3;
	if(s1=='1') i++;
	if(s2=='1') i++;
	if(s3=='1') i++;
	cout<<i<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
#define INF 1<<30

int main()
{
    vector<vector<int>> A(3,vector<int>(3));
    vector<vector<bool>> P(3,vector<bool>(3,false));
    REP(i,3){
        REP(j,3)cin >> A[i][j];
    }
    int N;
    cin >> N;
    int b;
    REP(i,N){
        cin >> b;
        REP(j,3){
            REP(k,3){
                if(b==A[j][k])P[j][k]=true;
            }
        }
    }
    bool tate1 = P[0][0] && P[1][0] && P[2][0];
    bool tate2 = P[0][1] && P[1][1] && P[2][1];
    bool tate3 = P[0][2] && P[1][2] && P[2][2];
    bool yoko1 = P[0][0] && P[0][1] && P[0][2];
    bool yoko2 = P[1][0] && P[1][1] && P[1][2];
    bool yoko3 = P[2][0] && P[2][1] && P[2][2];
    bool naname1 = P[0][0] && P[1][1] && P[2][2];
    bool naname2 = P[2][0] && P[1][1] && P[0][2];
    /*REP(i,3){
        REP(j,3) cout << P[i][j] << " ";
        cout << endl;
    }*/
    if(tate1||tate2||tate3||yoko1||yoko2||yoko3||naname1||naname2)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a

def lcm(a, b):
  return a * b // gcd (a, b)

A,B,C,D=map(int, input().split())
CD = lcm(C, D)

c_first = 0
c_last = 0
d_first = 0
d_last = 0
cd_first = 0
cd_last = 0

c_first = (A-1) // C
c_last = B // C
d_first = (A-1) // D
d_last = B // D
cd_first = (A-1) // CD
cd_last = B // CD

c_count = 0
d_count = 0
cd_count = 0
if c_last != 0:
  c_count = c_last - c_first
if d_last != 0:
  d_count = d_last - d_first
if cd_last != 0:
  cd_count = cd_last - cd_first
    
#print(c_first, c_last, d_first, d_last, cd_first, cd_last)
#print(c_count, d_count, cd_count)
print(B - A + 1 - (c_count + d_count - cd_count))



Measured memory_bytes: 3064
N = int(input())
dp = [0,0,0]
for _ in range(N):
    a, b, c = map(int, input().split())
    ndp = [0,0,0]
    ndp[0] = max(dp[1], dp[2]) + a
    ndp[1] = max(dp[0], dp[2]) + b
    ndp[2] = max(dp[0], dp[1]) + c
    dp = ndp
print(max(dp))


Measured memory_bytes: 3064
#include <iostream>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
using namespace std;

class UnionFind {
private:
  vector<int> par;              // 親
  vector<int> rank;             // 木の深さ

public:
  // n 要素で初期化
  UnionFind(int n) {
    par.resize(n);              // or MAX_N
    rank.resize(n);
    REP(i,0,n) {
      par[i] = i;
      rank[i] = 0;
    }
  }

  // 木の根を求める
  int find(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = find(par[x]);
    }
  }

  // xとyの属する集合を併合
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }

  // xとyが同じ集合に属するか否か
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

const int MAX_N = int(1e5+10);
int N,M;
int p[MAX_N];

int main()
{
  cin >> N >> M;
  REP(i,0,N) {
    cin >> p[i];
    p[i]--;                     // 0-indexed に変更
  }

  UnionFind uf(N);
  REP(i,0,M) {
    int x,y;
    cin >> x >> y;
    --x; --y;                   // 0-indexed に変更

    uf.unite(x,y);
  }

  // i と p[i] が同じグループになるような i を数える
  int ans = 0;
  REP(i,0,N) {
    if (uf.same(i, p[i])) ++ans;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
const ll N= 2e5 + 5;
const ll MOD=1e9 + 7;

ll n,u,v,deg[N];
pair<ll,ll> arr[N];
vector<ll> adj[N];
set<ll> st[N];
set<ll> chk[N];
map< pair<ll,ll> , ll> mp;
void dfs(ll src,ll pr){
    for(ll i=0;i<adj[src].size();i++){
        ll ele = adj[src][i];
        if(ele == pr)continue;
        u = src, v = ele;
        if(st[u].size()<st[v].size())swap(u,v);
        ll val = -1;
        for(set<ll>::iterator itr=st[v].begin() ; itr!=st[v].end() ; itr++)if(!chk[u].count(*itr)){val=*itr;break;}
        if(val==-1)for(set<ll>::iterator itr=st[u].begin() ; itr!=st[u].end() ; itr++)if(!chk[v].count(*itr)){val=*itr;break;}
        chk[u].insert(val);
        chk[v].insert(val);
        st[u].erase(val);
        st[v].erase(val);
        mp[make_pair(u,v)]=mp[make_pair(v,u)]=val;
        dfs(ele,src);
    }
}

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

    cin>>n;
    for(ll i=1;i<=n-1;i++){
        cin>>u>>v;
        deg[u]++;deg[v]++;
        adj[v].push_back(u);
        adj[u].push_back(v);
        arr[i]=make_pair(u,v);
    }
    cout<<*max_element(deg,deg+N)<<"\n";
    for(ll i=1;i<=n;i++)for(ll j=1;j<=deg[i];j++)st[i].insert(j);
    dfs(1,0);
    for(ll i=1;i<=n-1;i++)cout<<mp[arr[i]]<<"\n";
}


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

length = len(str(n))

if length == 1:
    res = n
elif length == 2:
    res = 9
elif length == 3:
    res = 9 + n - 99
elif length == 4:
    res = 909

elif length == 5:
    res = 9 + 900 + n - 9999
else:
    res = 90909

print(res)


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b, c;
int x, y;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  cin >> s;

  if ((s[0] == s[1] && s[2] == s[1]) || (s[3] == s[2] && s[2] == s[1]))
    Yes();
  else
    No();
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;   // -std=c++11

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<ll> xo(n), sm(n);
    for (int i = 0; i < n; i++) xo[i] = sm[i] = a[i];
    for (int i = 1; i < n; i++) xo[i] ^= xo[i - 1];
    for (int i = 1; i < n; i++) sm[i] += sm[i - 1];
    ll ans = 0;
    for (int left = 0; left < n; left++) {
        int ok = left, ng = n;
        while (ok + 1 != ng) {
            int md = (ok + ng) / 2;

            ll x = xo[md];
            if (left) x ^= xo[left - 1];

            ll s = sm[md];
            if (left) s -= sm[left - 1];

            if (x == s) ok = md;
            else ng = md;
        }
        ans += ok - left + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define rs resize
using namespace std;
ll g[101][100001];
ll d[101][100001];
main (){
ll n,m;
cin>>n>>m;
vector<pair<ll,ll> >a;
a.rs(n+1);
for (int i=1;i<=n;i++)
    cin>>a[i].x>>a[i].y;
for (int i=1;i<=n;i++)
for (int k=1;k<=m;k++)
{
    if (a[i].x>k)
        d[i][k]=d[i-1][k];
    else
        d[i][k]=max(d[i-1][k],d[i-1][k-a[i].x]+a[i].y);
}
cout<<d[n][m];

return 0;}


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

int main(){
  int i,N,max,x,h;
  cin >> N;
  max = 0;
  x = 0;
  for(i=0;i<N;i++){
    cin >> h;
    if(h>=max){
      max = h;
      x++;
    }
  }
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();

        String ans = a + b;
        Integer ansInt = Integer.parseInt(ans);

        double sqrt = Math.sqrt(ansInt);

        if((int)sqrt*sqrt == ansInt){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int k;
	cin >> k;
	long long s = 0;
	for (int i = 1; i <= k; i++) {
		 for (int j = 1; j <= k; j++) {
			 for (int l =1; l <= k; l++) {
				s += __gcd(i, __gcd(j, l));
			}
		}
	}
	cout << s << '\n';
	return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

struct UF {
  vector<int> parent_, rank_;

  UF(int N) : parent_(N + 5), rank_(N + 5, 0) {
    for (int i = 0; i <= N; ++i) {
      parent_[i] = i;
    }
  }

  int find_set(int x) {
    if (parent_[x] != x) {
      parent_[x] = find_set(parent_[x]);
    }
    return parent_[x];
  }

  void unite(int x, int y) {
    int sx = find_set(x), sy = find_set(y);
    if (sx == sy) { return; }
    if (rank_[sx] > rank_[sy]) {
      parent_[sy] = sx;
    }
    else {
      parent_[sx] = sy;
      if (rank_[sx] == rank_[sy]) {
        ++rank_[sy];
      }
    }
  }

  bool is_connected(int x, int y) {
    return find_set(x) == find_set(y);
  }
};

int main()
{
  int N, K, L; scanf("%d %d %d", &N, &K, &L);
  UF uf1(N + 5), uf2(N + 5);
  int a, b;
  for (int i = 0; i < K; ++i) {
    scanf("%d %d", &a, &b);
    uf1.unite(a, b);
  }
  for (int i = 0; i < L; ++i) {
    scanf("%d %d", &a, &b);
    uf2.unite(a, b);
  }
  vector<int> road(N + 5), rail(N + 5);
  vector<pair<int, int>> v(N);
  // map<pair<int, int>, int> freqs;
  for (int i = 1; i <= N; ++i) {
    road[i] = uf1.find_set(i);
    rail[i] = uf2.find_set(i);
    // ++freqs[make_pair(road[i], rail[i])];
    v[i - 1] = make_pair(road[i], rail[i]);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < N; ++i) {
    pair<int, int> p = make_pair(road[i + 1], rail[i + 1]);
    int ans = distance(lower_bound(v.begin(), v.end(), p),
                       upper_bound(v.begin(), v.end(), p));
    if (i == 0) { printf("%d", ans); }
    else { printf(" %d", ans); }
  }
  printf("\n");

  // for (int i = 1; i <= N; ++i) {
  //   pair<int, int> p = make_pair(road[i], rail[i]);
  //   int cnt = freqs[p];
  //   if (i == 1) { printf("%d", cnt); }
  //   else { printf(" %d", cnt); }
  // }
  // printf("\n");
  return 0;
}


Measured memory_bytes: 6912
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,M,V,P = MI()
A = [0] + LI()
A.sort()


def f(i):  # i番目の問題が採用されうるか
    a = A[i]
    v = V-i
    if A[-P] > a+M:
        return False
    v -= P-1
    if sum(a+M-A[j] for j in range(i+1,N-P+2)) >= M*v:
        return True
    return False


left = 0
right = N
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(N+1-right)


Measured memory_bytes: 86376
from collections import deque
n = int(input())
s = input()
q = int(input())
k = list(map(int,input().split()))

def search(k):
    d = 0
    m = 0
    count = 0
    ans = 0
    q = deque([])
    for i in range(n):
        if s[i] == "D":
            d += 1
        elif s[i] == "M":
            m += 1
            count += d
            q.append(d)
        elif s[i] == "C":
            ans += count
        if i>= k-1:
            if s[i-k+1] == "D":
                d -= 1
                count -= m
            elif s[i-k+1] == "M":
                m -= 1
                
        
    return ans
for i in k:
    print(search(i))

Measured memory_bytes: 245352
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;cin>>n;
  vl a(n),b(n),c(n),d(n);
  rep(i,n)cin>>a[i]>>b[i];
  rep(i,n)cin>>c[i]>>d[i];
  vector<P>R(n);
  rep(i,n){
    R[i].first=b[i];R[i].second=a[i];
  }
  vector<P>B(n);
  rep(i,n){
    B[i].first=c[i];B[i].second=d[i];
  }
  sort(R.begin(),R.end());
  reverse(R.begin(),R.end());
  sort(B.begin(),B.end());
  vector<bool>unuse(n,true);
  ll count=0;
  rep(i,n){
    rep(j,n){
      if(R[j].second<B[i].first && unuse[j] && R[j].first<B[i].second){
        unuse[j]=false;
        count++;
        break;
      }
    }
  }
  cout<<count<<endl;
}
        
    
    

    

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template<class T>
inline void read(T&);
template<class T>
inline void write(const T&);

typedef long long ll;
typedef unsigned long long ull;
typedef const int& ci;
typedef std::pair<int, int> pii;
const int iinf = 2147483647;
const ll llinf = 9223372036854775807ll;
using std::min;
using std::max;
using std::abs;
using std::sort;

int main () {
    int n, a, b;
    read(n), read(a), read(b);
    write(min(a * n, b)), EL;
    return 0;
}

template<class T>
void read(T &Re) {
    T k = 0;
    char ch = getchar();
    int flag = 1;
    while (!isNum(ch)) {
        if (ch == '-') {
            flag = -1;
        }
        ch = getchar();
    }
    while (isNum(ch)) {
        k = (k << 1) + (k << 3) + ch - '0';
        ch = getchar();
    }
    Re = flag * k;
}
template<class T>
void write(const T &Wr) {
    if (Wr < 0) {
        putchar('-');
        write(-Wr);
    } else {
        if (Wr < 10) {
            putchar(Wr + '0');
        } else {
            write(Wr / 10);
            putchar((Wr % 10) + '0');
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll dp[1111][BITLE(13)];
vector<pair<ll,ll>> key(1111);
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  for(int i=0;i<m;i++){
    ll a,b;cin>>a>>b;
    ll num=0;
    for(int j=0;j<b;j++){
      ll c;cin>>c;
      num+=BITLE(c-1);
    }
    key[i]=mp(a,num);
  }
  for(int i=0;i<BITLE(13);i++)
    for(int j=0;j<1111;j++)
      dp[j][i]=llINF;
  dp[0][0]=0;
  for(int i=0;i<m;i++){
    for(int j=0;j<BITLE(n);j++){
      if(dp[i][j]!=llINF){
	//	cout<<i<<" "<<j<<endl;
	//cout<<key[i].S<<" "<<key[i].F<<endl;
	dp[i+1][j|key[i].S]=min(dp[i+1][j|key[i].S],dp[i][j]+key[i].F);
	dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
      }
    }
  }
  if(dp[m][BITLE(n)-1]==llINF)
    cout<<-1<<endl;
  else cout<<dp[m][BITLE(n)-1]<<endl;
  return 0;
}

Measured memory_bytes: 71424
N = int(input())
S = input()

ans = 0
jyogai = 0

for i in range(N-1):
    nS = S[i+1:]
    kouho = []
    for w in ["R", "G", "B"]:
        if S[i] != w:
            kouho.append(nS.count(w))
    temp = i
    while True:
        temp += 1
        temp2 = temp - i
        if i + 2*temp2 > N-1:
            break
        b = [S[i], S[i + temp2], S[i + 2*temp2]]
        if len(set(b)) == 3:
            jyogai += 1

    ans += kouho[0] * kouho[1]

print(ans - jyogai)

Measured memory_bytes: 68536
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    int ans=0;
    rep(i,n){
        int a;
        cin>>a;
        ans+=a-1;
    }
    cout<<ans<<endl;
}

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

long long gcd(long long number1, long long number2)
{
  //最大公約数
  long long m = number1;
  long long n = number2;

  if (number2 > number1)
  {
    m = number2;
    n = number1;
  }
  long long r = n % m;
  while (r != 0)
  {
    n = m;
    m = r;
    r = n % m;
  }

  return m;
}

long long lcm(long long number1, long long number2)
{
  //最小公倍数
  return number1 * number2 / gcd(number1, number2);
}

int main()
{
  int A, B;
  cin >> A >> B;
  long long ans = lcm(A, B);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
#from copy import deepcopy
setrecursionlimit(10**6)

n=int(stdin.readline().rstrip())
a=[tuple(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
cnt=0
for i in range(n-1,-1,-1):
    now=(a[i][0]+cnt)%a[i][1]
    if now!=0:
        cnt+=a[i][1]-now
print(cnt)

Measured memory_bytes: 16612
#include<iostream>
using namespace std;
int main(){
  long n,num1,num2,dp[100000+1]={};
  cin >> n;
  int h[n];
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  for(int i=2;i<n;i++){
    num1=abs(h[i]-h[i-2])+dp[i-2];
    num2=abs(h[i]-h[i-1])+dp[i-1];
    dp[i]=(num1<num2)?num1:num2;
  }
  cout << dp[n-1]<<endl;
}


Measured memory_bytes: 1408
import sys

sys.setrecursionlimit(100000)
class Cmber:
    def __init__(self,gensize,mod=10**9+7):
        self.mod = mod
        self.g1=[1,1]
        self.g2 = [1, 1] #逆元テーブル
        self.inverse = [0, 1] #逆元テーブル計算用テーブル
        self.getgen(gensize)
    def getgen(self,N):
        for i in range( 2, N + 1 ):
            self.g1.append( ( self.g1[-1] * i ) % self.mod )
            self.inverse.append( ( -self.inverse[self.mod % i] * (self.mod//i) ) % self.mod )
            self.g2.append( (self.g2[-1] * self.inverse[-1]) % self.mod )
    def per(self,n,r):
        if ( r<0 or r>n ):
            return 0

        return self.g1[n] * self.g2[n-r]  % self.mod        


    def cmb(self,n, r):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod
 
    def cmb_very_high_n(self,n, r):
        if ( r<0 or r>n ):
            return 0
        g1=1
        r = min(r, n-r)
        for i in range(n-r+1,n+1):
            g1*=i
            g1%=self.mod
        return g1 * self.g2[r] % self.mod

    def multiple_cmb(self,vals):
        ans = self.g1[sum(vals)] % self.mod
        for i in vals:
            ans = (ans*self.g2[i])%self.mod
        return ans






def dfs(connections:list,node,oya,K,cmber:Cmber):

    if node == oya:
        children = connections[node]
        ans = cmber.per(K-1,len(children))

        for child in children:
            ans *= dfs(connections,child,node,K,cmber)
            ans %= cmber.mod

        return (ans * K) % cmber.mod

    if len(connections[node])==1:

        return 1


    children = [i for i in connections[node] if i != oya]

    ans = cmber.per(K-2,len(children))
    for child in children:
        ans *= dfs(connections,child,node,K,cmber)
        ans %= cmber.mod

    return ans





def resolve():
    N,K = map(int,input().split())
    connections= [[] for i in range(N)]
    for i in range(N-1):
        a,b = map(int,input().split())
        connections[a-1].append(b-1)
        connections[b-1].append(a-1)

    cmber = Cmber(K)
    print(dfs(connections,0,0,K,cmber))







if __name__ == "__main__":
    resolve()

Measured memory_bytes: 198432
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i=0;i<N;i++) cin >> d.at(i);
    int ans=0;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            ans += d.at(i) * d.at(j);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        sc.close();
        int l, r, score, ans=Integer.MAX_VALUE;
        for (int i=0; i<n-k+1; i++){
            l = arr[i];
            r = arr[i+k-1];
            if (l<0 && r>=0){
                l = Math.abs(l);
                score = Math.max(l, r) + 2*Math.min(l, r);
            }else{
                l = Math.abs(l);
                r = Math.abs(r);
                score = Math.max(l, r);
            }
            ans = Math.min(ans, score);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 59464
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する

vector<vector<int> > G;//子供


ll rec(int v) {
    if (G[v].size() == 0) return 0;

    vector<ll> child;
    for (auto e : G[v]) {
        child.push_back(rec(e));
    }

    sort(child.rbegin(),child.rend());
    for (int i = 0; i < child.size(); ++i) {
        child[i] += i + 1;
    }
    sort(all(child));
    return child.back();
}

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

    int N;
    cin >> N;
    G.resize(N + 1, vector<int>());

    for (int i = 2; i <= N; ++i) {
        int a;
        cin >> a;
        G[a].push_back(i);
    }

    cout << rec(1) << endl;

    return 0;
}


Measured memory_bytes: 15104
#include <stdio.h>
#include <stdlib.h>

int s[100010],t[100010],idx[100010];
int c(const void*p,const void*q){
	if(t[*(int*)p]<t[*(int*)q])return -1;
	return 1;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d%d",s+i,t+i);
	for(int i=0;i<n;i++)idx[i]=i;
	qsort(idx,n,sizeof(int),c);
	int ans=0,time=0;
	for(int i=0;i<n;i++){
		if(time<s[idx[i]]){
			time=t[idx[i]];
			ans++;
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll MOD = 1000000007;

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

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1){
    f[0] = f[1] = -1;
    for (ll i=2; i<=n; i++){
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i ){
        if(!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }

  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1 ){
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl){
      if(res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main()
{
  Sieve sieve(1e6);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  map<int, int> mp;
  rep(i,n) {
    auto f = sieve.factor(a[i]);
    for (auto p : f){
      mp[p.first] = max(mp[p.first], p.second);
    }
  }


  ll lcm = 1;
  for (auto p : mp) {
    rep(i, p.second){
      lcm = (lcm * p.first)%MOD;
    }
  }

  ll res=0;
  rep(i,n) {
    ll b = (lcm * modinv(a[i], MOD)) % MOD;
    res = (res + b) % MOD;
  }

  cout << res << endl;
}


Measured memory_bytes: 4984
#include<bits/stdc++.h>
#define pb emplace_back
#define xx first
#define yy second
using namespace std;
typedef pair<int, int>pi;
vector<pi>vec;
bool vis[1003];
int main()
{
    int n, m, x, y;
    while(scanf("%d %d", &n, &m)==2)
    {
        vec.clear();
        for(int i=0; i<m; i++)
        {
            scanf("%d %d", &x, &y);
            vec.pb(x, y);
        }sort(vec.begin(), vec.end());
        memset(vis, 0, sizeof vis);
        int ans= 0, c= 0, temp= 0;
        for(int i=0; i<m; i++)
            if(!vis[i])
            {
                int l= vec[i].xx;
                int r= vec[i].yy;
                while(i<m)
                {
                    if(vec[i].xx>r)break;
                    r= max(r, vec[i].yy);
                    vis[i]= 1;
                    i++;
                }i--;
                ans+= (r-l); temp+= (r-l+1);c++;
            }
        ans= ((n-temp)+c+1) +(ans*3);
        printf("%d\n", ans);
    }

    return 0;
}



Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int w[100010];
    ll sum_w = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> w[i];
        sum_w += w[i];
    }
    ll left = 0, right = sum_w;
    while(right - left > 1)
    {
        ll mid = left + (right - left) / 2;
        //cout << left << " " << mid << " " << right << endl;
        int pos = 0;
        bool flag = false;
        for(int i = 0; i < k; i++)
        {
            ll sum = 0;
            while(w[pos] + sum <= mid)
            {
                sum += w[pos];
                pos++;
                if(pos == n) flag = true;
            }
        }
        if(flag) right = mid;
        else left = mid;
    }
    cout << right << endl;
	return 0;
}




Measured memory_bytes: 3568
// #pragma GCC optimize("03")
#include <bits/stdc++.h>
#define ll long long 
#define fi first
#define se second
#define mod 1000000007

using namespace std;

int n, m;
int dp[3010][3010];
string a, b;
vector<char> sol;

ll getsum(int l, int r) {
    return dp[r] - dp[l - 1];
}

int main() {    
    // ifstream cin("tst.in");
    // ofstream cout("tst.out");
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> a >> b;
    n = a.size();
    m = b.size();
    
    a = '+' + a;
    b = '+' + b;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (a[i] == b[j])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

    while (n > 0 && m > 0 && dp[n][m] > 0) {
        while (dp[n - 1][m] == dp[n][m])
            n--;
        while (dp[n][m - 1] == dp[n][m])
            m--;
        sol.push_back(a[n]);
        n--;
        m--;
    }

    reverse(sol.begin(), sol.end());
    for (auto it : sol)
        cout << it;

    return 0;
}

Measured memory_bytes: 35584
#include <iostream>

int SumDigits(int num);

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

  if (n % SumDigits(n) == 0) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

  return 0;
}

int SumDigits(int num) {
  int sum = 0;
  while (num > 0) {
    sum += num % 10;
    num /= 10;
  }
  return sum;
}


Measured memory_bytes: 3584
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <stack>

typedef long long ll;
typedef std::vector< int > VI;

const double EPS = 1e-10;
const double PI  = acos(-1);
const ll     INF = 1 << 30;

int main(int argc, char* argv[])
{
  int n = 2;
  std::vector< int > vin (n, 0);
  std::vector< int > vout(n, 0);

  std::cin >> vin[0] >> vout[0] >> vin[1] >> vout[1];

  int s_time = *std::min_element(vin.begin(),  vin.end());
  int e_time = *std::max_element(vout.begin(), vout.end());

  std::vector< int > tbl(e_time - s_time + 1, 0);
  for (int i = 0; i < n; i++) {
    tbl[vin[i]  - s_time]++;
    tbl[vout[i] - s_time]--;
  }

  int ans = tbl[0] == 2 ? 1 : 0;
  for (int time = 1; time <= e_time - s_time; time++) {
    tbl[time] += tbl[time-1];
    if (tbl[time] == 2) {
      ans++;
    }
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
double ans,res;
int n,i,j,x[100010],y[100010],a[100010];
double f[10][10];
bool book[11];
inline void dfs(int step)
{
  if(step==n+1)
  {
    res=0;
    for(int i=1;i<n;i++)
      res+=f[a[i]][a[i+1]];
    ans+=res;
  }
  for(int i=1;i<=n;i++)
    if(book[i]==0)
    {
      book[i]=1;
      a[step]=i;
      dfs(step+1);
      book[i]=0;
    }
}
inline int fac(int x){int res=1;for(int i=2;i<=x;i++)res*=i;return res;}
int main()
{
  //freopen("t3.in","r",stdin);
  //freopen("t3.out","w",stdout);
  cin>>n;
  for(i=1;i<=n;i++)
    cin>>x[i]>>y[i];
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      if(i!=j)f[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
  /*for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
	  cout<<f[i][j]<<" ";cout<<endl;*/
  dfs(1);
  //cout<<ans<<endl;
  ans/=fac(n);
  printf("%.10f",ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll             long long int
#define lb             lower_bound
#define ub             upper_bound
#define fi             first
#define mp             make_pair
#define vll            vector<ll>
#define se             second
#define sz             size()
#define mod            1000000007

#define fast           ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define allr(v)        v.rbegin(),v.rend()
#define inp(V,n)       for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)       {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<double,double> &a,
               const pair<double,double> &b)
{
    if(a.fi==b.fi)
    {
    return (a.second >b.second);
    }
    else
        return (a.fi<b.fi);
}


int main()
{
   ll q=1;
   //cin>>q;
   while(q--)
   {
        ll n,m,i,j,k,l,r,sum=0,b,c=0,d,ans=0;
         cin>>n;
         if(n>=30)
            cout<<"Yes"<<endl;
         else cout<<"No"<<endl;

   }
   return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int n,cx=0,cy=0,ct=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int t,x,y,v,tt;
		cin>>t>>x>>y;
		v=abs(cx-x)+abs(cy-y);
		tt=abs(ct-t);
		if(tt<v||(tt-v)%2==1){
			cout<<"No";
			return 0;
		}
		cx=x;
		cy=y;
		ct=t;
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] b = new int[n+1];
        int sum = 0; // 取り除くべき要素の個数
        
        for(int i=1; i<=n; i++){
            int a = sc.nextInt();
            //入力された数字よりも配列の要素数が少なかったら無条件に取り除く
            //その数字を排除する数がSumなので1足す。
            if(a>n) sum++;
            else b[a]++;
        }
        for(int i=1; i<=n; i++){
            //配列の添え字と中身が一致しているとき
            if(i == b[i]) continue;
            //配列の中身よりも添え字が大きいときは全部取り除く
            if(i > b[i]) sum += b[i];
            //配列の中身よりも添え字が小さいときは 
            //”添え字 ＝ 配列の中身”となるように余った分を取り除く
            if(i < b[i]) sum =  sum + b[i] - i;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 51956
ans = ""
while True:
    rev = ""
    n = int(raw_input())
    if n == 0:
        break
    table = {}
    for i in range(0, n):
        line = raw_input().strip().split()
        table[line[0]] = line[1]
    
    m = int(raw_input())
    for i in range(0, m):
        s = raw_input().strip()
        if s in table:
            rev += table[s]
        else:
            rev += s
    ans += rev + "\n"
print ans,

Measured memory_bytes: 9380
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <list>
#include <bitset>
#include <numeric>
#include <utility>
#define INF 1e9
#define MOD 1000000007
#define ll long long
#define int long long
using namespace std;
typedef unsigned long long ull;
typedef pair<int, int> p;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=0;i<k;i++){
        if(i%2==0){
            if(a%2==1){
                a--;
            }
            b+=a/2;
            a/=2;
        }
        else{
            if(b%2==1){
                b--;
            }

            a+=b/2;
            b/=2;
        }
//        cout<<a<<" "<<b<<endl;
    }
    cout<<a<<" "<<b;
    return 0;
}

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

int main (){
    ll n;
    ll ans =0;
    cin >> n;
    for (ll i = 1; i <=n; ){
        ans+=i;
        i = i*2;
    }
    cout << ans<< endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int w = scan.nextInt();
		Character[][] masu = new Character[h+2][w+2];
		for(int i=0;i<w+2;i++) {
			masu[0][i]='.';
			masu[h+1][i]='.';
			}
		for(int i=0;i<h+2;i++) {
			masu[i][0]='.';
			masu[i][w+1]='.';
			}





		for (int i = 0; i < h; i++) {
			String s = scan.next();
			for (int l = 0; l < w; l++) {

				masu[i+1][l+1] = s.charAt(l);
			}
		}
		/*
		for (int i = 0; i < h+2; i++) {
			System.out.println();
					for (int l = 0; l < w+2; l++) {
			System.out.print(masu[i][l]);
					}
		}
*/

		for (int i = 1; i < h+1; i++) {
			for (int l = 1; l < w+1; l++) {
				/*
				//四隅だったらチェックが減る
				if ((i == 0 && l == 0) || (i == 0 && l == w - 1) || (i == h - 1 && l == 0)
						|| (i == h - 1 && l == w - 1)) {



					//端っこだったらチェックが減る
				} else if (i == 0 || i == h - 1) {

				} else if (l == 0 || l == w - 1) {

				} else { //それ以外
				*/
					if (masu[i][l] == '.') {
						int count = 0;
						if (masu[i][l - 1] == '#') {
							count++;
						}
						if (masu[i - 1][l - 1] == '#') {
							count++;
						}
						if (masu[i - 1][l] == '#') {
							count++;
						}
						if (masu[i - 1][l + 1] == '#') {
							count++;
						}
						if (masu[i][l + 1] == '#') {
							count++;
						}
						if (masu[i + 1][l + 1] == '#') {
							count++;
						}
						if (masu[i + 1][l] == '#') {
							count++;
						}
						if (masu[i + 1][l - 1] == '#') {
							count++;
						}
						String strC = String.valueOf(count);
						//System.out.println(strC);
						masu[i][l] = strC.charAt(0);
						//System.out.println(masu[i][l]);


					}

				}

			}


	for (int i =1 ; i < h+1; i++) {
System.out.println();
		for (int l = 1; l < w+1; l++) {
System.out.print(masu[i][l]);
		}

	}

	}

}


Measured memory_bytes: 24404
#abc081c
import collections

n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
cnt=collections.Counter(a)
l=[]
for k1,v in cnt.items():
 l.append(v)
l2=sorted(l,reverse=True)
temp=0
for i in xrange(min(k,len(l2))):
 temp+=l2[i]
print n-temp


Measured memory_bytes: 38760
n=int(input())
a=[int(x) for x in input().split()]
b=[x for x in a]
b.sort()
d={}
m=0
for c in range(n):
    if b[c]==m:
        d[m]=d[m]+1
    else:
        m=b[c]
        d[m]=1
s=0
for c in d:
    s=s+(d[c]*(d[c]-1))//2
for c in a:
    print(s-d[c]+1)

Measured memory_bytes: 26140
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N = input()

mod = 0
for i in range(len(N)):
    mod += int(N[i])
    mod %= 9

if mod%9 == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9368
#include <stdio.h>
int h, w, k;
char c[6][7];
int x[6], y[6];
int xx, yy, xi, yj, zz, z;
int main() {
	scanf("%d%d%d", &h, &w, &k);
	for (int i = 0; i < h; i++) {
		scanf(" %s", c[i]);
	}
	xx = 1;
	yy = 1;
	for (int i = 0; i < h; i++)xx *= 2;
	for (int i = 0; i < w; i++)yy *= 2;
	for (int i = 0; i < xx; i++) {
		xi = i;
		for (int j = 0; j < h; j++) {
			x[j] = xi % 2;
			xi /= 2;
		}
		for (int j = 0; j < yy; j++) {
			yj = j;
			for (int l = 0; l < w; l++) {
				y[l] = yj % 2;
				yj /= 2;
			}
			z = 0;
			for (int l = 0; l < h; l++) {
				for (int m = 0; m < w; m++) {
					if (c[l][m] == '#' && x[l] && y[m])z++;
				}
			}
			if (z == k)zz++;
		}
	}
	printf("%d\n", zz);
}

Measured memory_bytes: 1732
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func solution(n int, p []int) int {
	var c int
	var low int = 1<<31 - 1
	for i := 1; i <= n; i++ {
		pi := p[i-1]
		if low > pi {
			c++
			low = pi
		}
	}
	return c
}

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 10240*10240)

	n, err := strconv.Atoi(readLine(reader))
	checkError(err)
	p := make([]int, n)
	ss := strings.Split(readLine(reader), " ")
	for i := range ss {
		p[i], err = strconv.Atoi(ss[i])
		checkError(err)
	}
	fmt.Println(solution(n, p))
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}


Measured memory_bytes: 11776
//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
char s[105];
long long k;
const long long N=5000000000000000ll;
int main(){
	scanf("%s%lld",s+1,&k);
	int n=strlen(s+1);
	for(int i=1;i<=n;i++){
		if(s[i]=='1')k--;
		else {printf("%c\n",s[i]);exit(0);}
		if(k<=0){printf("%c\n",s[i]);exit(0);}
	}
}

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

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << (char)toupper(s1.at(0))<<(char)toupper(s2.at(0))<<(char)toupper(s3.at(0));

return 0;  
}

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

int main(){
	int n;
	string s;
	cin >> n >> s;
	vector<int> wh(n);
	vector<int> br(n);
	int whi = 0;
	int brk = 0;
	rep(i, n){
		if(s.at(i) == '.') whi++;
		else brk++;
		wh[i] = whi;
		br[i] = brk;
	}
	int mi = 1000000;
	rep(i, n-1){
		int sum = whi - wh[i] + br[i];
		if(mi > sum) mi = sum;
	}
	cout << min(min(mi, brk), whi) << endl;
	return 0;
}

Measured memory_bytes: 2180
from collections import deque
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n-1)]
px=[list(map(int,input().split())) for _ in range(q)]

adlist=[]
finish=set()

point=[0]*n
for h in range(n):    
    adlist.append([])
for j in range(n-1):
    x=ab[j][0]
    y=ab[j][1]
    adlist[x-1].append(y)
    adlist[y-1].append(x)
for i in range(q):
    point[px[i][0]-1]+=px[i][1]
#print(point)
deq=deque()
deq.append(1)


while deq:
    now=deq.pop()
       # print(now)
    finish.add(now)
    for i in range(len(adlist[now-1])):
        #print(adlist[now-1][i],now)
        if adlist[now-1][i] not in finish:
            point[adlist[now-1][i]-1]+=point[now-1]
            deq.append(adlist[now-1][i])

for i in range(n):
    print(point[i],end=" ")

Measured memory_bytes: 126188