akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();

		int[] arr = new int[n+1];

		for(int i=0; i<m; i++){
			int val = sc.nextInt();
			arr[val]++;
		}
		
		int minCost = n+1;
		int cost = 0;

		for(int i=x+1; i<n; i++){
			if(arr[i] > 0){
				cost++;
			}
		}

		if(minCost > cost){
			minCost = cost;
		}

		cost = 0;

		for(int i=x-1; i>0; i--){
			if(arr[i] > 0){
				cost++;
			}
		}

		if(minCost > cost){
			minCost = cost;
		}	

		System.out.println(minCost);
	}
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9+5;
void solve(long long& a,long long b)
{
    a=max(a,b);
    //cout<<a<<endl;
}
int main()
{
    int n,w;
    cin>>n>>w;
    vector<long long>dp(w+1);
    for(int i=0; i<n; i++)
    {
        int weight,value;
        cin>>weight>>value;
        for(int j=w-weight; j>=0; j--)
        {
            solve(dp[j+weight],dp[j]+value);
        }
    }
    long long s=0;
    for(auto x: dp){
        s=max(s,x);
    }
    cout<<s<<endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define ld long double
#define MAX (2000 + 10)
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = pow(10,9)+7;
ld eps = 1e-9;



void deal(){
	ll m, n;
	cin>>m>>n;
	ll s = 0;
	fori(n){
		ll  ed;
		cin>>ed;
		s+=ed;
	}
	m-=s;
	if(m < 0){
		m = -1;
	}
	cout<<m;
}


int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}





























Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair


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

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


char s[55][55];
int h, w;

cin >> h >> w;

rep(i, 1, w){
rep(j, 1, h)
cin >> s[i][j];

}

bool flag = true;

rep(i, 1, h){

    rep(j, 1, w){
    if(s[i][j]=='#'){
    bool f1 = false;
    rep(k, 0, 3){
    int x = dx[k]; int y = dy[k];
    if(s[i+x][j+y]=='#')f1 = true;
    }
    if(f1){
          s[i][j]='#';      continue;

    }else return 0*printf("No");
    }
    }
}

cout << "Yes" << endl;
return 0;}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (size_t i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
#define vec2d(T, v, m, n) vector<vector<T>> (v)(m, vector<T>(n))
#define nvec2d(T, v, m, n) vec2d(T, v, m, n); REP(j, m){REP(i, n) {cin>>(v[j])[i];}}

#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))

#define GCD(v) gcd(ALL(v), 0l)

/*template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}*/

template <typename T>
using vec =vector<T>;

template <typename T>
using vvec =vector<vector<T>>;

int main(){
  vector<int> prime(1,2);
  prime.reserve(10000);
  for (int i = 3; i < 1000000; i+=2) {
    bool isPrime=1;
    for (int j=0;j<prime.size()&&prime[j]<=sqrt(i);j++){
      if(i%prime[j]==0)isPrime=0;
    }
    if(isPrime==1)prime.push_back(i);
  }
  
  
  long long n;
  cin>>n;

  int m=0;
  for(int p:prime){
    int l=0;
    while(n%p==0){
      n/=p;
      l++;
    }
    //cout<<(sqrt(1+8*l)-1)/2<<endl;
    m+=(sqrt(1+8*l)-1)/2;
  }
  if(n!=1)m++;
  cout<<m;
}


/* きょむ〜 */


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
 
string s;
map<char, int> m;
 
int main(){
cin >> s;
for(int i =0; i<s.size(); i++){
    m[s[i]]++;
}
for(int i =0; i<s.size(); i++){
    if(m[s[i]]%2==1)return 0*printf("No");
}
cout << "Yes"<< endl;
 
return 0;}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
sum=0
for i in range(n):
  sum+=b[a[i]-1]
  if i>0 and a[i]==a[i-1]+1:
    sum+=c[a[i-1]-1]
  
print(str(sum))

Measured memory_bytes: 38384
#include<stdio.h>
int a, b, c;
int main(){
  a=getchar()-'0'; getchar();
  b=getchar()-'0'; getchar();
  c=getchar()-'0';
  if(a>b){a^=b; b^=a; a^=b;}
  if(a>c){a^=c; c^=a; a^=c;}
  if(b>c){b^=c; c^=b; b^=c;}
  printf("%d\n", a+b+c*10);
}


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

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    int cnt = 0;
    for(int i = 0; i < n; i++){
        
        if(a[i] == i + 1){
            if(i == n - 1) swap(a[i],a[i-1]);
            swap(a[i], a[i+1]);
            cnt++;
        }
    }
    cout << cnt << endl;
}







Measured memory_bytes: 640
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
N = l[0] * 1
M = l[1] * 1 
K = l[2] * 1
f = 0
for (i=0; i<=N; i++) {
  for (j=0; j<=M; j++) {
      if ((M - j) * i + (N - i) * j == K) {
          f = 1
      } 
  }
}
console.log(f ? 'Yes' : 'No')


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

int main(){
  string s;
  int count=0;
  cin >> s;
  for(int i=0;i<s.size()/2;i++){
    if(s[i]!=s[s.size()-1-i]){
      count ++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = long.Parse(line[0]);
        var k = long.Parse(line[1]);
        var t = n % k;
        if (t == 0) Console.WriteLine(0);
        else
        {
            var t1 = Abs(t - k);
            Console.WriteLine(Min(t, t1));
        }
    }
}


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

using namespace std;

int main()
{
    int N;
    map<string,int> gacha;
    string tmp;
    cin >> N;


    for(int i = 0; i < N; i++)
    {
        cin >> tmp;
        gacha.emplace(tmp,i);
    }

    cout << gacha.size() << endl;
    return 0;
}

Measured memory_bytes: 19120
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, k, a[200010];

signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = k; i < n; i++) {
		if (a[i - k] < a[i])cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


Measured memory_bytes: 4408
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	var a []int
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)

		a = append(a, tmp)
	}

	var shift []int

	for i := 0; i < n; i++ {
		shift = append(shift, 0)
		for ; a[i] > 1; a[i] /= 2 {
			if a[i]%2 == 0 {
				shift[i]++
			} else {
				break
			}
		}
	}

	var c int = shift[0]
	for i := 1; i < n; i++ {
		if c > shift[i] {
			c = shift[i]
		}
	}

	fmt.Printf("%d\n", c)
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void) {
  int a, b;
  cin >> a >> b;
  if (a == 1) a += 13;
  if (b == 1) b += 13;
  puts(a > b ? "Alice" : a == b ? "Draw" : "Bob");
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;


int main(){
  intl N;
  cin >>N;
  
  vi A(1000001,0);
  intl a,Amax=0;
  Rep(i,N){
    cin >>a;
    A[a] ++;
    Amax=max(a,Amax);
  }
  
  Rep1(i,1000000){
    if(A[i]){
      if(A[i] >1){A[i] =0;}
      for(intl j=i*2; j <= Amax; j+=i){
        A[j] = 0;
      }
    }
  }
  
  intl ans=0;
  Rep1(i,1000000) {
    ans += (A[i])?1:0;
  }
  
  cout <<ans;
}

Measured memory_bytes: 11172
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007


void solve()
{
		ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll x=b-a+1;
        ll ans=x;
        ans-=(b/c-(a-1)/c);
        ans-=(b/d-(a-1)/d);
        ll lm=lcm(c,d);
        ans+=(b/lm - (a-1)/lm);
        cout<<ans<<endl;    
        return;
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  char c; cin >> c;
  char ans;
  if (c == 'A')  ans ='T';
  if (c == 'T')  ans ='A';
  if (c == 'C')  ans ='G';
  if (c == 'G')  ans ='C';
  cout << ans<<endl;
  return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
int main(void){
	int i,x,n,q,a,v,aaa=0,vvv=0,f[1000000],vv[9000];
	scanf("%d %d",&n,&q);
	for(i=n;i>0;i--)f[i-1]=0;
	for(i=0;i<5000;i++)vv[i]=0;
	for(;q>0;q--){
		scanf("%d %d",&a,&v);
		x=f[a-1];
		if(vv[x]==a){
			for(i=a;f[i]!=x&&i<n;i++);
			if(i==n)vv[x]=0;
			else vv[x]=i+1;
		}
		f[a-1]+=v;
		x+=v;
		if(a<vv[x] || vv[x]==0)vv[x]=a;
		if(v>0){if(x>vvv || (x==vvv && a<aaa)){vvv=x;aaa=a;}}
		else if(a==aaa){
			for(i=vvv;vv[i]<1;i--);
			vvv=i;aaa=vv[i];
		}
		printf("%d %d\n",aaa,vvv);
	}
}

Measured memory_bytes: 4528
#include<iostream>
using namespace std;
int n,k,s,ans;

void dfs(int a=0,int sum=0,int cnt=0){
  if(cnt==k){
    if(sum==s)ans++;
    return;
  }
  for(int i=a+1;i<=n;i++)dfs(i,sum+i,cnt+1);
}

int main(){
  while(cin>>n>>k>>s,n){
    ans=0;
    dfs();
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c){
        cout<<"No"<<endl;
    }
    else if(a==b||b==c||a==c){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
 
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
 
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
 
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
str a,b,c;
int main(){
 
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  
  	cin>>a>>b>>c;
  	bool valid = false;
  	if((a.back() == b[0]) && (b.back())==c[0]) valid = true;
  	if(valid) cout<<"YES\n";
  	else cout<<"NO\n";
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String stringO = sc.next();
		String[] arrayO = stringO.split("");
		String stringE = sc.next();
		String[] arrayE = stringE.split("");
		String[] arrayZ = new String[stringO.length() + stringE.length()];
		for (int i=0;i<arrayO.length;i++) {
			arrayZ[i*2] = arrayO[i];
		}
		for (int i=0;i<arrayE.length;i++) {
			arrayZ[i*2+1] = arrayE[i];
		}
		String StringOE = String.join("",arrayZ);
		System.out.println(StringOE);
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n,x,t;
    cin>>n>>x>>t;
    int a=(n+x-1)/x;
    cout<<a*t<<endl;
}


Measured memory_bytes: 3624
#include<stdio.h>

int comb(int n, int r){
/*nCr を求める関数*/
	int ret = 0;
	if(n > 0 && r <= n){
		ret = 1;
		int i = 1, k = r;
		if(r > n/2) k = n - r; 
		for(i = 1; i <= k; i++){
			ret = ret*(n-i+1) / i;
		}
	}
	return ret;
}

int main(){
	int N, M;
	scanf("%d %d", &N, &M);
	int ret = 0;
	ret = comb(M, 2) + comb(N, 2);
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 128
n=int(input())
w=list(map(int, input().split()))
min = 100000000000
for i in range(0,n):
  left = 0
  right = 0
  for j in range(0,i):
    left = left +w[j]
  for k in range(i,n):
    right = right + w[k]
  if min > abs(left - right):
    min = abs(left-right)
print(min)

Measured memory_bytes: 3060
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
cnt = Counter(a)
q = int(input())
sum_c = sum([i * j for i, j in cnt.items()])
for _ in range(q):
    b, c = map(int, input().split())
    sum_c += cnt[b] * (c - b)
    cnt[c] = cnt[c] + cnt[b]
    cnt[b] = 0
    print(sum_c)

Measured memory_bytes: 24468
program main

  integer :: N, add

  integer, allocatable, dimension ( : ) :: A, B

  read ( *, * ) N

  allocate ( A ( 1:N-1 ) )

  allocate ( B ( 1:N ) )

  read ( *, * ) A ( 1:N-1 )

  B ( : ) = 0

  B ( 1 ) = A ( 1 )

  B ( N ) = A ( N - 1 )
  
  do i = 2, N - 1

     B ( i ) = min ( A ( i - 1 ), A ( i ) )
     
  end do
  
  print '(i0)', sum ( B ( 1:N ) )

end program main


Measured memory_bytes: 768
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
  int N,D;
  cin >> N >> D;
  vector<vector<int>> x(N,vector<int>(D));
  for(int i = 0; i<N; i++){
    for(int j= 0; j<D; j++){
    cin >> x.at(i).at(j);
  }
  }
  int count = 0;
  for(int i = 0; i<N-1; i++){
    for(int k = i+1; k<N; k++){
      int sum = 0;
    for(int j= 0; j<D; j++){
      sum += (x.at(i).at(j) - x.at(k).at(j))*(x.at(i).at(j) - x.at(k).at(j));
    }
  
    double ans = sqrt(sum);
   // cout << ans << endl;
    if(ans == floor(ans)){
      count ++;
    }
  }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#define N 1100
#define mmod 1000000007
#define LL long long
using namespace std;
struct mat{
	int a[3][3];
	mat() {memset(a,0,sizeof(a));}
	friend mat operator *(mat a,mat b)
	{
		mat c;
		for(int i=1;i<=2;i++)
			for(int j=1;j<=2;j++)
				for(int k=1;k<=2;k++)
					c.a[i][j]=(1ll*c.a[i][j]+1ll*a.a[i][k]*b.a[k][j])%mmod;
		return c;
	}
}A,g;
int n,m,a[N][N],b[N][N],ans;LL k;
char s[N];
void solve()
{
	int cnt=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cnt+=a[i][j];
	int g=1,t=cnt;
	k--;
	while(k)
	{
		if(k%2) g=1ll*g*t%mmod;
		k/=2;
		t=1ll*t*t%mmod;
	}
	printf("%d\n",g);
}
void qmod(LL b)
{
	g.a[1][1]=g.a[2][2]=1;
	while(b)
	{
		if(b%2) g=g*A;
		b/=2;
		A=A*A;
	}
}
int main()
{
	scanf("%d%d%lld",&n,&m,&k);
	if(k==0) {printf("1\n");return 0;}
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		for(int j=1;j<=m;j++) if(s[j]=='#') a[i][j]=1;
	}
	bool b1=0,b2=0;
	for(int i=1;i<=m;i++) if(a[1][i] && a[n][i]) b1=1;
	for(int i=1;i<=n;i++) if(a[i][1] && a[i][m]) b2=1;
	if(b1 && b2) {printf("1\n");return 0;}
	if(b1==0 && b2==0) {solve();return 0;}
	if(b1) 
	{
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				b[j][i]=a[i][j];
		swap(n,m);
		memset(a,0,sizeof(a));
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				a[i][j]=b[i][j];
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i][1] && a[i][m]) A.a[2][2]++;
		for(int j=1;j<=m;j++)
			if(a[i][j]) 
			{
				A.a[1][1]++;
				if(a[i][j+1]) A.a[1][2]--;
			}
	}
	qmod(k-1);
	ans=(g.a[1][1]+g.a[1][2])%mmod;
	ans=(ans+mmod)%mmod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9728
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
bc=[]
for i in range(m):
    bc.append([int(j) for j in input().split()])

a.sort()

from operator import itemgetter
bc.sort(key=itemgetter(1))
bc.reverse()

ans=0
for i in range(n):
    if bc!=[]:
        if a[i]<bc[0][1]:
            ans+=bc[0][1]
            if bc[0][0]==1:
                 del bc[0]
            else:
                bc[0][0]-=1
        else:
            ans+=a[i]
    else:
        ans+=a[i]
print(ans)


Measured memory_bytes: 27084
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main()
{
  int n;
  cin >> n;
  bool ok = false;
  for (int i = 1; i <= 9; i++)
  {
    for (int j = 1; j <= 9; j++) {
      if(n == i * j) {
        ok = true;
        break;
      }
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

typedef set<pair<int,int> > spair;

int C,N;
int pixel[1001][1001];
int D;
int r,c;
char buf[1001];
spair ver,hol;

int main(){	
	int ans = 0;
	ver = spair();
	hol = spair();
	scanf("%d%d",&C,&N);
	for(int i = 0; i < N; i++){
			scanf("%s",buf);
		for(int j = 0; j < N; j++){
			pixel[i][j] = buf[j] - 0x30;
		}
	}
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N/2; j++){
			// hol
			if(pixel[i][j] != pixel[i][N-j-1]){
				hol.insert(make_pair(i,j));
				hol.insert(make_pair(i,N-j-1));
			}
			// ver
			if(pixel[j][i] != pixel[N-j-1][i]){
				ver.insert(make_pair(j,i));
				ver.insert(make_pair(N-j-1,i));
			}
		}
	}
	if(hol.empty() && ver.empty()){
		ans = 1;
	}
	else{
		ans = 0;
	}
	// init end
	
	for(int otm = 0; otm < C-1; otm++){
		scanf("%d",&D);
		for(int itm = 0; itm < D; itm++){
			scanf("%d%d",&r,&c);
			r--;c--;
			pair<int,int> pr = make_pair(r,c);
			pair<int,int> pr_hr = make_pair(r,N-c-1);
			pair<int,int> pr_vr = make_pair(N-r-1,c);
			int res = hol.erase(pr);
			if(res == 0){
				hol.insert(pr);
				hol.insert(pr_hr);
			}
			else{
				hol.erase(pr_hr);
			}
			int res2 = ver.erase(pr);
			if(res2 == 0){
				ver.insert(pr);
				ver.insert(pr_vr);
			}
			else{
				ver.erase(pr_vr);
			}
		}
		if(hol.empty() && ver.empty()){
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 47536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    string s,t;
    cin >> N >> s >> t;
    int i;
    for(i=0;i<s.length();i++){
        if(s[i] == t[0]){
            bool flag = true;
            for(int j=0;j<s.length()-i;j++){
                if(s[i+j] != t[j]){
                    flag = false;
                    break;
                } 
            }
            if(flag)break;
        }
    }
    cout << i + t.length() << endl;

    return 0;
} 

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

int n, k;
string s;
int main() {
  cin >> n >> s >> k;
  --k;
  for (int i = 0; i < n; ++i) {
    if (s[i] != s[k]) s[i] = '*';
  }
  cout << s << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define INF 1e9

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,x; cin>>n>>m>>x;
    vi c(n);
    vector<vi> a(n, vi(m));
    rep(i,n){
        cin>>c[i];
        rep(j,m) cin>>a[i][j];
    }
    int ans=INF;
    rep(S,1<<n){
        int cand = 0;
        vi u(m,0);
        rep(i,n)if(S>>i&1){
            cand += c[i];
            rep(j,m) u[j]+=a[i][j];
        }
        bool ok=true;
        rep(i,m)if(u[i]<x){
            ok=false;
            break;
        }
        if (ok) chmin(ans, cand);
    }
    if (ans==INF){
        cout<<"-1\n";
    }else{
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3668
import java.util.Scanner;

public class Main {
	
	static int[][] area = new int[12][12];
	
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNextLine()) {
			int count = 0;

			for(int i = 0;i < area.length; i++) {
				char[] nums = sc.nextLine().toCharArray();
				for(int j = 0;j < area.length; j++) {
					area[i][j] = Character.getNumericValue(nums[j]);
				}

			}

			for(int i = 0;i < area.length; i++) {
				for(int j = 0;j < area.length; j++) {
					if(area[i][j] == 1) {
						count++;
						checkIsland(area,i,j);
					}
				}
			}
			System.out.println(count);
			if(sc.hasNextLine()) {
				sc.nextLine();
			}
		}
		
		
	}
	
	public static void checkIsland(int[][] area,int i,int j) {
		area[i][j] = 0;
		if(j < 11) {
			if(area[i][j + 1] == 1) {
				checkIsland(area,i,j + 1);
				
			}
		}
		if(i < 11) {
			if(area[i + 1][j] == 1) {
				checkIsland(area,i + 1,j);
				
			}
		}
		if(j > 0) {
			if(area[i][j - 1] == 1) {
				checkIsland(area,i, j - 1);
				
			}
		}
		if(i > 0) {
			if(area[i - 1][j] == 1) {
				checkIsland(area,i - 1,j);
				
			}
		}
		
	}

}

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

long pow2[61];

int main(){
  pow2[0]=1;
  for(int i=1; i<61; i++){
    pow2[i] = pow2[i-1]*2;
  }
  int n, p;
  cin >> n >> p;
  int odd=0;
  for(int i=0; i<n; i++){
    int tmp;
    cin >> tmp;
    if(tmp%2==1)odd++;
  }
  if(odd==0)cout << ((p+1)%2)*pow2[n];
  else cout << pow2[n-1];
  return 0;
}

Measured memory_bytes: 256
last = 0
answer = 0
dishes = []
dishes.append(int(input()))

for i in range(1,5):
	dish = int(input()) 
	dishes.append(dish)
	if dish % 10 != 0 and dishes[last] % 10 >  dish % 10:
		last = i


for i in range(5):
	if i == last:
		answer += dishes[i]
	else:
		if dishes[i] % 10 == 0:
			answer += dishes[i] 
		else:
			answer += ((dishes[i]//10)+1)*10

print(answer)

Measured memory_bytes: 80272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    vector<int> p(3);
    map<int, map<int, set<int>>> m;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        cin >> p[0] >> p[1] >> p[2];
        sort(p.begin(), p.end());
        if (m[p[0]][p[1]].count(p[2]) == 0) {
            m[p[0]][p[1]].insert(p[2]);
        } else {
            cnt++;
        }
    }
    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 3304
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cassert>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)

using namespace std;

struct P
{
  int weight,index;
  P(int weight=inf,int index=inf):weight(weight),index(index){}
  bool operator < (const P& a)const
  {
    return weight < a.weight;
  }
};

int n,m,W;

int main()
{
  int k;
  scanf("%d %d %d",&n,&m,&W);
  
  int idx = 0;
  vector<vector<P> > vec;
  vector<int> FLOOR;

  rep(i,n)
    {
      scanf("%d",&k);
      if(k == 0)
	{
	  if(i == 0)
	    {
	      FLOOR.push_back(i);
	      vec.push_back(vector<P>());
	    }
	  continue;
	}
      int cur = vec.size();
      vec.push_back(vector<P>(k));
      FLOOR.push_back(i);
      rep(j,k)
	{
	  scanf("%d",&vec[cur][j].weight);
	}
    }

  if(FLOOR[FLOOR.size()-1] == 0)
    {
      puts("0");
      return 0;
    }

  int ans = FLOOR[FLOOR.size()-1]+1-m;
  for(int i=FLOOR.size()-1;i>=1;i--)
    {
      //cout << "cost = " << FLOOR[i] << " - " << FLOOR[i-1] << endl;
      int cost = FLOOR[i] - FLOOR[i-1];
      assert(cost >= 0);
      int SIZE = vec[i].size();
      //cout << "SIZE = " << SIZE << endl;
      int dp[(1<<SIZE)];
      rep(j,(1<<SIZE))dp[j] = inf;
      dp[0] = 0;
      rep(state,(1<<SIZE))//今のフロアの状況 0 -> まだ移動してない, 1 -> 移動したたそ〜
	{
	  if(dp[state] == inf)continue;
	  vector<P> tmp;//まだこのフロアにるものたそ〜
	  rep(j,SIZE)
	    {
	      if((state>>j) & 1)continue;
	      tmp.push_back(P(vec[i][j].weight,j));
	    }

	  sort(tmp.begin(),tmp.end());
	  int limit = tmp.size();
	  rep(j,(1<<limit))//次に移動するもの
	    {
	      int sum = 0;
	      int tstate = 0;
	      rep(k,limit)
		{
		  if((j>>k) & 1)
		    {
		      tstate |= (1<<tmp[k].index);
		      sum += tmp[k].weight;
		    }
		}
	      assert(sum >= 0);
	      if(sum > W)continue;
	      assert((state ^ tstate) == (state | tstate));
	      int nstate = state | tstate;
	      dp[nstate] = min(dp[nstate],
			       dp[state]+2);
	    }
	}
      rep(j,vec[i].size())vec[i-1].push_back(vec[i][j]);
      assert((dp[(1<<SIZE)-1]-1)*cost >= 0);
      ans += (dp[(1<<SIZE)-1]-1)*cost;//新たな値を得るたそ〜
      assert(ans >= 0);
      //cout << "ans = " << ans << " dp = " << dp[(1<<SIZE)-1] << endl;
    }

  printf("%d\n",ans);//えるたそ〜

  return 0;
}

Measured memory_bytes: 1340
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define find(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

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

const ll MOD = 1000000007; // 10^9 + 7

string rotateRight(string s, int i) {
  string left = s.substr(s.size() - i, i);
  string right = s.substr(0, s.size() - i);

  return left + right;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  string s, t; cin >> s >> t;
  int n = t.size();
  for (int i = 0; i < n; i++) {
    if (rotateRight(s, i) == t) {
      Yes()
      return 0;
    }
  }
  No()
}


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

int main(int argc, char const *argv[]) {
  int w, h, x, y;
  int c = 0;
  double res;
  cin >> w >> h >> x >> y;
  res = (double(w) * double(h)) / 2;
  if (w == x * 2 && h == y * 2) c = 1;
  printf("%lf %d", res, c);
  return 0;
}


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

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

    ll a[100][100] = {};
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }

    ll b[100] = {};
    for (size_t i = 0; i < m; i++)
    {
        cin >> b[i];
    }

    ll ans[100] = {};
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < m; j++)
        {
            ans[i] += a[i][j] * b[j];
        }
    }

    for (size_t i = 0; i < n; i++)
    {
        cout << ans[i] << endl;
    }
}



Measured memory_bytes: 3176
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N; i++) cin >> L[i];
    
    sort(L.begin(), L.end());
    int siki;
    long long int ans = 0;
    for (int i = 0; i < N-2; i++) {
        for (int j = i+1; j < N-1; j++) {
            for (int k = j+1; k < N; k++) {
                if (k == j+1) {
                    siki = L[i]+L[j];
                }
                
                if (siki > L[k]) {
                    ans++;
                }
                else
                    break;
            }
        }
    }
    
    cout << ans << endl;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(ll, n);
  --n;
  ll x = 26;
  int l = 1;
  while (n >= x) {
    n -= x;
    x *= 26;
    ++l;
  }
  string s;
  rep(i, l) {
    s += 'a' + (n % 26);
    n /= 26;
  }
  reverse(all(s));
  out(s);
}


Measured memory_bytes: 3628
import java.util.Scanner;

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

		int N = scan.nextInt();

		long A = 1;
		long B = 1;
		for(int i = 0; i < N; i++){
			long x = scan.nextInt();
			long y = scan.nextInt();
			long n = Math.max((A+x-1)/x,(B+y-1)/y);
			A = n * x;
			B = n * y;
		}
		System.out.println(A+B);
	}
}


Measured memory_bytes: 25196
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void push(int);
int pop(void);
void initialize(void);
int isEmpty(void);
int isFull(void);

int top=0,a[101];

int main(){
  int x,x1;
  char s[101];
  
  initialize();
  while( scanf("%s",s) != EOF ){
    if ( s[0] == '+' ){
      x=pop()+pop();
      push(x);
    } else if ( s[0] == '-' ){
      x=pop();
      x1=pop();
      x = x1 - x;
      push(x);
    } else if ( s[0] == '*' ){
      x=pop()*pop();
      push(x);
    } else {
      x = atoi(s);
      push(x);
    }
    
  }
  
  printf("%d\n",a[0]);

  return 0;
}

void push(int x){
  if(isFull()) return;
  a[top]=x;
  top++;
}

int pop(void){
  if(isEmpty()) return;
  top--;
  return a[top];
}

void initialize(void){
  top=0;
  a[top]=0;
}

int isEmpty(void){
  return top==0;
}

int isFull(void){
  return top > 100-1;
}

Measured memory_bytes: 548
#include<bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
char c[100005];
int main()
{
	gets(c);
	int len=strlen(c);
	cout<<c[0];
	for(int i=1;i<len;i++)
		if(i%2==0)
			cout<<c[i];
	cout<<endl;
	return 0;
}

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

int main() {
  long long N;;

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

  sort(A.begin(), A.end());

  bool isDifferent = true;

  rep(i, N - 1) {
    if (A[i] == A[i+1]) isDifferent = false;
  }

  if (isDifferent) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


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

int main()
{
    int n;  cin >> n;
    int r[n];
    rep(i,n)  cin >> r[i];

    int maxv = -2000000000;
    int minv = r[0];

    for (int i = 1; i < n; i++) {
        maxv = max(maxv, r[i] - minv);
        minv = min(minv, r[i]);
    }

    cout << maxv << endl;
}


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

using namespace std;

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

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

string s0 = "qwertasdfgzxcvb";
set<char> s;

bool g(char c) {
    if (s.count(c) > 0) return 0;
    return 1;
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
    EACH(c, s0) s.insert(c);
    string str;
    while ( cin >> str, str != "#" ) {
        int bg = g(str[0]);
        int ans = 0;
        for (int i = 1; i < str.size(); ++i) {
            int ng = g(str[i]);
            if (bg != ng) ++ans;
            bg = ng;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
int a[1000001],b[1000001];
int main()
{
	int n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i],b[a[i]]++;
		if(b[a[i]]>=2) sum++;
	}
	if(sum%2==0)
	cout<<n-sum<<endl;
	else cout<<n-sum-1<<endl;
	return 0;
}

Measured memory_bytes: 4736
#include<stdio.h>
int main(void){
    int n,i=0;
    int d;
    int data[10000]={};
    int max,min;
    long long int sum;

    scanf("%d",&n);
        while(scanf("%d",&d)==1){
            data[i]=d;
            i++;
            if(i==n)break;       
    }

    max=data[0],min=data[0];

    for(i=0; i<n; i++){
  
        if(max<data[i]){
        max=data[i];
        }
        
        if(min>data[i]){
        min=data[i];
        }

        sum+=data[i];
    }

    printf("%d %d %lld\n",min,max,sum);
}


Measured memory_bytes: 2112
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
    int i;

    int sum = 0;
    char W[11], T[1001];

    scanf("%s", W);
    for( i = 0; W[i]; ++i ) W[i] = tolower(W[i]);
    while( 1 ){
        scanf("%s", T);
        if( strcmp("END_OF_TEXT", T) == 0 ) break;
        for( i = 0; T[i]; ++i ) T[i] = tolower(T[i]);
        if( strcmp(W, T) == 0 ) ++sum;
    }

    printf("%d\n", sum);

    return 0;
}


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

int main(void){
    int i,capa_odd,capa_even;
    string odd,even;
    vector<string> pass(110);
    cin >> odd;
    cin >> even;

    capa_odd = odd.size();
    capa_even = even.size();

    for(i=0; i<capa_odd; i++){
        pass.at(2*i+1) = odd.at(i);
    }

    for(i=0; i<capa_even; i++){
        pass.at(2*i+2) = even.at(i);
    }

    for(i=0; i<pass.size(); i++){
        cout << pass.at(i);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3616
N,M=map(int,input().split())
A=[]
if M==0:
    if N==1:
        print(0)
        exit()
    elif N==2:
        print(10)
        exit()
    else:
        print(100)
        exit()
        
else:
    for _ in range (M):
        s,c=map(int,input().split())
        A.append([s,c])

    for i in range(1000):
        i=str(i)
        if len(i)!=N:
            continue
        ans=0
        for X in A:
            x=X[0]
            y=X[1]
            x-=1
            if i[x]!=str(y):
                ans=1
                break
            else:
                continue
        if ans==0:
            print(i)
            exit()
print(-1)
    

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  
  sort(ALL(A));
  reverse(ALL(A));

  ll ans = A[0];
  FOR(i,2,N){
    ans+=A[i/2];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4860
#include<stdio.h>
int main()
{
	int N;
	while(scanf("%d",&N)!=EOF)
	{
		int max=0;
		int min=0;
		int n;
		int i;
		int a[1000+20];
		for (i=0;i<N;i++)
		{
			scanf("%d",&n);
			if(n/400<8)
				a[n/400]++;
			else
				max++;
		}
		for(i=0;i<9;i++)
		{
			if(a[i]!=0)
				min++;
		}
		max=min+max;
		if(min==0)
			min=1;
		printf("%d %d\n",min,max);	
	}
}

Measured memory_bytes: 128
n = gets.to_i

def prime?(number)
  return true if number == 2
  return false if number % 2 == 0
  i = 3
  max = Math.sqrt(number)
  while i <= max
    return false if number % i == 0
    i += 2
  end
  return true
end

a = []
n.times do
  a << gets.to_i
end

count = 0
a.each do |number|
  count += 1 if prime?(number)
end

puts count

Measured memory_bytes: 6196
from sys import stdin
from collections import deque
def judge(n,hs):
    stack = deque()
    ans = 0
    for i, h in enumerate(hs):
        j = -1
        while stack and stack[-1][1] > h:
            j, h2 = stack.pop()
            ans = max(ans, (i - j) * h2)
        if not stack or stack[-1][1] < h:
            stack.append((i if j == -1 else j, h))
    ans = max(ans, max((n - j) * h2 for j, h2 in stack))
    return ans
H,W = map(int,stdin.readline().split())
hs = [0]*W
result = 0
for i in range(H):
    ht = list(map(int, stdin.readline().split()))
    hs = list(map(lambda x,y:(x+1)*abs(y-1),hs,ht))
    result = max(result,judge(W,hs))
print(result)

Measured memory_bytes: 8188
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
int n,k,ans;
int main(){
	scanf("%d%d",&n,&k);
	ans=1;
	for(int i=1;i<=n;i++) ans+=min(ans,k);
	printf("%d\n",ans);
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
c = list(map(int,input().split(" ")))
m,j = [0,-1]
for i in a:
    m += b[i-1]
    if i == j + 1:
        m += c[j-1]
    j = i
print(m)

Measured memory_bytes: 3060
N=int(input())

li=[input() for i in range(N)]

temp=li[0][-1]
for j in range(N-1):
    if temp==li[j+1][0]:
        temp=li[j+1][-1]
    else:
        print("No")
        exit()
li.sort()

for k in range(N-1):
    if li[k]==li[k+1]:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 9100
L=[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]
print(L[int(input())-1])

Measured memory_bytes: 61820
#include<bits/stdc++.h>
using namespace std;
int n,m;
double ans;
int main() {
	cin>>n>>m;
	for (int i=1;i<=n;++i) {
		double x=1.0/n;
		int t=i;
		while(t<m) {
			t*=2;
			x/=2;
		}
		ans+=x;
	}
	printf("%.12lf\n",ans);
	return 0;
}

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

const int N = 505;

char arr[N][N];

int main()
{
	int n;	
	int i,j;
	cin >> n;

	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			cin >> arr[i][j];

	int cal = 0;

	bool all_white=true;

	for(j=0;j<n;j++)
		{
		bool all_bla = true;
		
		for(i=0;i<n;i++)	
			if(arr[i][j] == '.')
				all_bla = false;
			else
				all_white = false;

		if(!all_bla)	
			cal++;
		}

	int mi = (int)1e7;	

	for(i=0;i<n;i++)	
		{	
		int val = 0;
		bool pos = false;

		for(j=0;j<n;j++)
			if(arr[j][i]=='#')	
				pos = true;

		if(!pos) val++;
		
		for(j=0;j<n;j++)	
			if(arr[i][j]=='.')
				val++;
			mi = min(mi,val);
		}	
			
		

	if(all_white)
		cout<<-1<<endl;

	else 
		cout<<mi+cal<<endl;	

}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int cand[26];

void init(){
    rep(i, 26) cand[i] = 0;
}

int main(void){
    int N;
    while(true){
        init();
        cin >> N;
        if(N == 0) break;
        bool tie = true;
        bool output = false;
        rep(i, N){
            char temp; cin >> temp;
            if(output) continue;
            cand[temp-'A']++;
            //あとN-1-i回ループが回る
            //最大のものと二番目の差がN-1-iより大きければ確定
            int fst = 0, snd = 0;
            int idx = 0;
            rep(j, 26){
                if(fst <= cand[j]){
                    snd = fst;
                    fst = cand[j];
                    idx = j;
                }
                else if(snd <= cand[j]) snd = cand[j];
            }
            if(fst - snd > N-1-i){
                printf("%c %d\n", 'A'+idx, i+1);
                tie = false;
                output = true;
            }
        }
        if(tie) cout << "TIE" << endl;
    }
    return 0;
}


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

using namespace std;

#define pb push_back
#define MEM(a, x) memset(a, x, sizeof a)

typedef pair<int, int> ii;

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

	int h, w;
	char buf;
	bool grid[1005][1005];
	vector<ii> st;

	cin >> h >> w;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cin >> buf;
			grid[i][j] = (buf == '#') ? true : false;
			if(grid[i][j])
				st.pb({i,j});
		}
	}

	queue<ii> q;
	int u, d, ans;

	for(auto& it : st) {
		int idx = it.first * w + it.second;
		q.push({idx, 0});
	}

	while(!q.empty()) {
		u = q.front().first; d = q.front().second;
		q.pop();

		int i = u / w, j = u % w;

		if(!grid[i][j] || d == 0) {
			grid[i][j] = true;
			ans = d;
			//cout << i << ' ' << j << ' ' << d << endl;

			if(i < h - 1 && !grid[i+1][j]) q.push({(i+1) * w + j, d + 1});
			if(i > 0 && !grid[i-1][j]) q.push({(i-1) * w + j, d + 1});
			if(j < w - 1 && !grid[i][j+1]) q.push({i * w + j + 1, d + 1});
			if(j > 0 && !grid[i][j-1]) q.push({i * w + j - 1, d + 1});
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 17256