akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
public class Main {
    
    static int r,c;
    static char[][] a;
    static boolean canMove(int x, int y)
    {
        if(x < 0 || y < 0 || x >= r || y >= c || a[x][y] == '#' )
        {
            return false;
        }
        return true;
    }
    
    static class Pair
    {
        int x, y;
        Pair(int w, int z)
        {
            this.x = w;
            this.y = z;
        }
        public String toString()
        {
            return "("+this.x+","+this.y+")";
        }
    }
    
    public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      PrintWriter w = new PrintWriter(System.out);
      
      r = sc.nextInt(); c = sc.nextInt(); int sx = sc.nextInt()-1,sy = sc.nextInt()-1,ex = sc.nextInt()-1, ey = sc.nextInt()-1;
      a = new char[r][c];
      for(int i = 0; i < r; i++)
      {
          a[i] = sc.next().toCharArray();
      }
      
      
      int dist[][] = new int[r][c];
      for(int i = 0; i < r; i++)    Arrays.fill(dist[i],Integer.MAX_VALUE);
      dist[sx][sy] = 0;
      Deque<Pair> dq = new LinkedList<>();
      dq.addFirst(new Pair(sx,sy));
      int dx[] = new int[]{-1,1,0,0};
      int dy[] = new int[]{0,0,-1,1};
      while(!dq.isEmpty())
      {
          Pair temp = dq.removeFirst();
          int cx = temp.x, cy = temp.y;
          for(int i = 0; i < 4; i++)
          {
              int nx = cx + dx[i], ny = cy + dy[i];
              if(canMove(nx, ny))
              {
                  if(dist[nx][ny] > dist[cx][cy])
                  {
                      dist[nx][ny] = dist[cx][cy];
                      dq.addFirst(new Pair(nx, ny));
                  }
              }
          }
          for(int i = cx-2; i <= cx+2; i++)
          {
              for(int j = cy-2; j <= cy+2; j++)
              {
                  if(canMove(i,j))
                  {
                      if(dist[i][j] > (dist[cx][cy] + 1))
                      {
                          dist[i][j] = dist[cx][cy]+1;
                          dq.addLast(new Pair(i,j));
                      }
                  }
              }
          }
      }
      w.println(dist[ex][ey]==Integer.MAX_VALUE?-1:dist[ex][ey]);
      w.close();
    }
}

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

N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

c = list(map(int, input().split()))
c.sort(reverse = False)

tmp = len(graph[0])
start = 0
for index, x in enumerate(graph):
    if len(x) > tmp:
        tmp = len(x)
        start = index

ans = 0
ans_lst = [-1] * N
ans_lst[start] = c.pop()
stack = [start]
while stack:
    x = stack.pop()
    for next_ in graph[x]:
        if ans_lst[next_] == -1:
            tmp = c.pop()
            ans_lst[next_] = tmp
            stack.append(next_)
            ans += tmp

print (ans)
print (*ans_lst, sep = ' ')


Measured memory_bytes: 5916
import sys
import io
import math
import re

datalist = input().split()
data_a = int(datalist[0])
data_b = int(datalist[1])


if data_a - data_b >= 2:
  print(data_a*2-1)
elif data_b - data_a >= 2:
  print(data_b*2-1)
else:
  print(data_a+data_b)


Measured memory_bytes: 3188
import bisect
from collections import deque
def LIS(a):
    lis = deque()
    lis.append(-1)
    for i in range(len(a)):
        index = bisect.bisect_left(lis,a[i])
        if index == 0:
            lis.appendleft(a[i])
        else:
            lis[index-1] = a[i]
    return len(lis)

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    print(LIS(a))

if __name__ == "__main__":
    main()

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

int main() {
    int a, b;
    cin >> a >> b;
    string s1, s2;
    for (int i = 0; i < a; i++) {
        s1 += to_string(b);
    }
    for (int i = 0; i < b; i++) {
        s2 += to_string(a);
    }
    cout << min(s1, s2) << endl;
    return 0;
}


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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> p(N);
	int sum = 0;
	int ex = 0;
	for (int i = 0; i < N; i++) {
		int p;
		cin >> p;
		sum += p;
		ex = max(ex, p);
	}
	sum -= ex / 2;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>

#define LEN 100005


typedef struct pp{
  char name[100];
  int time;
}P;

P Q[LEN+1];

int head=0,tail=0,n;
void enqueue(P x){
  Q[tail]=x;
  if(tail+1==LEN)
    tail = 0;
  else
    tail++;

}
P dequeue(void){
  P x;
  
  x = Q[head];
  if(head+1==LEN)
    head=0;
  else
    head++;
  return x;
}
//int isEmpty(void);
//int isFull(void);

int main()
{
  int elaps = 0/*経過*/,j=1;
  int i,q;
  P u;
  scanf("%d%d",&n,&q);

  for(i=1;i<=n;i++){
    scanf("%s",u.name);
    scanf("%d",&u.time);
    enqueue(u);
  }
  while(1){
    u = dequeue();
    if(u.time<=q){
      elaps+=u.time;
      printf("%s %d\n",u.name,elaps);
      }

    else {
      elaps+=q;
      u.time-=q;
      enqueue(u);
    }
    if(head == tail)break;
    //printf("%s %d",Q[j].name,Q[j].time); 
  }
  return 0;

}



Measured memory_bytes: 12912
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






string S;
int N;
//---------------------------------------------------------------------------------------------------
// state
// =0:none
// =1:5
// =2:51
// =3:51? (?!=5)
// =4:515
// =5:51?3達成済み
ll memo[20][6][2];
ll f(int cu, int state, int isless) {
    if (cu == N) {
        if (state == 5) return 1;
        else return 0;
    }
    if (0 <= memo[cu][state][isless]) return memo[cu][state][isless];

    int c = S[cu] - '0';
    ll res = 0;
    rep(i, 0, 10) {
        if (!isless and c < i) continue;
        int nxisless = isless;
        if (i < c) nxisless = 1;

        if (state == 0) {
            if (i == 5) res += f(cu + 1, 1, nxisless);
            else res += f(cu + 1, 0, nxisless);
        }
        else if (state == 1) {
            if (i == 1) res += f(cu + 1, 2, nxisless);
            else if (i == 5) res += f(cu + 1, 1, nxisless);
            else res += f(cu + 1, 0, nxisless);
        }
        else if (state == 2) {
            if (i == 5) res += f(cu + 1, 4, nxisless);
            else res += f(cu + 1, 3, nxisless);
        }
        else if (state == 3) {
            if (i == 3) res += f(cu + 1, 5, nxisless);
            else if (i == 5) res += f(cu + 1, 1, nxisless);
            else res += f(cu + 1, 0, nxisless);
        }
        else if (state == 4) {
            if(i == 3) res += f(cu + 1, 5, nxisless);
            else if(i == 1) res += f(cu + 1, 2, nxisless);
            else if(i == 5) res += f(cu + 1, 1, nxisless);
            else res += f(cu + 1, 0, nxisless);
        }
        else if (state == 5) {
            res += f(cu + 1, 5, nxisless);
        }
    }

    return memo[cu][state][isless] = res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S;
    N = S.length();
    rep(cu, 0, N + 1) rep(state, 0, 6) rep(isless, 0, 2) memo[cu][state][isless] = -1;
    cout << f(0, 0, 0) << endl;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

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 kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}

ll n;



    vector<pair<ll,ll>>p;
void fs(ll a){
    for(ll i=2;i*i<=n;i++){
        ll cnt=0;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        p.emplace_back(i,cnt);
    }
    return;
}


int main()
{
ll x;
cin>>x;
for(ll i=-1000;i<=1000;i++){
    for(ll j=-1000;j<=1000;j++){
        ll a=pow(i,5);
        ll b=pow(j,5);
        if(a-b==x){
            cout<<i<<" "<<j<<endl;
            return 0;
        }
    }
}
}



Measured memory_bytes: 4064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a;
	for(int i=0;i<a.size();i++)
	{
		if(i!=5&&i!=13)
		{
			cout<<a[i];
		}
		else
		{
			cout<<' '; 
		} 
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
#define brep(i, st, n) for (int i = st; i >= n; --i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    int n; cin >> n;
    int a[3 * n]; rep(i, 3 * n) cin >> a[i];
    ll ans = -1e15;
    priority_queue<ll, vector<ll>, greater<ll> > v; //小さい順
    priority_queue<ll> vv;
    ll sum = 0;
    rep(i, n) {
        v.push(a[i]);
        sum += a[i];
    }
    ll sum2 = 0;
    brep(i, 3 * n - 1, 2 * n) {
        vv.push(a[i]);
        sum2 += a[i];
    }
    
    ll table[2][3 * n]; rep(i, 2) rep(j, 3 * n) table[i][j] = -1e15;
    table[0][n - 1] = sum;
    table[1][2 * n] = sum2;
    rrep(i, n, 2 * n) {
        sum += a[i];
        v.push(a[i]);
        sum -= v.top();
        table[0][i] = sum;
        //cout << v.top() << endl;
        v.pop(); //一番小さいの消した
        int key = 3 * n - 1 - i;
        
        sum2 += a[key];
        vv.push(a[key]);
        
        sum2 -= vv.top();
        vv.pop(); //忘れてた
        table[1][key] = sum2;
        
    }
    //rep(i, 2) {rep(j, 3 * n) cout << table[i][j] << " "; cout << endl;}
    rep(i, 3 * n - 1) {
        if (table[0][i] == -1e15 || table[1][i + 1] == -1e15) continue;
        ans = max(ans, table[0][i] - table[1][i + 1]);
    }
    cout << ans << endl;
}




Measured memory_bytes: 7796
#include <iostream>

using namespace std;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int a_sum = 0;
    int b_sum = 0;
    for (int i = 0; i < n; ++i) {
      int a, b;
      cin >> a >> b;
      if (a == b) {
        a_sum += a;
        b_sum += b;
      } else if (a < b) {
        b_sum += a + b;
      }
      else if (b < a) {
        a_sum += a + b;
      }
    }

    cout << a_sum << " " << b_sum << endl;
  }
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;

typedef long long ll;

const long long MOD = 1000000000 + 7;

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

//Union-Find tree
struct UnionFind{
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N;  i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る : root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { //xとyの木を併合
        int rx = root(x); //xの木の根をrx
        int ry = root(y); //yの木の根をyx
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)ときはそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時 : xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    ll cnt = 0;
    if(k<a){
        cout << k << endl;
        return 0;
    }else{
        cnt += a;
        k -= a;
    }
    if(k<b){
        cout << cnt << endl;
        return 0;
    }else{
        k -= b;
    }
    cout << cnt - k << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int max = 0;
  vector<int>data(s.size());
  for(int i = 0;i < s.size();i++){
    data[i] = s[i]-'0';
    max += data[i];
  }
  for(int i = 0;i < data.size()-1;i++){
    int sum = -1;
    if(data[i] == 0){
      continue;
    }
    for(int j = 0;j <= i;j++){
      sum += data[j];
    }
    sum += 9*(data.size()-i-1);
    if(sum > max) max = sum;
  }
  cout << max << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.length() % 2 != 0) {
            System.out.println("No");
            return;
        }
        for (int i = 0; i < s.length(); i+=2) {
            if (!s.substring(i, i + 2).equals("hi")) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 22996
import math
from functools import reduce

url = "https://atcoder.jp//contests/abc070/tasks/abc070_c"

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    count = int(input())
    clocks = []
    for i in range(count):
        clocks.append(int(input()))
    print(lcm(*clocks))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9524
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class AConnectionAndDisconnection {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    int calc(string s) {
        char prev = '-';
        int num = 0;
        int res = 0;
        REP(i, s.size()) {
            if (s[i] != prev) {
                res += num / 2;
                num = 1;
            } else {
                num++;
            }
            prev = s[i];
        }
        res += num / 2;
        return res;
    }

    void solve(std::istream& cin, std::ostream& cout) {
        string s;
        cin >> s;
        int K;
        cin >> K;

        if (K == 1 || s[0] != s[s.size() - 1]) {
            int n = calc(s);
            cout << n * K << endl;
            return;
        }

        string tmp = s + s;
        int pos = -1;
        FOR(i, 1, s.size() - 1) {
            if (s[i] != s[i - 1]) {
                pos = i;
                break;
            }
        }
        if (pos == -1) {
            cout << s.size() * K / 2 << endl;
            return;
        }
        auto ns = tmp.substr(pos, s.size());
        int n = calc(ns);
        int res = n * (K - 1);
        res += pos / 2;
        res += calc(s.substr(pos));
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    AConnectionAndDisconnection solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stack>
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
ll a, b, t;
int main()
{	
	while (~scanf("%lld%lld%lld", &a, &b, &t))
	{
		printf("%lld\n", t / a * b);
	}
}

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


int main(){
  string s;
  cin >> s;
  int a,b,c;
  a=0;
  b=0;
  c=0;
  for(int i=0;i<s.size();++i){
    if(s[i]=='a') a++;
    if(s[i]=='b') b++;
    if(s[i]=='c') c++;
  }
  if(abs(a-b)<=1 && abs(b-c)<=1 && abs(a-c)<=1){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int N, K, X, Y;

	scanf("%d", &N);
	scanf("%d", &K);
	scanf("%d", &X);
	scanf("%d", &Y);

	if (N - K == 0)
	{
		printf("%d\n", K*X);
	}
	else if (N - K < 0)
	{
		printf("%d\n", N*X);
	}
	else
	{
		printf("%d\n", (K*X) + (N - K)*Y);
	}

	return 0;
}

Measured memory_bytes: 128
n    = int(input())
a_s  = list(map(int, input().split()))
q    = int(input())
bc_s = [ list(map(int, input().split())) for _ in range(q) ]

s = sum(a_s)
m = { a: 0 for a in a_s }

for a in a_s:
    m[a] += 1

for b, c in bc_s:
    nb = m.get(b, 0)
    s += nb * (c - b)
    print(s)
    m[b] = 0
    m[c] = nb + m.get(c, 0)


Measured memory_bytes: 107408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n;cin>>n;
    vector<int> a(n+1),b(n+1),ans;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=n;i>=1;i--){
        int sum = 0;
        for(int j=i+i;j<=n;j+=i){
            sum ^= b[j];
        }
        b[i]=sum^a[i];
        if(b[i])ans.push_back(i);
    }
    cout<<ans.size()<<endl;
    rep(i,ans.size()){
        printf("%d%c",ans[i],i+1==ans.size()?'\n':' ');
    }
}

Measured memory_bytes: 3064
def depth(s):
    for i in ch[s]:
        dep[i] = dep[s]+1
        if len(ch[i]) != 0:
            depth(i)


def parent(t):
    for i in ch[t]:
        par[i] = t
        if len(ch[i]) != 0:
            parent(i)


n = int(input())
data = [list(map(int, input().split())) for _ in range(n)]


ch = {}
par = {}
dep = {}
kari = []
for i in range(n):
    kari.append(i)
#print(data)

for i in data:
    ch[i[0]] = list(i[2:])
    for j in list(i[2:]):
        kari.remove(j)


r = kari[0]
dep[r] = 0
par[r] = -1
#print(r)
#print(ans)
'''
for i in range(n):
    #print(i[0])
    try:
        par[i] = [k for k, v in ch.items() if i in v][0]
    except:
        par[i] = -1
        dep[i] = 0
        r = i
        '''

depth(r)
parent(r)


for i in range(n):
    if par[i] == -1:
        tmp = 'root'
    elif len(ch[i]) == 0:
        tmp = 'leaf'
    else:
        tmp = 'internal node'
    print('node {}: parent = {}, depth = {}, {}, {}'.format(i, par[i], dep[i], tmp, ch[i]))

#print(ch)
#print(par)
#print(dep)



Measured memory_bytes: 51512
#include <stdio.h>
#include <math.h>
int main(void){
  int d,e,x,y;
  double min,tmp;
  while(1){
    scanf("%d %d",&d,&e);
    if(!d)
      break;
    min=114514;
    for(x=0,y=d;y>=0;x++,y--){
      tmp=fabs(sqrt(x*x+y*y)-e);
      if(min>tmp)
	min=tmp;
    }
    printf("%f\n",min);
  }
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define MAX 10000007
#define PI acos(-1)
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define endl "\n"
#define MEM(a,x) memset(a,x,sizeof(a))

using namespace std;
typedef long long ll ;
const int inf= 1e9+7;
const int nmax = 1e5+10;

//priority_queue<int,vector<int>,greater<int>>pq; //ascending

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<long long,null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
{
    return (a.second<b.second);
}
*/
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.tie(NULL);
    int n,k,ans=0;
    cin>>n>>k;
    vector<int>v;
    map<int,int>mp;

    for(int i=0;i<n;i++)
    {
        int t;
        cin>>t;
        mp[t]++;
    }

    if((int)mp.size()<=k)cout<<0<<endl;
    else
    {
        for(auto i=mp.begin();i!=mp.end();i++)
            v.push_back(i->second);


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

    k=(int)mp.size()-k;

    for(int i=0;i<k;i++)ans+=v[i];

    cout<<ans<<endl;

    }


    return 0;
}


Measured memory_bytes: 10744
from fractions import gcd

A, B, C, D = map(int, input().split())
res = B - A + 1
CD = (C // gcd(C, D)) * D
# print(CD)
div_C = B // C - (A - 1) // C
# print(div_C)
div_D = B // D - (A - 1) // D
# print(div_D)
div_CD = B // (CD) - (A - 1) // (CD)

ans = res - (div_C + div_D - div_CD)
print(ans)


Measured memory_bytes: 5180
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String s1 = sc.next();
		if(s.compareTo(s1) == 0) {
			System.out.println("=");
		} else if(s.compareTo(s1) > 0) {
			System.out.println(">");
		} else {
			System.out.println("<");
		}
	}
}


Measured memory_bytes: 23764
def inp() a=gets.chomp.split(" ").map(&:to_i)end 
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b = na(a.max+1); a.each{|n|b[n]+=1};return b end
def na(n=0,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def uf(a,x)
  return x if (a[x] == x)
  a[x] = uf(a,a[x])
end
def ufa(a,x,p)
  root = a[x] = uf(a,x)
  conect = a[p] = uf(a,p)
  a[root] = conect
end
h = {}
n,k,l = inp
dk = na2(n+1,0)
da = na(n+1)
dl = na2(n+1,0)
db = na(n+1)
(n+1).times do |i|
  da[i] = i
  db[i] = i
end
(k).times do |i|
  d = inp
  ufa(da,d[1],d[0])
end
(l).times do |i|
  d = inp
  ufa(db,d[1],d[0])
end
(1..n).each do |i|
  uf(db,i)
  uf(da,(i))
end
(1..n).each do |i|
  h[[da[i],db[i]]] = 0 if(h[[da[i],db[i]]] == nil)
  h[[da[i],db[i]]] += 1
end
(1..n-1).each do |i|
  print "#{h[[da[i],db[i]]]} " 
end
puts h[[da[n],db[n]]]
=begin
max = c if max < c 
=end

Measured memory_bytes: 58132
import java.io.*;
import java.util.*;
import java.math.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int sum = 0;  
  
      	for ( int i=0; i<3; i++ ){
        	sum += sc.nextInt();
        }
        
      	if ( sum >= 22 ) System.out.println("bust");
      	else System.out.println("win");
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cctype>
using namespace std;

int main(){
	int n, m;
	while(cin >> n >> m && (n || m)){
		int total = 0;
		map<string, int> lot;
		for(int i = 0; i < n; i++){
			string s;
			int money;
			cin >> s >> money;
			lot[s] = money;
		}
		for(int j = 0; j < m; j++){
			string s;
			cin >> s;
			for(map<string, int>::iterator iter = lot.begin();
				iter != lot.end(); iter++)
			{
				string s2 = (*iter).first;
				int i = 7;
				while(i >= 0 && isdigit(s2[i]) && s2[i] == s[i]) i--;
				if(i < 0 || !isdigit(s2[i])) total += (*iter).second;
			}
		}
		cout << total << endl;
	}
	return 0;
}

Measured memory_bytes: 936
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
	char c, d;
	while(getchar()!=10);
	int ans=0;
	d=0;
	while((c=getchar())!=10){
		if(c!=d){
			ans++;
			d=c;
		}
	}
	printf("%d\n", ans);
}


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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    REP(i, N) {
        cin >> h[i];
    }
    int l = N - 1;
    int r = N - 1;
    int res = 0;
    for(int x = N - 2;0 <= x;x--) {
        if(h[x] >= h[x + 1]) {
            l--;
        }else{
            l = x;
            r = x;
        }
        res = max(res, r - l);
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
// nichijou
#define REP(i,a,b) for (int i(a); i < (b); ++i)
#define RP(i,n) REP(i,0,n)
#define PER(i,a,b) for(int i((a)-1); i >= (b); --i)
#define PR(i,n) PER(i,n,0)
#define REP1(i,a,b) REP(i,a,(b)+1)
#define RP1(i,n) REP1(i,1,n)
#define PER1(i,a,b) PER(i,(a)+1,b)
#define PR1(i,n) PER1(i,n,1)
#define DO(n) RP(__i,n)
template<class T,class U>
bool cmax(T & a, const U & b) {return a < b ? a = b, 1 : 0;}
template<class T,class U>
bool cmin(T & a, const U & b) {return b < a ? a = b, 1 : 0;}

// data type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define F first
#define S second

// STL container
typedef vector<int> vi;
typedef vector<ll> vll;
#define SZ(a) ((int)(a).size())
#define ALL(a) begin(a), end(a)
#define CLR(a) (a).clear()
#define BK(a) ((a).back())
#define FT(a) ((a).front())
#define DB(a) (a).pop_back()
#define DF(a) (a).pop_front()
#define PB push_back
#define EB emplace_back

/* I gave you my heart and then you turned around. */
void _BG(const char * s) {cerr<<s<<endl;};
template<class T, class ... TT>
void _BG(const char * s,T a, TT...b)
{
	for (int c = 0; *s && (c || *s != ','); ++s) {
		cerr<<*s;
		for (char x : "([{") c += *s == x;
		for (char x : ")]}") c -= *s == x;
	}
	cerr<<" = "<<a;
	if (sizeof...(b)) {
		cerr<<", ";
        ++s;
    }
    _BG(s,b...);
}
#define BG(...) do { \
	cerr << __PRETTY_FUNCTION__ << ':' << __LINE__ << ": "; \
	_BG(#__VA_ARGS__,__VA_ARGS__); \
} while(0)

/* Reading input is now 20% cooler! */
bool RD() {return 1;}
bool RD(char & a) {return scanf(" %c", &a) == 1;}
bool RD(char * a) {return scanf("%s", a) == 1;}
bool RD(double & a) {return scanf("%lf", &a) == 1;}
bool RD(int & a) {return scanf("%d", &a) == 1;}
bool RD(ll & a) {return scanf("%lld", &a) == 1;}

template<class T, class ... TT>
bool RD(T & a, TT & ... b) {return RD(a) && RD(b...);}

/* Do princesses dream of magic sheep? */
#define DR(T,...) T __VA_ARGS__; RD(__VA_ARGS__)
#define RI(...) DR(int,__VA_ARGS__)

/* For it's time for you to fulfill your output. */
void PT(const char & a) {putchar(a);}
void PT(char const * const & a) {fputs(a, stdout);}
void PT(const double & a) {printf("%.16f", a);}
void PT(const int & a) {printf("%d", a);}
void PT(const ll & a) {printf("%lld", a);}

/* The line will last forever! */
template<char s = ' ', char e = '\n'>
void PL() {if (e) PT(e);}
template<char s = ' ', char e = '\n', class T, class ... TT>
void PL(const T & a, const TT & ... b)
{PT(a); if (sizeof...(b) && s) PT(s); PL<s,e>(b...);}

/* Good Luck && Have Fun ! */
int main()
{
    ll x,y;
    RD(x,y);
    int ans = 1;
    while (x * 2 <= y)
        ++ans, x *= 2;
    PL(ans);
}


Measured memory_bytes: 256
N = int(input())
T_l = [int(i) for i in input().split()]
M = int(input())
PX = [[int(i) for i in input().split()] for j in range(M)]

P = [i[0] for i in PX]
X = [i[1] for i in PX]

for i in range(M):
    print(sum(T_l) - T_l[P[i]-1] + X[i])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

bool ifprime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=2;i*i<=x;i++){if(x%i==0)return false;}
    return true;
}
ll mod(ll x, ll y){if(x>=0||x%y==0) return x%y;return y+x%y;} //mod including minus
ll dv0(ll x, ll y){if(x>=0||x%y==0)return x/y;return x/y-1;} //rnd down
ll dv1(ll x, ll y){if(x%y==0) return dv0(x,y);return dv0(x,y)+1;} //rnd up

//Start from Here
int main(){
    int N, Q;
    cin>>N>>Q;
    vector<int> G[N];
    int a, b;
    rep(i, N-1){
        cin>>a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    int p, x,r[N];
    rep(i, N){
        r[i]=0;
    }
    rep(i, Q){
        cin>>p>>x;
        r[p-1]+=x;
    }
    queue<int> R;
    R.push(0);
    int n;
    int s[N];
    rep(i, N){
        s[i]=0;
    }
    s[0]=1;
    while(!R.empty()){
        n=R.front();
        R.pop();
        rep(i, G[n].size()){
            if(s[G[n].at(i)]!=1){
                r[G[n].at(i)]+=r[n];
                s[G[n].at(i)]=1;
                R.push(G[n].at(i));
            }
        }
    }
    rep(i, N){
        if(i==0){
            cout<<r[i];
        }else{
            cout<<" "<<r[i];
        }
    }
    cout<<endl;
}

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

ll N,K;
ll A[110000];

int main()
{
	cin >> N >> K;
	for(int i=0;i<N;++i) cin >> A[i];

	ll arg = 0; // fを最大化するarg

	// 制約以下の可能な全てのargを探索 - fの最大化を各桁で行う。
	// 10^12 < 2^40なので、桁ごとのビットを観察すれば40回の探索
	for(int i=40;0<=i;i--){
		int count = 0; // Aのなかで、i桁目のビットが立ってる物の数
		for(int j=0;j<N;++j){
			if(A[j] & (1LL<<i)){ // iけためのbitが立ってるAの数を数える
				count++;
			}
		}
		// i桁めのbitをたてた時のfの値への貢献度が、たてなかった時より大きい。 -> i桁めのbitが立ってるAの数(xorでその桁のbitが0)
		// & argのi桁目のbitを立てた値K未満であるなら argのi桁目を立てる
		if( count <= N - count && (arg|(1LL<<i)) <= K){
			arg |= (1LL<<i);
		}
	}

	ll ans = 0;
	for(int i=0;i<N;++i){
		ans += arg ^ A[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		TreeSet<Character> ts = new TreeSet<>();
		String s = scan.next();
		for (int i = 0; i < s.length(); i++) {
			ts.add(s.charAt(i));
		}
		if (ts.size() == s.length()) {
			System.out.println("yes");
		} else {
			System.out.println("no");
		}
	}

}

Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
using namespace std;
int p[100001];

int main(){
  int n;
  cin>>n;
for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    p[a]=i;
}
for(int i=1;i<=n;i++)
{
    cout<<p[i]<<' ';
}
}

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

max_a, min_a = max(a), min(a)
cnt = [0] * (max_a + 1)
for i in range(n):
    cnt[a[i]] += 1
    if a[i] > min_a:
        cnt[a[i]-1] += 1
    if a[i] < max_a:
        cnt[a[i]+1] += 1

print(max(cnt))

Measured memory_bytes: 20704
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll Pow_mod(ll a, ll b, ll p){
    ll ans = 1;
    a %= p;
    while (b){
        if (b & 1) ans = (ans * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return (ans % p);
}

const int N = 1e5 + 10;

int n;

struct Student{
    int a;
    int idx;
}s[N];

inline bool cmp(const Student &s1, const Student &s2){
    return s1.a < s2.a;
}

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i ++ ){
        scanf("%d", &s[i].a);
        s[i].idx = i;
    }
    sort(s + 1, s + n + 1, cmp);
    for (int i = 1; i < n; i ++ )
        printf("%d ", s[i].idx);
    printf("%d\n", s[n].idx);
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<stack>
#include<cctype>
#include<cstdlib>
using namespace std;

int main(void){
	stack<int> st;
	string ch;
	while(cin >> ch){
		if(isdigit(ch[0])){
			st.push(atoi(ch.c_str()));
		}
		else{
			int a = st.top();
			st.pop();
			int b = st.top();
			st.pop();
			if(ch == "+") st.push(b + a);
			if(ch == "-") st.push(b - a);
			if(ch == "*") st.push(b * a);
		}
	}
	cout << st.top() << endl;
	return 0;
}


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

#define ll long long
#define ull unsigned long long

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	int in, total = 0;
	for (int i=0; i<b; i++)
	{
		cin >> in;
		total += in;
	}
	if (a - total < 0) cout << -1;
	else cout << a-total;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
        class Node<T>
        {
            private int m_height;
            private Node<T> m_parent;
            public T Item { get; private set; }
            public Node(T item)
            {
                m_height = 0;
                m_parent = this;
                Item = item;
            }
            public Node<T> Find()
            {
                if (m_parent == this) { return this; }

                Node<T> parent = m_parent.Find();
                m_parent = parent;
                return parent;
            }
            public static void Unite(Node<T> a, Node<T> b)
            {
                Node<T> p = a.Find();
                Node<T> q = b.Find();
                if (p.m_height < q.m_height)
                {
                    p.m_parent = q;
                    q.m_height = Math.Max(p.m_height + 1, q.m_height);
                }
                else
                {
                    q.m_parent = p;
                    p.m_height = Math.Max(q.m_height + 1, p.m_height);
                }
            }
        }

        static int Solve(int N, int M, int[][] infos)
        {
            var nodes = new Node<int>[N];
            for (int i = 0; i < N; ++i) { nodes[i] = new Node<int>(i); }
            foreach (int[] info in infos)
            {
                int x = info[0] - 1;
                int y = info[1] - 1;
                Node<int>.Unite(nodes[x], nodes[y]);
            }
            var set = new HashSet<int>();
            foreach (var node in nodes) { set.Add(node.Find().Item); }
            return set.Count;
        }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int N = V[0], M = V[1];
            var infos = new int[M][];
            for (int i = 0; i < M; ++i) { infos[i] = ReadInts(); }
            Console.WriteLine(Solve(N, M, infos));
        }
    }
}


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

int n, m;
int WA[105000];
bool AC[105000];
void solve(){
	cin >> n >> m;
	int WAnum = 0;
	int ACnum = 0;
	for (int i = 1;i <= n;++i) {
		WA[i] = 0;
		AC[i] = false;
	}
	while (m--) {
		int p;
		string s;
		cin >> p >> s;
		if (AC[p])continue;
		if (s == "AC") {
			AC[p] = true;
			ACnum++;
			WAnum += WA[p];
		}
		else if (s == "WA") {
			WA[p]++;
		}
	}
	cout << ACnum << " " << WAnum << endl;
	return;
}

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

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

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

  for (int i = a.at(1); i > 1; i--) {
    bool found = false;
    bool notCorrect = false;
    for (int j = 0; j < n; j++) {
      int v = a.at(j);
      if (v%i == 0) {
        continue;
      }
      if (found) {
        notCorrect = true;
        break;
      }
      found = true;
    }
    if (!notCorrect) {
      cout << i << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
typedef pair<int, int> P;

int dm[2] = {-1, 1}, dn[2] = {-1, 1};

void solve() {
    int p, q;
    cin >> p >> q;
    set<P> S;
    for (int i = 1; i * i <= p * p + q * q; i++) {
        // i=m^2+n^2
        for (int m = 0; m * m <= i; m++) {
            int n = sqrt(i - m * m);
            if (m * m + n * n != i) continue;
            for (int j = 0; j < 2; j++) {
                for (int k = 0; k < 2; k++) {
                    int now_m = dm[j] * m;
                    int now_n = dn[k] * n;
                    int number1 = now_m * p + now_n * q;
                    int number2 = now_m * q - now_n * p;
                    if (number1 % i == 0 && number2 % i == 0) {
                        S.insert(P(now_m, now_n));
                    }
                }
            }
        }
        if (i * i == p * q) continue;
        int now_i = (p * p + q * q) / i;
        for (int m = 0; m * m <= now_i; m++) {
            int n = sqrt(now_i - m * m);
            if (m * m + n * n != now_i) continue;
            for (int j = 0; j < 2; j++) {
                for (int k = 0; k < 2; k++) {
                    int now_m = dm[j] * m;
                    int now_n = dn[k] * n;
                    int number1 = now_m * p + now_n * q;
                    int number2 = now_m * q - now_n * p;
                    if (number1 % now_i == 0 && number2 % now_i == 0) {
                        S.insert(P(now_m, now_n));
                    }
                }
            }
        }
    }
    if (S.size() == 8) cout << 'P' << endl;
    else cout << 'C' << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    for (int i = 0; i < T; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3132
N = map(int, input().split())
H = list(map(int, input().split()))
pre = 0
count = 0

for i in H :
    if pre <= i:
        pre = i
        continue
    else:
        c = i+1
        if pre <= c:
            pre = pre
            continue
        else:
            pre = c
            count += 1

if count == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include<stdio.h>
#define N 100


int main(){
  int i,j,n,num=0,tmp,A[N];

  scanf("%d",&n);
  for(i=0 ; i<n ; i++){
    scanf("%d",&A[i]);
  }

 for(i=0 ; i<n-1 ; i++){
    for(j=n-1 ; j>i ; j--){
      if(A[j]<A[j-1]){
	tmp=A[j];
	A[j]=A[j-1];
	A[j-1]=tmp;
	num++;
      }
    }
  }
  for(i=0 ; i<n ; i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
   
  }
  
  printf("\n");
  printf("%d\n",num);

  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
void solve(long long N, std::vector<long long> B){
  ll ans = B[0];
  for (int i = 0; i < N-2; i++) {
    ans += min(B[i],B[i+1]);
  }
  ans += B[N-2];
  cout << ans << endl;
}

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]);
	}
    solve(N, std::move(B));
}


Measured memory_bytes: 256
n,k = map(int, input().split())
x = list(map(int, input().split()))
ans = 10 ** 9
for i in range(n-k+1):
  a = abs(x[i+k-1] - x[i])
  ans = min(ans,min(abs(x[i+k-1])+a,abs(x[i])+a))
print(ans)


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

int main()
{
  int n,c=0;
  cin >> n;
  int ar[n];
  for(int i=1;i<=n;i++)
  {
    cin >> ar[i];
  }
  
  for(int i=1;i<=n;i++)\
  {
    if((i%2!=0) && (ar[i]%2!=0))
      c++;
  }
  
  cout << c;
  return 0;
}

Measured memory_bytes: 3560
using System;
using System.Collections.Generic;

namespace AtTest.ABC_105
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            input = Console.ReadLine().Split(' ');
            var array = new int[n];
            var sums = new int[n];
            for (int i = 0; i < n; i++)
            {
                array[i] = int.Parse(input[i]) % m;
                if (i == 0)
                {
                    sums[i] = array[i] % m;
                }
                else
                {
                    sums[i] = (sums[i - 1] + array[i]) % m;
                }
            }

            var marginDict = new Dictionary<int, int>();
            marginDict.Add(0, 1);
            long cnt = 0;
            for(int i = 0; i < n; i++)
            {
                if (marginDict.ContainsKey(sums[i]))
                {
                    cnt += marginDict[sums[i]];
                    marginDict[sums[i]]++;
                }
                else
                {
                    marginDict.Add(sums[i], 1);
                }
            }

            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 20448
import Data.Char

main = do
  input_line <- getLine
  let input = words input_line
  let a = read (input!!0) :: Int
  let b = read (input!!1) :: Int
  let c = read (input!!2) :: Int
  putStrLn $ if a + b == c || a + c == b || b + c == a
      then "Yes" else "No"

Measured memory_bytes: 508
#include <cstdio>



int main() {
    char ch;
    for (int i = 1; i <= 5; i++) {
        ch = fgetc(stdin);
        fputc(ch, stdout);
    }
    ch = fgetc(stdin);
    char space = ' ';
    fputc(space, stdout);
    for (int i = 1; i <= 7; i++) {
        ch = fgetc(stdin);
        fputc(ch, stdout);
    }
    ch = fgetc(stdin);
    space = ' ';
    fputc(space, stdout);
    for (int i = 1; i <= 5; i++) {
        ch = fgetc(stdin);
        fputc(ch, stdout);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

bool f(int r, int g, int b) {
    return (r * 100 + g * 10 + b) % 4 == 0; 
}

int main() {

    int r, g, b;
    cin >> r >> g >> b;

    if (f(r, g, b)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

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

    string s; cin >> s;
    int n = s.size();
    ll k; cin >> k;
    if (s == string(n, s[0])) {
        cout << n * k / 2 << endl;
    } else {
        int ans1 = 0;
        for (int i = 0; i + 1 < n; i++) {
            if (s[i] == s[i+1]) {
                ans1++;
                i++;
            }
        }
        int ans2 = 0;
        for (int i = 0; i + 1 < 2 * n; i++) {
            if (s[i%n] == s[(i+1)%n]) {
                ans2++;
                i++;
            }
        }
        cout << ans1 + (ans2 - ans1) * (k - 1) << endl;
    }
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[55],p[55];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
        int cnt;
    LL k=0;
    while(1) {
        cnt=0;
        for(int i=1;i<=n;i++)
            if(a[i]<n) cnt++;
        if(cnt==n) break;
        LL sum=0;
        for(int i=1;i<=n;i++) {
            p[i]=a[i]/n;
            sum+=p[i];
        }
        k+=sum;
        for(int i=1;i<=n;i++) {
            a[i]=a[i]-n*p[i]+(sum-p[i]);
        }
    }
    printf("%lld\n",k);
    return 0;
}

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

int main(){
	vector<int> a;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) a.push_back(i);
	do{
		cout<<a[0];
		for(int i=1;i<n;i++) cout<<" "<<a[i];
		cout<<endl;
	}while(next_permutation(a.begin(),a.end()));
	return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
     
int main(){
  int n,a;
  cin >> n >>a;
  
  int mod = n%500;
  
  if(mod <=a){
    cout << "Yes" << endl;
  }
  
  else{
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
A,B = map(int,input().split())

p = 1


if A > B:
    for y in range(100000000):
        e = (A * p) % B
        o = (A * p)
        if e == 0:
            print(int(o))
            break
        else:
            p += 1
else:
    for r in range(100000000):
        e = (B * p) % A
        o = (B * p)
        if  e == 0:
            print(int(o))
            break
        else:
            p += 1

Measured memory_bytes: 3064