akhauriyash/Code-Regression huggingface dataset:
/*
  coded by: mi_ni_
  "LIVE LONG AND PROSPER"
*/
 
#include <bits/stdc++.h>
using namespace std;

#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define newl '\n'
#define TEST_CASE(fun) int tc; cin>>tc; while(tc--){ fun(); }
#define TEST_CASE_2 int tc; cin>>tc; for(int i=1;i<=tc;i++)
#define TEST_CASE_3(fun) int tc; cin>>tc; for(int i=1;i<=tc;i++){ cout<<"Case #"<<i<<": "; fun(); }
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define forab(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define forabr(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define trav(i,x) for(auto& i:x)

using ll=long long int;
using ull=unsigned long long int;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vii=vector<pii>;
using vll=vector<pll>;

const ld pi=acosl(-1);
const int inf=(int)1e9+7;
const ll llinf=(ll)1e18+7;
const ld eps=1e-7;

//other
template<typename T> inline bool powerof2(T a){ return (a&&(!(a&(a-1)))); }
template<typename T> inline T log_2(T a){ T res=-1; while(a){ a/=2; res++; } return res; }

const int MAX = 1000001;
struct Query 
{ 
    int l, r, idx; 
}; 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
}
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
}
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(int arr[], int n, Query queries[], int q) 
{
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 
    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit));
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    {
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n);
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                     query(queries[query_counter].r + 1, bit, n)- 
                     query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
}

//make sure to choose TEST_CASE in main for multiple test cases
void solve(){
	int n,q;
	cin>>n>>q;
	int a[n];
	forn(i,n) cin>>a[i];
	Query queries[q];
	forn(i,q){
		cin>>queries[i].l>>queries[i].r;
		queries[i].l--;
		queries[i].r--;
		queries[i].idx=i;
	}
	sort(queries,queries+q,cmp);
	answeringQueries(a,n,queries,q);
}

int main(){
	FAST_IO
	cout<<fixed<<setprecision(15);
	cerr<<fixed<<setprecision(10);
	//init_fact();
	//TEST_CASE(solve)
	//TEST_CASE_2{}
	//TEST_CASE_3(solve)
	solve();
	return 0;
}

Measured memory_bytes: 19348
#include <iostream>
using namespace std;
int dp[2]={},ar[100001]={};
int main()
{
	int n;cin>>n;
	for (int i=0;i<n;i++) {cin>>ar[i];}
	dp[1] = 0;dp[0] = abs(ar[1]-ar[0]);
	for (int i=3;i<=n;i++)
	{
		dp[i%2] = min(dp[(i-1)%2] + abs(ar[i-1]-ar[i-2]),dp[i%2] + abs(ar[i-1]-ar[i-3]));
	}
	cout<<dp[n%2]<<"\n";
	return 0;
}

Measured memory_bytes: 640
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N, K = geta(int)
    R, S, P = geta(int)
    T = gete()

    def winner(c):
        return (R, 0, 0) if c == "s" else (0, P, 0) if c == 'r' else (0, 0, S)

    def fn(s):
        n = len(s)
        ret = 0
        dp = [[0] * 3 for _ in range(n)]

        dp[0] = winner(s[0])
        for i in range(1, n):
            w = winner(s[i])
            for j in range(3):
                dp[i][j - 2] = max(dp[i - 1][j - 1], dp[i - 1][j]) + w[j - 2]

        return (max(dp[n - 1]))

    print(sum(fn(T[i::K]) for i in range(K)))


if __name__ == "__main__":
    main()

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

int main(){

  int n, count = 0, begin=0, a;
  scanf("%d", &n);
  for(int i=1; i<=n; i++){
    scanf("%d", &a);
    if(a == i){
      begin++;
    }else{
      if(begin & 1)
        count++;
      count += begin >> 1;
      begin = 0;
    }
  }
      if(begin & 1)
        count++;
      count += begin >> 1;
  printf("%d\n", count);

}




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

//省略形
#define rep(i,n) for(auto i=0; i<n ; ++i)
#define REP(i,a,b) for(auto i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//よく使う定数
const int INF = 1e9;
const int MOD = 1e9+7;
//逆元
const int INV = 1e9+5;

//UnionFindTree
struct union_find{
  vector<int> data;
  union_find(int size) : data(size , -1) { }

  void merge(int x , int y){
    x = root(x); y = root(y);
    if(x == y) return;
    if(data[y] < data[x]) swap(x , y);
    data[x] += data[y];
    data[y] = x;
    return; 
  }

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

  int root(int x){
    return data[x] < 0 ? x : (data[x] = root(data[x]));
  }

  int size(int x){
    return -data[root(x)];
  }
};

//プロトタイプ宣言
void faster(void);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);
template <class T>
T modpow(T , T , T);
bool is_palindrome(string);

//メモ
//最大公約数:__gcd　|　最小公倍数:__lcm
//回文は反転させて一致すればよい

int main(){
  faster();
  int n , tmp;
  cin >> n;
  vi a(n);
  rep(i,n-1){
    cin >> tmp;
    a[tmp-1]++; 
  }
  rep(i,n) cout << a[i] << endl;
}























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//繰り返し自乗法
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 

//繰り返し自乗法(剰余)
template <class T>
T modpow(T x , T y , T mod){
  if(y == 0) return 1;
  if(y%2 == 1){
    ll temp = modpow(x,y-1,mod);
    return temp*x%mod;
  }
  else{
    ll temp = pow_mod(x,y/2,mod);
    return temp*temp%mod;
  }
}

bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}

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

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,lessl<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define double long double

#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()

#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define endl "\n"

#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)

#define bp __builtin_popcountll
#define inf 1e18

const int N = 1e5 + 5;
const int M = 1e9 + 7;
void solve()
{
	int n;
	cin >> n;
	if (n >= 30)
		cout << "Yes";
	else
		cout << "No";
}

signed main()
{
	FAST

#ifndef ONLINE_JUDGE
	freopen("input_sublime.txt", "r", stdin);
	freopen("output_sublime.txt", "w", stdout);
#endif

	int t = 1;
	// cin>>t;
	for (int tc = 1; tc <= t; tc++)
	{
		// cout<<"Case #"<<tc<<": ";
		solve();
	}

#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
}


Measured memory_bytes: 3664
import sys
input=sys.stdin.readline
n=int(input())
s=input().rstrip()
r=[0]
g=[0]
b=[0]
for i in range(n-1,-1,-1):
    if s[i]=='R':
        r.append(r[-1]+1)
        g.append(g[-1])
        b.append(b[-1])
    elif s[i]=='G':
        r.append(r[-1])
        g.append(g[-1]+1)
        b.append(b[-1])
    elif s[i]=='B':
        r.append(r[-1])
        g.append(g[-1])
        b.append(b[-1]+1)
r.reverse()
g.reverse()
b.reverse()
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i]==s[j]:
            continue
        if s[i]!='R' and s[j]!='R':
            d=j-i
            k=j+d
            ans+=r[j+1]
            if k<n:
                if s[k]=='R':
                    ans-=1
        elif s[i]!='G' and s[j]!='G':
            d=j-i
            k=j+d
            ans+=g[j+1]
            if k<n:
                if s[k]=='G':
                    ans-=1
        elif s[i]!='B' and s[j]!='B':
            d=j-i
            k=j+d
            ans+=b[j+1]
            if k<n:
                if s[k]=='B':
                    ans-=1
print(ans)








Measured memory_bytes: 68552
#include<iostream>
#include<cmath>
using namespace std;
const int MAXN = 2e5 + 100;
long long x,sum[MAXN],n,min_,i;
int main()
{
    cin>>n;
    sum[0]=0;
    for(i=1;i<=n;i++)
       {
           cin>>x;
           sum[i]=sum[i-1]+x;
       }
    min_=abs(2*sum[1]-sum[n]);
   for(i=2;i<n;i++)
   {
       min_=min_<abs(2*sum[i]-sum[n])?min_:abs(2*sum[i]-sum[n]);
   }
    cout<<min_;
}

Measured memory_bytes: 1792
/// {{{
#include "bits/stdc++.h"
#define   ALL(x)  x.begin(), x.end()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
#define   rep(i, s, t)       for(int i = int(s); i < int(t); ++i)
using namespace std;
typedef long long i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}


signed main()
{
  int N, K;

  auto f = [&](int n) {
    int cnt = 0;
    while(n < K) {
      n *= 2;
      ++cnt;
    }
    return cnt;
  };

  cin >> N >> K;

  long double ans = 0;
  const long double p = 1.0 / N;

  for (int i = 1; i <= N; ++i) {
    ans += (p * (1.0 / (1 << f(i))));
  }

  cout << setprecision(11) << ans << endl;

  return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

int X1, X2, Y1, Y2;

int main() {
	cin >> X1;
	if (X1 & 1) {
		Y1 = X1 / 2;
		Y2 = X1 / 2 + 1;
	}
	else {
		Y1 = Y2 = X1 / 2;
	}
	cout << Y1 * Y2 << endl;
	return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d%d%d", $h,$w,$k);
$estr = str_repeat(".", $w);
$sline=-1;
for($i=0;$i<$h;$i++){
    $tmp = trim(fgets(STDIN));
    if($tmp == $estr){
        $emp[]=1;
    }else{
        $emp[]=0;
        if($sline == -1){
            $sline = $i;
        }
    }
    $map[] = str_split($tmp);
}
$num = 1;
$end = -1;
for($i=$sline+1;$i<$h;$i++){
    if($emp[$i]==1){
        $end = $i;
    }else{
        $end = $i -1;
        break;
    }
}
if($end == -1){
    $end = $h-1;
}
$first = 0;
foreach($map[$sline] as $i=>$row){
    if($row=="#"){
        if($first != 0) {
            $num++;
        }else{
            $first = 1;
        }
    }
    for($j=0;$j<=$end;$j++){
        $ans[$j][$i] = $num;
    }
}
$sline = $end+1;
while($sline < $h){
    for($i=$sline+1;$i<$h;$i++){
        if($emp[$i]==1){
            $end = $i;
        }else{
            $end = $i -1;
            break;
        }
    }
    if($sline == $h-1){
        $end = $sline;
    }
    $first = 0;
    $num++;
    foreach($map[$sline] as $i => $row){
        if($row=="#"){
            if($first != 0) {
                $num++;
            }else{
                $first = 1;
            }
        }
        for($j=$sline;$j<=$end;$j++){
            $ans[$j][$i] = $num;
        }
    }
    $sline = $end + 1;
}

foreach($ans as $row){
    echo implode(" ",$row).PHP_EOL;
}



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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> s(3);
  for(int i = 0; i < 3; i++) cin >> s[i];
  int t = 0, l[3] = {0, 0, 0};
  while(1) {
    if(l[t] == s[t].length()) {
      printf("%c\n", 'A' + t);
      return 0;
    }
    t = s[t][l[t]++] - 'a';
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <cmath>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  int Min = 100000000;
  for(int i = 0; i < n; i++)cin >> a[i];
  for(int i = 1; i <= 100; i++){
    int sum = 0;
    for(int j = 0; j < n; j++){
    	sum+=pow(abs(i-a[j]), 2);
    }
    Min = min(Min, sum);
  }
  cout << Min << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  long long n,nmon;
  long long sum=0,avr;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>nmon;
    sum+=nmon;
  }
  avr=sum/n;
  cout<<avr<<endl;
  return 0;
}

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

int main(void){
  int H, W, count=0;

  cin >> H >> W;
  do{
    for( int i = 0; i < H; i++ ){
      for( int j = 0; j < W; j++ ){
	if( count % 2 == 0) {
	  cout << '#';
	  count++;
	}else{
	  cout << '.';
	  count++;
	}
      }
      if ( W % 2 == 0){
	count++;
      }
      cout << endl;
    }
    cout << endl;
      
    count = 0;
      
    cin >> H >> W;
  }while( H != 0 || W != 0);
  
  return 0;
}

Measured memory_bytes: 3108
from collections import deque
d=deque(list(range(1,10)))
for i in range(int(input())):
  x=d.popleft()
  r=x%10;c=x*10+r
  if r!=0:d.append(c-1)
  d.append(c)
  if r!=9:d.append(c+1)
print(x)

Measured memory_bytes: 18896
#include<bits/stdc++.h>
#define N 100009
using namespace std;

int n,m,ans,a[N],fst[N],nxt[N];
int dfs(int x){
	int i,tmp=0;
	for (i=fst[x]; i; i=nxt[i]) tmp=max(tmp,dfs(i));
	if (x==1) return 0;
	tmp++;
	if (tmp==m && a[x]!=1){
		tmp=0; ans++;
	}
	return tmp;
}
int main(){
	scanf("%d%d",&n,&m);
	int i;
	for (i=1; i<=n; i++){
		scanf("%d",&a[i]);
		if (i==1)
			ans+=(a[i]!=1);
		else{
			nxt[i]=fst[a[i]]; fst[a[i]]=i;
		}
	}
	dfs(1);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6144
import java.util.Scanner;

public class Main {
	static int N,K;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextInt();
		int ans = 1000000007;
		int tmp;
		Integer x[] = new Integer[N];
		for (int i=0; i<N; i++) x[i] = sc.nextInt();
		for (int i=0; i<N-K+1; i++) {
			int a = Math.abs(x[i]) + Math.abs(x[i+K-1] - x[i]);
			// -2 -1 0 1 ▼正から行った方が早い
			int b = Math.abs(x[i+K-1]) + Math.abs(x[i+K-1] - x[i]);
			tmp = Math.min(a, b);
			ans = Math.min(ans, tmp);
		}
		System.out.println(ans);

	}
}

Measured memory_bytes: 63196
#include <stdio.h>

int main(void) 
{
	int n, m, p, x, lt, wx;
	int i;
	
	while(1) {
		scanf("%d%d%d", &n, &m, &p);
		if (n == 0 && m == 0 && p == 0) break;
		
		lt = 0;
		for (i = 1; i <= n; i++) {
			scanf("%d", &x);
			lt += x;
			if (i == m) wx = x;
		}
		if (wx == 0)
			puts("0");
		else
			printf("%d\n", lt * (100 - p) / wx);
	}

	return 0;
}
		

Measured memory_bytes: 612
# -*- coding: utf-8 -*-
from collections import Counter

n = int(input().strip())
v_list = list(map(int, input().rstrip().split()))
#-----

v_odd = [ v_list[i] for i in range(0,len(v_list),2) ]
v_even  = [ v_list[i] for i in range(1,len(v_list),2) ]

sort_cnt_v_odd  = sorted( Counter(v_odd).items(), key=lambda x:x[1], reverse=True)
sort_cnt_v_even = sorted(Counter(v_even).items(), key=lambda x:x[1], reverse=True)


ans=0
# カウント数最大の数値が、v_oddとv_evenで異なるとき
# v_oddとv_evenそれぞれを、1種類の数値に書き換え
if sort_cnt_v_odd[0][0] != sort_cnt_v_even[0][0]:
    ans +=  len(v_odd) -  sort_cnt_v_odd[0][1]
    ans += len(v_even) - sort_cnt_v_even[0][1]
else:
# カウント数最大の数値が、v_oddとv_evenで一致

    # v_oddとv_evenそれぞれで、数値が1種類のとき
    # v_oddを全書き換え
    if len(sort_cnt_v_odd)==len(sort_cnt_v_even)==1:
        ans = len(v_odd)
        
    # v_oddの、数値が1種類のとき、v_evenは2番目に多いカウント数の数値に書き換え
    elif len(sort_cnt_v_odd)==1 and len(sort_cnt_v_even)!=1:
        ans =   len(v_odd) -  sort_cnt_v_odd[0][1] \
              + len(v_even) - sort_cnt_v_even[1][1]
        
    # v_evenの、数値が1種類のとき
    elif len(sort_cnt_v_odd)!=1 and len(sort_cnt_v_even)==1:
        ans =    len(v_odd) -  sort_cnt_v_odd[1][1] \
              + len(v_even) - sort_cnt_v_even[0][1]
        
    # 以下2パターンの少ない方を採用
    #   v_odd　 最大カウント数、v_even　2番目のカウント数
    #   v_even　最大カウント数、v_odd　 2番目のカウント数
    elif len(sort_cnt_v_odd)!=1 and len(sort_cnt_v_even)!=1:
        tmp1 =    len(v_odd) -   sort_cnt_v_odd[0][1] \
               + len(v_even) -  sort_cnt_v_even[1][1]
        
        tmp2 =    len(v_odd) -  sort_cnt_v_odd[1][1] \
               + len(v_even) - sort_cnt_v_even[0][1]
              
        ans = min(tmp1,tmp2)
        

print(ans)


Measured memory_bytes: 21084
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	int n,m,i,j;cin>>n>>m;vs v(n);vvi d(n+1,vi(m+1,0));
	for(i=0;i<n;i++) cin>>v[i];d[0][0]=1;
	for(i=0;i<n;i++) for(j=0;j<m;j++){
		if(v[i][j]=='.') d[i+1][j]=(d[i+1][j]+d[i][j])%mod,d[i][j+1]=(d[i][j+1]+d[i][j])%mod;
	}cout<<d[n-1][m-1]<<endl;
//	for(i=0;i<=n;i++){
//		print(d[i]);
//	}

}


Measured memory_bytes: 10368
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> B(N - 1);
  for (int i = 0; i < N - 1; i++)
  {
    scanf("%lld", &B[i]);
  }
  int ans = B[0] + B[N - 2];
  for (int i = 0; i < N - 2; ++i)
  {
    ans += min(B[i], B[i + 1]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter
 
rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
 
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)
 
def modinv(a, m):
    g, x, y = egcd(a, m)
    return x % m
 
def solve(N, P, S):
    A = map(int, S)
    if P == 2 or P == 5:
        ans = 0
        for i, x in enumerate(A):
            if x % P == 0:
                ans += i + 1
        return ans

    powers = [0] * N
    pwr = 1
    for i in xrange(N-1, -1, -1):
        powers[i] = pwr
        pwr *= 10; pwr %= P

    #Xinv = modinv(10, P)
    count = Counter()
    count[0] += 1
    s = 0
    ans = 0
    for i in xrange(N-1, -1, -1):
        w = A[i] * powers[i] % P
        s += w; s %= P
        ans += count[s]
        count[s] += 1
        #print("!", ans)
    return ans
 
 
N, P = rrm()
print solve(N, P, rr())


Measured memory_bytes: 35868
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

ll expo(ll a, ll b){
    ll ex = 1;
    rep(i, b){
        ex *= a;
    }
    return ex;
}

ll fact(ll a){
    ll fc = 1;
    REP(i, 1, a+1){
        fc *= i;
    }
    return fc;
}

int main() {
    ll k;
    str s;
    cin >> k >> s;
    if(s.size()<k+1){
        cout << s << endl;
    }
    else {
        rep(i, k) {
            cout << s[i];
        }
        cout << "..." << endl;
    }
}

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

int main(){
  int n, l;
  cin >> n >> l;
  
  if(l >= 0){
   cout << (n - 1) * (l + l + n)/2.0 << "\n";  
  }else if(l + n - 1 <=0){
   cout << (n - 1) * (l + l + n - 2)/2.0 << "\n"; 
  }else
   cout << n * (l + l + n - 1)/2.0 << "\n";
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    int[] array = new int[3];
    for (int i = 0; i < 3; i++) {
      array[i] = sc.nextInt();
    }
    
    Arrays.sort(array);
    
    int a = array[2] * 10;
    
    System.out.println(a + array[1] + array[0]);
  }
}

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

int IMOS[200002];

struct TV {
	int s, t, c;
	TV(int s=0, int t=0, int c=0):s(s),t(t),c(c){}

	bool operator<(const TV& r)const {
		return s < r.s;
	}
};

int main() {
	int N, C; cin >> N >> C;
	vector<vector<TV>>tv(C);
	for (int i = 0; i < N; i++) {
		int s, t, c; cin >> s >> t >> c;
		tv[c-1].push_back(TV(s, t, c));
	}
	for (int i = 0; i < C; i++)sort(tv[i].begin(), tv[i].end());
	for (int i = 0; i < C; i++) {
		int last = 0;
		for (int j = 1; j < tv[i].size(); j++) {
			if (tv[i][j].s == tv[i][last].t) {
				tv[i][last].t = tv[i][j].t;
				tv[i][j].s = 0;
			}
			else {
				last = j;
			}
		}
	}
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < tv[i].size(); j++) {
			tv[i][j].s = tv[i][j].s * 2 - 1;
			tv[i][j].t = tv[i][j].t * 2;

			if (tv[i][j].s == -1)continue;

			IMOS[tv[i][j].s]++;
			IMOS[tv[i][j].t]--;
		}
	}

	int ans = IMOS[0];
	for (int i = 0; i < 200001; i++) {
		IMOS[i + 1] += IMOS[i];
		ans = max(ans, IMOS[i + 1]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main() {
	int ans,t,n,tt;
	cin>>n>>t;
	tt=t;
	ans=t;
	for(int i=2;i<=n;i++){
		cin>>t;
		if(t>tt)ans+=t-tt;
		tt=t;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

trait IntoIntegerIndexedVec {
    type Output;
    #[warn(dead_code)]
    fn into_i32_indexed_vec(self, offset: usize) -> IntegerIndexedVec<Self::Output>;
}
impl<T> std::ops::IndexMut<i32> for IntegerIndexedVec<T> {
    #[warn(dead_code)]
    fn index_mut(&mut self, index: i32) -> &mut T {
        let actual_index = index + (self.offset as i32);
        &mut self.v[actual_index as usize]
    }
}
impl<T> std::ops::Index<i32> for IntegerIndexedVec<T> {
    type Output = T;
    #[warn(dead_code)]
    fn index(&self, index: i32) -> &Self::Output {
        let actual_index = index + (self.offset as i32);
        &self.v[actual_index as usize]
    }
}
impl<T> IntoIterator for IntegerIndexedVec<T> {
    type Item = T;
    type IntoIter = std::vec::IntoIter<T>;
    #[warn(dead_code)]
    fn into_iter(self) -> std::vec::IntoIter<T> {
        self.v.into_iter()
    }
}
impl<T> IntegerIndexedVec<T> {
    fn new(v: Vec<T>, offset: usize) -> Self {
        IntegerIndexedVec { v, offset }
    }
    #[allow(dead_code)]
    fn iter(&self) -> std::slice::Iter<T> {
        self.v.iter()
    }
}
#[derive(Debug, Clone)]
struct IntegerIndexedVec<T> {
    v: Vec<T>,
    offset: usize,
}
impl<T> IntoIntegerIndexedVec for Vec<T> {
    type Output = T;
    #[warn(dead_code)]
    fn into_i32_indexed_vec(self, offset: usize) -> IntegerIndexedVec<T> {
        IntegerIndexedVec::new(self, offset)
    }
}

fn sieves(n: i32) -> IntegerIndexedVec<bool> {
    let mut s = vec![true; (n + 1) as usize].into_i32_indexed_vec(0);
    s[0] = false;
    s[1] = false;
    let mut i = 2;
    while i*i <= n {
        if s[i] {
            for j in ((i*2)..=n).step_by(i as usize) {
                s[j] = false;
            }
        }
        i += 1;
    }
    s
}

fn solve(_q: usize, lr: &[(i32, i32)]) -> Vec<usize> {
    const N: i32 = 100000;
    let s = sieves(N);
    let r = (0..=N).map(|i| i % 2 != 0 && s[i] && s[(i + 1) / 2]).collect::<Vec<_>>().into_i32_indexed_vec(0);
    let c = r.iter().scan(0, |s, &b| {
            *s += if b { 1 } else { 0 };
            Some(*s)
    }).collect::<Vec<_>>().into_i32_indexed_vec(0);
    lr.iter().map(|&(l, r)| c[r] - c[l-1]).collect::<Vec<_>>()
}

fn main() {
    input! {
        q: usize,
        lr: [(i32, i32); q],
    }
    let r = solve(q, &lr);
    for x in r {
        println!("{}", x);
    }
}


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

int main() {
    while(1){
    string x;
        cin >> x;
        if(x=="0") break;
        int num=0;
        for(int i=0; i<x.size(); i++){
          num += (x[i]-'0');
        }
        cout << num << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

#define roop(i,p) for(int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){

	ll int N;
	cin >> N;
	ll int A;
	map<ll int,int> m;
	roop(i,N){
	cin >> A;
	if(m[A] == 1){
	cout << "NO";
	return 0;
	}
	else{
		m[A]=1;
	}
	}
	cout << "YES";









	return 0;

}



Measured memory_bytes: 12800
# -*- coding: utf-8 -*-
S = input()
ans = 0
left, right = 0, len(S)-1
while left < right:
    if S[left] == S[right]:
        left += 1
        right -= 1
    elif S[left] == 'x':
        left += 1
        ans += 1
    elif S[right] == 'x':
        right -= 1
        ans += 1
    else:
        print(-1)
        exit()

print(ans)


Measured memory_bytes: 39664
h, w = gets.chomp.split.map(&:to_i)
n = gets.to_i
a = gets.chomp.split.map(&:to_i)

c = Array.new(h) { Array.new(w, 0) }
painted = 0
0.step(n - 1) do |i|
  0.step(a[i] - 1) do |j|
    x = (painted + j) / w
    y = (x % 2 == 0)? (painted + j) % w : w - 1 - (painted + j) % w
    c[x][y] = i + 1
  end
  painted += a[i]
end

puts c.map {|row| row.join(" ") }

Measured memory_bytes: 2428
#include<bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
using namespace std;
template<typename T> inline void read(T &x)
{
	T data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
template<typename T> inline void write(T x,char c='\0')
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
	if(c!='\0')putchar(c);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
int main()
{
	int n,m,ans=0;
	std::map<string,int> M;
	std::string s;
	read(n);
	for(register int i=1;i<=n;++i)
	{
		std::cin>>s;
		M[s]++;
	}
	read(m);
	for(register int i=1;i<=m;++i)
	{
		std::cin>>s;
		M[s]--;
	}
	for(std::map<string,int>::iterator it=M.begin();it!=M.end();++it)
		if(it->second)chkmax(ans,it->second);
	write(ans,'\n');
	return 0;
}

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


int main() {
    ll A, B, V, W, T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;

    ll length = abs(A-B);
    if (length <= (V-W)*T ){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

Measured memory_bytes: 3620
s = input()

format = []
for i in range(2 ** (len(s) - 1)):
    pat = ""
    for j in range(len(s) - 1):
        pat += s[j]
        if i >> j & 1:
            pat += "+"
        else:
            pat += "-"

    pat += s[-1]    
    format.append(pat)

for i in range(len(format)):
    if eval(format[i]) == 7:
        print(format[i] + "=7")
        exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n;
char s[300005];
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	int ans,sum=0;
	for(int i=2;i<=n;i++) if(s[i]=='E') sum++;
	ans=sum;
	for(int i=2;i<=n;i++){
		if(s[i]=='E') sum--;
		if(s[i-1]=='W') sum++;
		ans=min(ans,sum);
	}
	printf("%d",ans);
	return 0;
}

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

long long n;
vector<long long> a;

long long solve();

int main() {
  cin >> n;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  int id = 0, res = 0, i;
  for(i = 1; i <= n; ++i) {
    while(id < n && i != a[id]) ++id, ++res;
    if(id == n) break;
    ++id;
  }
  if(i == 1) return -1;
  return res;
}

Measured memory_bytes: 1792
n,m = list(map(int,input().split()))
gate = []
for i in range(m): gate.append(list(map(int,input().split())))

l = -1
r = n+1
for i in range(m):
  l = max(l,gate[i][0])
  r = min(r,gate[i][1])
print((r-l+1)*(l <= r))


Measured memory_bytes: 27344
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 1e5 + 10;
int x[maxN], y[maxN];
int p[maxN];
int find(int a) {
    if (a == p[a]) return a;
    return p[a] = find(p[a]);
}
bool unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return false;
    if (rand() & 1) swap(a, b);
    p[a] = b;
    return true;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    vector < pair < int, int > > byX, byY;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
        byX.emplace_back(x[i], i);
        byY.emplace_back(y[i], i);
    }
    sort(byX.begin(), byX.end());
    sort(byY.begin(), byY.end());
    vector < pair < int, pair < int, int > > > edges;
    for (int i = 0; i + 1 < n; i++) {
        edges.emplace_back(byX[i + 1].first - byX[i].first, make_pair(byX[i].second, byX[i + 1].second));
        edges.emplace_back(byY[i + 1].first - byY[i].first, make_pair(byY[i].second, byY[i + 1].second));
    }
    sort(edges.begin(), edges.end());
    ll ans = 0;
    for (int i = 1; i <= n; i++) p[i] = i;
    for (auto it : edges) {
        if (unite(it.second.first, it.second.second)) ans += it.first;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 7912
#coding:utf-8

def NSS(s1,s2):
    s1list=list(s1)
    n=len(s1list)
    s2list=list(s2)
    for i in range(n):
        ans=0
        if len(s1list)>=len(s2list) and s1list[0]==s2list[0]:
            ans+=1
            for j in range(1,len(s2list)):
                if s1list[j]==s2list[j]:
                    ans+=1
        if ans==len(s2list):
            print(i)
        s1list.pop(0)

if __name__=="__main__":
    s1=input()
    s2=input()
    NSS(s1,s2)
        
            

Measured memory_bytes: 7524
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
  public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
  public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};


int main(){
  int n,k; cin >> n >> k;
  int A = (n-1)*(n-2)/2;
  int cnt = A - k;
  if(cnt < 0){
    cout << -1 << endl;
    return 0;
  }

  int m = n-1 + cnt;

  int G[n][n];
  rep(i,n) rep(j,n) {
    if(i == j) G[i][j] = 0;
    else if(i == 0 || j == 0) G[i][j] = G[j][i] = 1;
    else G[i][j] = G[j][i] = 0;
  }

  int c = 0;
  rep(i,n) rep(j,n) {
    if(c == cnt){
      goto next;
    }
    
    if(i == j) continue;
    if(G[i][j]) continue;
    G[i][j] = G[j][i] = 1;
    c++;
  }
next:
  cout << m << endl;
  for(int i = 0; i < n; i++) {
    for(int j = i+1; j < n; j++) {
      if(G[i][j]) printf("%d %d\n", i+1, j+1);
    }
  }

}

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String l,s="";
		while ((l=br.readLine())!=null) s+=l;
		s=s.replace(" ","").toLowerCase();
		char[] a={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
		int r;
        for(char c:a){
        	r=0;
        	for(int i=0;i<s.length();i++){
            	if(s.charAt(i)==c) r+=1; 
        	}
        	System.out.println(c+" : "+r);
        }
	}
}

Measured memory_bytes: 24672
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

int n, dp[N];
vector<int> v[N];

void dfs(int x) {
	int re = 0;
	for(auto i : v[x])
		dfs(i);
	sort(v[x].begin(), v[x].end(), [&] (int a, int b) {
		return dp[a] < dp[b];
	});
	reverse(v[x].begin(), v[x].end());
	for(int i = 0; i < v[x].size(); i++)
		re = max(dp[v[x][i]] + i + 1, re);
	dp[x] = re;
}

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n;
	for(int i = 2; i <= n; i++) {
		int a;
		cin >> a;
		v[a].pb(i);
	}
	dfs(1);
	cout << dp[1];
}

Measured memory_bytes: 34176
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
//max=({});
//条件式が真ならwhileの中身を回し続ける

int main() {
	double W, H,x,y;
	cin >> W >> H >> x >> y;
	double ans = W * H / 2;
	int flag = 0;
	if (x == W / 2 && y == H / 2)flag++;
	cout << ans << " " << flag << endl;
	return 0;
}


Measured memory_bytes: 256
m = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
d = ["Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"]
while True:
  a, b = map(int, input().split())
  if a + b == 0:
    break
  mon = 0
  for i in range(a):
    mon += m[i]
  day = mon + b
  print(d[day % 7])


Measured memory_bytes: 5596
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.Char
import qualified Data.ByteString.Char8 as C
import Data.List
import qualified Data.Vector.Unboxed as U

main = sol <$> (get <$> C.getLine) <*> (get <$> C.getContents) >>= print

sub [n,a,b] = sol [n,a,b] <$> replicateM n readLn

get = unfoldr (C.readInt . C.dropWhile isSpace) 

sol [n,a,b] hs = bs 0 hi p
  where
  v = U.fromListN n hs
  hi = U.foldr' ((+) . (`dc` a)) 0 v
  p x = (x>=) $ U.foldr' ((+) . flip dc (a-b) . max 0 . subtract (x*b)) 0 v
  bs !l !r p
    | l+1>=r    = r
    | p m       = bs l m p
    | otherwise = bs m r p
    where !m = (l+r) `div` 2

dc p q = (p+q-1) `div` q

Measured memory_bytes: 4348
n = int(input())
a = [int(c) for c in input().split()]
c = [0 for _ in range(n)]
for i in range(n):
    c[a[i]-1]+=1
count = sum(c[i] * (c[i]-1) / 2 for i in range(n))
for i in range(n):
    pp = c[a[i]-1]
    print(int(count - pp * (pp - 1) / 2 + (pp-1) * (pp-2) / 2))

Measured memory_bytes: 26140
#include <stdio.h>

long long dp[99][21];

int main(void) {
    int N, d, i, j;

    scanf("%d", &N);
    for (i = 0; i < 21; i++) dp[0][i] = 0;
    scanf("%d", &d);
    dp[0][d] = 1;
    for (i = 1; i < N - 1; i++) {
        scanf("%d", &d);
        for (j = 0; j < 21; j++) { // op: +
            if (j - d >= 0) dp[i][j] = dp[i-1][j-d];
            else dp[i][j] = 0;
        }
        for (j = 0; j < 21 - d; j++) {
            dp[i][j] += dp[i-1][j+d];
        }
    }
    scanf("%d", &d);
    printf("%lld\n", dp[N-2][d]);

    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define all(x) x.begin(),x.end()
#define nl      '\n'

typedef long long int ll;
typedef unsigned long long int  llu;


int main()
{
	faster
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans=max(a*c,a*d);
	ll ans2=max(b*c,b*d);
	ll mx=max(ans,ans2);
	cout<<mx<<nl;
	return 0;
}


Measured memory_bytes: 3684
#include<iostream>
#include<vector>
#define rep(i, n) for (int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

struct UnionFind{
    // d<0のときそのインデックスは親でその木のサイズd[i]*-1
    // d>0のときそのインデックスの親はd[i]
    vector<int> d;
    UnionFind(int n): d(n, -1) {}
    int find(int x){
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if(x== y) return false;
        if(d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y){ return find(x) == find(y);}
    int size(int x){ return -d[find(x)];}
};

int deg[100005];
vector<int> block[100005];

int main(){
    int N, M, K; cin >> N >> M >> K;
    UnionFind uf(N);
    rep(i, M){
        int a, b; cin >> a >> b;
        a--;
        b--;
        deg[a]++;
        deg[b]++;
        uf.unite(a, b);
    }
    rep(i, K){
        int a, b; cin >> a >> b;
        a--;
        b--;
        block[a].push_back(b);
        block[b].push_back(a);
    }
    rep(i, N){
        int ans = uf.size(i)-1-deg[i];
        for(int u: block[i]){
            if(uf.same(i, u)) ans--;
        }
        cout << ans << " ";
    }
}


Measured memory_bytes: 6784
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, x;
	cin >> n >> x;
	long long sum = 0;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	if (sum == x) {
		cout << n << endl;

		return 0;
	}
	else if (sum < x) {
		cout << n - 1 << endl;

		return 0;
	}

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

	for (int i = n - 1; i >= 0; i--) {
		sum -= a[i];
		if (sum <= x) {
			cout << i << endl;

			return 0;
		}
	}

	return 0;
}

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

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(c % gcd(a,b) == 0) {
        cout << "YES";
    }else {
        cout << "NO";
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
//#define ll __int64
#define ll long long
const int INF=1000000007;
int h,w,n;
int t[111][111];
int c[11111];

int main(){
cin>>h>>w>>n;
rep(i,n)cin>>c[i];

int pos=0;
int cnt=0;
	
	for(int i=1;i<=h;i++){

		rep(j,w){
			if(i%2)t[i-1][j]=pos+1;
			else t[i-1][w-1-j]=pos+1;
			cnt++;
			if(cnt>=c[pos])cnt=0,pos++;
		}
	}
	
	rep(i,h){
		rep(j,w){
			cout<<t[i][j];
			if(j!=w-1)cout<<" ";
		}	
		cout<<endl;
	}
	return 0;
}

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

const int mod = 1e9 + 7;
const int kmax = 510000;
 
long long fact[kmax], fact_inv[kmax], inv[kmax];


int gcd(int a, int b) {
    if (!b) return a; 
    return gcd(b, a % b);
}
 
void init_comb() {
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}
 
long long comb(int n, int r) {
    if (n < r) return 0; 
    if (n < 0 || r < 0) return 0; 
    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}
 
int main() {
    init_comb(); 
    int n, m, k; cin >> n >> m >> k;
 
    long long comb_value = comb(n * m - 2, k - 2);
    long long ans = 0;
    for (int x_distance = 1; x_distance < m; x_distance++) {
        ans += comb_value * n * n % mod * (m - x_distance) * x_distance % mod;
        ans %= mod;
    }
 
    for (int y_distance = 1; y_distance < n; y_distance++) {
        ans += comb_value * m * m % mod * (n - y_distance) % mod * y_distance % mod;
        ans %= mod;
    }
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12160
import java.util.Scanner;

public class Main {
	

	
	void main() {
		try(Scanner sc = new Scanner(System.in)){
			for(;;) {
				int x =sc.nextInt();
				int y =sc.nextInt();
				if(x ==0 && y ==0)break;
				
				System.out.println(Math.min(x, y)+" "+Math.max(x,y));
				}
			}
			}
	
		
	public static void main(String[] args) {
		new Main().main();


	}

}



Measured memory_bytes: 35980
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double sx[2100];
double sy[2100];
double sz[2100];
double sr[2100];
double tx[21];
double ty[21];
double tz[21];
double tb[21];
double x,y,z;
int dp[2100][20];
inline int chk(int a,int b){
	if(~dp[a][b])return dp[a][b];
	double L=0;
	double R=1;
	bool Q=false;
	double d3=sqrt((sx[a]-tx[b])*(sx[a]-tx[b])+(sy[a]-ty[b])*(sy[a]-ty[b])+(sz[a]-tz[b])*(sz[a]-tz[b]));
	double d4=sqrt((sx[a]-x)*(sx[a]-x)+(sy[a]-y)*(sy[a]-y)+(sz[a]-z)*(sz[a]-z));
	if(d3<sr[a]&&d4<sr[a])return dp[a][b]=0;
	for(int i=0;i<100;i++){
		double m1=(L*2+R)/3;
		double m2=(L+R*2)/3;
		double px=x*m1+tx[b]*(1.0-m1);
		double py=y*m1+ty[b]*(1.0-m1);
		double pz=z*m1+tz[b]*(1.0-m1);
		double qx=x*m2+tx[b]*(1.0-m2);
		double qy=y*m2+ty[b]*(1.0-m2);
		double qz=z*m2+tz[b]*(1.0-m2);
		double d1=sqrt((sx[a]-px)*(sx[a]-px)+(sy[a]-py)*(sy[a]-py)+(sz[a]-pz)*(sz[a]-pz));
		double d2=sqrt((sx[a]-qx)*(sx[a]-qx)+(sy[a]-qy)*(sy[a]-qy)+(sz[a]-qz)*(sz[a]-qz));
		if(d1<sr[a]||d2<sr[a]){return dp[a][b]=1;}
		if(d1<d2)R=m2;
		else L=m1;
	}

	return dp[a][b]=0;
}
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		for(int i=0;i<a;i++)scanf("%lf%lf%lf%lf",sx+i,sy+i,sz+i,sr+i);
		for(int i=0;i<b;i++)scanf("%lf%lf%lf%lf",tx+i,ty+i,tz+i,tb+i);
		scanf("%lf%lf%lf",&x,&y,&z);
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)dp[i][j]=-1;
		double ret=0;
		for(int i=0;i<(1<<b);i++){
			double val=0;
			for(int j=0;j<b;j++)if(i&(1<<j)){
				val+=tb[j]/((tx[j]-x)*(tx[j]-x)+(ty[j]-y)*(ty[j]-y)+(tz[j]-z)*(tz[j]-z));
			}
			int cnt=0;
			for(int j=0;j<a;j++){
				bool ok=true;
				for(int k=0;k<b;k++){
					if(i&(1<<k)){
						if(chk(j,k)){ok=false;break;}
					}
				}
				if(!ok)cnt++;
				if(cnt>c)break;
			}
			if(cnt<=c){
				ret=max(ret,val);
			//	printf("%d\n",i);
			}
		}
		printf("%.12f\n",ret);
	}
}

Measured memory_bytes: 1316
#include<stdio.h>
#include<string.h>
int main(){
	char s[1010];
	scanf("%s",s);
	int cnt[130]={0};
	int len=strlen(s);
	for (int i=0;i<len;i++){
		cnt[s[i]]=1;
	}
	if (!cnt['N']==!cnt['S']&&!cnt['E']==!cnt['W']){
		printf("Yes");
	}
	else {	
		printf("No");
	}
}

Measured memory_bytes: 128
/* Don't try to copy it!
                    nhi too,
                         goli maar ke cheed bana dunga...;););)
 
                 
    _/﹋\_
    (҂`_´)
    <,︻╦╤─҉- - - - - - - - => - => - =>
    _/﹋\_
                
*/
 
#include "bits/stdc++.h"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define vll vector<ll>
#define T ll t; cin>>t; while(t--)
#define freeopen freopen("input.txt","r",stdin);
#define freeclose freopen("output.txt","w",stdout);
#define MOD 1000000007
using namespace std;
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 r,c;
char grid[1005][1005];
ll dp[1005][1005];
ll ways(ll x,ll y)
{
    if(dp[x][y]!=-1)
        return dp[x][y];

    if(x==r-1 && y==c-1)
        return 1;
   if(x>=r || y>=c)
    return 0;
    
    if(grid[x][y]=='#')
        dp[x][y]=0;
    else
    dp[x][y]=(ways(x+1,y)+ways(x,y+1))%MOD;

    return dp[x][y];
}
//. for clear and # for wall
main()
{
    memset(dp,-1,sizeof(dp));
    cin>>r>>c;
    for(ll i=0;i<r;i++)
    {
        for(ll j=0;j<c;j++)
        {
            cin>>grid[i][j];
        }
    }


    ll ans=ways(0,0);
    cout<<(ans)%MOD;

}



Measured memory_bytes: 12532
using System;

class Prog{
    static void Main(){
        int[] ls = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int k = ls[0];
        int x = ls[1];
        for (int i = x - k + 1;i < x + k ;i++){
            Console.Write(i+" ");
        }
    }
}

Measured memory_bytes: 13140