akhauriyash/Code-Regression huggingface dataset:
import itertools,math
A = [int(input()) for _ in range(5)]
p = 2 ** 10 - 1
tens = 0
for i in range(5):
    if 0 < A[i] % 10 < p:
        p = A[i] % 10
    tens += math.ceil(A[i]/10)
if p == 2 ** 10 - 1:
    print(tens * 10)
else:
    print((tens-1) * 10 +p)

Measured memory_bytes: 3060
use std::io::{BufRead, Write};
use std::io;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut s = String::new();
    input.read_line(&mut s).unwrap();
    s.clear();
    input.read_line(&mut s).unwrap();
    let a: Vec<i64> = s.split_whitespace().map(|s| s.parse().unwrap()).collect();
    let sum: i64 = a.iter().sum();
    let mut acc = 0;
    let result = (1..a.len())
        .map(|x| {
            acc += a[x - 1];
            (acc * 2 - sum).abs()
        })
        .min()
        .unwrap();
    writeln!(output, "{}", result).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }
    #[test]
    fn case1() {
        test(
            "6
1 2 3 4 5 6\n",
            "1\n",
        );
    }
    #[test]
    fn case2() {
        test(
            "2
10 -10\n",
            "20\n",
        );
    }
}


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

typedef long long ll;

pair<int,int> pt[100010];
ll ret;
bool vis[100010];
vector<pair<int,int>> vx, vy;
set<pair<int,int>> sx, sy;
map<pair<int,int>, int> id;

int main() {
    int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
    a--,b--;

	for(int i = 0; i<n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		pt[i] = make_pair(x-y, x+y);
		sx.insert(make_pair(x-y, x+y));
		sy.insert(make_pair(x+y, x-y));
		vx.push_back(make_pair(x-y, x+y));
		vy.push_back(make_pair(x+y, x-y));		
		id[pt[i]] = i;
	}

	sort(vx.begin(),vx.end());
	sort(vy.begin(),vy.end());

	int d = max(abs(pt[a].first-pt[b].first), abs(pt[a].second-pt[b].second));

	queue<int> que;
	que.push(a);
	que.push(b);

	while (!que.empty()) {
		int v = que.front(); que.pop();
		if (vis[v]) continue;
		vis[v] = true;

		int x = pt[v].first, y = pt[v].second;

		auto it = sx.lower_bound(make_pair(x-d, y-d));

		while (it != sx.end()) {
			if (it->first != x-d || it->second > y+d) break;
			que.push(id[*it]);
			it = sx.erase(it);
		}

		it = sx.lower_bound(make_pair(x+d, y-d));
		while (it != sx.end()) {
			if (it->first != x+d || it->second > y+d) break;
			que.push(id[*it]);
			it = sx.erase(it);
		}

		it = sy.lower_bound(make_pair(y-d, x-d));

		while (it != sy.end()) {
			if (it->first != y-d || it->second > x+d) break;
			que.push(id[make_pair(it->second, it->first)]);
			it = sy.erase(it);
		}

		it = sy.lower_bound(make_pair(y+d, x-d));
		while (it != sy.end()) {
			if (it->first != y+d || it->second > x+d) break;
			que.push(id[make_pair(it->second, it->first)]);
			it = sy.erase(it);
		}
	}

	for(int i = 0; i<n; i++){
        if(!vis[i])
            continue;
		int x = pt[i].first, y = pt[i].second;

		int rr = ret;
		auto it = lower_bound(vx.begin(), vx.end(), make_pair(x-d, y-d));
		auto it2 = upper_bound(vx.begin(), vx.end(), make_pair(x-d, y+d));
		ret += it2 - it;

		it = lower_bound(vx.begin(), vx.end(), make_pair(x+d, y-d));
		it2 = upper_bound(vx.begin(), vx.end(), make_pair(x+d, y+d));
		ret += it2 - it;

		it = lower_bound(vy.begin(), vy.end(), make_pair(y-d, x-d));
		it2 = upper_bound(vy.begin(), vy.end(), make_pair(y-d, x+d));
		ret += it2 - it;

		it = lower_bound(vy.begin(), vy.end(), make_pair(y+d, x-d));
		it2 = upper_bound(vy.begin(), vy.end(), make_pair(y+d, x+d));
		ret += it2 - it;

		if (id.count(make_pair(x-d, y-d))) --ret;
		if (id.count(make_pair(x-d, y+d))) --ret;		
		if (id.count(make_pair(x+d, y-d))) --ret;		
		if (id.count(make_pair(x+d, y+d))) --ret;	
	}

	printf("%lld\n", ret / 2);

	return 0;
}


Measured memory_bytes: 18664
gets
t = ARGF.map(&:to_i)
max2 = max = 0
t.each do |d|
  if(d > max)
    max2 = max
    max = d
    next
  end
  if(d > max2)
    max2 = d
  end
end
t.each do |d|
  if(d!=max)
    puts max
  else
    puts max2
  end
end


Measured memory_bytes: 4732
s = list(map(int, input().split(" ")))

a = s[0]
b = s[1]
m = s[2]

a_l = list(map(int, input().split(" ")))
b_l = list(map(int, input().split(" ")))

ans = min(a_l) + min(b_l)

for i in range(m):
    x = list(map(int, input().split(" ")))
    if ans > (a_l[x[0] - 1] + b_l[x[1] -1] - x[2]):
        ans = a_l[x[0] -1] + b_l[x[1] -1] - x[2]


print(ans)

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

int main() {
  int number[200];
  int n;
  int flag =0;
  int count=0;
  
  cin >> n;
  
  for(int i=0; i<n; i++)
  {
    cin >> number[i];
  }
 
  for(int i=0; i<n; i++)
  {
    if( number[i]%2 ==1)
      flag = 1;

  }
  while(flag != 1){
    
  for(int i=0; i<n; i++)
  {
    if( number[i]%2 ==1)
      flag = 1;
   

  }
     if(flag == 1)
      break;
  
  for(int i=0; i<n ; i++)
  {
    number[i] = number[i]/2;
  }
    count++;
  
  }
  cout << count;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll p,q,r;
  cin >> p >> q >> r;
  ll ans = p+q;
  CHMIN(ans,q+r);
  CHMIN(ans,p+r);
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 256
//SkGeN
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<climits>
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;
const int N = 2 * 1e5 + 10;
const ll inf = 1e18 + 100;
const ll mod = 1e9 + 7;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve() {
    ll n;
    cin>>n;
    vector<vector<ll>> dp (10,vector<ll>(10, 0));

    for(int i = 1; i <= n ;i++) {
        ll pp = 1 , x = i;

        while(x > 9) {
            x = x / 10;
            pp *= 10;
        }
        //cout<<i/pp<<" "<<i%10<<"\n";
        dp[i/pp][i%10]++;
    }

    ll ans =0 ;
    for(int i = 1 ; i < 10 ; i++) {
        for(int j = 1; j < 10 ;j++) {

            ans += dp[i][j] * dp[j][i];
        }

    }

    cout<<ans<<"\n";

}
int main()
{
    DANGER;
    ll t = 1;
    //cin>>t;
    while(t--) {
        solve();
    }
return 0;
}
//---->O ,,

Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 1e5 + 20 ;
int n , m , k , x[N] , st ;

struct mat {
	int a[N] ;
	mat () {
		for (int i = 0 ; i < N ; i ++) a[i] = i ;	
	}
} mt ;

mat operator * (mat a , mat b) {
	mat c ;
	for (int i = 0 ; i < n ; i ++) c.a[i] = a.a[b.a[i]] ;
	return c ;
}

mat operator ^ (mat a , int b) {
	mat res ;
	while (b) {
		if (b & 1) res = res * a ;
		a = a * a ;
		b >>= 1 ;
	}
	return res ;
}

int32_t main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;

	cin >> n ;
	for (int i = 0 ; i < n ; i ++) cin >> x[i] ;
	st = x[0] ;
	
	n -- ;
	for (int i = 0 ; i < n ; i ++) x[i] = x[i + 1] - x[i] ;

	cin >> m >> k ;
	while (m --) {
		int x ;
		cin >> x ;
		x -= 2 ;
		swap(mt.a[x] , mt.a[x + 1]) ;
	}

	mt = mt ^ k ;

	for (int i = 0 ; i <= n ; i ++) {
		cout << st << '\n' ;	
		st += x[mt.a[i]] ;
	}
}


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

int main(){
  int64_t X;
  cin >> X;
  int64_t A,B;
  bool end = false;
  // + +
  for(A=0; pow(A,5)<=X; A++){
    int64_t Apow = pow(A,5);
    for(B=0; Apow+pow(B,5)<=X; B++){
      if(A<B)
        break;
      if(Apow + pow(B,5) == X){
        end = true;
        cout << A << " " << -1*B << endl;
        break;
      }
    }
    if(end)
      break;
  }
  if(end)
    return 0;
  // + -
  for(A=0; pow(A,5)-pow(A-1,5)<=X; A++){
    int64_t Apow = pow(A,5);
    for(B=0; B<A; B++){
      if(Apow - pow(B,5) == X){
        end = true;
        cout << A << " " << B << endl;
        break;
      }
    }
    if(end)
      break;
  }
  
}

Measured memory_bytes: 4100
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
     Scanner scan = new Scanner(System.in);
     int a = scan.nextInt();
     int b = scan.nextInt();
     int c = scan.nextInt();
     if( a < b && b < c){
         System.out.println("Yes");
     }else{
         System.out.println("No");
     }
    }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
ll a[200000+10];
ll n, k;
bool p(ll x){
    ll tmp = k;

    REP(i,n){
        tmp -= ((a[i]+x-1) / x -1);
    }
    return tmp >= 0;
}

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

    cin >> n >> k;
    REP(i,n) cin >> a[i];
    sort(a,a+n);
    ll lef = 0;
    ll rig = a[n-1];

    while(rig-lef>1){
        ll mid = (lef+rig) / 2;
        if(p(mid)) rig = mid;
        else lef = mid;
    }

    cout << rig <<endl;





    
    return 0;
}



Measured memory_bytes: 5092
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <limits>
#include <map>

using namespace std;

int main(){
    int n;
    string tmps;
    cin >> n;
    map<string,int> vs;
    for(int i=0;i < n;i++){
        cin >> tmps;
        vs[tmps]++;
    }
    int maxnum=0;
    for(const auto& e:vs){
       maxnum=max(maxnum,e.second);
    }
    for(const auto& e:vs){
        if(e.second == maxnum) cout<<(e.first)<<endl;
    }

    return 0;
}

Measured memory_bytes: 25216
#include "bits/stdc++.h"
#include <unordered_set>

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define INF 1000000000
#define PI 3.14159265358979323846

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<LL> vll;
//==============================================
int cnt = 0;

void merge(vi &A, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;

	vi L(n1);
	vi R(n2);

	copy(A.begin() + left, A.begin() + mid, L.begin());
	copy(A.begin() + mid, A.begin() + right, R.begin());

	L.push_back(INF + 5);
	R.push_back(INF + 5);

	auto itL = L.begin();
	auto itR = R.begin();

	for (auto itA = A.begin() + left; itA != A.begin() + right; itA++) {
		cnt++;
		if (*itL <= *itR) {
			*itA = *itL;
			itL++;
		} else {
			*itA = *itR;
			itR++;
		}
	}
}

void mergeSort(vi &A, int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);

		merge(A, left, mid, right);
	}
}

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

	int n;
	cin >> n;

	vi A(n);
	REP(i, n) cin >> A[i];

	mergeSort(A, 0, n);

	REP(i, n) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << "\n";

	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 8836
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		double total = 0;
		for (int i = 1; i <= n; i++) {
		    double base = 1 / (double)n;
		    int start = i;
		    while (start < k) {
		        base /= 2;
		        start *= 2;
		    }
		    total += base;
		}
		System.out.println(java.math.BigDecimal.valueOf(total).toPlainString());
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define Sz(a) ((int)(a).size())
const int maxn = 200009;
const int MOD = 1e9 + 7;
int main(){
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int x,y;cin>>x>>y;
  int b=(y-2*x)/2,a=x-b;
  if(a>=0&&b>=0&&a+b==x&&2*a+4*b==y){
    cout<<"Yes\n";
  }else{
    cout<<"No\n";
  }
  
  return 0;
}
//2020.06.14 20:26:14


Measured memory_bytes: 3644
from fractions import gcd
m = int(input())
P = [list(map(int, input().split())) for _ in range(m)]
tmp = {}
for i, pi in enumerate(P):
    for j, pj in enumerate(P):
        if i == j:
            break
        x = pi[0] - pj[0]
        y = pi[1] - pj[1]
        k = (x / gcd(x, y), y / gcd(x, y))
        if k in tmp:
            tmp[k].append([pi, pj])
        else:
            tmp[k] = [[pi, pj]]

dic = {}
for t in tmp:
    if len(tmp[t]) == 1:
        continue
    dic[t] = tmp[t]

ans = 0 
for d1 in dic:
    line1 = []
    line1.append(dic[d1])
    used1 = [p for pp in dic[d1] for p in pp]
    for d2 in dic:
        tmp = []
        for t in dic[d2]:
            if t[0] in used1 or t[1] in used1:
                continue
            tmp.append(t)
        if 1 == len(tmp):
            continue
        line2 = line1 + [tmp]
        used2 = used1 + [p for pp in tmp for p in pp]

        for d3 in dic:
            tmp = []
            for t in dic[d3]:
                if t[0] in used2 or t[1] in used2:
                    continue
                tmp.append(t)
            if 1 == len(tmp):
                continue
            line3 = line2 + [tmp]
            used3 = used2 + [p for pp in tmp for p in pp]

            for d4 in dic:
                tmp = []
                for t in dic[d4]:
                    if t[0] in used3 or t[1] in used3:
                        continue
                    tmp.append(t)
                    if 1 == len(tmp):
                        continue
                line4 = line3 + [tmp]
                anstmp = 0
                for l in line4:
                    anstmp += len(l) * (len(l) - 1) / 2
                ans = max(anstmp, ans)
print(int(ans))
                        



Measured memory_bytes: 7016
import Control.Monad
import Data.List

main :: IO()
main = do
    n <- readLn
    lis <- replicateM n getLine
    --replicateM n getLine←これ使う
    --let list = scan n
    if siritori lis (n-1)
        then let list = sort lis in if loop list (n-1) then putStrLn "Yes" else putStrLn "No"
        else putStrLn "No" 

{-
scan :: String -> IO [String]
scan 0 = return []
scan n = do
    w <- getLine
    l <- scan $ n-1
    return w:l
-}


loop :: [String] -> Int -> Bool
loop list n
    | ( n == 0 ) = True
    | (list !! n) == (list !! (n-1)) = False
    | otherwise = loop list (n-1)
{-
elemm :: (Eq a) => a -> [a] -> Bool
elemm a [] = False
elemm a (x:xs)
    | ( x == a ) = True
    | otherwise = elemm a xs
-}


siritori :: [String] -> Int -> Bool
siritori list n
    | ( n == 0 ) = True
    | last (list !! (n-1)) /= head (list !! n) = False
    | otherwise = (siritori list (n-1))

Measured memory_bytes: 636
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b , c = MAP()
d = (a-b)
# print(c-d)
if c-d <= 0:
    print(0)
else:
    print(c-d)
# print(c)




Measured memory_bytes: 5712
#include <stdio.h>

int main(void)
{
    int r;
    int c;
    int cell[101][101] = {0};

    scanf("%d %d", &r, &c);

    for ( int i = 0; i < r; i++ ) {
        for ( int j = 0; j < c; j++ ) {
            scanf("%d", &cell[i][j]);
        }
    }

    for( int i = 0; i < r; i++ ) {
        for ( int j = 0; j < c; j++ ) {
            cell[i][c] += cell[i][j];
            cell[r][j] += cell[i][j];
        }
    }

    for ( int j = 0; j < c; j++ ) {
        cell[r][c] += cell[r][j];
    }

    for ( int i = 0; i <= r; i++ ) {
        for ( int j = 0; j <= c; j++ ) {
            printf("%d", cell[i][j]);
            if ( j == c ) {
                printf("\n");
            } else {
                printf(" ");
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{	int N, K ,sum;
 	cin >> N >> K;
 
 	for(int i = 0;i < N;i++){
     int x;
     cin >> x;
       if(K >= 2*x){
         sum += 2*x;
       }
       else if(K < 2*x){
         sum += 2*(K - x);
      }
    }
 cout << sum << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using vv = vector<V<T>>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int n;
  cin >> n;
  int a = n;
  int d = 0;
  for(;a>0;a/=10){
    d += a%10;
  }
  cout << (n%d==0?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
typedef long long ll;
using namespace std;

int main(void){
  int w[100];
  int n,i,t,sum=0,min=1000000;

  cin>>n;
for(i=0;i<n;i++){
  cin>>w[i];
  sum+=w[i];
}

t=0;
int d;

for(i=0;i<n;i++){
  t+=w[i];
  if(min>abs(sum-2*t)){
    min=abs(sum-2*t);
  }
}

  cout<<min<<endl;

	return 0;
}

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    ll N,A,B;
    cin >> N >> A >> B;
    ll ans = (N/(A+B))*A;
    ll md = N%(A+B);
    ans+=min(A,md);
    cout << ans << endl;

}

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


Measured memory_bytes: 256
//b
#include <iostream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <functional>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>

#define REP(i,b,n) for(int i=b;i<n;i++)
#define REPR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PB push_back
#define MP make_pair

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;

int n;
int s[400], l[400], p[400];
int seg = 0;
int m;
int w[400];
queue<int> res;

int dp[400][400];

bool solve(){
	
	for(int k=0; k<m; ++k){
		
		CLR(dp);
		
		for(int i=0; i<n; ++i){
			for(int j=0; j<=w[k]; ++j){
			
					if(j<s[i])
						dp[i+1][j] = dp[i][j];
					else
						dp[i+1][j] = max(dp[i][j], dp[i+1][j-s[i]] + p[i]);
			}
		}
		
		
		int ret = 0;
		
		for(int i=w[k]; i>=w[k]-seg; --i){
			if(dp[n][i] != 0)
				ret = max(ret, dp[n][i]);
		}
		
		if(ret == 0)
			return false;
		
		res.push(ret);
	}
	
	return true;
}

int main(){
	
	cin >> n;
	
	for(int i=0; i<n; ++i){
		cin >> s[i] >> l[i] >> p[i];
		seg += l[i]-s[i];
	}
	
	cin >> m;
	
	for(int i=0; i<m; ++i){
		cin >> w[i];
	}
	
	if(solve()==false)
		cout << -1 << endl;
	else{
		while(!res.empty()){
			cout << res.front() << endl;
			res.pop();
		}
	}
	
	return 0;
}

Measured memory_bytes: 1844
//Deploy bubble-sort.
#include <bits/stdc++.h> 
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
vector<int> bubbleSort(vector<int> &a, int &c) {
   bool flag = true;
   while(flag) {
       flag = false;
       for(int i=a.size()-1; i>0; --i) {
           if(a[i] < a[i-1]) {
                int v = a[i];
                a[i] = a[i-1];
                a[i-1] = v;
                flag = true;
                c++;
           }
       }
   }
   return a;
}

int main() {
    int N;
    cin >> N;
    int count=0;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    bubbleSort(A, count);

    rep(i,N) {
        if(i == N-1) {
            cout << A[i] << endl;
        } else {
            cout << A[i] << " ";
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3164
#include <iostream>

using namespace std;

int saidaikouyaku(int a, int b);

int main(){
	int n, xs;
	cin >> n >> xs;

	int result;
	int x1, x2;
	for(int i = 0; i < n; i++){
		cin >> x1;
		x1 = abs(x1-xs);
		if(i == 0)
			x2 = x1;
		else if(i != 0)
			x2 = saidaikouyaku(x1, x2);
	}

	cout << x2 << endl;

	return 0;
}

int saidaikouyaku(int a, int b) {
	if(a < b){
		int tmp = a;
		a = b;
		b = tmp;
	}

	int r = a % b;
	while(r != 0){
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc126/tasks/abc126_d

import sys
sys.setrecursionlimit(100000)

def dfs(i):
  for v,w in V.get(i, []):
    if (w % 2) == 0:
      if color[v] == -1:
        color[v] = color[i]
      elif color[v] == color[i]:
        continue
      elif color[v] != color[i]:
        return False
    else:
      if color[v] == -1:
        color[v] = 0 if color[i] else 1
      elif color[v] == color[i]:
        return False
      elif color[v] != color[i]:
        continue
    dfs(v)
  return True

if __name__ == '__main__':
  n = int(input())
  V = {} # key:vertex, value:[[vertex opposited, wight]]
  color = {} # 0 or 1 or -1
  for i in range(1, n):
    u,v,w = map(int, input().split())
    if not V.get(u, False):
      V[u] = [[v,w]]
    else:
      V[u].append([v,w])

    if not V.get(v, False):
      V[v] = [[u,w]]
    else:
      V[v].append([u,w])
    # 同じ頂点間で複数の辺はないと仮定
  for i in range(1, n+1):
    color[i] = -1

  while True:
    i = 0
    for j in range(1, n+1):
      if color[j] == -1:
        i = j
        color[i] = 0
        break
    if i == 0:
      for j in range(1, n+1):
        print(color[j])
      break
    else:
      if not dfs(i):
        print('No')
        break

  

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

int main(){
int N;
cin>>N;
if(N==1){
cout<<1<<endl;
}
if(N<=3&&N>=2){
cout<<2<<endl;
}
if(N<=7&&N>=4){
cout<<4<<endl;
}
if(N<=15&&N>=8){
cout<<8<<endl;
}
if(N<=31&&N>=16){
cout<<16<<endl;
}
if(N<=63&&N>=32){
cout<<32<<endl;
}
if(N<=100&&N>=64){
cout<<64<<endl;
}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
 int n,i,j,k,temp;
 int A[101];

/*????´??????°?????\???*/
 scanf("%d",&n);

/*??????????????\???*/
 for(i=0;i<n;i++){
  
 if(i==n-1){
    scanf("%d",&A[n-1]);
   }else{
    scanf("%d ",&A[i]);
   }

 }

for(k=0;k<n;k++){
  
  if(k==n-1){
     printf("%d\n",A[n-1]);
    }else{
     printf("%d ",A[k]);
    }

  }





 for(i=1;i<n;i++){

  temp=A[i];
  
  for(j=i-1;j>=0;j--){

   if(temp<A[j]){
    A[j+1]=A[j];
    A[j]=temp;
   }

  }


  for(k=0;k<n;k++){
  
  if(k==n-1){
     printf("%d\n",A[n-1]);
    }else{
     printf("%d ",A[k]);
    }

  }

 }

return 0;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v);
#ifndef ONLINE_JUDGE
#define debug(a) cout<<#a<<" --> "<<(a)<<"\n";
#define debug2(a) cout<<#a<<" --> "<<(a)<<" ";
#define HERE cout<<"here - "<<__LINE__<<"\n";
#else
#define debug(a)
#define debug2(a)
#define HERE
#endif
const ll mod = 998244353  ;
const int N = 1e6+1;

int cnt[N+5];
vector<int>divisors[N+5];
void Divisors()
{
    int n= N;
    int i;
    int j;
    for(i = 1; i*i <= n; i++)
    {
        for(j = i*i; j <= n; j += i)
        {
            divisors[j].push_back(i);
        }
    }
}

void TEST_CASES(int cas)
{
    Divisors();
    //debug("here");
    int n;
    scanf("%d",&n);
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        cnt[a[i]]++;
    }
    if(cnt[1])
    {
        if(cnt[1]==1)
        {
            printf("1\n");
        }
        else{
            printf("0\n");
        }
        return;
    }
    int ans =0;
    for(int i:a)
    {
        if(cnt[i]>1)
            continue;
        bool flag= true;
        for(int j:divisors[i])
        {
            if(i/j== i && cnt[i/j]==1)
                continue;
            if(cnt[j])
            {
                flag= false;
                break;
            }
            if(cnt[i/j])
            {
                flag= false;
                break;
            }
        }
        if(flag)
            ans++;
    }
    printf("%d\n",ans);
}


/*

*/

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1,cas=0;
    //scanf("%d",&t);
    while(t--)
    {
        TEST_CASES(++cas);
    }

    return 0;
}



//os.order_of_key(v): returns how many elements strictly less than v
//os.find_by_order()

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v)
{
    for(auto i:v)
    {
        os<<"Key : "<<i.first<<" , Value : "<<i.second<<endl;
    }
    return os;
}


Measured memory_bytes: 92148
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		int ans=0,num;
		rep(i,n/4){
			cin>>num;
			ans+=num;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int>app[35],vec;
int cnt[35],n,tp[200005],opp[200005];
char str[200005];
ll sum[200005];
inline void modify(int pos,int x)
{
	for(;pos<=n;pos+=pos&-pos)
		sum[pos]+=x;
}
inline ll query(int pos)
{
	ll res=0;
	for(;pos;pos-=pos&-pos)
		res+=sum[pos];
	return res;
}
int main()
{
	cin>>str;
	n=strlen(str);
	for(int i=0;i<n;i++)
		app[str[i]-'a'].push_back(i);
	bool odd=false;
	for(int i=0;i<26;i++){
		if(app[i].size()&1){
			if(odd){
				puts("-1");
				return 0;
			}
			odd=true;
		}
	}
	for(int i=0;i<n;i++){
		int c=str[i]-'a';
		if(cnt[c]<app[c].size()/2)
			tp[i]=0;
		else if((app[c].size()&1)&&(cnt[c]==app[c].size()/2))
			tp[i]=2;
		else{
			tp[i]=1;
			opp[i]=app[c][app[c].size()-cnt[c]-1];
		}
		cnt[c]++;
	}
	int cnt0=0;
	ll ans=0;
	for(int i=0;i<n;i++){
		if(tp[i]==1)
			vec.push_back(opp[i]+1);
		else if(!tp[i]){
			cnt0++;
			ans+=vec.size();
		}
		else
			ans+=vec.size()+(n-1>>1)-cnt0;
	}
	for(int i=0;i<vec.size();i++){
		ans+=query(vec[i]);
		modify(vec[i],1);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4216
/*                  ___
               :                
               ;                
              :                 
              ;                 
             /                  
           o/                   
         ._/\___,                
             \                  
             /                   
             `      
	bug
*/
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

using namespace std;
#define PI 3.14159265359
#define eps 1e-8
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,n) FOR(i,0,n)
typedef long long int ll;
const int INF = 1<<29;
typedef long long ll;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double tick() { 
	static clock_t oldticks;
	clock_t newticks = clock();
	double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC; 
	oldticks = newticks;
	return diff;
}

inline int toInt(string s){
	return atoi(s.c_str());
}

inline int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}

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

inline bool isPrime(int n){
	ll j;
	j=sqrt(n);

	if(n<2)
		return 0;
	for(int i=2;i<=j;i++){
		if(n%i==0)
			return false;
	}
	return true;
}

int n;

int main(){
	ios_base::sync_with_stdio(false); //Fast I/O
	cin.tie(NULL);
	//freopen("in.txt","r",stdin);
	//freopen("output.txt","w",stdout);	
	cin >> n;

	int cc,m=8,res=0;

	for(int i=1;i<=n;i+=2){
		cc=0;
		for(int j=1;j<=i;j++){
			if(i%j==0)
				cc++;
		}
		if(cc==m)
			res++;
	}

	cout << res << endl;

    //cerr << tick();

	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int k,n;
    cin >> k >> n;
    vector<int > a(n);
    vector<int > b(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    b[0] = a[0] + k - a[n-1];
    for (int i=1; i<n; i++){
        b[i] = a[i] - a[i-1];
    }
    int max = *max_element(b.begin(), b.end());
    cout << k-max << endl;
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

class modint {
  private:
    ll m_val;
    ll m_mod;
  public:
    constexpr modint() : m_val(0), m_mod() { m_mod = MOD; }
    constexpr modint(const ll x) : m_val(0), m_mod(0) { m_mod = MOD; m_val = x % m_mod; }
    constexpr modint(const ll x, const ll mod) : m_val(0), m_mod(0) { m_mod = mod; m_val = x % m_mod; }
    constexpr ll val() const { return m_val; }
    constexpr modint operator+(const modint &rhs) const { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const { return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint &rhs) {
      m_val += rhs.m_val;
      if (m_val >= m_mod) m_val -= m_mod;
      return *this;
    }
    constexpr modint &operator-=(const modint &rhs) {
      if (m_val < rhs.m_val) m_val += m_mod;
      m_val -= rhs.m_val;
      return *this;
    }
    constexpr modint &operator*=(const modint &rhs) {
      m_val = m_val * rhs.m_val % m_mod;
      return *this;
    }
    constexpr modint &operator/=(const modint &rhs) {
      *this *= rhs.inv();
      return *this;
    }
    constexpr modint pow(ll n) const {
      if (n == 0) return 1;
      modint o = pow(n >> 1);
      o *= o;
      if (n & 1) o *= *this;
      return o;
    }
    constexpr modint inv() const {
      return pow(m_mod - 2);
    }
    friend ostream& operator<<(ostream& os, const modint &a) { os << a.val(); return os; }
};

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

  string sa, sb;
  cin >> sa >> sb;

  modint ans = 1;
  ll vertical = -1;
  for (ll i = 0; i < n;) {
    if (sa[i] == sb[i]) {
      if (vertical < 0) ans *= 3;
      else if (vertical == 1) ans *= 2;
      vertical = 1;
      ++i;
    } else {
      if (vertical < 0) {
        ans *= 3; ans *= 2;
      } else if (vertical == 0) {
        ans *= 3;
      } else if (vertical == 1) {
        ans *= 2;
      }
      vertical = 0;
      i += 2;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3612
from heapq import heappush, heappop
from functools import reduce
from operator import or_

# 入力
N, M = map(int, input().split())
a, b, c = (
    zip(*(map(int, input().split()) for _ in range(M))) if M else
    ((), ())
)

# 各頂点に対してダイクストラ法により最短経路を求める
G = [{} for _ in range(N + 1)]
for x, y, w in zip(a, b, c):
    G[x][y] = w
    G[y][x] = w

INF = 10**10


def dijkstra(G, s):
    dp = [INF for _ in range(len(G))]
    q = []
    res = set()
    heappush(q, (0, s, s))
    while q:
        c, i, p = heappop(q)
        if c < dp[i]:
            dp[i] = c
            for j, w in G[i].items():
                heappush(q, (c + w, j, i))
        if c == dp[i] and i != p:
            res.add((p, i))
    return res


# 最短経路に含まれない辺の数を求める
ans = M - len(reduce(or_, (dijkstra(G, i) for i in range(1, N + 1)))) // 2

# 出力
print(ans)


Measured memory_bytes: 4324
//#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007



typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L;
ll A[300005] = {};
ll B[101][100005] = {};
ll C[300005] = {};
bool f, ff;
string S;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset[50];
multiset<ll> llmset;


struct ST
{
	int kaisuu;
	int dan;
	int score;
	char situ[52][2][2];
	

	bool operator<(const ST& another) const
	{
		return dan < another.dan;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


ll minn, maxx;
double ansa;

string SS[3];


int main() {

	cin >> N>>M;

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

	for (int i = 0; i < N-1; i++) {
		e += min(A[i + 1] - A[i], M);
	}
	e += M;


	cout << e << endl;

	//cout << fixed << setprecision(10) << ansa << endl;
	return 0;



}


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

int main() {
  char c;
  cin>>c;
  if (c=='a'||c=='i'||c=='u'||c=='e'||c=='o')
  cout<<"vowel"<<endl;
  else
  {
    cout<<"consonant"<<endl;
  }
  
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

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

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

mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}

mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}


int main() {
    string s; cin >> s;
    bool t = true;
    rep(i,s.size()){
        if (i % 2 == 0 && s[i] == 'L'){
            t = false;
            break;
        }
        if (i % 2 == 1 && s[i] == 'R'){
            t = false;
            break;
        }
    }
    if (t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		System.out.println((n-1)*(m-1));
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


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

using namespace std;
#define ll long long
#define REP(i, n) for(auto i = 0;i < n;i++)
#define REPR(i, n) for(auto i = n-1;i >= 0;i--)


typedef pair<ll, ll> LP;

const ll mod = 1e9+7;

struct UnionFind {
	vector<int> data;
	// dataの各要素について
	// 負の値:その集合のルートであること示す。また、その絶対値は集合の要素数となっている。
	// 正の値:親ノードの番号(dataのインデックス)。root()を呼び出すたびに集合のルートを指すように書きなおされるので木はそんなに深くならない

	//初期化 size:最大要素数
	UnionFind(int size): data(size, -1) {}
	
	// 集合を併合する
	// すでに同じ集合だった場合は、falseが返る
	bool unite(int x, int y){
		x=root(x);
		y=root(y);
		if( x != y ){
			// 要素数の大きな方へ合併するためのswap
			if( data[y] < data[x] ) swap(x, y);
			// 要素数を加算する
			data[x] += data[y];
			// yの属する集合のルートをxに変更
			data[y] = x;
		}
		return x!=y;
	}

	// 同じ集合かどうか判定
	bool same(int x, int y){ 
		return root(x) == root(y);
	}

	// 集合の識別番号を返す
	// 負の値を持つものがその集合のルート
	// 正の値は同じ集合に属するものを指す(辿ればいずれルートへ着く)
	int root(int x){ 
		return (data[x] < 0)? x : data[x]=root(data[x]);
	}
	// 集合の要素数を返す
	int size(int x){ 
		return -data[ root(x) ];
	}
};

int main(){
	ll n, m;
	cin >> n >> m;
    vector<LP> AB(m);
    REP(i, m){cin>>AB[i].first>>AB[i].second;}
    UnionFind tree(n);
    ll ans[m];
    ll sum = n * (n-1) /2;
    REPR(i, m){
        ans[i] = sum;
        if (!tree.same(AB[i].first-1, AB[i].second-1)){
            sum -= tree.size(AB[i].first-1) * tree.size(AB[i].second-1);
            tree.unite(AB[i].first-1, AB[i].second-1);
        }
    }
    REP(i, m){cout << ans[i] << endl;}
}

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

#define M_PI	3.141592653589793

int main()
{
	int dis, r;
	double x = 0, y = 0;
	int theta = 90;

	while( scanf("%d,%d", &dis, &r) != EOF ) {
		if (dis == 0 && r == 0) {
			break;
		}
		x += dis * cos(2 * M_PI  * theta / 360);
		y += dis * sin(2 * M_PI  * theta / 360);
		theta += -r;
	}
	printf("%d\n%d\n", (int)x, (int)y);
	return 0;
}



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

using namespace std;

#define LL           long long
#define ULL          long long unsigned
#define LD           long double
#define FOR(i,n)     for(int i=0;i<n;i++)
#define FLR(i,n)     for(LL i=0;i<n;i++)
#define RFOR(i,n)    for(int i=n-1;i>=0;i--)
#define RFLR(i,n)    for(LL i=n-1;i>=0;i--)
#define rep(i,a,b)   for(int i=a;i<=b;i++)
#define repl(i,a,b)  for(LL i=a;i<=b;i++)
#define fast         ios_base::sync_with_stdio(0);cin.tie(0);
#define all(a)       a.begin(),a.end()
#define ABS(x)       ((x)<0?-(x):(x))
#define endl         "\n"
#define PB           push_back
int main()
{
    fast;
    int a,b,c;
    cin>>a>>b;
    if((a+b)%2==0)cout<<(a+b)/2;
    else cout<<"IMPOSSIBLE";

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<iomanip>
#include<algorithm>
#include<list>
using namespace std;


int main()
{
	int n, a[101], count = 0;

	//入力
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}

	//選択ソート
	for (int i = 0; i < n; i++){
		int minj = i;
		for (int j = i; j < n; j++){
			if (a[j] < a[minj]){
				minj = j;
			}
		}
			int tmp = a[i];
			a[i] = a[minj];
			a[minj] = tmp;
			if (i != minj){
				count++;
			}
	}



	//出力
	for (int i = 0; i < n; i++){
		if (i < n - 1){
			cout <<a[i] << " ";
		}
		else{
			cout << a[i] << endl;
		}
	}
	cout << count << endl;
	return 0;
}

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

int main()
{
    string x;
    cin >> x;
    int n=x.length();
    char c=x[0];
    int total=0;
    for(int i=1;i<n;i++)
    {
        if(c==x[i])
        {
            total++;
            if(c=='0') c='1';
            else c='0';
        }
        else c=x[i];
    }
    cout << total;
    return 0;
}

Measured memory_bytes: 512