akhauriyash/Code-Regression huggingface dataset:
import math
a,b,h,m=(int(i) for i in input().split())

r2=math.radians(360*m/60)
r1=math.radians(30*h)+r2/12
x1,y1=(a*math.cos(r1),a*math.sin(r1))
x2,y2=(b*math.cos(r2),b*math.sin(r2))

print(math.sqrt((x1-x2)**2+(y1-y2)**2))

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

#define ll long long

vector <int> g[110000];
vector <int> dp(110000, -1);

int solve(int a){
    if(dp[a] != -1)
        return dp[a];
    int ret = 0;
    for(int i = 0; i < g[a].size(); i++){
        ret = max(ret, solve(g[a][i]) + 1);
    }
    return dp[a] = ret;
}

int main(){
    int n,m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++){
        int a,b;
        scanf("%d%d", &a, &b);
        g[a].push_back(b);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans = max(ans, solve(i));
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 8448
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
	int N;
	cin >> N;
	vi L;
	for (int i = 0; i < 2 * N; i++){
		int l;
		cin >> l;
		L.push_back(l);
	}
	sort(L.begin(), L.end());
	int ans = 0;
	for (int i = 0; i < N; i++){
		ans += L[i * 2];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;

class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int x = int.Parse(input[0]);
    int t = int.Parse(input[1]);
    
    int ans = x - t;
    if(ans < 0) ans = 0;
    
    Console.WriteLine("{0}", ans);
  }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    int a[n];
    for( int i = 0; i < n; ++i ) cin >> a[i];
    int gcd = a[0];
    int mx = a[0];
    for( int i = 1; i < n; ++i ) {
        gcd = __gcd( gcd, a[i] );
        mx = max( mx, a[i] );

    }

    if( !( k % gcd ) && k <= mx ) cout << "POSSIBLE";
    else cout << "IMPOSSIBLE";
    cout << endl;

    return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
int main() {
	int N;
	cin >> N;
	double sum = 0;
	int d[100010];
	for (int i = 1; i <= N; i++) {
		cin >> d[i];
	}
	sort(d + 1, d + N + 1);

	cout << d[N / 2 + 1] - d[N / 2];
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

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

    int n;
    cin >> n;

	VL vl(n);
	FOR(i,n){
		cin >> vl[i];
	}

	ll ans = 0;
	FOR(i,n-1){
		if (vl[i] > vl[i+1]){
			ans += vl[i] - vl[i+1];	
			vl[i+1] = vl[i];
		}
	}

	cout << ans;

    return 0;
}












Measured memory_bytes: 4756
n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]
zoro = 0
ans = 0
for a in d:
    if a[0] == a[1]:
        zoro += 1
    else:
        zoro = 0
    ans = max(ans, zoro)
if ans >= 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{	
	ll n, k;
	cin >> n >> k;

	ll a = 0;
	while (true) {
		ll tmp = pow(k, a);
		if (n < tmp) break;
		a++;
	}
	cout << a << endl;
}

Measured memory_bytes: 384
import heapq
n,m = list(map(int, input().split()))
a = list(map(lambda x:-x, map(int, input().split())))

heapq.heapify(a)

for _ in range(m):
    x = heapq.heappop(a)
    x *= -1
    x //= 2
    heapq.heappush(a, -x)

print(-sum(a))

Measured memory_bytes: 14252
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    System.out.println(fun(s));
  }
  public static int fun(String s){
    int len=s.length(),res=0;
    for(int i=0;i<len/2;i++){
      if(s.charAt(i)!=s.charAt(len-1-i)) res++;
    }
    return res;
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,k=0,i;
	cin>>a>>b;
	string s[a];
	for(i=0;i<a;i++)cin>>s[i];
		b=0;
    for(i=0;i<a*2;i++){
       cout<<s[k]<<endl;
       if(b==1){b=0;k++;}
       else b++;
    }
	return 0;
}

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


int loop(int);


int keta;
int aa[11];

int main(){

int N,i,j,a,count,x3,x5,x7,x,y,z;

for(j = 0; j <= 10 ; j++){aa[j]=0;}


count=0;
keta=9;

   x3=0;
   x5=0;
   x7=0;


scanf("%d", &N);





a=0;



while( a <= N){

  a=0;

  loop(0);
;
  for(i = 0; i <= 10 ; i++){
    if( (i==9) && (aa[i]!=0)){aa[i]=1;}
    a = a + (aa[i]* pow(10,i));
  }


  for(i = 0; i <= 10 ; i++){
      if(aa[i]==3){x3=1;}
      if(aa[i]==5){x5=1;}
      if(aa[i]==7){x7=1;}
  }
      if((x3==1) && (x5==1) && (x7==1) && (a <= N)){count++;
      //printf("%d \n",a);
                                                   }

      x3=0;
      x5=0;
      x7=0;

  
  //printf("%d \n",a);
}

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


int loop(int w){

   

   switch (aa[w]) {
	case 0:
             aa[w]=3;      
	     break;  
	case 3:
	     aa[w]=5;     
	      break;  
        case 5:
	     aa[w]=7;      
	     break;  
        case 7:
             aa[w]=3;
	     loop(w+1);     
	     break;  
	default:
	   break;     

   }
   
   return(0);
} 




Measured memory_bytes: 128
class String
  def is_lower?
    self == self.downcase
  end
end

# 初期値
s = gets.chomp.chars
res = [false, false, false]

# 1つめの条件
if s[0] === 'A'
  res[0] = true
end

# 2つめの条件
pos = nil

tmp_s1 = s.slice(2..-2)
c_count = tmp_s1.select{|i| i === 'C'}.count
if c_count === 1
  pos = s.index('C')
  res[1] = true
end

# 3つめの条件
tmp_s = s
if !pos.nil?
  [pos, 0].each do |i|
    tmp_s.delete_at(i)
  end
else
  tmp_s.delete_at(0)
end

res[2] = true if tmp_s.count === tmp_s.select{|i|i.is_lower?}.count

puts res == [true, true, true] ? 'AC' : 'WA'

Measured memory_bytes: 1788
#include <bits/stdc++.h>
  
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
 
#define pb emplace_back
#define fi first
#define se second

using namespace std;
 
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
 
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-8;
const ll MOD = 1e9+7;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }
ll in(){ ll x; scanf( "%lld" , &x ); return x; }
 
// head

struct Mod{
  unsigned n;
  Mod(){}
  Mod( ll x ){
    if( x < 0 ) n = x%MOD+MOD;
    else n = x%MOD;
  }
};
Mod operator + ( Mod a  , Mod b ){ return Mod( a.n + b.n ); }
Mod operator +=( Mod &a , Mod b ){ return a = a + b; }
Mod operator - ( Mod a ){ return Mod( MOD - a.n ); }
Mod operator - ( Mod a  , Mod b ){ return Mod( a.n + MOD - b.n ); }
Mod operator -=( Mod &a , Mod b ){ return a = a - b; }
Mod operator * ( Mod a  , Mod b ){ return Mod( (ll)a.n * b.n ); }
Mod operator *=( Mod &a , Mod b ){ return a = a * b; }
Mod modpow( Mod x , ll k ){
  Mod res = 1;
  while( k ){
    if( k & 1 ) res *= x;
    k /= 2;
    x *= x;
  }
  return res;
}
ll extgcd( ll a , ll b , ll &x , ll &y ){
  ll d = a;
  if( b != 0 ){
    d = extgcd( b , a % b , y , x );
    y -= a / b * x;
  } else {
    x = 1, y = 0;
  }
  return d;
}
Mod inv( Mod a ){ ll x, y; assert( extgcd( a.n , MOD , x , y ) == 1 ); return Mod( x ); }
// Mod inv( Mod a ){ return modpow( a , MOD-2 ); }
Mod operator / ( Mod a  , Mod b ){ return Mod( (ll)a.n * inv(b).n ); }
Mod operator /=( Mod &a , Mod b ){ return a = a / b; }

char cs[100010];
string stin(){ scanf( "%s" , cs ); return cs; }
 
int n, m;
string s;
 
Mod dp[5010][5010];
 
int main(){
 
  n = in();
  m = SZ( stin() );
 
  dp[0][0] = 1;
  
  REP( i , n ){
    REP( j , i+1 ){
      Mod cur = dp[i][j];
      dp[i+1][j+1] += cur * 2;
      dp[i+1][max(0LL,j-1)] += cur;
    }
  }

  Mod ans = dp[n][m] / modpow( 2 , m );
  
  printf( "%d\n" , (int)ans.n );
  
  return 0;
}


Measured memory_bytes: 67072
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  ll n,m;
  cin >> n >> m;
  priority_queue<ll>p;
  rep(i,n){
    ll tmp;
    cin >> tmp;
    p.push(tmp);
  }
  rep(i,m){
    ll tmp = p.top();
    p.pop();
    tmp /= 2;
    p.push(tmp);
  }
  ll ans = 0;
  rep(i,n){
    ans += p.top();
    p.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<62;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    bool operator==(const mint a){
        return (x == a.x);
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// 2項係数を求める
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

//nが非常に大きく、aが小さい場合
mint choose(int n, int a){
    mint x = 1, y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

int main(){

    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vector<ll> cum(N+1,0);
    rep(i,N){
        cum[i+1] = (cum[i] + A[i]) % MOD;
    }

    mint ans = 0;
    for(int i = 0; i < N; i++){
        ans += (A[i] * (cum[N]-cum[i+1])) % MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6408
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var n=arr.shift()-0;
   if(n===0)break;
   var ary=arr.shift().split(" ");
   var obj={};
   ary.forEach(function(v){obj[v]=0;});
   ary.forEach(function(v){obj[v]++;});
   var ans="NO COLOR";
   var half=n/2;
   for(var k in obj){
      if(obj[k]>half){ans=k;break;}
   }
   console.log(ans);
}

Measured memory_bytes: 139424
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N=1<<10;
int n;
char s[N];
int p[N];
vector<pair<int,int> > solve(int S,int now)
{
	vector<pair<int,int> >res;
	for(int i=now+1;i<n;i++)
		if(S&(1<<i))
		{
			vector<pair<int,int> > t=solve(S,i);
			for(int j=now;j<=i-1;j++)
				res.push_back(make_pair(j,1));
			for(auto [x,y]:t)
				res.push_back(make_pair(x,y));
			for(int j=i;j>=now;j--)
				res.push_back(make_pair(j,1));
			res.push_back(make_pair(now,0));
			res.push_back(make_pair(now+1,0));
			for(int j=now+1;j<=i;j++)
				res.push_back(make_pair(j,1));
			reverse(t.begin(),t.end());
			for(auto [x,y]:t)
				res.push_back(make_pair(x,y));
			for(int j=i-1;j>=now+1;j--)
				res.push_back(make_pair(j,1));
			res.push_back(make_pair(now+1,0));
			res.push_back(make_pair(now,0));
			return res;
		}
	res.push_back(make_pair(now,1));
	res.push_back(make_pair(now+1,1)); 
	res.push_back(make_pair(now+1,0));
	res.push_back(make_pair(now,0));
	return res;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	for(int i=0;i<(1<<n);i++)
		p[i]=s[i]-'0';
	if(p[0]==0)
	{
		printf("Impossible");
		return 0;
	}
	for(int s=0;s<(1<<n);s++)
		if(p[s]==1)
			for(int i=s;i;i=(i-1)&s)
				if(p[i]==0)
				{
					printf("Impossible");
					return 0;
				}
	vector<pair<int,int> >ans;
	ans.push_back(make_pair(0,0));
	for(int s=1;s<(1<<n);s++)
		if(p[s]==0)
		{
			bool flag=true;
			for(int i=(s-1)&s;i;i=(i-1)&s)
				if(p[i]==0)
				{
					flag=false;
					break;
				}
			if(!flag) continue;
			vector<pair<int,int> >res;
			vector<pair<int,int> >t;
			int u=0;
			for(u=0;u<n;u++)
				if(s&(1<<u))
				{
					t=solve(s,u);
					break;
				}
			if(ans.back()!=make_pair(0,0)) res.push_back(make_pair(0,0));
			for(int i=0;i<=u-1;i++)
				res.push_back(make_pair(i,1));
			for(auto [x,y]:t)
				res.push_back(make_pair(x,y));
			for(int i=u;i>=0;i--)
				res.push_back(make_pair(i,1));
			res.push_back(make_pair(0,0));
			for(auto [x,y]:res)
				ans.push_back(make_pair(x,y));
		}
	printf("Possible\n");
	int len=ans.size()-1;
	printf("%d\n",len);
	for(auto [x,y]:ans)
		printf("%d %d\n",x,y);
	return 0;
}

Measured memory_bytes: 3920
/**
 *	Author: houtaru
 *	Create: 29.01.2018 21:51:20
 */

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

const int MOD = 1e9 + 7;

int n, p, cnt;

int main() {
    scanf("%d%d", &n, &p);
    for (int i = 0; i < n; ++i) {
        int x; scanf("%d", &x);
        cnt += x % 2;
    }
    if (cnt > 0) n--;
    long long answer = 0;
    if (!p) {
        answer = (1ll << n);
    } else if (cnt) {
        answer = (1ll << n);
    }
    printf("%lld\n", answer);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
typedef unsigned long long ull;
const int maxn=1e6+10;

int n;
int ans=inf;

inline int sum (int x)
{
   int res=0;
   while(x)
   {
    res+=x%10;
    x/=10;
   }
   return res;
}

int main()
{
   cin>>n;
   int j=0;
   for(int i=1;i<n;i++)
   {
      j=n-i;
      ans=min(ans,sum(i)+sum(j));
   }   
   cout<<ans;
   return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby

HH, WW = ARGF.gets.chomp.split.collect {|el| el.to_i}

$dp = Array.new(HH + 1) {Array.new(WW + 1)}

ss = ["." * (WW + 1)]
HH.times do
  ss << ("." + ARGF.gets.chomp)
end

$dp[0][1] = 0
$dp[1][0] = 0

for hh in 2..HH
  $dp[hh][0] = HH + WW + 10
end

for ww in 2..WW
  $dp[0][ww] = HH + WW + 10
end

for hh in 1..HH
  for ww in 1..WW
    if ss[hh][ww] == "."
      $dp[hh][ww] = [$dp[hh - 1][ww], $dp[hh][ww - 1]].min
    else
      if ss[hh - 1][ww] == "."
        uu = $dp[hh - 1][ww] + 1
      else
        uu = $dp[hh - 1][ww]
      end
      if ss[hh][ww - 1] == "."
        rr = $dp[hh][ww - 1] + 1
      else
        rr = $dp[hh][ww - 1]
      end
      #p uu, rr
      $dp[hh][ww] = [uu, rr].min
    end
    #p $dp
  end
end


puts $dp[HH][WW]


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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;
#define ret() return 0;

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll k(ll x, ll y) {
    return x / y;
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    if (c == 1 || d == 1) {
        cout << 0 << endl;
        ret();
    }

    ll g = lcm(c, d);

    ll kac = k(a - 1, c);
    ll kad = k(a - 1, d);
    ll kag = k(a - 1, g);

    ll kbc = k(b, c);
    ll kbd = k(b, d);
    ll kbg = k(b, g);

    ll aa = kac + kad - kag;
    ll ba = kbc + kbd - kbg;

    ll ans = b - a + 1 - (ba-aa);
    cout << ans << endl;

}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=1000000;
vector<int> an[maxn];
int a[maxn],b[maxn];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&a[i],&b[i]);
		an[a[i]].push_back(b[i]);

	}
	for(int i=1;i<=n;i++)
		sort(an[i].begin(),an[i].end());
	for(int i=0;i<m;i++){
		
		int t=lower_bound(an[ a[i] ].begin(),an[a[i]].end(),b[i] )-an[a[i]].begin()+1;
		printf("%06d%06d\n",a[i],t);
	
	}
		
			
	return 0;
}

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

int main() {
  int n, m, S = 0, c = 0;
  cin >> n >> m;
  vector<int> A(n);
  for (int i = 0;i < n;i++) {
    int a;
    cin >> a;
    A[i] = a;
    S += a;
  }
  for (int x : A) {
    if (4 * m * x >= S) c++;
  }
  cout << ((c >= m) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t;
	map<ll,ll> mp;
	cin>>n;
	for(i=0;i<n-1;i++)
	{
		cin>>j;
		mp[j]++;
	}
	for(i=1;i<=n;i++)
	cout<<mp[i]<<endl;
}

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

char w[100100];
int cg,cp;

main()
{
	scanf("%s",w);
	for(int i=0;w[i];i++)
	{
		if(w[i]=='g')
		{
			cg++;
		}
		else
		{
			cp++;
		}
	}
	int dif=cg-cp;
	dif/=2;
	printf("%d\n",dif);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
struct Union{
  Union *par;
  int val=-1;
  int rank=1;
};

Union *root(Union *t){
  if (t->par==t) return t;
  else return root(t->par);
}

void unite (Union *a,Union *b){
  if (a->rank>b->rank) root(b)->par=root(a);
  else {
    root(a)->par=root(b);
    if (a->rank==b->rank) b->rank++;
  }

}
bool same(Union *a,Union *b){
  return root(a)==root(b);
}

int main(){
  Union u[13];
  for(int i=0;i<13;i++) u[i].par=&u[i];
  unite(&u[1],&u[3]);
  unite(&u[1],&u[5]);
  unite(&u[1],&u[7]);
  unite(&u[1],&u[8]);
  unite(&u[1],&u[10]);
  unite(&u[1],&u[12]);
  unite(&u[6],&u[4]);
  unite(&u[9],&u[6]);
  unite(&u[11],&u[4]);
  int x,y;
  cin>>x>>y;
  if(same(&u[x],&u[y])) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve()
{
	string s, t;
	cin >> s >> t;
	int n = t.length();
	if (s.length() + 1 == t.length() && t.substr(0, n - 1) == s)
		cout << "Yes" << ln;
	else
		cout << "No" << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;

// nPnの順列に対して処理を実行する
void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}

int main(int argc, const char *argv[]) {
    long long N;
    cin >> N;
    long long P[N];
    long long Q[N];
    long long sumP = 0;
    long long sumQ = 0;
    long long itr = 1;
    for (int i = 0; i < N; ++i) {
        cin >> P[i];
        sumP += itr * P[i];
        itr *= 10;
    }
    itr = 1;
    for (int i = 0; i < N; ++i) {
        cin >> Q[i];
        sumQ += itr * Q[i];
        itr *= 10;
    }

    int ordP, ordQ = -1;
    int num = 0;
    foreach_permutation(N, [N, &num, &ordP, &ordQ, sumP, sumQ](int *indexes) {
        long long it = 1;
        long long sum = 0;
        for (int i = 0; i < N; ++i) {
            sum += it * (indexes[i] + 1);
//            cout << indexes[i] + 1 << ",";
            it *= 10;
        }
//        cout << endl;
        if (sum == sumP) {
            ordP = num;
        }
        if (sum == sumQ) {
            ordQ = num;
        }
        num += 1;
    });

    if (ordP - ordQ >= 0) {
        cout << ordP - ordQ << endl;
    } else {
        cout << ordQ - ordP << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

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

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

mint factorial(ll n) {
  mint answer = 1;
  while (n > 1) {
    answer *= n;
    n--;
  }
  return answer;
}

mint combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

mint permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

// setprecision(8) 桁数指定
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  string n;
  cin >> n;
  if (n[0] == '9' || n[1] == '9') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
H,W,D = map(int,input().split())
Data = [0] * (H*W)
for h in range(H):
    tmp = list(map(int,input().split()))
    for w in range(W):
        s = tmp[w]
        Data[s-1] = [h,w]

Q = int(input())
Questions = []
for _ in range(Q):
    Questions.append(list(map(int,input().split())))

Acc = [0] * (H*W+1)
Acc[0] = 0
for i in range(1,H*W+1):
    if i < D:
        Acc[i] = 0
    else:
        plus  = abs(Data[i-1][0]-Data[i-D-1][0])
        plus += abs(Data[i-1][1]-Data[i-D-1][1])
        Acc[i] = Acc[i-D] + plus

#for i in range(H*W):
#    print(i+1,Data[i])
#print(Acc)

for l,r in Questions:
    print(Acc[r]-Acc[l])


Measured memory_bytes: 41412
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 100100;

    ll fa[maxN];

    ll find(ll x){
        return fa[x] == x ? x : fa[x] = find(fa[x]);
    }

    void solve() {
        ll n, m, x, y, z, cnt = 0;
        cin >> n >> m;
        repA(i, 1, n) fa[i] = i;
        rep(i, m) { 
            cin >> x >> y >> z;
            x = find(x), y = find(y);
            if(x!=y) fa[x] = y;
           
        }
        repA(i, 1, n) if(fa[i] == i) cnt++; 
        cout << cnt << endl;
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
     
      //te
      solve();
      return 0;
    } 


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
map < int , int > dp[3];
int h[3][100005];
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++) {
		cin>>h[0][i]>>h[1][i]>>h[2][i];
	}
	for(int i=0;i<n;i++) {
		dp[0][i]=h[0][i]+max(dp[1][i-1],dp[2][i-1]);
		dp[1][i]=h[1][i]+max(dp[0][i-1],dp[2][i-1]);
		dp[2][i]=h[2][i]+max(dp[1][i-1],dp[0][i-1]);
	}
	cout<<max(max(dp[0][n-1],dp[1][n-1]),dp[2][n-1]);
	return 0;
}

Measured memory_bytes: 16768
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
    int N,T;
    cin >> N >> T;
    int MIN,MAX=0;
    cin >> MIN;
    int dif[N],a;
    dif[0] = 0;
    for (int i=1;i<N;i++){
        cin >> a;
        dif[i] = a-MIN;
        MAX = max(dif[i],MAX);
        MIN = min(MIN,a);
    }
    int count =0;
    for (int i=0;i<N;i++){
        if (dif[i]==MAX) count++;
    }
    cout << count << endl;

    return 0;


}


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

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> a, b;
    char before = 'x';
    int cnt = 0;
    int score = 0;
    for (const auto& c : s) {
        if (before == 'x') {
            before = c;
            continue;
        }
        if (before == c) {
            score++;
            continue;
        }
        before = c;
        cnt++;
    }
    for (int i = 0; i < k; ++i) {
        if (cnt == 0) break;
        if (cnt > 1) {
            score += 2;
            cnt -= 2;
        }
        else if (cnt == 1) {
            score += 1;
            cnt -= 1;
        }
    }
    cout << score << endl;
}


Measured memory_bytes: 3764
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, s, t;
  std::cin >> n >> s >> t;
  s--,t--;
  int root = t;
  std::vector<std::vector<int>> graph(n);
  loop(n-1) {
    int u, v; std::cin >> u >> v;
    u--,v--;
    graph.at(u).emplace_back(v);
    graph.at(v).emplace_back(u);
  }
  debug(graph);

  int D = 0;
  std::vector<int> h(n,-1);
  auto dfs = [&] (auto&& dfs, int x, int p, int d) -> void {
    if (x == s) D = d;
    for (auto&& y : graph.at(x)) {
      if (y == p) continue;
      dfs(dfs,y,x,d+1);
      cmx(h.at(x), h.at(y));
    }
    h.at(x)++;
  };
  dfs(dfs,root,root,0);
  debug(D);

  int ans = D;
  auto efs = [&] (auto&& efs, int x, int p, int d) -> bool {
    bool ret = x == s;
    for (auto&& y : graph.at(x)) {
      if (y == p) continue;
      ret |= efs(efs,y,x,d+1);
    }
    if (ret == true && D / 2 < d) {
      lint tmp = d + h.at(x);
      debug(x,d,h.at(x),D,tmp);
      cmx(ans,tmp);
      debug(ans,tmp);
    }
    return ret;
  };
  efs(efs,root,root,0);

  ans--;
  // debug(h);
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 9984
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k,l;
vector<int> G[2][200001];
int num[200001];
int cnt,size,now;
map<P,int> group;
bool used[200001];
int res[200001];
int vs[200001];

void dfs(int v){
	num[v]=cnt;
	for(int i=0;i<G[0][v].size();i++){
		if(num[G[0][v][i]]==-1){
			dfs(G[0][v][i]);
		}
	}
}

void dfs2(int v){
	used[v]=true;
	group[P(now,num[v])]++;
	vs[size++]=v;
	for(int i=0;i<G[1][v].size();i++){
		if(!used[G[1][v][i]]){
			dfs2(G[1][v][i]);
		}
	}
}

int main(void){
	scanf("%d%d%d",&n,&k,&l);
	for(int i=0;i<k;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		f--;
		t--;
		G[0][f].push_back(t);
		G[0][t].push_back(f);
	}
	for(int i=0;i<l;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		f--;
		t--;
		G[1][f].push_back(t);
		G[1][t].push_back(f);
	}
	memset(num,-1,sizeof(num));
	cnt=0;
	for(int i=0;i<n;i++){
		if(num[i]==-1){
			dfs(i);
			cnt++;
		}
	}
	memset(used,false,sizeof(used));
	for(int i=0;i<n;i++){
		if(!used[i]){
			size=0;
			dfs2(i);
			for(int j=0;j<size;j++){
				res[vs[j]]=group[P(now,num[vs[j]])];
			}
			now++;
		}
	}
	for(int i=0;i<n;i++){
		printf("%d%c",res[i],i+1==n?'\n':' ');
	}
	return 0;
}


Measured memory_bytes: 25856
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>
#include <algorithm>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define all(v) ((v).begin(),(v).end())
#define Sort(v) sort(all(v))
#define INF 1000000000
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

int main(){
    int n;
    cin>>n;
    ll ans=0;
    rep(i,0,n){
        int x; cin>>x; ans+=x;
    }
    cout<<ans-n<<endl;

}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,i;
    char s[120000];
    while(~scanf("%d",&n))
    {
        int acm=1;
        scanf("%s",s);
        for(i=0;i<n-1;i++)
            if(s[i]!=s[i+1])
                acm++;
        printf("%d\n",acm);
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String input = scanner.next();

		for(int i = 0,len = input.length(); i < len;i+=2) {
			System.out.print(input.charAt(i));;
		}
		scanner.close();
	}

}


Measured memory_bytes: 28400
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	ll a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	ll ans = -1;
	for(int i=0;i<=200000;i++){
		ll tmp=0;
		tmp = i*c;
		if( i/2 < x){
			tmp += a * (x - i/2);
		}
		if( i/2 < y){
			tmp += b * (y - i/2);
		}
		if(ans == -1 || tmp<ans)ans = tmp;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = [int(input()) for i in range(n)]
a_list_sort = sorted(a_list)
a_list_max1 = max(a_list)
a_list_max2 = a_list_sort[-2]
for i in range(n):
    if a_list_max1 == a_list[i]:
        print(a_list_max2)
    else:
        print(a_list_max1)

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

using namespace std;

bool solve(const string& S, const string& T)
{
    auto N = S.size();
    map<char, char> s_table, t_table;

    for (size_t i = 0; i < N; ++i)
    {
        auto c = S[i];
        auto d = T[i];
        auto it = s_table.find(c);

        if (it == s_table.end())
        {
            auto it = t_table.find(d);

            if (it == t_table.end())
            {
                s_table[c] = d;
                t_table[d] = c;
            } else
                return false;
        } else if (it->second != d)
                return false;
    }

    return true;
}

int main()
{
    ios::sync_with_stdio(false);

    string S, T;
    cin >> S >> T;

    auto ans = solve(S, T);

    cout << (ans ? "Yes" : "No") << '\n';

    return 0;
}


Measured memory_bytes: 916
#include <bits/stdc++.h>
#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)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

const int mod = 1000000007;

struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

    int n; ll K;
    cin >> n >> K;
    auto a = make_vec<mint>(60, n, n);
    rep(i, n) rep(j, n) cin >> a[0][i][j];
    rep(t, 59) {
        rep(i, n) rep(j, n) {
            rep(k, n) a[t+1][i][k] += a[t][i][j] * a[t][j][k];
        }
    }
    auto ans = make_vec<mint>(n, n);
    rep(i, n) ans[i][i] = 1;
    rep(t, 60) {
        if (K >> t & 1) {
            auto pre = make_vec<mint>(n, n);
            swap(pre, ans);
            rep(i, n) rep(j, n) {
                rep(k, n) ans[i][k] += pre[i][j] * a[t][j][k];
            }
        }
    }
    mint res = 0;
    rep(i, n) rep(j, n) res += ans[i][j];
    cout << res << endl;
}


Measured memory_bytes: 4988
h,w,k = map(int,input().split())
u = [list(input()) for i in range(h)]

from itertools import product
a = list(product([0,1],repeat=h))
b = list(product([0,1],repeat=w))

co2=0
for p in a:
    for q in b:
        co1=0
        for i in range(h):
            for j in range(w):
                if p[i]==0 and q[j]==0:
                    if u[i][j]=='#':
                        co1+=1
        if co1==k:
            co2+=1
print(co2)

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

ll func(std::vector<ll> R, std::vector<ll> G, std::vector<ll> B ) {
    ll ans = 0;
    rep(i, R.size()) {
        rep(j, G.size()) {
            rep(k, B.size()) {
                ll I = min(R[i], min(G[j], B[k]));
                ll K = max(R[i], max(G[j], B[k]));
                ll J = R[i]+G[j]+B[k]-I-K;
                if ( 2*J != I+K ) {
                    ans++;
                }
            }
        }
    }
    return ans;
}

ll func2( /*ll n,*/ std::vector<ll> R, std::vector<ll> G, std::vector<ll> B ) {
    ll ans = 0;

    if ( B.empty() ) return 0;

    rep(i, R.size()) {
        rep(j, G.size()) {
            ll num = abs(R[i]-G[j])+max(R[i], G[j]);
            // if ( num > n ) break;
            if ( num > B.at(B.size()-1) ) continue;

            if ( find_num(B, num) ) {
                // cout << "num " << num << endl;
                ans++;
            }
        }
    }
    return ans;
}

int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    std::vector<ll> R, G, B;
    rep(i, s.length()) {
        if ( s[i] == 'R' ) {
            R.push_back(i+1);
            // cout << "r " << i+1 << endl;
        } else if ( s[i] == 'G' ) {
            G.push_back(i+1);
            // cout << "g " << i+1 << endl;
        } else {
            B.push_back(i+1);
            // cout << "b " << i+1 << endl;
        }
    }
    ll ans = 0;
    // ans += func(R, G, B);

    ans += R.size()*G.size()*B.size();
    ans -= func2(/*n,*/ R, G, B);
    ans -= func2(/*n,*/ R, B, G);
    ans -= func2(/*n,*/ G, B, R);

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


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 333;
ll mat[N][N];
int n;

int main() {
    ios::sync_with_stdio(false);
    cout.precision(10);
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            cin >> mat[i][j];
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            if(i == j) continue;
            bool has = false;
            for(int k = 1; k <= n; k++) {
                if(k == i || k == j) continue;
                if(mat[i][j] > mat[i][k] + mat[k][j]) {
                    cout << -1 << endl;
                    return 0;
                }
                if(mat[i][j] == mat[i][k] + mat[k][j]) {
                    has = true;
                }
            }
            if(!has) {
                ans += mat[i][j];
            }
        }
    }
    ans >>= 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#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);
	cin.tie(0);

	int N; cin >> N;
	vector<int> a(N, 0);
	rep (i, N){
		cin >> a[i];
	} // end rep

	int res = 0;
	int i = 0;
	while(i < N){
		int len = 1, j = i + 1;
		for (; j < N; ++j){
			if (a[i] == a[j]){
				++len;
			}else{
				break;
			} // end if
		} // end for
		res += len / 2;
		i = j;
	} // end while

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256