akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;

public class Main {
    static int n,k;
    static long ans=0;
    static int freq[];
    static long M;
    static int gcd(int a,int b){
        if(b==0)
            return a;
        return gcd(b,a%b);
    }
    static void calc(int arr[]){
        int gcd=arr[0];
        for(int i=1;i<n;i++)
            gcd=gcd(gcd,arr[i]);
        freq[gcd]++;
        ans+=gcd;
    }
    static void recurse(int i,int arr[]){
        if(i==n){
            calc(arr);
            return;
        }

        for(int j=1;j<=k;j++) {
            arr[i] = j;
            recurse(i+1,arr);
        }
    }
    static long pow(long a,long b){
        if(b==0)
            return 1;
        long ans=pow(a,b/2);
        ans=(ans*ans)%M;
        if(b%2==1)
            ans=(ans*a)%M;
        return ans;
    }
    public static void main(String[] args)throws Exception {
        FastReader in = new FastReader(System.in);
        StringBuilder sb = new StringBuilder();
        M=1000_000_007;
        int i,j;
        n=in.nextInt();
        k=in.nextInt();
        freq=new int[k+1];
        long fr[]=new long[k+1];
        long an=0;
        for(i=k;i>=1;i--){
            long z=pow(k/i,n);
            for(j=i+i;j<=k;j+=i){
                z=(z-fr[j]+M)%M;
            }
            fr[i]=z;
        }
        for(i=1;i<=k;i++){
            an=(an+fr[i]*i)%M;
        }
        /*recurse(0,new int[n]);
        for(i=1;i<=k;i++)
            System.out.println(i+"->"+freq[i]);*/
        System.out.println(an);

    }
}

class FastReader {

    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;

    FastReader(InputStream is) {
        in = is;
    }

    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }

    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }

    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }

    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
}





Measured memory_bytes: 33800
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    X, Y = [int(x) for x in input().split()]
    ans = float("inf")

    if Y - X >= 0:
        ans = min(ans, Y - X)

    if Y - -X >= 0:
        ans = min(ans, Y - -X + 1)

    if -Y - X >= 0:
        ans = min(ans, -Y - X + 1)

    if -Y - -X >= 0:
        ans = min(ans, -Y - -X + 2)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
    int a,b;
    char op;
    for(int i=0;i<999999;i++){
        cin >> a >> op >> b;
        if(op=='+'){
            cout << a+b << endl;
        }
        else if(op=='-'){
            cout << a-b << endl;
        }
        else if(op=='*'){
            cout << a*b << endl;
        }
        else if(op=='/'){
            cout << a/b << endl;
        }
        else{
            break;
        }
    }
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

bool is_palindrome(string s) {
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] != s[n - i - 1])
      return false;
  }

  return true;
}

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

  string s;
  cin >> s;

  int n = s.size();
  int ans = 0, l = 0, r = n - 1;
  while (l < r) {
    if (s[l] == s[r]) {
      l++;
      r--;
    } else if (s[l] == 'x') {
      l++;
      ans++;
    } else if (s[r] == 'x') {
      r--;
      ans++;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;
}

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

int main(){
  int a[26] = {0};
  int b[26] = {0};
  string s,t;
  cin >> s >> t;
  for(int i = 0 ; i < s.length(); i++){
    a[s[i] - 'a']++;
    b[t[i] - 'a']++;
  }
  int c[200001] = {0};
  int d[200001] = {0};
  for(int i = 0 ; i < 26; i++){
    c[a[i]]++;
    d[b[i]]++;
  }
  for(int i = 0; i < s.length(); i++){
    if(c[i] != d[i]){
      cout << "No" << endl;
      return 0;
    }
  }
/*  for(int i = 0; i < 26; i++){
    if( (a[i] != 0 && b[i] == 0) || (a[i] == 0 && b[i] != 0)){
      cout << "No" << endl;
      return 0;
    }
  }*/

  cout << "Yes" << endl;
}


Measured memory_bytes: 2312
<?php
  fscanf(STDIN, "%d", $n);
  $a = explode(" ", trim(fgets(STDIN)));

  $ans = 0;
  for ($i=0; $i<$n; $i++) {
    while(($a[$i]&1) == 0) {
      $ans++;
      $a[$i] >>= 1;
    }
  }
  
  echo $ans
?>

Measured memory_bytes: 4856
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


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

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> food(M + 10, 0);
  for(int i = 0; i < N; i++){
    int K, A;
    cin >> K;
    for(int j = 0; j < K; j++){
      cin >> A;
      food[A]++;
    }
  }
  
  int ans = 0;
  for(int i = 0; i < M + 1; i++){
    if(food[i] == N) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  const int sizeG = 100;
  int a, b;
  vector<vector<int>> d, lBound;
  Solver2(LL n, LL m) : a(n), b(m), d(a + 1, vector<int>(b + 1)), lBound(sizeG + 1, vector<int>(sizeG + 1, 0)){};
  void impossible() {
    cout << "Impossible" << endl;
    exit(0);
  }
  void solve() {
    for (int i = 1; i <= a; ++i) {
      for (int j = 1; j <= b; ++j) {
        cin >> d[i][j];
      }
    }
    for (int i = 1; i <= a; ++i) {
      for (int j = 1; j <= b; ++j) {
        for (int k = 0; k <= sizeG; ++k) {
          for (int l = 0; l <= sizeG; ++l) {
            //path with 'X' : k times
            //path with 'Y' : l times
            lBound[k][l] = max(lBound[k][l], d[i][j] - i * k - j * l);
          }
        }
      }
    }
    for (int i = 1; i <= a; ++i) {
      for (int j = 1; j <= b; ++j) {
        int minDistance = INF;
        for (int k = 0; k <= sizeG; ++k) {
          for (int l = 0; l <= sizeG; ++l) {
            minDistance = min(minDistance, i * k + j * l + lBound[k][l]);
          }
        }
        if (minDistance > d[i][j]) impossible();
      }
    }
    cout << "Possible" << endl;
    cout << sizeG * 2 + 2 << ' ' << (sizeG + 1) * (sizeG + 1) + 2 * sizeG << endl;
    for (int k = 0; k <= sizeG; ++k) {
      for (int l = 0; l <= sizeG; ++l) {
        cout << k + 1 << ' ' << sizeG * 2 + 2 - l << ' ' << lBound[k][l] << endl;
      }
    }
    for (int i = 0; i < sizeG; ++i) {
      cout << i + 1 << ' ' << i + 2 << " X" << endl;
      cout << i + sizeG + 2 << ' ' << i + sizeG + 3 << " Y" << endl;
    }

    cout << 1 << ' ' << sizeG * 2 + 2 << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n, m;

int dist(vi &s, vi &t){
	int q=count(ALL(s), 1);
	int j=0,k=0;
	int res = 0;
	REP(i, q){
		while(!s[j++]);
		while(!t[k++]);
		res += abs(j-k);
	}
	return res;
}

main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	vi d(n), e(m);
	REP(i, n) cin >> d[i];
	REP(i, m) cin >> e[i];
	int ans = INF;
	REP(k, 2){
		vi tar;
		int t=k;
		FOR(it, e){
			REP(i, *it) tar.push_back(t);
			t=!t;
		}
		if(count(ALL(tar), 0) != count(ALL(d), 0)) continue;
		ans = min(ans, dist(d, tar));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) cin >> A[i];
  int q;
  cin >> q;
  while (q--) {
    int b, e, k;
    cin >> b >> e >> k;
    cout << count(A.begin() + b, A.begin() + e, k) << endl;
  }
  return 0;
}


Measured memory_bytes: 3144
#include <iostream>
using namespace std;
#define ll long long
#define max 100000 
using namespace std;


int main () {
  ll N, W;
  cin >> N >> W;
  ll w[N + 1], v[N + 1];
  for (ll i = 1; i <= N; i++) {
    cin >> w[i] >> v[i];
  }
  
  // dp[i][j] ... i個目の時点でjだけの価値がある場合の重さ
  ll dp[N + 1][max + 1];
  for (ll i = 0; i <= N; i++) {
    for (ll j = 0; j <= max; j++) dp[i][j] = -1;
    dp[i][0] = 0;
  }
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    for (ll j = 1; j <= max; j++) {
      dp[i][j] = dp[i - 1][j];
      if (dp[i - 1][j - v[i]] != -1) {
        if (dp[i - 1][j - v[i]] + w[i] <= W) {
          ll sub = dp[i - 1][j - v[i]] + w[i];
          if (sub <= dp[i][j] || dp[i][j] == -1) {
            dp[i][j] = sub;
          }
        }
      }
      if (i == N && dp[i][j] >= 0) {
      	ans = j;  
      }
    }
  }
  cout << ans << endl;
}

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

ll x = 1e9 + 7; 
const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x; --y;
  vector<int> ans(n);
  rep(sv,n) {
    vector<int> dist(n, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != INF) return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      int d = dist[v];
      if (v-1 >= 0) push(v-1, d+1);
      if (v+1 < n) push(v+1, d+1);
      if (v == x) push(y, d+1);
      if (v == y) push(x, d+1);
    }
    rep(i,n) ans[dist[i]]++;
  }
  rep(i,n) ans[i] /= 2;
  for (int i = 1; i <= n-1; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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


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

int N,K,Q,A[2020];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int k;
    cin>>k;
    int n=s.size();

    for(int i=0;i<n-1;i++){
        int t = ('z' - s[i] + 1)%26;
        if(t<=k){
            k-=t;
            s[i]='a';
        }
        else continue;
    }
    k %= 26;
    for(int j=0;j<k;j++){
        s[n-1]++;
        if(s[n-1]>'z') s[n-1]='a';
    }

    cout<<s<<endl;

}


Measured memory_bytes: 592
import itertools
N,M,Q=map(int,input().split())
q=[list(map(int,input().split())) for i in range(Q)]
point=0
for A in itertools.combinations_with_replacement(range(1,M+1),N):
    point=max(point,sum(d for (a,b,c,d) in q if A[b-1]-A[a-1]==c))
print(point)

Measured memory_bytes: 9056
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var N int
	fmt.Scan(&N)
	S := strconv.Itoa(N)
	ss := strings.Split(S, "")
	sn := 0
	for r := range ss {
		t, e := strconv.Atoi(ss[r])
		if e != nil {
			panic(e)
		}
		sn += t
	}
	if N%sn == 0 {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}


Measured memory_bytes: 640
N, K = map(int, input().split())
#print(K)

A = list(set((map(int, input().split()))))

if len(A) == 1:
    if K == A[0]:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
elif K in A:
    ans = 'POSSIBLE'
elif K > max(A):
    ans = 'IMPOSSIBLE'
else:
    A.sort()

    #print(A)

    a = A[0]
    lenA = len(A)
    for i in range(1,lenA):
        if A[i]%a > 0:
            b = A[i]
            break
        if i == lenA-1:
            b = A[1]

    while True:
        c = b - a
        if c == 0:
            break
        if c < a:
            b = a
            a = c
        else:
            b = c

    if K%a == 0:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
    #print(a)

print(ans)


Measured memory_bytes: 19856
import sys
input=sys.stdin.readline

k=int(input())

print(50)
x=k//50
y=k%50

a=49+x
for i in range(50-y):
    print(a-y,end='')
    print(' ',end='')
for i in range(y):
    print(a+51-y,end='')
    print(' ',end='')

Measured memory_bytes: 62252
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

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

int n, a, b, c;
int l[8];
int getCost(int i, string s) {
  int res = INF;
  if (i == n) {
    int aa = a;
    int bb = b;
    int cc = c;
    int sza = 0;
    int szb = 0;
    int szc = 0;
    rep(i, n) {
      if (s[i] == 'a') {
        aa -= l[i];
        sza++;
      }
      if (s[i] == 'b') {
        bb -= l[i];
        szb++;
      } 
      if (s[i] == 'c') {
        cc -= l[i];
        szc++;
      }
    }
    if (sza == 0 || szb == 0 || szc == 0) return INF;
    res = abs(aa) + abs(bb) + abs(cc) + max((sza - 1) * 10, 0) + max((szb - 1) * 10, 0) + max((szc - 1) * 10, 0);
  } else {
    res = min(res, getCost(i+1, s + 'a'));
    res = min(res, getCost(i+1, s + 'b'));
    res = min(res, getCost(i+1, s + 'c'));
    res = min(res, getCost(i+1, s + 'x'));
  }
  return res;
}

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

  cin >> n >> a >> b >> c;

  fillInt(l, n);

  cout << getCost(0, "") << endl;
}


Measured memory_bytes: 256
/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	ll n;
	cin>>n;
	vl a(n),b(n+1);
	for(ll i=0;i<n;i++)
	cin>>b[i];
	a[n-1]=b[n-2];
	for(ll i=n-2;i>0;i--)
	a[i]=min(b[i],b[i-1]);
	a[0]=b[0];
	ll ans=0;
	for(ll i=0;i<n;i++)
	ans+=a[i];
	cout<<ans<<nl;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    printf("%d %d\n", min(a, b), max(0, a+b-n));
    return 0;
}


Measured memory_bytes: 3732
n,k=map(int,input().split())
a=list(map(int,input().split()))

dp=["INF" for _ in range(n)]
dp[0]=0
#print(r)

for i in range(n):
  for j in range(min(k,n-i-1)):
    if dp[i+j+1]=="INF":
      dp[i+j+1]=dp[i]+abs(a[i+j+1]-a[i])
    else:
      dp[i+j+1]=min(dp[i+j+1],dp[i]+abs(a[i+j+1]-a[i]))
      #print(i,i+j,">>",r)
  
print(dp[-1])


Measured memory_bytes: 60768
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
    int n;
    cin >> n;
    vector<long long> l(n);
    rep(i,n) cin >> l.at(i);
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k <n; k++){
                if(l.at(i) != l.at(j) && l.at(j) != l.at(k) && l.at(k) != l.at(i)){
                   int len = l.at(i) + l.at(j) + l.at(k);
                   int ma = max(l.at(i),max(l.at(j),l.at(k)));
                   int rest = len - ma;
                    if(ma < rest){
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
// https://atcoder.jp/contests/abc164/tasks/abc164_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N, M, S;
  cin >> N >> M >> S;

  struct Edge {
    ll to, silver_cost, time_cost;
  };

  ll sum_silver_cost = 0;

  V<V<Edge>> edge_list(N);
  VL change_cts(N);
  VL change_time_costs(N);

  rep(i, M) {
    ll u, v, silver, time;
    cin >> u >> v >> silver >> time;
    --u, --v;
    sum_silver_cost += silver;
    edge_list[u].push_back({v, silver, time});
    edge_list[v].push_back({u, silver, time});
  }

  rep(i, N) {
    cin >> change_cts[i];
    cin >> change_time_costs[i];
  }

  // ダイクストラ
  // costs[i][silver_ct]: silver_ct の枚数を持った頂点 i までの最小コスト
  VVL costs(N, VL(sum_silver_cost + 1, INF));

  ll initial_s = min(S, sum_silver_cost);

  priority_queue<tuple<ll, ll, ll>, V<tuple<ll, ll, ll>>,
                 greater<tuple<ll, ll, ll>>>
      q;
  q.emplace(0, initial_s, 0);

  while (!q.empty()) {
    auto p = q.top();
    q.pop();

    auto [cur_time, cur_silver, u] = p;

    if (cur_time > costs[u][cur_silver]) continue;

    for (auto e : edge_list[u]) {
      rep(changed_ct, INF) {
        ll n_silver = cur_silver + change_cts[u] * changed_ct - e.silver_cost;
        if (n_silver < 0) continue;
        if (n_silver > sum_silver_cost) break;
        ll n_time = cur_time + change_time_costs[u] * changed_ct + e.time_cost;

        if (chmin(costs[e.to][n_silver], n_time)) {
          q.emplace(n_time, n_silver, e.to);
        }
      }
    }
  }

  rep(i, N) {
    if (i == 0) continue;
    ll res = *min_element(all(costs[i]));
    cout << res << "\n";
  }
}


Measured memory_bytes: 53476
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string R; cin >> R;
    int q; cin >> q; //クエリ数
    int t, f; string c; //クエリを受け取るやつ
    string L;
    rep(i,q) {
        cin >> t;
        if (t == 1) swap(L,R);
        else {
            cin >> f >> c;
            if (f == 1) L = L + c;
            else R = R + c;
        }
    }
    reverse(L.begin(), L.end());
    cout << L << R << endl;
}

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

int main() {
  int a, b;
  char op;
  cin >> a >> op >> b;
  
  if( op == '+' ){
    cout << a + b << endl;
  }
  
  if( op == '-'){
    cout << a - b << endl;
  }
  
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(x) ll t; cin >> t; x.push_back(t);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

ll w[110] = {0};
ll v[110] = {0};
ll dp[110][100010] = {0};

int main() {
    ll N, W;
    cin >> N >> W;

    REP(i, N) {
        cin >> w[i] >> v[i];
    }

    REP(i, N) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {
            if (sum_w - w[i] >= 0) {
                dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - w[i]] + v[i]);
            }

            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w]);
        }
    }

    MSG(dp[N][W])
}


Measured memory_bytes: 79360
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void rec(int d, long long val, vector<long long> &all) {
    all.push_back(val);
    if (d == 10)  return;

    for (int j = -1; j <= 1; j++) {
        int add = (val % 10) + j;
        if (add >= 0 && add <= 9) rec(d+1, val*10+add, all);
    }
}


void solve() {
    int K; cin >> K;
    vector<long long> all;
    for (int v = 1; v < 10; v++) rec(1, v, all);

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

    cout << all[K-1] << endl; 
}


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

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

LL memo1[200001];
LL memo2[200001];

void solve(long long N, std::vector<long long> A){
    REP(i, N) {
        memo1[A[i]]++;
    }

    LL ans = 0;
    REP(i, 200001) {
        memo2[i] = memo1[i] * (memo1[i]-1) / 2;
        ans += memo2[i];
    }

    REP(i, N){
        cout << (ans - memo2[A[i]] + (memo1[A[i]]-1) * (memo1[A[i]]-2) / 2) << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 6272
///////////////////////////////////////////////////
/* __                                       __   */
/*|  |--.-----.---.-.----.----.-----.-----.|  |_ */
/*|  _  |  -__|  _  |  __|  __|  -__|  _  ||   _|*/
/*|_____|_____|___._|____|____|_____|   __||____|*/
/*                                  |__|         */
///////////////////////////////////////////////////
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long lint; using namespace std;
#define rep(counter, limit) for (int counter = 0; counter < limit; counter++)
#define INF 1000000000000
#define MOD 10000007
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){cin.tie(0);ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}setupios;
int main() {

  double n;
  cin>>n;
  int a=0;
  while(a < 50000){
    a++;
    if(int(a*1.08) == n){
      cout<<a<<endl;
      return 0;
    }
  }
  cout<<":("<<endl;
}


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

using namespace std;

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

struct perm {
  vector<int> a;
  perm(int n) : a(n) {}
  int size() { return a.size(); }
  int &operator[](int k) { return a[k]; }
};

perm operator*(perm a, perm b) {
  const int n = a.size();
  perm ans(n);
  REP(i, n) ans[i] = a[b[i]];
  return ans;
}

perm inv(perm a) {
  const int n = a.size();
  perm ans(n);
  REP(i, n) ans[a[i]] = i;
  return ans;
}

perm pow(perm a, int b) {
  const int n = a.size();
  perm ans(n);
  REP(i, n) ans[i] = i;
  while (b > 0) {
    if (b & 1) ans = ans * a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}

void print(perm a) {
  for (int i = 0; i < a.size(); i++) {
    if (i > 0) cout << ' ';
    cout << a[i] + 1;
  }
  cout << '\n';
}

int main() {
  int N, K;
  cin >> N >> K;
  perm P(N), Q(N);
  REP(i, N) cin >> P[i], P[i]--;
  REP(i, N) cin >> Q[i], Q[i]--;
  auto X = Q * inv(P) * inv(Q) * P;
  auto Y = inv(P) * Q * P * inv(Q);
  vector<perm> A;
  A.push_back(P);
  A.push_back(Q);
  for (int i = 0; i < 5; i++) {
    A.push_back(A[i + 1] * inv(A[i]));
  }
  A.erase(A.begin());
  if (K == 1) {
    print(P);
    return 0;
  }
  K -= 2;
  perm ans = pow(X, K / 6) * A[K % 6] * pow(Y, K / 6);
  print(ans);
}

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

typedef long long ll;
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    // もともと１個のソケットがあって、a - 1　個ずつ増やしていったとき、bを超えるのは何回目ですか？
    int numSocket = 1;
    int counter = 0;
    while (numSocket < b) {
        numSocket += a - 1;
        ++counter;
    }
    cout << counter << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll N;

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int calc(int x) {
  if (x<=2) return 1;
  int a=0;
  while(a*(a+1)/2<=x) {
    a++;
  }
  return a-1;
}

int main() {
  INCANT;
  cin >> N;
  map<ll, int> ret = prime_factor(N);
  int ans = 0;
  for (auto p: ret) ans +=calc(p.second);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3656
/*input
aabcc
1
1 5
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=80000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
string s;
string L,R;

vector<int> bound[maxn];

pii itv[maxn];

int d[maxn];
int tg[maxn];
int main()
{
	IOS;
	cin>>s;
	int n;
	cin>>n;
	REP(i,n) cin>>itv[i].F>>itv[i].S;
	REP(i,n) itv[i].F--;

	REP(i,n){
		itv[i].F=min(itv[i].F,SZ(s)-itv[i].F);
		itv[i].S=min(itv[i].S,SZ(s)-itv[i].S);
		if(itv[i].F>itv[i].S) swap(itv[i].F,itv[i].S);
	}
	for(int i=0;i<SZ(s)/2;i++) L.pb(s[i]);
	for(int i=0;i<SZ(s)/2;i++) R.pb(s[SZ(s)-1-i]);

	REP(i,n) if(itv[i].F<itv[i].S) bound[itv[i].F].pb(itv[i].S);
	REP(i,SZ(s)/2){
		SORT_UNIQUE(bound[i]);
		for(int j=1;j<SZ(bound[i]);j++){
			bound[bound[i][j-1]].pb(bound[i][j]);
		}
		while(SZ(bound[i])>1) bound[i].pop_back();
	}
	// REP(i,SZ(s)/2){
	// 	for(int j:bound[i]) cout<<j<<' ';
	// 	cout<<'\n';
	// }
	// cout<<L<<' '<<R<<'\n';
	REP(i,SZ(s)/2){
		d[i]=(L[i]-R[i]+26)%26;
	}
	// REP(i,SZ(s)/2) cout<<d[i]<<" \n"[i==SZ(s)/2-1];
	int dd=0;
	for(int i=0;i<SZ(s)/2;i++){
		dd+=tg[i];
		dd=(dd%26+26)%26;
		d[i]+=dd;
		d[i]%=26;

		if(SZ(bound[i])){
			int tmp=26-d[i];
			d[i]+=tmp;
			d[i]%=26;
			dd+=tmp;
			tg[bound[i][0]]-=tmp;
		}
	}
	REP(i,SZ(s)/2) if(d[i]){
		cout<<"NO\n";
		return 0;
	}
	cout<<"YES\n";
	return 0;
}


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

int main() {
  int N;
  cin>>N;
  if(N/1000==N%1000/100){
     if(N%1000/100==N%100/10)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
    else if (N%1000/100==N%100/10){
      if(N%100/10==N%10)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<tuple>
#include<set>
#include<map>
#include<cctype>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

int N;
int main(void) {
	cin >> N;
	ct(800*N-200*(N/15));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  char c;
  cin >> c;
  if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
    cout << "vowel" << endl;}
  else {
    cout << "consonant" << endl;}
  }
    
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int cunt,cunt0,color[9],a;

int main(){
    int N;
    cin>>N;

    for(int i=0;i<N;i++){
        cin>>a;
        if(a<3200)color[a/400]++;//color[0]~color[7]
        else color[8]++;
    }
    for(int i=0;i<8;i++){
        if(color[i])cunt++;
    }

    int min_cunt=max(cunt,1);

    int max_cunt=cunt+color[8];

    cout<<min_cunt<<" "<<max_cunt<<"\n";

    return 0;
}


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

int main() {
	string S;
	cin>>S;
	if(S=="SUN") cout<<7<<endl;
	if(S=="SAT") cout<<1<<endl;
	if(S=="FRI") cout<<2<<endl;
	if(S=="THU") cout<<3<<endl;
	if(S=="WED") cout<<4<<endl;
	if(S=="TUE") cout<<5<<endl;
	if(S=="MON") cout<<6<<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(itr,data) for(__typeof((data).begin()) itr=(data).begin();itr!=(data).end();++itr)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long UInt64;
typedef long long Int64;

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;

int n,m;



bool solve() {
    bool mat[21][21];
    int cnt=0;
    rep(i,21) rep(j,21) mat[i][j]=false;
    int x,y;
    rep(i,n) {
        cin>>x>>y;
        mat[x][y]=true;
    }

    x=10;
    y=10;
    
    cin>>m;

    rep(i,m) {
        char c;
        int d;
        cin>>c>>d;
        if(c == 'N') {
            while(d --> 0) {
                y++;
                if(mat[x][y]) {
                    cnt++;
                    mat[x][y]=false;
                }
            }
        }
        if(c == 'E') {
            while(d --> 0) {
                x++;
                if(mat[x][y]) {
                    cnt++;
                    mat[x][y]=false;
                }
            }
        }
        if(c == 'S') {
            while(d --> 0) {
                y--;
                if(mat[x][y]) {
                    cnt++;
                    mat[x][y]=false;
                }
            }
        }
        if(c == 'W') {
            while(d --> 0) {
                x--;
                if(mat[x][y]) {
                    cnt++;
                    mat[x][y]=false;
                }
            }
        }
    }

    return cnt == n;

}

int main()
{
    while(cin>>n) {
        if(!n) return 0;

        cout<<(solve()?"Yes":"No")<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 1152
n,k=map(int,input().split())
arr=list(map(int,input().split()))
fans=100000000000000000000000000000
for i in range(n-k):
    if(arr[i]<0 and arr[i+k-1]<=0):
        fans=min(fans,abs(arr[i]))
    elif(arr[i]<0 and arr[i+k-1]>0):
        if(abs(arr[i])>=arr[i+k-1]):
            fans=min(fans,abs(arr[i])+(arr[i+k-1]*2))
        else:
            fans=min(fans,(abs(arr[i])*2)+arr[i+k-1])
    else:
        fans=min(fans,arr[i+k-1])
if(arr[n-k]<0 and arr[n-1]<=0):
    fans=min(fans,abs(arr[n-k]))
elif(arr[n-k]<0 and arr[n-1]>0):
    if(abs(arr[n-k])>=arr[n-1]):
        fans=min(fans,abs(arr[n-k])+(arr[n-1]*2))
    else:
        fans=min(fans,(abs(arr[n-k])*2)+arr[n-1])
else:
    fans=min(fans,arr[n-1])
print(fans)


Measured memory_bytes: 14172
#include"bits/stdc++.h"
using namespace std;
int a,b,c,x,num=0;

int main(){
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if((i*500+j*100+k*50)==x){
					num++;
				}
			}
		}
	}
	cout<<num<<endl;
	return 0;
}

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

int main()
{
	string s;
	cin>>s;
	int n = s.size();
	int ans = 0;
	for(size_t i = 0; i<(n+1)/2; i++)
	{
		if(s[i]!=s[n-i-1])
		{
			ans = 1;
		}
	}
	n = n/2;
	for(size_t i = 0; i<(n+1)/2; i++)
	{
		if(s[i]!=s[n-i-1])
		{
			ans = 1;
		}	
	}
	if(ans==0)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a,b;
        a=sc.nextInt();
        b=sc.nextInt();
        if(a<b){
            System.out.println("a < b");
        }else if(a>b){
            System.out.println("a > b");
        }else{
            System.out.println("a == b");
        }
    }
}

Measured memory_bytes: 17348
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	class Node {
		int parent;
		public Node(int x) {
			this.parent = x;
		}
	}
	
	class DisjointSet {
		Node[] p;
		int[] rank;
		
		public DisjointSet(int size) {
			p = new Node[size];
			rank = new int[size];
			for (int i = 0; i < size; i++) {
				makeSet(i);
			}
		}

		private void makeSet(int x) {
			p[x] = new Node(x);
			rank[x] = 0;
		}
		
		private int findSet(int x) {
			while (x != p[x].parent) {
				x = p[x].parent;
			}
			return x;
		}
		
		public boolean same(int x, int y) {
			return findSet(x) == findSet(y);
		}
		
		public void unite(int x, int y) {
			link(findSet(x), findSet(y));
		}

		private void link(int x, int y) {
			if (rank[x] > rank[y]) {
				p[y].parent = x;
			} else {
				p[x].parent = y;
				if (rank[x] == rank[y]) {
					rank[y]++;
				}
			}
		}
	}
	
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		DisjointSet ds = new DisjointSet(n);
		int q = Integer.parseInt(st.nextToken());
		for (int i = 0; i < q; i++) {
			st = new StringTokenizer(reader.readLine());
			int c = Integer.parseInt(st.nextToken());
			int x = Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			if (c == 0) {
				ds.unite(x, y);
			} else {
				System.out.println(ds.same(x, y)?"1":"0");
			}
		}
		reader.close();
	}
}


Measured memory_bytes: 61112
#include <iostream>
#include <algorithm>
#include <cmath>
#include <ctime>
using namespace std;

void solve()
{
    long long N; cin>>N;
    int n = sqrt(N);
    long long A,B;
    for (int i = 1; i <= n; ++i){
        if(N%i==0) A=i,B=N/i;
    }
    int a=0,b=0;
    while(A!=0) A/=10,++a;
    while(B!=0) B/=10,++b;
    cout << max(a,b) << endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    // int ti = clock();
    // input();
    solve();
    // printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <stack>
using namespace std;


int main(){

	string cliff;
	int pond=0;
	cin >> cliff;

	stack<int> S1;
	stack<pair<int, int> > S2;

	for(int i=0; i < cliff.length(); i++){
		if(cliff[i] == '\\'){
			S1.push(i);
		}else if(cliff[i] == '/'){
			if(S1.size() > 0){
				int cliff_left_i = S1.top();
				int subpond = i - cliff_left_i;
				pond += subpond;
				S1.pop();
			
				if(S2.size() == 0){
					S2.push(make_pair(cliff_left_i, subpond));
				}else{
					// ?????§????°´????????????????????´???
					while(S2.size() > 0 && S2.top().first > cliff_left_i){
						int newsubpond_left = S2.top().first;
						int oldsubpond = S2.top().second;
						subpond += oldsubpond;
						S2.pop();
					}
					S2.push(make_pair(cliff_left_i, subpond));
				}
				
			}
		}
	}
	


	cout << pond << endl;
	int n_subponds = S2.size();
	int subponds[n_subponds];
	for(int i=0; i < n_subponds; i++){
		subponds[i] = S2.top().second;
		S2.pop();
	}
	cout << n_subponds;
	for(int i=n_subponds-1; i >= 0; i--){
		cout << " " << subponds[i];
	}
	cout << endl;

	return 0;

}

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

int main()
{
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a;
        cin >> a;
        n-=a;
    }
    if (n < 0) cout << -1 << endl;
    else cout << n << endl;
    return 0;
}

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String[] strArr = br.readLine().split("\\s");
		      double[] p1 = {Double.parseDouble(strArr[0]), Double.parseDouble(strArr[1])};
		      double[] p2 = {Double.parseDouble(strArr[2]), Double.parseDouble(strArr[3])};
		      
		      double ans = Math.sqrt(Math.pow((p1[0] - p2[0]), 2) + Math.pow(p1[1] - p2[1], 2));
		      System.out.printf("%.4f\n",ans);
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
		
	}

}



Measured memory_bytes: 24844
# -*- coding: utf-8 -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
write = sys.stdout.write
# template


def solve():
    n,k=map(int, readline().split())
    a = list(map(int, readline().split()))
    b=[0]*(n+1)

    for i in range(n):
        b[i+1]=b[i]+a[i]-1
        b[i+1]%=k
    count=0
    from collections import defaultdict
    dp=defaultdict(list)
    for i in range(n+1):
        dp[b[i]].append(i)
    #print(dp,b)
    for item in dp:
        #print(count)
        if len(dp[item])<2:
            continue
        l=0
        r=1
        li=dp[item]
        while(l<len(li)):
            if l==r:
                r+=1
                continue
            if r<len(li) and li[r]-li[l]<k:
                r+=1
            else:
                count+=r-l-1
                l+=1
    print(count)

        
'''
    for i in range(k):
        if dp[i]<2:
            continue
        count+=dp[i]*(dp[i]-1)//2
'''
    


if __name__ == "__main__":
    solve()

Measured memory_bytes: 95512
#include<bits/stdc++.h>
using namespace std;
string a,b="CODEFESTIVAL2016";
int c=16;//全错
int main(){
    cin>>a;
    for(int i=0;i<16;i++)
    c-=(a[i]==b[i])?1:0;
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long k, std::string s){
    cout << s.substr(0, k);
    if(s.size() > k)
        cout << "...";
    cout << endl;
}


signed main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 3712