akhauriyash/Code-Regression huggingface dataset:
require "matrix"

K = gets.to_i
X, Y = gets.chomp.split(" ").map(&:to_i)

def solve2step(x, y)
  b = Matrix[[K], [K], [x], [y]]
  [-1, 1].each{|i|
    [-1, 1].each{|j|
      [-1, 1].each{|k|
        [-1, 1].each{|l|
          a = Matrix[[i, j, 0, 0], [0, 0, k, l], [1, 0, 1, 0], [0, 1, 0, 1]]
          if a.determinant != 0 then
            ary = (a.inverse * b).column(0).to_a
            return ary.map(&:to_i) if ary.all?{|e| e.abs <= K && e.denominator == 1}
          end
        }
      }
    }
  }
  [0, 0, 0, 0]
end

ans = [[0, 0]]
if K.odd? || (X - Y).abs.even? then
  x1, y1 = [0, 0]
  signx = X.positive? ? 1 : -1
  K.step(X.abs - 1, K){|x| ans << [x * signx, 0]; x1 = x * signx}
  signy = Y.positive? ? 1 : -1
  K.step(Y.abs - 1, K){|y| ans << [x1, y * signy]; y1 = y * signy}
  if (X.abs + Y.abs) % K == 0 && (X - x1).abs + (Y - y1).abs == K then
    ans << [X, Y]
  else
    n = x1.abs / K + y1.abs / K
    if K.odd? && (X - Y + n).abs.odd? then
      if (X - x1).abs + (Y - y1).abs < K && ans.size > 1 then
        ans.pop
        x1, y1 = ans[-1]
      else
        y1 += (K * signy)
        ans << [x1, y1]
      end
    elsif (X - x1).abs + (Y - y1).abs < K && ans.size > 1 && K.even? then
      ans.pop
      x1, y1 = ans[-1]
    end
    x2, y2, x3, y3 = solve2step(X - x1, Y - y1)
    ans << [x1 + x2, y1 + y2]
    ans << [x1 + x2 + x3, y1 + y2 + y3]
  end
end

puts ans.size == 1 ? -1 : ans.size - 1
ans.each_with_index{|(x, y), i| printf("#{x} #{y}\n") if i > 0}


Measured memory_bytes: 19068
def examA():
    A, B = LI()
    ans = A*B
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 1<<60
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 76544
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;

void swap(int &x, int &y){
    int tmp = x;
    x = y;
    y = tmp;
    return;
}

struct UnionFind{
    vi par;
    UnionFind(int n){
        par = vi(n, -1);
    }
    int root(int x){
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return;
    }
    int size(int x){
        return -par[root(x)];
    }
};

int main(void){
    int n, m;
    cin >> n >> m;
    UnionFind UF(n);
    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        a -= 1; b -= 1;
        UF.unite(a, b);
    }
    int v = 0;
    for(int i=0; i<n; i++){
        if(v < UF.size(i)) v = UF.size(i);
    }
    cout << v << '\n';
    return 0;
}

Measured memory_bytes: 4060
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  std::string N;
  std::cin >> N;
  std::cout << std::count_if(N.begin(), N.end(), [](const char& c) { return c == '2'; }) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include "iostream"
using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[100];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = n-1; i >=0; i--)
	{
		if (i != n-1)
		{
			cout << " ";
		}
		cout << a[i];
	}
	cout<<endl;
	return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)

int main() {
  int N;
  cin >> N;
  vector<int> A(N+1);
  vector<int> B(N);
  rep(i, 0, N+1) {
    cin >> A[i];
  }
  rep(i, 0, N) {
    cin >> B[i];
  }
  ll ans = 0;
  rep(i, 0, N) {
    int bi = B[i];
    int ai = A[i];
    if (bi >= ai) {
      ans += ai;
      if (bi - ai >= A[i + 1]) {
        ans += A[i + 1];
        A[i + 1] = 0;
      } else {
        A[i + 1] -= bi - ai;
        ans += bi - ai;
      }
    } else {
      ans += bi;
    }
  }

  cout << ans << endl;
};


Measured memory_bytes: 1024
from collections import Counter
N,K,L = map(int,input().split())
roads = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(K)]
rails = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(L)]

class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1

uf_road = UnionFind(N)
for a,b in roads:
    if uf_road.is_same(a,b): continue
    uf_road.unite(a,b)

uf_rail = UnionFind(N)
for a,b in rails:
    if uf_rail.is_same(a,b): continue
    uf_rail.unite(a,b)

for i in range(N):
    uf_road.root(i)
    uf_rail.root(i)

ctr = Counter()
for i in range(N):
    r1 = uf_road.root(i)
    r2 = uf_rail.root(i)
    ctr[(r1,r2)] += 1

ans = []
for i in range(N):
    r1 = uf_road.root(i)
    r2 = uf_rail.root(i)
    ans.append(ctr[(r1,r2)])
print(*ans)

Measured memory_bytes: 80388
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
typedef long long lint;
const int N=2e5+5;
int n,val[N];

namespace utils{
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline char get_c(){
		static char buf[20000],*h,*t;
		if(h==t){
			t=(h=buf)+fread(buf,1,20000,stdin);
			if(h==t) return EOF;
		}
		return *h++;
	}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=get_c())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=get_c());
		while(x=x*10-48+c,(c=get_c())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	n=nxi();
	for(int i=1; i<=n; ++i){
		val[i]=nxi()+(n-i);
	}
	std::nth_element(val+1,val+((n+1)>>1),val+n+1);
	lint ans=0;
	for(int mid=(n+1)>>1,i=1; i<=n; ++i){
		ans+=i<=mid?val[mid]-val[i]:val[i]-val[mid];
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    rep(i,k){
        if(a < b && b < c){
            break;
        }
        else{
            if(c <= a || c <= b ){
                c *= 2;
            }
            else if( b <= a ){
                b *= 2;
            }
        }
    }
    if( a < b && b < c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
  int h,i,j,max,counter;

  scanf("%d",&counter);

  int a[counter][3];

  for (i=0;i<counter;i++){
    scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
  }

  for (h=0;h<counter;h++){
    for (i=0;i<3;i++){
      max=a[h][i];
      for (j=i+1;j<3;j++){
        if(max<a[h][j]){
          max=a[h][j];
          a[h][j]=a[h][i];
          a[h][i]=max;
        }
      }
    }
  }

  for (h=0;h<counter;h++){
    if(pow(a[h][0],2)==pow(a[h][1],2)+pow(a[h][2],2)){
      printf("YES\n");
    }
    else printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 592
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
            Console.WriteLine((input[0] < input[1]) ? 0 : 10);
        }
    }
}


Measured memory_bytes: 13268
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    vector<ll> x(5);
    for (ll i = 0; i < 5; i++) {
        cin >> x[i];
        if (i > 0) {
            x[i] = min(x[i], x[i - 1]);
        }
    }

    ll ans = 0;
    for (ll i = 0; i < 5; i++) {
        //今ここにN - x[i] * ans人いる
        //それを運ぶのにかかる時間をansに足す
        ans += (max((N - x[i] * (ans - i)), (ll)0) + x[i] - 1) / x[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long h,w;
	cin>>h>>w;
	long long odd=0;
	long long even =0;
	if(h==1 || w==1){
		cout<<1<<"\n";
	}else{
	
		for(int i=0;i<w;i++){
			if(i%2==0){
				even+=1;
			}else{
				odd+=1;
			}
		}
		
		long long x=0;
		for(int i=0;i<h;i++){
			if(i%2==0){
				x+=even;
			}else{
				x+=odd;
			}
			
		}
		cout<<x<<"\n";
	}
 
	
	
	
	
	return 0;
}

Measured memory_bytes: 3552
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<ll> vl;
const int INF=1e+9;
const ll INFLL=1e+17;
ll N;
vl divisor(ll a){//aの約数が全列挙されたベクトルを返す
  vl res;
  for(ll i=1;i*i<=a;i++){//iはsqrt(a)まで調べれば十分
    if(a%i==0){
      res.push_back(i);
      if(i!=a/i) res.push_back(a/i);
    }
  }
  return res;
}
int digit(ll x){
  int res=1;
  while(x>=10){
    x/=10;
    res++;
  }
  return res;
}
int solve(){
  int res=INF;
  vl v=divisor(N);
  int vs=v.size();
  rep(i,vs){
    res=std::min(res,std::max(digit(v[i]),digit(N/v[i])));
  }
  return res;
}
int main(){
  cin>>N;
  prin(solve());
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef unsigned long long ll;

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

ll gcd(ll x, ll y){
    if (x > y) swap(x, y);
    if (x == 0) return y;
    return gcd(y%x, x);
}

void solve(void){
    int N;
    cin >> N;
    ll ans = 1LL;
    vector <ll> as(N);
    rep(N, i) cin >> as.at(i);
    uniq(as);
    for (ll a : as) {
        ans = ans / gcd(ans, a) * a;
        //cout << gcd(ans, a) << ' ' << ans << '\n';
    }
    cout << ans << '\n';

}

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


Measured memory_bytes: 256
function main()
  
  (A,B,K) = map(x -> parse(Int,x), split(readline()))
  
  nums = Int[]
  
  for i in 1:gcd(A,B)
    
    if A%i == 0 && B%i == 0
      push!(nums,i)
    end
    
  end
  
  println(nums[end-K+1])
  
end

main()

Measured memory_bytes: 111560
#include<cstdio>
#include<cmath>
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	int tl=0,k=b;
	while(k!=0) tl++,k/=10;
	int l=10;
	for(int i=1;i<tl;i++)
		l*=10;
	int num=l*a+b;
	if(int(sqrt(num))*int(sqrt(num))==num)
		printf("Yes\n");
	else
		printf("No\n");
}

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


int main()
{
    string S, T;
    string ans = "No";
    cin >> S >> T;
    string U = T.substr(0, S.size());
    if ((U == S)&&(T.size()==S.size()+1)){
        ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
import itertools

def checker(num):
    if A[rules[num][1] - 1] - A[rules[num][0] - 1] == rules[num][2]:
        return rules[num][3]
    else:
        return 0

N,M,Q = map(int,input().split())
rules = []

temp = []
for i in range(M):
    temp.append(i + 1)
    
test = list(itertools.combinations_with_replacement(temp, N))

for _ in range(Q):
    rules.append(list(map(int,input().split())))
    

output = 0

for i in range(len(test)):
    A = test[i]
    
    score = 0
    for i in range(Q):
        score += checker(i)
    output = max(output,score)
    
print(output)

Measured memory_bytes: 21476
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s;
  R s;
  set<char> se;
  rep(i,s.size()) se.insert(s[i]);
  rep(i,26) {
    if(se.count((char)(i+'a'))) continue;
    s+=(char)(i+'a');
    pr(s);
    return;
  }
  string t="{";
  se.clear();
  rep(i,s.size()) {
    string r=s.substr(0,i);
    if(s[i]!='z') {
      char c=s[i]+1;
      while(se.count(c)) c=c+1;
      if(c!='{') {
        r+=c;
        t=min(t,r);
      }
    }
    se.in(s[i]);
  }
  if(t=="{") pr(-1);
  else pr(t);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
 
using namespace std;

int main(){
    string X;   cin >> X;
    int l = X.length();
    int cs, ct, ans;
    ans = l;
    for(int i=0; i<l; i++){
        if(X[i] == 'T'){
            if(cs > 0){
                cs--;
                ans -= 2;
            }
        }else   cs++;
    }
    print(ans);
    return 0;
}

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

int main() {
	int N,K;
	cin>>N>>K;
	int count=0;
	vector<int> height(N);
	
	for(int i=0;i<N;i++){
		cin>>height.at(i);
	}
	for(int i=0;i<N;i++){
		if(height.at(i)>=K){
			count++;
		}
		
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 640
package main

import "fmt"

func same(a, b, c byte) bool {
	return a == b && b == c
}

func main() {
	var s string
	fmt.Scan(&s)
	if same(s[0], s[1], s[2]) || same(s[1], s[2], s[3]) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"

ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

int main(){
  int a[32] ={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k; cin>>k;
  cout << a[k-1]<<"\n";
}


Measured memory_bytes: 256
use std::cmp;

const INF: i64 = 1e17 as i64;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let a: Vec<i64> = sc.read_vec(n);
    let mut graph = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let v = sc.read::<usize>() - 1;
        let u = sc.read::<usize>() - 1;
        graph[v].push(u);
        graph[u].push(v);
    }

    let mut dp1 = vec![vec![]; n];
    let mut dp2 = vec![vec![]; n];
    dfs(0, 0, &graph, &a, &mut dp1, &mut dp2);

    for i in 1..(n + 1) {
        if dp1[0][i] < INF {
            println!("{}", i - 1);
            return;
        }
        if dp2[0][i] < 0 {
            println!("{}", i - 1);
            return;
        }
    }
}

fn dfs(
    v: usize,
    p: usize,
    graph: &Vec<Vec<usize>>,
    a: &Vec<i64>,
    dp1: &mut Vec<Vec<i64>>,
    dp2: &mut Vec<Vec<i64>>,
) {
    dp1[v].push(INF);
    dp1[v].push(if a[v] > 0 { a[v] } else { INF });
    dp2[v].push(INF);
    dp2[v].push(a[v]);
    for &next in graph[v].iter() {
        if next == p { continue; }
        dfs(next, v, graph, a, dp1, dp2);

        dp1[v] = connect(&dp1[v], &dp1[next], &dp2[next], true);
        dp2[v] = connect(&dp2[v], &dp1[next], &dp2[next], false);
    }
}

fn connect(dp: &Vec<i64>, child1: &Vec<i64>, child2: &Vec<i64>, power_only: bool) -> Vec<i64> {
    let mut ans = vec![INF; dp.len() + child1.len() - 1];
    for groups in 0..dp.len() {
        if dp[groups] == INF { continue; }
        for child_groups in 0..child1.len() {
            let total_groups = groups + child_groups;

            if total_groups >= 1 {
                if child1[child_groups] != INF {
                    ch_min(&mut ans[total_groups - 1], dp[groups] + child1[child_groups]);
                }
                if child2[child_groups] != INF && !power_only {
                    ch_min(&mut ans[total_groups - 1], dp[groups] + child2[child_groups]);
                }
            }
            if child1[child_groups] != INF || child2[child_groups] < 0 {
                ch_min(&mut ans[total_groups], dp[groups]);
            }
        }
    }
    ans
}

fn ch_min<T: PartialOrd>(a: &mut T, b: T) {
    if *a > b {
        *a = b;
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 211836
import sys
from copy import deepcopy

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def drop(H, G):
    G = [[n for n in col if n != -1] for col in zip(*G)]
    G = [[-1] * (H - len(col)) + col for col in G]
    G = [list(row) for row in zip(*G)]
    return G


def main():
    H, W, K = map(int, readline().split())
    G_init = [list(map(int, list(readline().strip()))) for _ in range(H)]

    ans = 0
    for i in range(H):
        for j in range(W):
            G = deepcopy(G_init)
            G[i][j] = -1
            G = drop(H, G)

            current_ans = 0
            step = 0
            while True:
                score = 0
                for row in G:
                    seq = [[row[0], 1]]
                    for n in row[1:]:
                        if n == seq[-1][0]:
                            seq[-1][1] += 1
                        else:
                            seq.append([n, 1])
                    idx = 0
                    for n, c in seq:
                        if n != -1 and c >= K:
                            score += n * c
                            row[idx : idx + c] = [-1] * c
                        idx += c

                if score == 0:
                    break

                current_ans += score * pow(2, step)
                step += 1
                G = drop(H, G)

            if current_ans > ans:
                ans = current_ans

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61020
main(s,t,a,b,c,d){scanf("%d%d%d%d",&a,&b,&c,&d);s=a+b+c+d;scanf("%d%d%d%d",&a,&b,&c,&d);t=a+b+c+d;printf("%d\n",s>t?s:t);return 0;}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	int N; cin >> N;
	vector<ll> r(N, 0 );
	rep (i, N ) cin >> r[i];

	ll minv = r[0];
	ll res = -(1LL<<60);
	for (int i = 1; i < N; i++ ){
		if (r[i] - minv > res ) res = r[i] - minv;
		if (minv > r[i] ) minv = r[i];
	} // end rep
	cout << res << endl;	
		
	return 0;
}

Measured memory_bytes: 2588
#pragma GCC optimize("Ofast","inline")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const double pi=acos(-1);
const int mod=200003,G=2,N=mod*3;
int lim,rev[N],gid[mod],gpw[mod],cnt[mod],n,l;
long long ans;

struct cpx{
	double x,y;
	cpx (double xx=0,double yy=0){x=xx,y=yy;}
	cpx operator + (const cpx &nt) const {return cpx(x+nt.x,y+nt.y);}
	cpx operator - (const cpx &nt) const {return cpx(x-nt.x,y-nt.y);}
	cpx operator * (const cpx &nt) const {return cpx(x*nt.x-y*nt.y,x*nt.y+y*nt.x);}
}f[N];

void fft(cpx *a,int n,int op){
	for(int i=0;i<n;i++) if(i<rev[i]) swap(a[i],a[rev[i]]);
	for(int mid=1;mid<n;mid<<=1){
		cpx w0(cos(pi/mid),op*sin(pi/mid));
		for(int len=mid<<1,i=0;i<lim;i+=len){
			cpx w(1,0);
			for(int j=0;j<mid;j++,w=w*w0){
				cpx x=a[i+j],y=w*a[i+mid+j];
				a[i+j]=x+y;
				a[i+mid+j]=x-y;
			}
		}
	}
}

signed main(){
	for(int i=0,mul=1;i<mod;i++,mul=mul*G%mod) gid[mul]=i,gpw[i]=mul;
	read(n);
	for(int i=1,x;i<=n;i++) if(read(x)) f[gid[x]].x++,cnt[x]++;
	for(lim=1,l=0;lim<=mod<<1;lim<<=1,l++) ;
	for(int i=0;i<lim;i++) rev[i]=rev[i>>1]>>1|(i&1)<<l-1;
	fft(f,lim,1);
	for(int i=0;i<lim;i++) f[i]=f[i]*f[i];
	fft(f,lim,-1);
	for(int i=0;i<mod<<1;i++) ans+=(long long)(f[i].x/lim+0.5)*gpw[i%(mod-1)];
	for(int i=0;i<mod;i++) ans-=cnt[i]*(1ll*i*i%mod);
	write(ans/2);
}

Measured memory_bytes: 17724
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Poll
	var N int
	fmt.Scanf("%d", &N)

	var temp string
	S := make(map[string]int, N)
	for i := 0; i < N; i++ {
		temp = nextStr()
		S[temp]++
	}

	var max int
	key := make([]string, N)
	var count int
	for i, v := range S {
		if max < v {
			max = v
		}
		key[count] = i
		count++
	}

	sort.Sort(sort.StringSlice(key))

	for i := 0; i < len(key); i++ {
		if max == S[key[i]] {
			fmt.Println(key[i])
		}
	}
}


Measured memory_bytes: 18104
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  std::string s, t;
  std::cin >> s >> t;
  const i64 s_size = s.size();

  std::set<char> s_set(s.begin(), s.end()), t_set(t.begin(), t.end());
  if (std::includes(s_set.begin(), s_set.end(), t_set.begin(), t_set.end())) {
    std::unordered_map<char, std::vector<i64>> index_table;
    const std::string a_to_z = "abcdefghijklmnopqrstuvwxyz";
    for (i64 i = 0; i < s_size; ++i) {
      index_table[s[i]].push_back(i);
    }
    for (const char& c : a_to_z) {
      std::vector<i64> orig = index_table[c];
      for (const i64& i : orig) {
        index_table[c].push_back(s_size + i);
      }
    }

    i64 answer = 0;
    for (const char& t_i : t) {
      answer += *std::lower_bound(index_table[t_i].begin(), index_table[t_i].end(), answer % s_size) - (answer % s_size) + 1;
    }
    std::cout << answer << std::endl;
  } else {
    std::cout << -1 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3512
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;

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

template<typename T>
istream& operator >> (istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    vector<int64_t> a(n);
    cin >> a;
    vector<int64_t> p(n + 1, 0), pp(n + 1, 0), sp(n + 1, 0);
    for (int i = 1; i <= n; ++i) p[i] = p[i - 1] + a[i - 1];
    for (int i = 1; i <= n; ++i) {
        pp[i] = pp[i - 1] + max(a[i - 1], (int64_t)0);
        sp[i] = sp[i - 1] + max(a[n - i], (int64_t)0);
    }
    // cout << pp << sp << endl;
    int64_t max_ans = 0;
    for (int ks = 0; ks + k <= n; ++ks) {
        // cout << ks << " " << pp[ks] << " " << sp[n - ks - k] << " " << p[ks + k] - p[ks] << endl;
        max_ans = max(max_ans, pp[ks] + sp[n - ks - k] + max((int64_t)0, p[ks + k] - p[ks]));
    }
    cout << max_ans;

}


Measured memory_bytes: 6332
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cmath>
using namespace std;

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

bool match(int x,int y) {
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			if (a[x + i][y + j] != b[i][j]) return false;
		}
	}
	return true;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < m; i++)cin >> b[i];
	bool judge = false;
	for (int i = 0; i <= n - m; i++) {
		for (int j = 0; j <= n - m; j++) {
			if (match(i,j))judge = true;
		}
	}
	if (judge)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(int i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<vector<ll>>a(n,vector<ll>(n,-1));
  rep(i,n){
    ll ai;cin>>ai;
    rep(j,ai){
      ll x,y;cin>>x>>y;
      x--;
      a[i][x]=y;
    }
  }
  ll res=0;
  rep(i,1<<n){
    bitset<16>ti=i;
    ll f=1;
    ll cnt=0;
    rep(j,n)cnt+=ti[j];
    rep(j,n){
      if(!ti[j])continue;
      rep(k,n){
        if(a[j][k]==-1)continue;
        if(a[j][k]!=ti[k]){f=0;break;}
      }
    }
    if(f)chmax(res,cnt);
  }

  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n,k,count = 0,d,e;
    char  z[100];
    for(int i = 0; i < 100; i++){
        z[i] = 0;
    }
    scanf("%d %d",&n,&k);
    for(int i = 0; i < k; ++i){
        scanf("%d",&d);
        for(int j = 0; j < d; ++j){
            scanf("%d",&e);
            z[e] = 1;
        }
    }
    for(int i = 1; i <= n; ++i){
        if(z[i] == 0){
            count = count + 1;
        }
    }
    printf("%d",count);
    return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define rep(i, n) for(LL i = 0;i < n;i++)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
string s;
map<char, bool> mp;
/**********************************************/

signed main(){
    cin >> s;
    rep(i, s.size()){
        mp[s[i]] = true;
    }
    int ssize = s.size();
    char ans;
    bool flag = false;
    for(; ssize >= 0; ssize--){
        flag = false;
        rep(i, 26){
            if(mp[(char)(i+'a')] == false && (char)(i+'a') > s[ssize]){
                ans = (char)(i+'a');
                flag = true;
                break;
            }
        }
        if(!flag){
            mp[s[ssize]] = false;
        }else{
            break;
        }
    }
    if(flag == false){
        cout << -1 << endl;
    }else{
        rep(i, ssize){
            cout << s[i];
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
import math


def main():
    n = int(input())

    sqrt_n = math.ceil(math.sqrt(n)) + 1
    ans = 10**12 + 1
    for i in range(1, sqrt_n):
        q, mod = divmod(n, i)
        if mod == 0:
            ans = min(ans, i + q - 2)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
// long long -> lint
using lint = long long;
// fast cin and cout from hitonanode-san's code
// w/o 71 ms -> w/ 18 ms (tested on ABC148-D with C++14(GCC 5.4.1))
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;


int main(){
    // input
    int N;
    cin >> N;
    vector<int> P(N);
    for( int i=0; i<N; i++ ){
        cin >> P[i];
    }

    // calc
    int ans     = 0;
    int min_val = 2*1e5+1;
    for( int i=0; i<N; i++ ){
        if( min_val >= P[i] ) {
            min_val = P[i];
            ans++;
        }
    }

    // out
    cout << ans << endl;
} 

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


string b(string s) {
  int len = (int) s.size();
  ll sum = 0;
  for(int i = 0; i< len; i++) {
    sum += (ll ((char) s[i] - '0'));
  }
  if(sum % 9 == 0) {
    return "Yes";
  }
  return "No";
}

int main() {
  string n;
  cin >> n;
  cout << b(n);
}

Measured memory_bytes: 3924
//#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("unroll-loops")

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

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

const int N = 2e5 + 123, K = 4e9;	
int n, m, h, x,d;
pii a[N];
string s;
unordered_map < int , int > t;
void upd(int v , int tl, int tr , int l , int r, int x){
	if(l > r or tr < l or r < tl)
		return;
	if(l <= tl and tr <= r)
		return void(t[v] += x);
	int tm = (tl + tr) >> 1;
	upd(v << 1ll, tl , tm , l , r, x);
	upd(v << 1ll|1ll, tm + 1 ,tr , l, r, x);
}
int get(int v, int tl , int tr , int pos){
	if(tl == tr)
		return t[v];
	int tm = (tl + tr) >> 1l;
	if(pos <= tm)
		return t[v] + get(v << 1ll, tl, tm ,pos);
	return t[v] + get(v << 1ll|1ll, tm + 1, tr , pos);
}
main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	int d1;
	cin >> n >> d1 >> x;
	for(int i = 1;i <= n; i++){
		cin >>a[i].fi >> a[i].se;
		a[i].fi++;
	}	
	sort(a + 1, a + 1 + n);
	int ans = 0;
	for(int i = 1 ; i <= n; i++){
		int y = get(1 , 1 , K, a[i].fi);
		int d = a[i].se - y;
		if(d <= 0)continue;
		int tmp = d / x + (int)(d % x != 0);
		ans += tmp;
		upd(1 , 1 , K, a[i].fi , a[i].fi + 2ll * d1, tmp * x);
//		cerr << a[i].fi << ' ' << a[i].fi + 2ll * d << '\n';
	}
	cout << ans;
}
	                             


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

using namespace std;

const int MX = 500;

char s[MX][MX + 1];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf(" %s", s[i]);
	
	bool ok = false;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			ok = ok || s[i][j] == '#';
	
	if (ok == false) {
		printf("-1\n");
		
		return 0;
	}
	
	int bad_cols = 0;
	for (int i = 0; i < n; i++) {
		bool bad = false;
		for (int j = 0; j < n; j++)
			bad = bad || s[j][i] == '.';
		
		if (bad) bad_cols++;
	}
	
	int ans = n * n;
	for (int i = 0; i < n; i++) {
		int cur = bad_cols;
		for (int j = 0; j < n; j++) cur += s[i][j] == '.' ? 1 : 0;
		
		int add = 1;
		for (int j = 0; j < n; j++)
			if (s[j][i] == '#')
				add = 0;
		
		ans = min(ans, cur + add);
	}
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 512
function main(input) {
   input = input.trim();
  const a = input.split("");
 
	console.log(a[0]=="A"?"T"
			   :a[0]=="C"?"G"
	 		   :a[0]=="G"?"C"
			   :"A");
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29492
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	x := nextInt()

	fmt.Println(nextPrime(x))
}

func nextPrime(num int) int {
	const limit = 200000
	m := make(map[int]bool)

	for i := 2; i <= limit; i++ {
		m[i] = true
	}

	for i := 2; i <= int(math.Ceil(math.Sqrt(limit))); i++ {
		if m[i] {
			for j := i*2; j<= limit; j+=i {
				m[j] = false
			}
		}
	}

	for i := num; i <= limit; i++ {
		if m[i] {
			return i
		}
	}

	return -1
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

int main()
{
    int n;
    cin >> n;
    int mx = -2e9, mn = 2e9;
    ll sum = 0;
    rep(i, 0, n) {
        int x;
        cin >> x;
        mx = max(mx, x);
        mn = min(mn, x);
        sum += x;
    }
    cout << mn << " " << mx << " " << sum << endl;
}



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

ans = 0
for i in range(1, n+1):
  keta = 0
  # print('target: ', i)
  while i > 0:
    i = i // 10
    keta += 1
  # print('keta: ', keta)
  if keta % 2 != 0:
    ans += 1
print(ans)

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

signed main(void)
{
	int n, ans, cnt;
	cin >> n;
	int b[n + 1], w[n + 1];
	string s;

	cin >> s;
	for(int i = 0; i <= n; i++)
		b[i] = w[i] = 0;
	rep(i, n)
	{
		if (s[i] == '#')
			b[i + 1]++;
		else if (s[i] == '.')
			w[i + 1]++;
	}
	rep(i, n)
	{
		b[i + 1] += b[i];
		w[i + 1] += w[i];
	}
	ans = 1e9;
	rep(i, n + 1)
	{
		cnt = 0;
		cnt += b[i];
		cnt += w[n] - w[i];
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
	int N;
	cin>>N;
	
	long long int a[3*N];
	for(int i=0;i<N*3;i++)
		cin>>a[i];
	
	sort(a,a+N*3,greater<long long int>());

	long long int ans=0;
	for(int i=1;i<2*N;i+=2){
			ans+=a[i];
			//cout<<a[i]<<endl;
		}
	
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<tuple>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};

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

	int n;
	cin >> n;

	int a[n],b[n],c[n];
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++) cin >> b[i];
	for(int i=0;i<n;i++) cin >> c[i];

	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);

	int la[n],gc[n];
	int ida=0,idc=0;
	for(int i=0;i<n;i++){
		while(ida < n && a[ida] < b[i]) ida++;
		la[i]=ida;
	}
	for(int i=n-1;i>=0;i--){
		while(n-idc-1 >= 0 && c[n-idc-1] > b[i]) idc++;
		gc[i]=idc;
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		ans += 1LL*la[i]*gc[i];
	}
	cout << ans << "\n";
	
	return 0;
}

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


int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> vecx(n);
    vector<int> vecy(m);
    for (size_t i = 0; i < n; i++) cin >> vecx[i];
    for (size_t i = 0; i < m; i++) cin >> vecy[i];
    vecx.push_back(x);
    vecy.push_back(y);
    int MAX_x = *max_element(vecx.begin(),vecx.end());
    int MIN_y = *min_element(vecy.begin(), vecy.end());

    int found_ans = numeric_limits<int>::max();
    if(MAX_x < MIN_y){
        for(int i = MAX_x + 1; i <= MIN_y;i++){

            bool ans = true;
            if( i< x && y >=i){
                for(int xx : vecx){
                    if(xx > i) {
                        ans = false;
                        break;
                    }
                }
                for(int yy : vecy){
                    if(yy < i){
                        ans = false;
                        break;
                    }
                }
            }
            if(ans){
                cout << "No War" << endl;
                exit(0);
            }
        }
    }
    cout << "War" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

const int MAX = 100010;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//main関数にCOMinit();を忘れない

void solve(int ca){
    COMinit();
    
    int n; cin>>n;
    int gap=0;
    vector<int> f(n+10,-1);
    int a;
    for (int i = 0; i < n+1; ++i) {
        cin>>a; --a;
        if(f[a]>=0) gap=i-f[a]-1;
        f[a]=i;
    }
    for (int i = 1; i <= n + 1; ++i) {
        ll ans=COM(n-1,i);
        (ans+=COM(n-1,i-2))%=MOD;
        (ans+=COM(n-1,i-1)*2ll%MOD)%=MOD;
        (ans-=COM(n-gap-1,i-1)-MOD)%=MOD;
        cout<<ans<<"\n";
    }



}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 3968
package main

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

var sc *bufio.Scanner

func nextString() string {
	sc.Scan()
	i := sc.Text()
	return i
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func listPrint(a []int) {
	for i, k := range a {
		fmt.Print(k)
		if i == len(a)-1 {
			fmt.Print("\n")
		} else {
			fmt.Print(" ")
		}
	}
}

func insertionSort(a []int, n int) {
	var v int
	var j int
	listPrint(a)
	for i := 1; i < n; i++ {
		v = a[i]
		j = i - 1
		for j >= 0 && a[j] > v {
			a[j+1] = a[j]
			j--
		}
		a[j+1] = v
		listPrint(a)
	}
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	insertionSort(a, n)
}



Measured memory_bytes: 1192
N,K,L=map(int,input().split())
Road_P=[i for i in range(N+1)]
Road_size=[1 for i in range(N+1)]

def find_road(a):
    if a==Road_P[a]:
        return a
    else:
        return find_road(Road_P[a])
        
def union_road(b,c):
    B=find_road(b)
    C=find_road(c)
    if Road_size[B]>=Road_size[C]:
        Road_P[C]=Road_P[B]
        Road_size[B]+=Road_size[C]
    else:
        Road_P[B]=Road_P[C]
        Road_size[C]+=Road_size[B]

for i in range(K):
    p,q=map(int,input().split())
    if find_road(p)!=find_road(q):
        union_road(p,q)
#print(Road_P)

Rail_P=[i for i in range(N+1)]
Rail_size=[1 for i in range(N+1)]

def find_rail(a):
    if a==Rail_P[a]:
        return a
    else:
        return find_rail(Rail_P[a])
        
def union_rail(b,c):
    B=find_rail(b)
    C=find_rail(c)
    if Rail_size[B]>=Rail_size[C]:
        Rail_P[C]=Rail_P[B]
        Rail_size[B]+=Rail_size[C]
    else:
        Rail_P[B]=Rail_P[C]
        Rail_size[C]+=Rail_size[B]

for i in range(L):
    p,q=map(int,input().split())
    if find_rail(p)!=find_rail(q):
        union_rail(p,q)

#print(Rail_P)

comb={}
for i in range(1,N+1):
    if (find_road(i),find_rail(i)) in comb:
        comb[(find_road(i),find_rail(i))]+=1
    else:
        comb[(find_road(i),find_rail(i))]=1

#print(comb)

for i in range(1,N+1):
    print(comb[(find_road(i),find_rail(i))])


Measured memory_bytes: 55848
d,n = map(int,input().split())

if d ==0:
    if n ==100:
        print(101)
    else:
        print(n)
elif d==1:
    if n==100:
        print(10100)
    else:
        print(100*n)
else:
    if n==100:
        print(1010000)
    else:
        print(10000*n)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int R;
	cin >> R;
	printf("%.10f\n", 2 * R * M_PI);
}



Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl;
#define rep(i,n) for(ll i = 0;i < n;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0);

const ll INF = 1e9+7;

// 各桁の和
template<typename T>
T digit(T num){
  T sum = 0;
  while(num){
    sum += num % 10;
    num /= 10;
  }
  return sum;
}

template<typename T>T gcd(T a,T b){
  if(b == 0)
    return a;
  return gcd(b,a%b);
}
template<typename T>T lcm(T a, T b){
  T g = gcd(a,b);
  return a/g*b; 
}
template<typename T>T power(T a,T b){
  T tmp = 1;
  rep(i,b){
    tmp *= a;
  }
  return tmp;
}
int main(){
  string o,e;cin>>o>>e;
  
  rep(i,e.size()){
    cout<<o[i]<<e[i];
  }
  if(e.size() != o.size())print(o[o.size()-1])
  return 0;
}


Measured memory_bytes: 256