akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;
  if (a * b == 15) {
    cout << "*" << endl;
    return 0;
  }
  if (a + b == 15) {
    cout << "+" << endl;
    return 0;
  }
  cout << "x" << endl;   
  return 0;
}


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

int main(){
    int res = 0, a;
    for(int i = 0; i < 5; i++){
        scanf("%d", &a);
        res += max(a, 40);
    }
    printf("%d\n", res /  5);
    return 0;
}

Measured memory_bytes: 1028
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] num = new int[n];
		for(int i=0;i<n;i++){
			num[i] = sc.nextInt();
		}
		int etc = (int)Math.sqrt(100000000)+3;
		boolean[] prime = new boolean[etc];
		Arrays.fill(prime, true);
		prime[0] = false;
		prime[1] = false;
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i=2;i<etc;i++){
			if(prime[i]){
				list.add(i);
				for(int j=i*2;j<etc;j=j+i){
					prime[j] = false;
				}
			}
		}

		int count = 0;
		for(int i=0;i<n;i++){
			boolean flag = true;
			for(int j=0;j<list.size();j++){
				int x = list.get(j);
				if(num[i] <= x){
					break;
				}
				if(num[i]%x==0){
					flag = false;
				}
			}
			if(flag){
				count++;
			}
		}

		System.out.println(count);

	}
}




Measured memory_bytes: 41928
#include <iostream>
#include <bits/stdc++.h>
#include <assert.h>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <iomanip>
#define initrand mt19937 mt_rand(time(0));
#define rand mt_rand()
#define int long long
#define INF 10000000000000
#define mid(l, u) ((l+u)/2)
#define lchild(i) (i*2 + 1)
#define rchild(i) (i*2 + 2)
using namespace std;
const int N = 500005;
int seg[4*N];
int update(int l, int u, int i, int x, int y){
    if(l==u && l==x) return seg[i] = y;
    if(l>x || u<x) return seg[i];
    return seg[i] = update(l, mid(l, u), lchild(i) ,x, y) + update(mid(l,u)+1, u, rchild(i), x, y);
}
int query(int l, int u, int i, int ll, int uu){
    if(l>=ll && u<=uu) return seg[i];
    if(l>uu || u<ll) return 0;
    return query(l, mid(l, u), lchild(i), ll, uu) + query(mid(l,u)+1, u, rchild(i), ll, uu);
}
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b){
    return a.first.second < b.first.second;
}
signed main(){
    int n, q;
    cin>>n>>q;
    int arr[n+1];
    int prev[n+5];
    for(int j = 0;j<=n;j++) prev[j] = 0;
    for(int i =1 ;i<=n;i++) cin>>arr[i];
    vector<pair<pair<int, int>, int>> qq;
    for(int j = 0;j<q;j++){
        int l, r;
        cin>>l>>r;
        qq.push_back({{l, r}, j});
    }
    sort(qq.begin(), qq.end(), cmp);
    int currr = 0;
    int ans[q];
    for(pair<pair<int, int> ,int> j: qq){
        int l = j.first.first;
        int r = j.first.second;
        int ind = j.second;
        //cout<<ind<<endl;
        while(currr < r){
            currr++;
            if(prev[arr[currr]]){
                update(1, n, 0, prev[arr[currr]], 0);
            }
            prev[arr[currr]] = currr;
            update(1, n, 0, prev[arr[currr]], 1);
        }
        /*cout<<"r = "<<r<<endl;
        for(int jj = 1;jj<=r;jj++){
            cout<<"Distinct "<<jj<<" "<<r<<" = "<<query(1, n, 0, jj, r)<<endl;
        }*/
        ans[ind] = query(1, n, 0, l, r);
    }
    for(int j = 0;j<q;j++) cout<<ans[j]<<endl;
}

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

using namespace std;

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

  int d;
  int64_t g;
  cin >> d >> g;
  g /= 100;
  vector<int64_t> p(d), c(d);
  for (int i = 0; i < d; ++i) {
    cin >> p[i] >> c[i];
    c[i] /= 100;
  }
  int ans = INT_MAX;
  for (int i = 0; i < pow(2, d); ++i) {
    int solves = 0;
    int max_nonsolve = -1;
    int64_t score = 0;
    int pattern = i;
    for (int j = 0; j < d; ++j) {
      if (pattern & 1) {
        score += p[j] * (j + 1) + c[j];
        solves += p[j];
      } else {
        max_nonsolve = j;
      }
      pattern >>= 1;
    }
    if (score < g) {
      int64_t rest = g - score;
      if (rest <= (max_nonsolve + 1) * (p[max_nonsolve] - 1)) {
        solves += rest / (max_nonsolve + 1) + (0 < rest % (max_nonsolve + 1));
      } else {
        continue;
      }
    }
    ans = min(ans, solves);
  }
  cout << ans << "\n";
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
struct ToUpper {
	char operator()(char c) { return toupper(c); }
};

int main() {
	string st;
	while (getline(cin,st)) {
		st.erase(remove_if(st.begin(), st.end(), [](const char c) {
			return !isalpha(c);
		}), st.end());
		transform(st.begin(), st.end(), st.begin(), ToUpper());
		vector<string>anss;
		for (int i = 0; i < st.size(); ++i) {
			int l = i;
			int r = i;
			while(1) {
				if (l<0||r>=st.size()||st[l] != st[r]) {
					if (r - l - 1 >= 2) {

						anss.push_back(st.substr(l + 1, r - l - 1));
					}
					break;
				}
				l--; r++;
			}
		}
		for (int i = 0; i < int(st.size())-1; ++i) {
			int l = i;
			int r = i + 1;
			while (1) {
				if (l<0 || r >= st.size() || st[l] != st[r]) {
					if (r - l-1 >= 2) {

						anss.push_back(st.substr(l + 1, r - l-1));
					}
					break;
				}
				l--; r++;
			}
		}
		sort(anss.begin(), anss.end());
		anss.erase(unique(anss.begin(), anss.end()), anss.end());
		vector<bool>flags(anss.size(),true);
		for (int i = 0; i < anss.size(); ++i) {
			for (int j = 0; j < anss.size(); ++j) {
				if (anss[i].size() < anss[j].size()&&!((anss[j].size()-anss[i].size())%2)) {
					if (anss[i] == anss[j].substr((anss[j].size() - anss[i].size()) / 2, anss[i].size())) {
						flags[i] = false;
					}
				}
			}
		}
		{
			vector<string>trueanss;
			for (int i = 0; i < anss.size(); ++i) {
				if (flags[i]&&anss[i].size()>=3)trueanss.push_back(anss[i]);
			}
			anss = trueanss;
		}
		if (anss.empty())cout << endl;
		for (int i = 0; i < anss.size(); ++i) {
			cout << anss[i];
			if (i == anss.size() - 1)cout << endl;
			else cout << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
const double EPS = 1e-10;
struct Point {
  double x;
  double y;

  Point() : x(0.0),y(0.0){} 
  Point(double _x,double _y) :x(_x),y(_y){}  
  
  Point operator+(const Point& other) const { return { x + other.x , y + other.y }; }
  Point operator-(const Point& other) const { return { x - other.x , y - other.y }; }
  bool operator==(const Point& other) const { return (abs(x - other.x) < EPS && abs(y - other.y) < EPS ); }
  
  double dot(const Point& other) const { return x * other.x + y * other.y; }
  double cross(const Point& other) const { return x * other.y - y * other.x; }
  double length() const { return sqrt(x * x + y * y); }
};
// A とB のなす角θ cosθ, sinθ を返す
double Cos(const Point A, const Point B) { return A.dot(B) / (A.length()*B.length()); }
double Sin(const Point A, const Point B) { return A.cross(B) / (A.length()*B.length()); }

// 線分AB上に点Cがあるかどうかの判定
bool IsOnLine(const Point A, const Point B, const Point C) {  return abs(Sin(A - C, B - C)) < EPS && Cos(A - C, B - C) < 0; }

// 線分の交差判定
bool CrossCheck(const Point a, const Point b, const Point c, const Point d) {
  if(a == c || a == d || b == c || b == d) return true; // 端点が等しい場合はtrue
  Point AB = b - a, AC = c - a, AD = d - a;
  Point CA = a - c, CB = b - c, CD = d - c;
  double s = AB.cross(AC) * AB.cross(AD);
  double t = CD.cross(CA) * CD.cross(CB);

  if(abs(Sin(AB, CD)) < EPS) { // 平行のとき
    if(abs(Sin(AB, AC)) < EPS) { // 同一直線上にあるか？
      return (CA.dot(CB) - EPS < 0 || (a - d).dot(b - d) - EPS < 0 || AC.dot(AD) - EPS < 0);
    }
    else return false;
  }
  else return s < EPS && t < EPS;
}

double Dist(const Point &a, const Point &b) { return (a - b).length(); }

struct Circle {
  Point p;
  double r;

  Circle() : p({0,0}), r(0) {}
  Circle(Point p, double r) : p(p), r(r) {}
};

int CrossCheckCircle(Circle a, Circle b) {
  double d = Dist(a.p, b.p);
  if(abs(a.r - b.r) > d) return 0;
  else if(abs(abs(a.r - b.r) - d) < EPS) return 1;
  
  if(a.r + b.r < d) return 4;
  else if(abs(a.r + b.r - d) < EPS) return 3;
  else return 2;
}

int main()
{
  Circle c1, c2;
  cin >> c1.p.x >> c1.p.y >> c1.r;
  cin >> c2.p.x >> c2.p.y >> c2.r;
  cout << CrossCheckCircle(c1, c2) << "\n";
  return 0;
}



Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)

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

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//CODE TONOY
	int n;
    string s;
    cin >> n >> s;
 
    int r=0, g=0, b=0;
    for (int i=0;i<n;i++){
        if(s[i]=='R') r++;
        if(s[i]=='G') g++;
        if(s[i]=='B') b++;
    }
 
    ll ans = (ll) r * g * b;
 
    for (int i=0;i<n;i++){
        for (int j=0;j<n;j++){
            if(i<j){
                int k = j*2-i;
                if(k<n && s[i] != s[j] && s[j] != s[k] && s[k] != s[i]){
                    ans--;
                }
            }
        }
    }
    cout << ans << endl;
	return 0;
}

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

int main(){
int x,y,z,k;
cin >> x >> y >> z >> k;
vector <long long> a(x);
vector <long long> b(y);
vector <long long> c(z);
vector <long long> mix(x*y);
vector <long long> ans(k*z);

for (int i=0; i<x; i++){
cin >> a[i];
}
for (int i=0; i<y; i++){
cin >> b[i];
}
for (int i=0; i<z; i++){
cin >> c[i];
}

for (int i=0; i<x; i++){
for (int j=0; j<y; j++){
mix[i*y+j] = a[i] + b[j];
}
}

sort(mix.begin(),mix.end());
reverse(mix.begin(),mix.end());
sort(c.begin(),c.end());
reverse(c.begin(),c.end());

for (int i=0; i<min(k,x*y); i++){
for (int j=0; j<z; j++){
ans[i*z+j]=mix[i]+c[j];
}
}

sort(ans.begin(),ans.end());
reverse(ans.begin(),ans.end());

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

}

Measured memory_bytes: 31616
N, M = map(int,input().split())

room = {}
startRoom = {1:1}

for i in range(M):
  A, B = map(int,input().split())
  room.setdefault(A, []).append(B)
  room.setdefault(B, []).append(A)
  
targetRoom = [1]
while len(targetRoom) != 0:
  nextTarget = []
  for i in targetRoom:
    roomList = room[i]
    for j in roomList:
      if j not in startRoom:
        startRoom[j] = i
        nextTarget.append(j)
  targetRoom = nextTarget
  
if len(startRoom) != N:
  print("No")
else:
  print("Yes")
  for i in range(2, N+1):
    print(startRoom[i])

Measured memory_bytes: 47444
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = readInts >>= putStrLn . which "YES" "NO" . elem [ 1, 9, 7, 4 ] . permutations

Measured memory_bytes: 380
#include <cstdio>
#include <algorithm>

int dp[100001];
int main()
{
	int h, n;
	scanf("%d%d", &h, &n);
	int a[1000], b[1000];
	for (int i = 0; i < n; ++i)
	{
		scanf("%d%d", a + i, b + i);
	}
	for (int i = 0; i <= n; ++i)
	{
		std::fill(dp, dp + h, (int)1e9);
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = h; j >= 0; --j)
		{
			if (j - a[i] <= 0)
			{
				dp[0] = std::min(dp[0], dp[j] + b[i]);
			}
			else
			{
				dp[j - a[i]] = std::min(dp[j - a[i]], dp[j] + b[i]);
			}
		}
	}
	printf("%d\n", dp[0]);
	return 0;
}


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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

typedef long long ll;
//{
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define dumo dump
#define sysp system("pause")
//}

#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}
inline long long digitsum(long long v){long long d=0;while(v){d+=v%10;v/=10;}return d;};
//}

int m,n,ans,fre,lis[8],dif;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int dis;
		cin>>dis; 
		if(dis>=3200){
			fre++;
		}else{
			dif++;
			lis[dis/400]++;
		}
	}
	if(fre!=0&&dif==0){
		cout<<1<<' '<<fre<<endl;
	}else{
		for(int i=0;i<8;i++){
			if(lis[i])m++;
		}
		cout<<m<<' '<<m+fre<<endl;
	}
	sysp;
}
 



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

int main(){
	int a,b,c;cin >> a >> b >> c;
  	int ans=abs(a-b)+abs(b-c)+abs(a-c);
  	cout << ans-max(abs(a-b),max(abs(b-c),abs(a-c)));
  	return 0;
}


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

using namespace std;

int main() {
    long long int N;
    long long int res = 0;

    cin >> N;

    for (long long int i = 1; i <= N; ++i) {
        if (i % 15 != 0 && i % 5 != 0 && i % 3 != 0) {
            res += i;
        }
    }

    cout << res;
    return 0;
}



Measured memory_bytes: 3636
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Asum = [A[0]]
Bsum = [B[0]]
for i in range(1, N):
	Asum.append(Asum[-1]+A[i])
	Bsum.append(Bsum[-1]+B[i])
max = 0
for i in range(0, N):
	sum = Asum[i] + Bsum[-1]
	if i != 0:
		sum -= Bsum[i-1]
	if max < sum:
		max = sum
print(max)

Measured memory_bytes: 38256
S = input()
a = int(S[:2])
b = int(S[2:])
if 0 < a < 13:
    if 0 < b < 13:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 0 < b < 13:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 2940
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):

    if N <= A : print(N)    
    else :
        k = N // (A+B)
        rem = N - (A+B)*k
        if  rem >= A:
            print(k*A+A)
        elif rem >= 0:
            print(k*A+rem)
        else : print(k*A)


    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
using namespace std;

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

  int outFlag = 0;
  set<string> W;
  string tmp, before;
  cin >> tmp;
  W.insert(tmp);
  before = tmp;

  for(int i=1;i<N;i++){
    cin >> tmp;

    // 重複がないか
    if(W.find(tmp) != W.end()){
      outFlag = 1;
    }

    if(before.back() != tmp.front()){
      outFlag = 1;
    }

    W.insert(tmp);
    before = tmp;
  }


  if(outFlag == 1){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  int sum_of_A = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    sum_of_A += A.at(i);
  }
  
  
  double border = (double) sum_of_A / (4 * M);
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
//  cout << border<< endl;
//  cout << A.at(M-1) << endl;
//  cout << sum_of_A << endl;
  
  if (A.at(M-1) < border) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
typedef long long ll;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    if(a.at(0)){
        cout << -1 << endl;
        return 0;
    }
    ll tmp = a.back();
    if(tmp > n-1){
        cout << -1 << endl;
        return 0;
    }
    ll ans = tmp;
    for(i = n-2;i >= 0;--i){
        if(a.at(i) < tmp){
            if(a.at(i) != tmp-1){
                cout << -1 << endl;
                return 0;
            }else{
                tmp = a.at(i);
                continue;
            }
        }else{
            if(a.at(i) > i){
                cout << -1 << endl;
                return 0;
            }else{
                tmp = a.at(i);
                ans += tmp;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int K, N;
    cin >> K >> N;
    int A[N];
    for(int i=0;i<N;i++)
        cin >> A[i];

    int dist[N];
    for(int i=1;i<N;i++){
        dist[i] = A[i] - A[i-1];
    }
    dist[0] = (K - A[N-1]) + A[0];
    // 降順ソート
    sort(dist, dist + N, greater<int>());

    cout << K - dist[0] << endl;

}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int n;cin >> n;
    vector<int> vec;
    for(int i = 0;i < n;i++){
        int b;cin >> b;
        vec.push_back(b);
    }
    int ans = 0;
    for(int i = 1;i < n-1;i++){
        vector<int> q;
        q.push_back(vec.at(i-1));
        q.push_back(vec.at(i));
        q.push_back(vec.at(i+1));
        sort(q.begin(),q.end());
        if(q.at(1) == vec.at(i))ans++;
    }
    cout<<ans<<endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()


int main(){
    string A,B;
    cin>>A>>B;
    cout<<B+A<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
from collections import defaultdict
from math import gcd

mod = 10 ** 9 + 7

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

d = defaultdict(int)
zero = 0
for a, b in ab:
    # zero　別処理
    if a == b == 0:
        zero += 1
        continue
    if a == 0:
        d[(0, 1)] += 1
        continue
    if b == 0:
        d[(1, 0)] += 1
        continue

    # a[i]が絶対に非負になるように
    if a < 0:
        a *= -1
        b *= -1
    g = gcd(a, b)
    d[(a // g, b // g)] += 1

all = n - zero
ans = 1
for k1, v in d.items():
    k2 = (k1[1], -k1[0])
    if k2 in d.keys():
        all -= v
        all -= d[k2]
        ans = ans * (pow(2, v, mod) + pow(2, d[k2], mod) - 1) % mod
ans = ans * pow(2, all, mod) % mod
print((ans - 1 + zero) % mod)


Measured memory_bytes: 73484
//This code is written by Anubhav Srivastava(anubhavsrivastavawebpage.wordpress.com)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >>n;
    cout << (n/500)*1000 + ((n%500)/5)*5 ;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
std::pair<int, int> count_min_value(const std::vector<long long int>& red, const std::vector<long long int>& green, const int remove_count) {
	long long int min = 0, max = std::max(red.back(), green.back());
	while (min < max) {
		const auto mid = (min + max) / 2;
		const auto red_count = std::distance(red.begin(), std::upper_bound(red.begin(), red.end(), mid));
		const auto green_count = std::distance(green.begin(), std::upper_bound(green.begin(), green.end(), mid));
		if (red_count + green_count < remove_count) {
			min = mid + 1;
		}
		else {
			max = mid;
		}
	}
	const auto red_count = std::distance(red.begin(), std::lower_bound(red.begin(), red.end(), max));
	const auto green_count = std::distance(green.begin(), std::lower_bound(green.begin(), green.end(), max));
	return std::make_pair(red_count, green_count);
}
int main() {
	int x, y, a, b, c; std::cin >> x >> y >> a >> b >> c;
	std::vector<long long int> red(a), green(b), white(c);
	for (auto& r : red) std::cin >> r;
	for (auto& g : green) std::cin >> g;
	for (auto& w : white) std::cin >> w;
	std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int>> rq, gq, wq;
	for (const auto r : red) rq.push(r);
	for (const auto g : green) gq.push(g);
	for (const auto w : white) wq.push(w);
	while (rq.size() > x) rq.pop();
	while (gq.size() > y) gq.pop();
	while (rq.size() + gq.size() + wq.size() > x + y) {
		const auto min = std::min({ rq.empty() ? LLONG_MAX : rq.top(), gq.empty() ? LLONG_MAX : gq.top(), wq.empty() ? LLONG_MAX : wq.top() });
		if (!rq.empty() && rq.top() == min) {
			rq.pop();
		}
		else if (!gq.empty() && gq.top() == min) {
			gq.pop();
		}
		else {
			wq.pop();
		}
	}
	long long int result{ 0 };
	while (!rq.empty()) {
		result += rq.top(); rq.pop();
	}
	while(!gq.empty()) {
		result += gq.top(); gq.pop();
	}
	while (!wq.empty()) {
		result += wq.top(); wq.pop();
	}
	std::cout << result << std::endl;
}


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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000007LL
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(i=a;i<=b;i++)

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

ll mypow(ll a, ll b) { if(b == 0) return 1; ll temp=mypow(a,b/2); temp=(temp*temp); if(b%2 == 1) temp=(a*temp); return temp; }
int mygcd(int a, int b) { if(b==0) return a; return mygcd(b,a%b); }
int cntBits(ll a) { int ret=0; while(a>0) { ret++; a/=2; } return ret; }
int main()
{
	ios::sync_with_stdio(0);
	int tt=1,tcase; 
	//cin >> tt;
	rep(tcase,1,tt)
	{
		ll m,k,mval; cin >> m >> k;
		mval = mypow(2,m)-1;
		if(k==0)
		{
			for(int i=0;i<=mval;i++) cout << i << ' ' << i << ' ';
			cout << "\n";
			return 0;
		}
		else if(m==1) cout << -1 << "\n";
		else if(mval+1<=k) cout << -1 << "\n";
		else
		{
			cout << k << ' ';
			for(int i=0;i<=mval;i++) if(i!=k) cout << i << ' ';
			cout << k << ' ';
			for(int i=mval;i>=0;i--) if(i!=k) cout << i << ' ';
			cout << "\n";
		}
	}
	return 0;
}


Measured memory_bytes: 1792
class UnionFind:

    def __init__(self, n):
        # parent[x] < 0 means x is root and abs(parent[x]) == size[x]
        self.parent, self.depth = [-1] * n, [0] * n

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        if self.isSame(x, y):
            return
        x, y = self.find(x), self.find(y)

        if self.depth[x] > self.depth[y]:
            self.parent[x] += self.parent[y]
            self.parent[y] = x
        else:
            self.parent[y] += self.parent[x]
            self.parent[x] = y
            if self.depth[x] == self.depth[y]:
                self.depth[y] += 1

    def numTree(self):
        return sum([1 for p in self.parent if p < 0])


N, M = map(int, input().split())
E = [tuple(map(int, input().split())) for _ in range(M)]

ans = 0
for i in range(M):
    U = UnionFind(N)
    for a, b in E[:i] + E[i + 1:]:
        U.unite(a - 1, b - 1)
    if U.numTree() == 2:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include<stdio.h>

int main()
{

  int n,S[100000],q,T[50000],i,j;
  int count=0;
  int l,r,m;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&T[j]);
  }

  for(j=0;j<q;j++){
    l=0;
    r=n;

    while(l<r){

      m=(l+r)/2;

      if(S[m]==T[j]){
	count++;
	break;
      }
      else if(S[m]>T[j]){
	r=m;
      }
      else{
	l=m+1;
      }
    }
  }
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

    if((a + b) % 2 == 0)
        cout << (a + b) / 2 << endl;
    else 
        cout << "IMPOSSIBLE" << endl;

    return 0;
}


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


long long mod = 1000000007;
vector<long long> v;

void init(long long n)
{
	for (long long i = 1; i <= n; ++i) {
		v[i] = v[i - 1] * i % mod;
	}
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

long long comb(long long n, long long r) {
	long long ret = 1;

	ret = v[n] * modinv(v[n - r], mod) % mod;
	ret = ret * modinv(v[r], mod) % mod;

	return ret;
}

int main()
{
	long long n, k;
	cin >> n >> k;

	v.resize(n + 1, 1);
	
	init(n);

	if (n <= k) {
		k = n - 1;
	}

	long long ret = 1;
	for (long long i = 1; i <= k; ++i) {
		ret = (ret + (comb(n, i) * comb(n - 1,n - i - 1) % mod)) % mod;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)malloc(sizeof(int)*(n+1));
  int i;
  for(i=1;i<=n;i++) scanf("%d",a+i);
  int64 ans=a[1]/2;
  a[1]%=2;
  for(i=2;i<=n;i++){
    int c=MIN(a[i-1],a[i]);
    ans+=c;
    a[i]-=c;
    ans+=a[i]/2;
    a[i]%=2;
  }
  printf("%lld\n",ans);
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 512
# ref: https://qiita.com/masashi127/items/0c794e28f4b295ad82c6
import heapq
import itertools


def astar(init_pos, goal,dg):
    passed_list = [init_pos]
    init_score = distance(passed_list) + heuristic(init_pos,goal)
    checked = {init_pos: init_score}
    searching_heap = []
    heapq.heappush(searching_heap, (init_score, passed_list))
    while len(searching_heap) > 0:
        score, passed_list = heapq.heappop(searching_heap)
        last_passed_pos = passed_list[-1]
        if last_passed_pos == goal:
            return passed_list
        for pos in nexts(dg,last_passed_pos):
            new_passed_list = passed_list + [pos]
            pos_score = distance(new_passed_list) + heuristic(pos,goal)
            if pos in checked and checked[pos] <= pos_score:
                continue
            checked[pos] = pos_score
            heapq.heappush(searching_heap, (pos_score, new_passed_list))
    return []

def solve_dungeon(dungeon):
    init = find_ch(dungeon,"S")
    goal = find_ch(dungeon,"G")
    path = astar(init, goal,dungeon)

    if len(path) > 0:
        return True
    else:
        return False

def find_ch(dg,ch):
    for i, l in enumerate(dg):
        for j, c in enumerate(l):
            if c == ch:
                return (i, j)

def nexts(dg,pos):
    wall = "x"
    for a, b in [[' + 1',''], [' - 1',''], ['',' + 1'], ['',' - 1']]:
        if a or b:
            if dg[eval('pos[0]' + a)][eval('pos[1]' + b)] != wall:
                yield (eval('pos[0]' + a), eval('pos[1]' + b))

def heuristic(pos,goal):
    return ((pos[0] - goal[0]) ** 2 + (pos[1] - goal[1]) ** 2) ** 0.5

def distance(path):
    return len(path)

def render_path(dg,path):
    buf = [[ch for ch in l] for l in dg]

    for pos in path[1:-1]:
        buf[pos[0]][pos[1]] = "*"

    buf[path[0][0]][path[0][1]] = "s"
    buf[path[-1][0]][path[-1][1]] = "g"
    return ["".join(l) for l in buf]

if __name__ == "__main__":
    while(True):
        w,h = map(int,input().split())
        if w == 0 and h == 0:
            break
        xs,ys = map(int,input().split())
        xg,yg = map(int,input().split())
        n = int(input())
        d = [ list(map(int,input().split())) for _ in range(n)]
        m = [[0]*w for _ in range(h)]
        for e in d:
            for r in m[e[3]-1:e[3]+2*(e[1]+1)-1]:
                r[e[2]-1:e[2]+2*(2-e[1])-1] = [e[0]]*2*(2-e[1])
        ans = False
        for col in range(1,6):
            txt = [''.join(str(' ' if e==col else 'x') for e in f)  for f in m]
            if txt[ys-1][xs-1] == "x" or txt[yg-1][xg-1] == "x":
                continue
            txt[ys-1] = txt[ys-1][:xs-1] + 'S' + txt[ys-1][xs:]
            txt[yg-1] = txt[yg-1][:xg-1] + 'G' + txt[yg-1][xg:]
            for i in range(len(txt)):
                txt[i] = 'x' + txt[i] + 'x'
            txt.insert(0,'x'*(w+2))
            txt.append('x'*(w+2))
            ans |= solve_dungeon(txt)
            if ans:
                print("OK")
                break
        if not ans: print("NG")




Measured memory_bytes: 5992
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long int
int main(void){
	char s[11];
	ll ans=0,tmp;
	scanf("%s",s);
	int l = strlen(s),i,j,a[11];
	for(i=0;i<l;i++)a[i]=s[i]-'0';
	for(i=0;i<(1<<(l-1));i++){
		tmp=a[0];
		for(j=0;j<l;j++){
			if(j==l-1 || i&(1<<j)){
				ans+=tmp;
				tmp=0;
				if(j==l-1)break;
			}
			tmp*=10;
			tmp+=a[j+1];
		}
	}
	
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef double DD;
const int N = -1;


int main()
{
	int q, h, s, d;
	long long ans , n;
	scanf("%d%d%d%d", &q, &h, &s, &d);
	q *= 4;
	h *= 2;
	scanf("%lld", &n);
	ans = min(s, min(h, q));
	int t = n >> 1;
	ans = min(ans * n, 1ll * d * t + (n - t * 2) * ans);
	printf("%lld\n", ans);
}


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


int main()
{
    int n;
    cin>>n;
    vector<vector<int>> happy(n,vector<int>(3,0));
    for(int i=0;i<n;i++)
        for(int j=0;j<3;j++)
        cin>>happy[i][j];
  
    vector<vector<int>> dp(n,vector<int>(3,0));;
    dp[n-1][0]=happy[n-1][0];
    dp[n-1][1]=happy[n-1][1];
    dp[n-1][2]=happy[n-1][2];
    
    for(int i=n-2;i>=0;i--)
    {
        dp[i][0]=happy[i][0]+max(dp[i+1][1],dp[i+1][2]);
        dp[i][1]=happy[i][1]+max(dp[i+1][0],dp[i+1][2]);
        dp[i][2]=happy[i][2]+max(dp[i+1][1],dp[i+1][0]);
    }
   cout<<max(dp[0][0],max(dp[0][1],dp[0][2]))<<endl;
}

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

int main() {
  int N, now=-1, count=0;
  cin >> N;
  vector<int> H(N);
  for (int i=0; i<N; i++) cin >> H.at(i);
  for (int i=0; i<N; i++) {
    if (H.at(i) >= now) {
      count++;
      now = H.at(i);
    }
  }
  cout << count << endl;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

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

    int A, B;
    std::cin >> A >> B;

    if(A * B % 2 == 1){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 256
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e6+69, INF=2e9+6969;

int n;

int main()
{
	cin >> n;
	cout << n +n*n + n*n*n;
	return 0;
}


Measured memory_bytes: 3616
def GCD(x,y):
    if y == 0:
        return x
    return GCD(y,x%y)

A,B = map(int,input().split())
g = GCD(A,B)
ans = 1

for i in range(2,int(g**0.5)+1):
    if g % i == 0:
        ans += 1
        while g%i == 0:
            g //= i
if g != 1:
    ans += 1
print(ans)

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

int n, m;

int solve(int A, int B, int C){
	if( !A && !B ) return 0;
	if( C & 1 ) return solve(A >> 1, B >> 1, C >> 1);
	if( B & 1 ) return solve(C >> 1, B >> 1, A >> 1) + solve((A|B|C) >> 1, 0, 0) + 1;
	if( A & 1 ) return solve(A >> 1, B >> 1, C >> 1) + 2 * solve((A|B|C) >> 1, 0, 0) + 2;
}

int main(){
	while( cin >> n >> m , n || m ){
		int cup[3] = {0};
		for(int i=0 ; i < 3 ; i++ ){
			int k, e;
			cin >> k;
			for(int j=0 ; j < k ; j++ ){
				cin >> e;
				cup[i] |= 1 << e - 1;
			}
		}
		int ans = min(solve(cup[0], cup[1], cup[2]), solve(cup[2], cup[1], cup[0]));
		if( m < ans ) ans = -1;
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
using System;
using System.Linq;
using System.Collections.Generic;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {            
            var s = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
            var a1 = s[0] + s[1] - s[2];
            var a2 = s[0] + s[2] - s[1];
            var a3 = s[1] + s[2] - s[0];

            if(a1 == 0 || a2 == 0 || a3 == 0){
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

#define LL long long

const int MAXN = 200000 + 5;

struct Camel{
    int K, L, R;
};

struct Camel a[MAXN], b[MAXN];

bool cmp(Camel x, Camel y){
    return x.K < y.K;
}

LL solve(Camel *a, int n){
    priority_queue<int, vector<int>, greater<int> > q;
    LL ret = 0;
    for (int i = 0; i < n; i ++){
        if(a[i].K == 0){
            ret += (LL)a[i].R;
        }
        else if (a[i].K > q.size()){
            ret += (LL)a[i].L;
            q.push(a[i].L - a[i].R);
        }
        else{
            int t = q.top();
            if (t >= a[i].L - a[i].R){
                ret += (LL)(a[i].R);

            }
            else{
                q.pop();
                q.push(a[i].L - a[i].R);
                ret += a[i].L - t;
            }
        }
    }
    return ret;
}

int main()
{
    int T, N, na, nb;
    cin >> T;
    while (T --){
        LL ans = 0;
        cin >> N;
        na = nb = 0;
        int K, L, R;
        for (int i = 0; i < N; i ++){
            cin >> K >> L >> R;
            if (L >= R){
                a[na].K = K;
                a[na].L = L;
                a[na].R = R;
                na ++;
            }
            else{
                b[nb].K = N - K;
                b[nb].L = R;
                b[nb].R = L;
                nb ++;              
            }
        }

        
        if (na > 0){
            sort(a, a + na, cmp);
            ans += solve(a, na);
        }
        if (nb > 0){
            sort(b, b + nb, cmp);
            ans += solve(b, nb);
        }
        cout << ans << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 6376
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T> using vv=vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;


int main() {
    while(1) {
        char s[80000] = {};
        int l;
        scanf("%s",s);
        if(s[0] == '0') {
            break;
        }
        l = (int)strlen(s);
        int dp[80001][11] = {};
        int sum = 0;
        dp[0][(int)(s[0]-'0')] = 1;
        FOR(i,1,l) {
            int t = (int)(s[i]-'0');
            rep(j,11){
                if(t-j>=0) {
                    dp[i][t-j] = dp[i-1][j];
                } else {
                    dp[i][11-j+t] = dp[i-1][j];
                }
            }    
            if(t!= 0) {
                dp[i][t] += 1;
            }
            sum += dp[i][0];
        }
        cout << sum << endl;
    }
	return 0;
}

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

int main() {
	int w, d;
	while (cin >> w >> d, w) {
		int ans = 0;

		vector<int> h1(w), h2(d);
		for (int i=0; i<w; ++i) {
			cin >> h1[i];
			ans += h1[i];
		}
		for (int i=0; i<d; ++i) {
			cin >> h2[i];
			ans += h2[i];
		}

		for (int i=0; i<w; ++i) {
			for (int j=0; j<d; ++j) {
				if (h1[i] == h2[j]) {
					ans -= h1[i];
					h2[j] = -1;
					break;
				}
			}
		}
		cout << ans << endl;
	}
}


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

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

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int mod = (int)1e7+9;
#define REP0(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<=n;i++)
#define F first
#define S second
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define inf (int)(1e18)
#define prec(x) fixed<<setprecision(x)<<x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(x) x.begin(),x.end()

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

void solve(){
    ll n;
    cin>>n;
    n--;
    ll ans = 0;
    REP(i,1,n){
        ans += n/i;
    }
    cout<<ans<<endl;
}


int main(){
    fastio;
    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif
    int tc = 1;
    // cin>>tc;
    for(int i=1;i<=tc;i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string>
#include<string.h>
using namespace std;

int main(){
	double x1, y1, x2, y2;
	double A;
	cin >> x1 >> y1 >> x2 >> y2;
	A = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
	printf("%f\n", sqrt(A));
	return 0;
}


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

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

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int from, to;
    cin >> from >> to;
    ans += to - from + 1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;

#define huge 1000000007

int main(void) {
	
	int m = 0, n = 0;

	cin >> n >> m;

	cout << (n-1)*(m-1) << endl;

	return 0;


}

Measured memory_bytes: 256
import Foundation

let  num = (readLine()!)  .components(separatedBy: " ").map{Int($0) ?? 0 }
let mod: Int = 1000000007
 
var total = 0

func f(_ k: Int) -> Int {
  return  (((num[0])*2-k+1) * k/2) - (k * (k-1) / 2) + 1
}

for i in num[1]...num[0]+1 {
     total += f(i) 
}
 
print(total % mod)


Measured memory_bytes: 14168
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define in insert
#define pi 3.14159265358979323846
#define rep(i,a,b) for(int i = a ; i < b ; i++)
#define repr(i,a,b) for(int i = b ; i > a ; i--)
  
long long fact(long long a, long long b){
    int r= max(a, b);
    int v= min(a, b);
    int l=1;
    // if(v==0)
    for(int i=r+1; i<=a+b; i++){
        l*=i;
    }
    for(int i=v; i>=2; i--){
        l/=i;
    }
    return l;
}

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

int powr(int a) { 
    int var=1;
    for(int i=0; i<a; i++){
        var*=2;
    }
    return var;
}

void func(int a, bool i){
    cout << a;
    if(a==100){
        i=1;
    }
    else if(a==0){
        return;
    }
    if(!i)
        func(a+1, i);
    else
        func(a-1, i);
}

signed main(){   
    fast;
    int n,k;
    cin>>n>>k;
    int a[n];
    int mn = INT_MAX;
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
        mn = min(mn,a[i]);
    }
    vector<bool> dp(k+1,0);
    for(int i=0;i<mn;++i)
    {
        dp[i] = false;
    }
    for(int i=mn;i<=k;++i)
    {
        int flag = false;
        for(int j=0;j<n;++j)
        {
            if(a[j]<=i)
            {
                if(dp[i-a[j]]==false)
                {
                    flag = true;
                    break;
                }
            }
        }
        if(flag)
        {
            dp[i] = true;
        }
        else
        {
            dp[i] = false;
        }
    }
    if(dp[k])
    {
        cout<<"First"<<endl;
    }
    else
    {
        cout<<"Second"<<endl;
    }
 
    
    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d, N, ans=0;
    vector<int> v(3);
    vector<char> L(3);
    char tmp, tmp2;
    string S, S2, S3;
    bool flag=true;
    
    cin >> a >> b;

    cout << (a<=8 && b<=8? "Yay!" : ":(") << endl;
    // ans = a<=b ? a:a-1;

    
    // ans = min(A, B) + min(C, D);
    // cout << ans<< endl;

    // if(S[1]==S[2] &&(S[0]==S[1] | S[2]==S[3]))
    // 	cout << "Yes" <<endl;
    // else
    // 	cout << "No" <<endl;

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(abs(a-b) <=d && (b-c) <=d ||abs(c-a)<=d)
    // 	puts("Yes");
    // else
    // 	puts("No");
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func toIntSliceFromStr(str string) []int {
	strSlice := strings.Split(str, " ")
	var slice []int
	for _, str := range strSlice {
		num, _ := strconv.Atoi(str)
		slice = append(slice, num)
	}
	return slice
}

func main() {
	i1, i2, i3 := nextLine(), nextLine(), nextLine()

	n, _ := strconv.Atoi(i1)
	v := toIntSliceFromStr(i2)
	v2 := toIntSliceFromStr(i3)

	sum := 0
	for i := 0; i < n; i++ {
		diff := v[i] - v2[i]
		if diff > 0 {
			sum += diff
		}
	}

	fmt.Println(sum)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+3;
 
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n;
      cin>>n;
      int b[n];
      for(int i=0;i<n-1;i++) cin>>b[i];
      int a[n];
      a[0]=b[0];
      for(int i=1;i<n-1;i++)
      {
            a[i]=min(b[i-1],b[i]);
      }
      a[n-1]=b[n-2];
      int ans=0;
      for(auto x:a) ans+=x;
      cout<<ans;
}
// I never lose. I either win or I learn

Measured memory_bytes: 256