akhauriyash/Code-Regression huggingface dataset:
use std::collections::BTreeMap;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let a: Vec<i64> = (0..n).map(|_| sc.read()).collect();
    let mut map: BTreeMap<i64, usize> = BTreeMap::new();
    map.insert(0, 1);
    let mut ans = 0;
    let mut cur: i64 = 0;
    for &a in &a {
        cur += a;
        let count = match map.get(&cur) {
            Some(c) => *c,
            None => 0,
        };
        ans += count;
        map.insert(cur, count + 1);
    }
    println!("{}", ans);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


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

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	ll max_a = a[0];
	ll ans = 0;
	rep(i,n){
		if(max_a > a[i]){
			ans += max_a - a[i];
		}else{
			max_a = max(max_a, a[i]);
		}
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String s;
            while ((s = br.readLine()) != null) {
                int[] n_x = Stream.of(s.split(" "))
                        .mapToInt(Integer::parseInt)
                        .toArray();
                if (n_x.length != 2) {
                    throw new IllegalTestCaseException();
                }
                int n = n_x[0];
                int x = n_x[1];
                if (n == 0 && x == 0) {
                    break;
                }
                System.out.println(findCombinations(n, x));
            }
        } catch (IllegalTestCaseException
                | IOException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }

    private static int findCombinations(int n, int x) {
        int count = 0;
        boolean[][][] found = new boolean[n][n][n];
        for (int i = 1; i <= n; i++) {
            for (int j = 2; j <= n; j++) {
                if (i == j) {
                    continue;
                }
                if (i + j > x) {
                    continue;
                }
                for (int k = 3; k <= n; k++) {
                    if (i == k || j == k) {
                        continue;
                    }
                    if (i + j + k == x) {
                        int[] s = IntStream.of(i, j, k).sorted().toArray();
                        if (found[s[0] - 1][s[1] - 1][s[2] - 1]) {
                            continue;
                        }
                        ++count;
                        found[s[0] - 1][s[1] - 1][s[2] - 1] = true;
                    }
                }
            }
        }
        return count;
    }

    private static class IllegalTestCaseException extends RuntimeException {
        IllegalTestCaseException() {
            super("Illegal condition.");
        }
    }
}



Measured memory_bytes: 68584
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
using namespace std;
int main(int argc,char** argv){
  int h,w;
  cin >> h >> w;
  bool height[h],width[w];
  for(int i = 0; i<h;i++){
    height[i] =false;
  }
  for(int j = 0; j<w;j++){
    width[j] =false;
  }

  char a[h][w];
  for(int i = 0; i<h;i++){
    for(int j = 0; j<w;j++){
      cin >> a[i][j];
      if(a[i][j] == '#'){
        height[i] = true;
        width[j] = true;
      }
    }
  }

  for(int i = 0;i<h;i++){
    if(height[i]){
      for(int j = 0;j<w;j++){
        if(width[j]){
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
  return 0;
}


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

int main() {
    long N, M;
    cin >> N >> M;

    if (N == 1 && M == 1) {
        cout << 1 << endl;
    } else if (N == 1) {
        cout << M-2 << endl;
    } else if (M == 1) {
        cout << N-2 << endl;
    } else {
        cout << (N-2) * (M-2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int n;
int a[N];
map<int, int> m, f;

int32_t main()
{
	IOS;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		m[a[i]]++;
	}
	for(auto &it:m)
	{
		int reduce=(it.second-1)/2;
		it.second-=reduce*2;
		f[it.second]++;
	}
	int ans=f[1] + f[2] - f[2]%2;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 7296
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	static long MOD = 1000000007L;

	static class Combination {
		long n;
		long[] array;

		public Combination(long n) {
			this.n = n;
			this.array = new long[(int) (n + 1)];
			array[0] = 0L;
			array[1] = 1L;
			for (long i = 2; i <= n; ++i) {
				int index = (int) i;
				array[index] = array[index - 1] * i % MOD;
			}

		}

		static long pow(long base, long n) {
			long result = 1L;
			long y = base;
			long times = n;
			while (times != 0) {
				if ((times & 1L) > 0) {
					result = (result * y) % MOD;
				}
				y = (y * y) % MOD;
				times /= 2;
			}
			return result;
		}

		static long inv(long val) {
			long result = 1L;
			long k = MOD - 2L;
			long y = val;
			while (k != 0) {
				if ((k & 1L) > 0) {
					result = (result * y) % MOD;
				}
				y = (y * y) % MOD;
				k /= 2;
			}
			return result;
		}

		static long simpleCombi(long n, long c) {
			long result = 1L;
			if (c == 0 || c == n) {
				return 1L;
			}
			if (c > n / 2) {
				return simpleCombi(n, n - c);
			}
			for (long i = n; i > n - c; --i) {
				result *= i;
				result %= MOD;
			}
			for (long i = c; i > 0; --i) {
				result *= inv(i);
				result %= MOD;
			}
			return result;

		}

		long calcCombi(long c) {
			if (c == 0) {
				return 1L;
			}
			// まず階乗の配列を計算する
			long val = array[(int) (n)];
			val *= inv(array[(int) (n - c)]);
			val %= MOD;
			val *= inv(array[(int) (c)]);
			val %= MOD;
			return val;
		}

	}

	int n;
	long k;
	Map<Long, Combination> combiMap = new HashMap<>();
	long result = 0L;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Combination getCombi(Long n) {
		if (!combiMap.containsKey(n)) {
			combiMap.put(n, new Combination(n));
		}
		return combiMap.get(n);
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		n = Integer.parseInt(tokens[0]);
		k = Long.parseLong(tokens[1]);
	}

	long sub(long n, long m) {
		long val = getCombi(n).calcCombi(m);
		val *= getCombi(n - 1).calcCombi((n - m) - 1) % MOD;
		return val;
	}

	void calc() {
		result = 1;
		for (long i = 1; i <= Math.min(k, n - 1); ++i) {
			result += sub(n, i);
			result %= MOD;
		}
	}

	void showResult() {
		System.out.println(result);
	}

}

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

int main() {
    int a,b,k;
    cin >> a >> b >> k;
    int now = 0;
    for(int i = min(a,b); i > 0; i--) {
        if(a%i == 0 && b%i == 0) {
            now++;
            if(now == k) {
                cout << i << endl;
                break;
            }
        }
    }
}

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

int a[100005];
int dp[100005];

main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)cin >> a[i];
	
	dp[1] = a[1];
	dp[2] = abs(a[1] - a[2]);
	dp[3] = abs(a[1] - a[3]);
	
	for(int i = 4; i <= n; i++)
	{
		dp[i] = min( dp[i - 1] + abs(a[i] - a[i-1]) , dp[i - 2] + abs(a[i] - a[i-2]) );
	}
	
	//for(int i = 1; i <= n; i++)cout << dp[i] << " ";
	
	cout << dp[n] << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
using namespace std;
#define inf 1000000009
#define int long long
int graf[51][51];
int a[51], b[51];
void init() {
	for (int i = 0; i < 51; i++)
		for (int j = 0; j < 51; j++)graf[i][j] = inf;
	for (int i = 0; i < 51; i++)graf[i][i] = 0;
	return;
}
void war(int n) {
	for (int k = 0; k < n; k++)
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			graf[i][j] = min(graf[i][j], graf[i][k] + graf[k][j]);

}
signed main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)cin >> a[i] >> b[i];

	int ans = 0;
	for (int i = 0; i < m; i++) {
		init();
		for (int j = 0; j < m; j++) {
			if (i != j) {
				graf[a[j] - 1][b[j] - 1] = 1;
				graf[b[j] - 1][a[j] - 1] = 1;
			}
		}war(n);
		int flg = 0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)if (graf[i][j] == inf)flg++;
		if (flg)ans++;
	}
	cout << ans << endl;
	}

Measured memory_bytes: 256
n, m = map(int, input().split())
c = [False for i in range(200001)]
d = [False for i in range(200001)]
for i in range(m):
	a, b = map(int, input().split())
	if a == 1:
		c[b] = True
	if b == n:
		d[a] = True
for i in range(200001):
	if c[i] and d[i]:
		print ("POSSIBLE")
		exit()
print ("IMPOSSIBLE")

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

int main() {
  int N,i,j;
  int a[40];

  cin >> N;

  i=0;
  if(N==0) {
    a[0] = 0;
    i = 1;
  }else {
    while(N!=0) {
      a[i] = (N%2==0)?0:1;
      N = (N-a[i])/(-2);
      i++;
    }
  }
  
  for(j=i-1;j>=0;j--) cout << a[j];
  cout << endl;


  return 0;
}


Measured memory_bytes: 256
// ABC113_A
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

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

    // input
    ll N, M;
    cin >> N >> M;
    
    // calculation
    cout << N + M/2 << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.awt.Point;
import java.util.*;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
while(!(str=br.readLine()).equals("0 0")){
String[] value=str.split(" ");
int h=Integer.parseInt(value[0]);
int w=Integer.parseInt(value[1]);
char[][] map=new char[h][w];
for(int i=0;i<h;i++){
map[i]=br.readLine().toCharArray();
}
Queue <Point> fifo  =new  LinkedList<Point>();
            int ans=0;
            for(int m=0;m<h;m++){
                for(int n=0;n<w;n++){
            if(map[m][n]!='.'){
                ans++;
                Point p = new Point(n,m);
                fifo.add(p);
            while(fifo.peek()!=null){
                p=fifo.poll();
                int x=p.x;
                int y=p.y;
                char crop = map[y][x];
                map[y][x]='.';
                int [] dx ={0,1,0,-1};
                int [] dy ={1,0,-1,0};
                 
                for(int i=0;i<4;i++){
                    int nx =x+dx[i];
                    int ny =y+dy[i];
                    if(0<=nx&&nx<w&&0<=ny&&ny<h&&map[ny][nx]==crop&&map[ny][nx]!='.'){
                        Point np = new Point();
                        np.x=nx;
                        np.y=ny;
                        fifo.add(np);
                         
                    }
                }
            }
            }
                }
            }System.out.println(ans);
           }
        }
}

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

struct edge{
  int to;
  int64_t cost;
  edge(){}
  edge(int t,int64_t c):to(t),cost(c){}
};
vector<vector<edge>> adj;
vector<int64_t> dist;

void dfs1(int cur,int prv){
  for(auto nxt:adj[cur]){
    if(nxt.to==prv)continue;
    dfs1(nxt.to,cur);
    dist[cur] = max(dist[cur],dist[nxt.to]+nxt.cost);
  }
}

int64_t dfs2(int cur,int d_prv,int prv){
  vector<pair<int,int64_t>> d_child;
  d_child.emplace_back(0,-1);
  for(auto nxt:adj[cur]){
    if(nxt.to==prv)d_child.emplace_back(d_prv+nxt.cost,nxt.to);
    else d_child.emplace_back(nxt.cost+dist[nxt.to],nxt.to);
  }
  sort(rbegin(d_child),rend(d_child));
  int64_t res = d_child[0].first + d_child[1].first;
  for(auto nxt:adj[cur]){
    if(nxt.to==prv)continue;
    res = max(res,dfs2(nxt.to,d_child[d_child[0].second==nxt.to].first,cur));
  }
  return res;
}

signed main(){

  int n;
  cin>>n;
  adj.resize(n);
  dist.resize(n);
  for(int i=0;i<n-1;++i){
    int s,t,w;
    cin>>s>>t>>w;
    adj[s].emplace_back(t,w);
    adj[t].emplace_back(s,w);
  }
  dfs1(0,-1);
  cout<< dfs2(0,0,-1) <<endl;

}


Measured memory_bytes: 32300
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int info = sc.nextInt();

    int[][][] floors = new int [4][3][10];

    for(int i = 0; i < info; i++) {
      int tou = sc.nextInt();
      int floor = sc.nextInt();
      int roonNum = sc.nextInt();
      int persons = sc.nextInt();
      floors[tou - 1][floor - 1][roonNum - 1] += persons;
    }
    sc.close();

    printArray(floors);
  }

  public static void printArray(int[][][] floorData) {
    for(int i = 0; i < floorData.length; i++) {
      for(int j = 0; j < floorData[i].length; j++) {
        for(int l = 0; l < 10; l++) {
          System.out.print(" " + floorData[i][j][l]);
        }
        System.out.println();
      }

      if(i != 3) {
        System.out.print("####################");
        System.out.println();
      }
    }
  }
}


Measured memory_bytes: 29456
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x) {
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

int n, m;

int a[1234];
int b[1234];

int f(){
  int way = 1, tot = 0;
  if(a[1] != n * m || b[1] != n * m){
    return 0;
  }
  for(int i = n * m, x = 1, y = 1; i >= 1; i--){
    if(x <= n && a[x] == i && y <= m && b[y] == i){
      x++; y++;
    } else if(x <= n && a[x] == i){
      x++;
      way = 1ll * way * (y - 1) % mod;
    } else if(y <= m && b[y] == i){
      y++;
      way = 1ll * way * (x - 1) % mod;
    } else {
      way = 1ll * way * (((x - 1) * (y - 1)) - tot) % mod;
    }
    //cout << way << " " << x << " " << y << " " << i << " " << tot << '\n';
    tot++;
  }
  return way;
}

int main(){
  fastScan(n);
  fastScan(m);
  for(int i = 1; i <= n; i++){
    fastScan(a[i]);
  }
  for(int i = 1; i <= m; i++){
    fastScan(b[i]);
  }
  sort(a + 1, a + n + 1, greater < int > ());
  sort(b + 1, b + m + 1, greater < int > ());
  printf("%d\n", f());
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		sc.close();
		int wa = 0, max = 0;;
		for(int i = 0; i < N; i++) {
			int a = 0;
			if(i == N - 1) a = K - A[i] + A[0];
			else a = A[i + 1] - A[i];
			wa += a;
			if(a > max) max = a;
		}
		System.out.println(wa - max);
	}
}

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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

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

    vector<ll> A(N);
    rep(i, N) cin >> A[i];

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

    ll ans = 1;
    rep(i,N){
        if(ans != 0 && 1100100100100100100L / ans < A[i]){
            ans = -1;
            break;
        }
        ans *= A[i];
        if (ans > 1000000000000000000L || ans < 0)
        {
            ans = -1;
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4116
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int x;
	cin >> x;
	
	for(int i = 1; i * 100 <= x; ++i) {
		if( x - i * 100 <= i * 5) {
			cout << 1 << endl;
			return 0;
		}
	}
	
	cout << 0 << endl;
	
	return 0;
}


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


auto solve(long long n, long long m){
    return (n-1) * (m-1);
}

int main(){
    long long n;
    scanf("%lld",&n);
    long long m;
    scanf("%lld",&m);
    auto result = solve(n, m);
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  int n,k;
  cin>>n>>k;
  vector<P> a(n);
  rep(i,n){
    cin>>a[i].F;
    a[i].S=i+1;
  }


  sort(all(a));
  reverse(all(a));

  vector<int> ans;

  rep(i,n){
    ans.PB(a[i].S);
    a[i].F--;
  }
  int m=a[n-1].S;

  
  while(k--){
    sort(all(a));
    reverse(all(a));
    int l=-1;
    rep(i,n){
      if(a[i].S==m) continue;
      ans.PB(a[i].S);
      a[i].F--;
      l=a[i].S;
    }
    m=l;
  }

  rep(i,n){
    if(a[i].F<0){
      cout<<-1<<endl;
      return 0;
    }
  }

  cout<<ans.size()<<endl;
  rep(i,ans.size()){
    cout<<ans[i]<<' ';
  }
  cout<<endl;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

ll n,k;

void init(){
	cin>>n>>k;
}

int main(void){
	init();
	if(n>=10){
		cout<<k<<endl;
	}else{
		cout<<k+100*(10-n)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll X;
  cin >> X;

  REP(i, 1, X+1) {
    if (100 * i <= X && X <= 105 * i) {
      cout << "1" << endl;
      return 0;
    }
  }
  cout << "0" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
	string S, T;
	cin >> S >> T;

	int N = S.size() - T.size(); // 先頭の選び方
	int Ans = T.size();	// 答え(初期値は取りうる最大値)

	for (int i =0; i <= N; i++) {
		int count = 0;	// 一時的に合わない数を補完
		for (int j =0; j < T.size(); j++) {
			if(S[i+j] != T[j]) {
				count++; // 異なる文字の時countを増やす	
			}
		}
		Ans = min(Ans, count);	// countとansで一致度が高いほうをAnsに
	}

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

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

typedef long long ll;
#define int long long
int N;
const int INF=1e9;
int A[112345];
vector<int> B,C;
map<int,int>mp;
ll ans;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define dump(x) cerr<<#x<<"="<<x<<endl
signed main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
        mp[A[i]]=i;

        if(i%2==0)B.push_back(A[i]);
        else{
            C.push_back(A[i]);
        }
    }
    sort(A,A+N);
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());
    B.push_back(INF+1);


    {
        rep(i,N){
            ans+=abs(mp[A[i]]-i)%2;
        }
    }
    cout<<ans/2<<endl;
}


Measured memory_bytes: 8048
import java.util.*;

class Main
{
  public static void main(String args[]){
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int d=s.nextInt();
    if(n>=10)
      System.out.print(d);
    else 
      System.out.print(d+100*(10-n));
  }
}

Measured memory_bytes: 21716
func main() {
let n = Int(readLine()!)!
var A = readLine()!.split(separator: " ").map{Int($0)!}

let q = Queue(2*n, 0)
A.sort{$0>$1}

q.enque(A[0])
var sum = 0
for i in 1..<A.count {
	q.enque(A[i])
	q.enque(A[i])
	sum += q.dequeue()
}
print(sum)
}
main()

class Queue<T> {
	private var q: [T]
	private var head = 0
	private var index = 0
	init(_ max: Int, _ defaultValue: T){
		q = Array(repeating: defaultValue, count: max)
	}

	func enque(_ value: T){
		q[index] = value
		index = (index + 1) % q.count
	}

	func dequeue() -> T {
		let val = q[head]
		head = (head + 1) % q.count
		return val
	}
}


Measured memory_bytes: 21352
# coding: utf-8

import sys
input = sys.stdin.readline

def f4(n, h, a):
    bit = [0] * (n + 1)

    def getmax(h):
        x = h - 1
        m = 0
        while x != 0:
            if m < bit[x]:
                m = bit[x]
            x -= x & -x
        return(m)

    def update(h, v):
        x = h
        while x <= n:
            if bit[x] < v:
                bit[x] = v
            x += x & -x

    for i in range(1, n + 1):
        m = getmax(h[i])
        update(h[i], m + a[i])
    return(max(bit))

n = int(input()) # 1 <= n <= 2 x 10^5
h = [0] + list(map(int, input().split()))
a = [0] + list(map(int, input().split()))

print(f4(n, h, a))


Measured memory_bytes: 112752
#pragma region

#ifdef LOCAL
#define debug cout
#else
#define debug \
    if (0) cout
#endif

#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[ ";
    for (auto e : v) os << e << " ";
    return os << "]";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, set<T, V> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V, typename S>
ostream& operator<<(ostream& os, map<T, V, S> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, pair<T, V> x) {
    return os << "( " << x.first << ", " << x.second << " )";
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& e : v) is >> e;
    return is;
}

template <typename T, typename V>
istream& operator>>(istream& is, pair<T, V>& x) {
    return is >> x.first >> x.second;
}

void solve();

int main() {
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    solve();
}

#pragma endregion

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    cin >> a;
    vector<vector<ll>> dp(n + 2, vector<ll>(n + 2, 0));
    for (int s = 1; s <= n; ++s) {
        for (int i = 1; i + s - 1 <= n; ++i) {
            int j = i + s - 1;
            if (s % 2 == n % 2) {
                dp[i][j] = max(a[i - 1] + dp[i + 1][j], a[j - 1] + dp[i][j - 1]);
            } else {
                dp[i][j] = min(-a[i - 1] + dp[i + 1][j], -a[j - 1] + dp[i][j - 1]);
            }
        }
    }
    cout << dp[1][n] << "\n";
}

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

int main()
{
  int N; cin >> N;
  vector<int> D(N);
  for(int i=0;i<N;i++)
    {
      cin >> D[i];
    }
  int sum = 0;
  for(int i=0;i<N;i++)
  {
    for(int j=i+1;j<N;j++){
      sum += D[i] * D[j];
    }
  }
  cout << sum << endl;
  return 0; 
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] a = new int[n + 1];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		long sum = 0;
		for (int i = 0; i < n; i++) {
			sum += a[i] / 2;
			a[i] %= 2;
			if (0 < a[i] && 0 < a[i + 1]) {
				sum++;
				a[i]--;
				a[i + 1]--;
			}
		}
		System.out.println(sum);
	}

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


Measured memory_bytes: 22104
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

type Num int
type Nums []Num

func (a Nums) Len() int {
	return len(a)
}

func (a Nums) Less(i, j int) bool {
	return a[i] < a[j]
}

func (a Nums) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make(Nums, n)
	for i := range a {
		a[i] = Num(nextInt())
	}
	sort.Sort(a)

	ans := 0
	l, r := 0, 0
	for r < n {
		for r+1 < n && a[l] == a[r+1] {
			r++
		}
		ans += (r - l + 1) % 2
		r++
		l = r
	}
	fmt.Println(ans)
}


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

#define LL long long
#define RG register

using namespace std;
template<class T> inline void read(T &x) {
	x = 0; RG char c = getchar(); bool f = 0;
	while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;
	while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();
	x = f ? -x : x;
	return ;
}
template<class T> inline void write(T x) {
	if (!x) {putchar(48);return ;}
	if (x < 0) x = -x, putchar('-');
	int len = -1, z[20]; while (x > 0) z[++len] = x%10, x /= 10;
	for (RG int i = len; i >= 0; i--) putchar(z[i]+48);return ;
}
const int N = 2e5 + 10, inf = 1e9;
int n;
struct node {
	int x, y;
} a[N];
bool cmp(node a, node b) {
	return a.x < b.x;
}
int lmx1[N], rmx1[N], lmn1[N], rmn1[N];
int lmx2[N], rmx2[N], lmn2[N], rmn2[N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	read(n);
	for (int i = 1; i <= n; i++) {
		read(a[i].x); read(a[i].y);
		if (a[i].x > a[i].y) swap(a[i].x, a[i].y);
	}
	sort(a + 1, a + 1 + n, cmp);
	int Rmax = -inf, Rmin = inf, Lmax = -inf, Lmin = inf;
	for (int i = 1; i <= n; i++) {
		lmx1[i] = Lmax = max(Lmax, a[i].x); lmn1[i] = Lmin = min(Lmin, a[i].x);
		rmx1[i] = Rmax = max(Rmax, a[i].y); rmn1[i] = Rmin = min(Rmin, a[i].y);
	}
	Rmax = -inf, Rmin = inf, Lmax = -inf, Lmin = inf;
	for (int i = n; i >= 1; i--) {
		lmx2[i] = Lmax = max(Lmax, a[i].x); lmn2[i] = Lmin = min(Lmin, a[i].x);
		rmx2[i] = Rmax = max(Rmax, a[i].y); rmn2[i] = Rmin = min(Rmin, a[i].y);
	}
	LL ans = 1ll * (Rmax - Rmin) * (Lmax - Lmin);
	for (int i = 2; i <= n; i++) {
		Lmax = max(lmx2[i], rmx1[i - 1]); Lmin = min(lmn2[i], rmn1[i - 1]);
		Rmax = max(rmx2[i], lmx1[i - 1]); Rmin = min(rmn2[i], lmn1[i - 1]);
		ans = min(ans, 1ll * (Rmax - Rmin) * (Lmax - Lmin));
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 8064
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn calc(a: i64, c: i64) -> i64 {
    a - a / c
}

fn calc2(a: i64, c: i64, d: i64) -> i64 {
    calc(a, c) + calc(a, d) - calc(a, c * d / gcd(c, d))
}

fn main() {
    let v = read_vec::<i64>();
    let (a, b, c, d) = (v[0], v[1], v[2], v[3]);
    let ans = calc2(b, c, d) - calc2(a - 1, c, d);
    //debug!(calc2(b, c, d), calc2(a - 1, c, d));
    println!("{}", ans);
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
vector<pair<ll,ll> > adj[100002];
vector<ll> vis(100002,0);
vector<ll> col(100002,0);
void dfs(ll src)
{
	vis[src]=1;
	for(auto i:adj[src])
	{
		if(vis[i.first]==0)
		{
			if(i.second%2==0)
			{
				col[i.first]=col[src];
			}
			else
			{
				col[i.first]=abs(col[src]-1);
			}
			dfs(i.first);
		}
		
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	col[1]=1;
	ll i=0;
	ll u,v,w;
	for(i=0;i<n;i++)
	{
		cin>>u>>v>>w;
		adj[u].pb(mp(v,w));
		adj[v].pb(mp(u,w));
	}
	col[0]=1;
	col[1]=1;
	dfs(1);
	for(i=1;i<=n;i++)
	{
		cout<<col[i]<<"\n";
	}
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std ; 
int main()
{
	long long x , y ; 
	cin >> x >> y ; 
	int ans = 0 ; 
	while(x <= y)
	{
		x*=2 ; 
		ans++ ; 
	} 
	cout << ans << endl ; 
}

Measured memory_bytes: 256
r, op, l = gets.split
a = r.to_i
b = l.to_i

while op != "?"
if op == "+"
 puts a + b
elsif op == "-"
 puts a - b
elsif op == "*"
 puts a * b
else
 puts a / b
end

r, op, l = gets.split
a = r.to_i
b = l.to_i

end


Measured memory_bytes: 6872
#include<cstdio>
#include<cstring>

char s[100001];
int length, left = -1, right = -1;

int main() {
    scanf("%s", s);
    length = strlen(s);
    for(int i=0; i<length-2; i++) {
    	if(s[i] == s[i+1]) {
    		left = i + 1;
    		right = i + 2;
    		break;
    	} else if(s[i] == s[i+2]) {
    		left = i + 1;
    		right = i + 3;
    		break;
    	} else if(s[i+1] == s[i+2]) {
    		left = i + 2;
    		right = i + 3;
    		break;
    	}
    }

    if(left == -1 && s[length-2] == s[length-1]) {
    	left = length - 1;
    	right = length;
    }
    printf("%d %d\n", left, right);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007

int main(){
    int h,w,n;
    cin>>h>>w>>n;
    if(h>=w){
        if(n%h==0){
        cout << n/h<<endl;
        }
        else{
            cout<<n/h+1<<endl;
        }
    }
    else{
        if(n%w==0){
            cout<<n/w<<endl;
        }
        else{
            cout<<n/w+1<<endl;
        }
    }
}

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

using namespace std;

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

  int n,m;
  cin >> n >> m;
  vector<string> a(n),b(m);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < m; i++) cin >> b[i];

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i+m-1 > n or j+m-1 > n) continue;

      bool flag = true;
      for(int y = 0; y < m; y++){
        for(int x = 0; x < m; x++){
          if(a[i+y][j+x] != b[y][x]){
            flag = false;
            y = x = m;
          }
        }
      }
      if(flag){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdio>
#define int long long
using namespace std;

int n, m;
int l[200000], r[200000], d[200000];
vector<int> et[100000];
vector<int> ec[100000];
bool used[100000];
int cst[100000];

signed main() {
	int i, j;
	
	scanf("%lld%lld", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%lld%lld%lld", l + i, r + i, d + i);
		l[i]--; r[i]--;
		et[l[i]].push_back(r[i]);
		ec[l[i]].push_back(d[i]);
		et[r[i]].push_back(l[i]);
		ec[r[i]].push_back(-d[i]);
	}
	
	static queue<int> que;
	for (i = 0; i < n; i++) {
		if (used[i]) continue;
		used[i] = true;
		que.push(i);
		while (!que.empty()) {
			int v = que.front(); que.pop();
			for (j = 0; j < et[v].size(); j++) {
				int nv = et[v][j];
				if (!used[nv]) {
					used[nv] = true;
					que.push(nv);
					cst[nv] = cst[v] + ec[v][j];
				}
			}
		}
	}
	
	for (i = 0; i < m; i++) {
		if (cst[r[i]] - cst[l[i]] != d[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 23168
/*
ID: seekho
PROG: friday
LANG: C++14                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
// const int N = 100005;

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);

    int n,m;
    cin >> n >> m;

    vector<int> cnt(m,0);

    int in1;
    rep(i,n) {
        cin >> in1;
        int te;
        while(in1--) {
            cin >> te;te--;
            cnt[te]++;
        }
    }
    int cc = 0;
    rep(i,m) {
        if(cnt[i] == n) cc++;
    }
    cout << cc << "\n";
}

Measured memory_bytes: 256
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
ll p[2*MAX],q[2*MAX];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,i,j,x,c=0;
    //vector <pll> v;
    map <ll,ll> m1;
    cin>>n;
    for(i=0;i<n;++i){
    	cin>>x;
    	p[i]=x-i;
    	q[i]=x+i;
    	m1[q[i]]++;
	}
	for(i=0;i<n;++i){
		if(p[i]<0){
			c+=m1[-p[i]];
		}
	}
	cout<<c;
}

Measured memory_bytes: 20460
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	int n,k,p[1004],ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	sort(p,p+n);
	for(int i=0;i<k;i++){
		ans+=p[i];
	}
	cout<<ans<<endl;
    return(0);
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

ll dfs(string s, ll cost){
  if(s.size() == 0) return cost;
  ll res = 0;
  rep(i,s.size()){
    //cout << s.substr(0,i+1) << endl;
    res += dfs(s.substr(i+1,s.size()-(i+1)), cost + toLL(s.substr(0,i+1)));
  }
  return res;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;

  ll ans = dfs(s,0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
#define INF 0x3f3f3f3f
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
double L;

int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    cin>>L;
    cout<<fixed<<setprecision(12)<<L*L*L/3/3/3<<endl;    
    
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n; cin >> n; ll count = 0;
  map<string,ll> table;
  
  for(ll i=0; i < n; i++){
    string str; cin >> str; sort(all(str));
    
    if(table.count(str)){
      table[str]++;
      count += table[str];
    }
    else table[str] = 0;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 11136
// https://atcoder.jp/contests/abc079/tasks/abc079_d
#include <bits/stdc++.h>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>

using namespace std;
using namespace boost;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

const int SZ = 10;
int cost[SZ][SZ], mcost[SZ][SZ];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, t;
    cin >> h >> w;
    REP(i, SZ) REP(j, SZ) cin >> cost[i][j];
    vector<vector<int>> v(h);
    REP(i, h) REP(j, w) {
        cin >> t;
        v[i].push_back(t);
    }
    // undirectedS は無向グラフ、directedS は有向グラフ
    adjacency_list<listS, vecS, directedS, no_property,
                   property<edge_weight_t, int>>
        graph1(SZ);
    REP(i, SZ) REP(j, SZ) {
        if (i != j) {
            add_edge(i, j, cost[i][j], graph1);
        }
    }

    // k からの最短距離を求める
    vector<int> dist(SZ);
    vector<int> par(SZ);
    REP(i, SZ) {
        dijkstra_shortest_paths(
            graph1, i, distance_map(dist.data()).predecessor_map(par.data()));
        REP(j, SZ) {
            mcost[i][j] = dist[j];
            // cout << mcost[i][j] << " ";
        }
        // cout << endl;
    }
    ll sum = 0;
    REP(i, h) REP(j, w) {
        int a = v[i][j];
        if (a >= 2 || a == 0) {
            sum += mcost[a][1];
        }
    }
    cout << sum << endl;

    return 0;
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

int main() {
    int m, d;
    cin >> m >> d;
    int ans = 0;
    REP1(i, m) {
        if (i == 1) continue;
        REP1(j, d) {
            if (j / 10 == 1 || j % 10 == 1) continue;
            if (i == (j / 10) * (j % 10)) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define loop(i,a,b) for(int i=int(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
typedef vector<int> vi;

int np(const vi& w, const vi& v, int W){
    vi cur(W+1);
    int n=w.size();
    rep(i,n){
        vi next = cur;
        rep(j,W+1){
            if(j-w[i]>=0) next[j]=max({cur[j-w[i]]+v[i],next[j-w[i]]+v[i],cur[j]});
        }
        swap(cur,next);
    }
    return cur[W];
}

int main(){
    int n,C;
    while(cin>>n>>C){
        vi c(n), s1(n), s2(n), s3(n);
        rep(i,n){
            string s;
            cin.ignore();
            getline(cin,s);
            cin >> c[i] >> s1[i] >> s2[i] >> s3[i];
        }

        int ans =-1;
        ans = max(ans, np(c,s1,C));
        ans = max(ans, np(c,s2,C));
        ans = max(ans, np(c,s3,C));
        cout << ans << endl;
    }
}

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

int main() {
	while (1) {
		int a;
		cin >> a;
		if (a == 0)break;
		vector<int>s(12);
		for (int b = 0; b < 12; b++) {
			int c, d;
			cin >> c >> d;
			s[b] = c - d;
			if (a <= 0) {
				cout << b + 1 << endl; break;
			}
		}
		for (int f = 0; f < 12; f++) {
			a -= s[f];
			if (a <= 0) { cout << f + 1 << endl; break; }
			if (f == 11) { cout << "NA" << endl; break; }
		}
	}
}

Measured memory_bytes: 3056
def has_duplicates2(seq):
    seen = []
    unique_list = [x for x in seq if x not in seen and not seen.append(x)]
    return len(seq) != len(unique_list)

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort(reverse=True)

NGcount = 0
sumA = sum(A)
Z = -(-sumA // (4 * M))

for x in range(M):
    if A[x] < Z:
        NGcount = NGcount + 1

if M > N:
    print('No')
elif has_duplicates2(A):
    print('No')
elif min(A) == 0:
    print('No')
else:
    if NGcount == 0:
        print('Yes')
    else:
        print('No')

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

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

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

using namespace std;
using ll = long long;

int main() {
    vector<int> ans(10001,0);
    for (int x = 1; x <= 100; ++x) {
        for (int y = 1; y <= 100; ++y) {
            for (int z = 1; z <= 100; ++z) {
                int q=x*x+y*y+z*z+x*y+y*z+z*x;
                if(q<=10000)ans[q]++;
            }
        }
    }
    int n;
    cin>>n;
    for (int i = 1; i <= n; ++i) {
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
def solve():
    MOD = 998244353

    N, S = map(int, input().split())
    As = list(map(int, input().split()))

    dp1 = [0] * (S+1)
    dp2S = 0
    for A in As:
        dp2S += dp1[S]
        if S-A >= 0:
            dp2S += dp1[S-A]
        if S-A == 0:
            dp2S += 1
        dp2S %= MOD
        for sm in reversed(range(A+1, S+1)):
            dp1[sm] += dp1[sm-A]
            dp1[sm] %= MOD
        if S-A >= 0:
            dp1[A] += dp1[0] + 1
            dp1[A] %= MOD
        dp1[0] += 1

    print(dp2S)


solve()


Measured memory_bytes: 3316
#import<bits/stdc++.h>
using namespace std;long M=1000000007,s,t=(M+1)/2,a,z,A,m[1<<20],l[1<<20];vector<long>n(1<<20,1);main(){cin>>A;while(cin>>A)if(a^=A){(m[a]+=(n[a]+=m[a]*(z-l[a]))%=M)%=M;s+=n[a];l[a]=z;}else++z,(t*=2)%=M;cout<<(a?n[a]:(s+t)%M)<<endl;}

Measured memory_bytes: 24832