akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4

int main(){
  int N; cin >> N;
  
  if (N%10==3) cout << "bon" << endl;
  else if (N%10==0 || N%10==1 || N%10==6 ||N%10==8) cout << "pon" << endl;
  else cout << "hon" << endl;
 
  return 0;
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        try {
 
            String str[] = br.readLine().split("\\s+");
            int array[] = new int[str.length];
 
            for(int i = 0; i < str.length; i++){
                array[i] = Integer.parseInt(str[i]);
            }
 
            Dice dice = new Dice();
            dice.setNumber(array[0], array[1], array[2], array[3], array[4], array[5]);
 
            int Q = Integer.parseInt(br.readLine());
 
            String tmp_str[] = new String[2];
            int top_num,front_num;
 
            for(int loop = 0; loop < Q; loop++){
 
                tmp_str = br.readLine().split("\\s+");
                top_num = Integer.parseInt(tmp_str[0]);
                front_num = Integer.parseInt(tmp_str[1]);
 
                System.out.println(dice.query(top_num, front_num));
            }
 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
class Dice{
 
    private int number[];
    private int work[];
    private final String order = "NNNNWNNNWNNNENNNENNNWNNN";
 
    Dice(){
        number = new int[6];
        work = new int[6];
    }
 
 
    public void roll(char dst){
        for(int i = 0; i < 6; i++) work[i] = number[i];
        switch(dst){
        case 'E':
            setNumber(work[3],work[1],work[0],work[5],work[4],work[2]);
            break;
        case 'N':
            setNumber(work[1],work[5],work[2],work[3],work[0],work[4]);
            break;
        case 'S':
            setNumber(work[4],work[0],work[2],work[3],work[5],work[1]);
            break;
        case 'W':
            setNumber(work[2],work[1],work[5],work[0],work[4],work[3]);
            break;
        }
    };
 
    public int query(int top_num,int front_num){
 
        int save_data[] = new int[6];
        for(int i = 0; i < number.length; i++){
            save_data[i] = number[i];
        }
 
        int ret = -1;
 
        for(int i = 0; i < order.length(); i++){
            roll(order.charAt(i));
            if(number[0] == top_num && number[1] == front_num){
                ret = number[2];
                break;
            }
        }
 
        for(int i = 0; i < save_data.length; i++){
            number[i] = save_data[i];
        }
 
        return ret;
    }
 
    public int getTop(){
        return number[0];
    }
 
    public void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
        number[0] = n0;
        number[1] = n1;
        number[2] = n2;
        number[3] = n3;
        number[4] = n4;
        number[5] = n5;
    }
};


Measured memory_bytes: 24404
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a,a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x - a)*(x - a) + (y - b)*(y - b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cout << a[k] << " ";} cerr << "\n"; }
#define PI 3.14159265358979323846

int main(){
	FASTIO;
	string s; cin >> s;
	deque<char> ans;
	for (char c: s) ans.pb(c);
	ll op = 0;
	ll q; cin >> q;
	for ( int k = 0; k < q; k++ ){
		ll x; cin >> x;
		if (x == 1) {
			op = !op;
			continue;
		}
		cin >> x;
		char c; cin >> c;
		if ((x + op) % 2)
			ans.push_front(c);
		else
			ans.pb(c);
	}
	if (op)
		reverse(all(ans));
	for (char c : ans)
		cout << c;
	cout << endl;
	return 0;
}

Measured memory_bytes: 976
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define show(x) cout << #x << " = " << x << endl;
ll a[55];
int n;
vector<pii>ans;
bool check(){
    rep(i,n-1){
        if(a[i] > a[i+1])return false;
    }
    return true;
}
void sei(){
    rep(i,n-1){
        ans.push_back(pii(i,i+1));
        a[i+1] += a[i];
    }
}
void hu(){
    rep(i,n-1){
        ans.push_back(pii(n-1-i,n-2-i));
        a[n-2-i] += a[n-1-i];
    }
}
int main(){
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    if(check()){
        cout << 0 << endl;
        return 0;
    }
    ll ma = *max_element(a,a+n);
    int ma_index = (int)(max_element(a,a+n) -a);
    ll mi = *min_element(a,a+n);
    int mi_index = (int)(min_element(a,a+n) -a);
    if(mi >= 0){
        sei();
    }else if(ma <0){
        hu();
    }else if(mi < 0 and ma >= 0){
        if(ma >= -mi){
            rep(i,n){
                if(i != ma_index){
                    ans.push_back(pii(ma_index,i));
                    a[i] += ma;
                }
            }
            sei();
        }else{
            rep(i,n){
                if(i != mi_index){
                    ans.push_back(pii(mi_index,i));
                    a[i] += mi;
                }
            }
            hu();
        }
    }
    rep(i,n){
        //cout << a[i] << endl;
    }
    cout << ans.size() << endl;
    rep(i,ans.size()){
        cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int K = scan.nextInt();
        int p[] = new int[N];
        for(int i=0;i < N;i++){
            p[i] = scan.nextInt();
        }
        Arrays.sort(p);
        int min = p[K-1] - p[0];
        for(int i=1;i+K <= N;i++){
            if(min > (p[i + K - 1] - p[i])){
                min = (p[i + K - 1] - p[i]);
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 52212
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    rep(i,len(s)-1){
        if(s[i] == 'A' && s[i+1] == 'C'){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#define int long long 
using namespace std;
signed main(){
  int N;
  cin >> N;
  int A[N], B[N], C[N];
  for(int i = 0; i < N; ++i) cin >> A[i];
  for(int i = 0; i < N; ++i) cin >> B[i];
  for(int i = 0; i < N; ++i) cin >> C[i];
  sort(A,A+N);
  sort(B,B+N);
  sort(C,C+N);
  int t = 0, k = 0;
  int ans = 0;
  for(int i = 0; i < N; ++i){
    int b = B[i];
    while(t < N && A[t] < b) ++t;
    while(k < N && C[k] <= b) ++k;
    //cout << t << " " << k << endl;
    if(A[t-1] < b && b < C[k]){
      ans += (t)*(N-k);
    }else{
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n)cin >> v[i];
    int odd = 0, even = 0;
    for (ll l : v)
        if (l % 2 == 0) odd++;
        else even++;

    if (even % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;

#define INF INT_MAX

class RMQ{
public:

  vector<int> rangeMin;
  int n;

  
  RMQ(int size);
  void init(int size);
  void update(int k, int a);
  int find(int a, int b);
  int query(int a, int b, int k, int l, int r);


};


int main(){
  
  int n,q;

  cin >> n >> q;
  RMQ rmq(n);

  for(int i=0; i<q; i++){
    int com,x,y;
    cin >> com >> x >> y;

    if(com == 0)rmq.update(x,y);
    else{
      cout << rmq.find(x,y) << endl;
    }
  }
  
  return 0;
}




//===========================================
//===========================================

RMQ::RMQ(int size){
  init(size);
}
//@end RMQ()



void RMQ::init(int size){
  n=1;
  
  // calc necessary size of array
  while(n < size )n*=2;
  
  rangeMin.resize(2*n-1);
  for(int i=0; i<2*n-1; i++){
    rangeMin[i] = INF;
  }
}
//@end init()


void RMQ::update(int k, int a){
  k += n-1;
  rangeMin[k] = a;
  while( k>0 ){
    k = (k-1)/2;
    rangeMin[k] = min(rangeMin[k*2+1] , rangeMin[k*2+2]);
  }
}
//@end update()



int RMQ::find(int a, int b){
  return query(a, b+1, 0, 0, n);
}
//@end findMin()



int RMQ::query(int a, int b, int k, int l, int r){
  if( r <= a || b <= l )return INF;
  if( a <= l && r <= b )return rangeMin[k];

  int vl = query(a,b, k*2+1, l, (l+r)/2);
  int vr = query(a,b, k*2+2, (l+r)/2, r);
  return min(vr,vl);
}
//@end query()



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

public class Main {
    public static InputReader in;
    public static PrintWriter out;
    public static void main(String[] args) {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] a = new int[n];
        int[] sum = new int[n];
        int[][] bitsum = new int[n][22];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            sum[i] = a[i];
            for (int j = 0; j < 21; j++) {
                int bit = ((a[i] >> j) & 1);
                bitsum[i][j] = bit;
            }
            if (i > 0) {
                sum[i] += sum[i - 1];
                for (int j = 0; j < 21; j++) {
                    bitsum[i][j] += bitsum[i - 1][j];
                }
            }
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            if (i == 0) {
                ans += 1;
                continue;
            }
            int l = -1, r = i, md;
            while (l < r) {
                md = (l + r) >> 1;
                int[] val = new int[22];
                for (int j = 0; j < 21; j++) {
                    val[j] = bitsum[i][j];
                }
                if (md >= 0) {
                    for (int j = 0; j < 21; j++) {
                        val[j] -= bitsum[md][j];
                    }
                }
                boolean flag = true;
                for (int j = 0; j < 21; j++) {
                    if (val[j] > 1) flag = false;
                }
                if (flag == false) l = md + 1;
                else r = md;
            }
            ans += (i - l);
        }
        out.println(ans);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public Long nextLong() {
            return Long.parseLong(next());
        }
        public Double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}



Measured memory_bytes: 177076
class Problem
  attr_accessor :s, :t, :n, :m
  def initialize
    @s = gets.chomp
    @t = gets.chomp
    @n = s.size
    @m = t.size
  end
  
  def solve
    (n-m).downto(0) do |i|
      return merge(i) if eql(i)
    end
    return "UNRESTORABLE"
  end

  def merge(i)
    ans = s.dup
    ans.gsub!(/\?/,"a")
    ans[i,m] = t
    ans
  end

  def eql(i)
    m.times.all? do |j|
      s[i+j] == "?" || s[i+j] == t[j]
    end
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end


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

#define N (1<<17)
#define ll long long
#define ld long double
#define M 1000000007
#define INF 0x5ADFACE5
#define LINF 0x51DEEFFEC7C0DECALL
#define pii pair<ll, ll>
#define pll pair<long long, long long>
#define F first
#define S second

using namespace std;

int main () {
	int n, m;
	cin>>n>>m;
	int t = 100 * (n - m) + 1900 * m;
	cout<<t * (1<<m)<<endl;
}

Measured memory_bytes: 764
#include <stdio.h>
 
main(){
 
  int i, N;
 
  scanf("%d", &N);
 
  int A[N+1], key, j, p;
 
  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
  }
  for(i = 1; i < N+1; i++){
    for(p = 0; p < N; p++){
      if(p > 0) printf(" ");
      printf("%d", A[p]);
    }
    printf("\n");
    key = A[i];
    j = i - 1;
    while( j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
    }
  }
  return 0;
}

Measured memory_bytes: 604
package main

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

func max(a int, b int) int {
	if a >= b {
		return a
	}
	return b
}

type Node struct {
	Index     int
	Value     int
	Neighbors []*Node
	Len       int
	IsSearched  bool
}

var nodes []*Node
var already map[int]bool


func main() {
	sc.Split(bufio.ScanWords)
	S := nextLine()
	if S == "ABC" {
		fmt.Printf("ARC")
	} else {
		fmt.Printf("ABC")
	}
}


//const MAX_INT int = 1_000_000_000
var sc = bufio.NewScanner(os.Stdin)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)

func nextLine() string {
	buffer := make([]byte, 0)
	for true {
		line, isPrefix, err := reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func nextInt(A ...*int) {
	L := strings.Split(nextLine(), " ")
	for i, a := range A {
		*a, _ = strconv.Atoi(L[i])
	}
}
func nextInts(A *[]int) {
	L := strings.Split(nextLine(), " ")
	(*A) = make([]int, len(L))
	for i, l := range L {
		(*A)[i], _ = strconv.Atoi(l)
	}
}

func nextInt64() int64 {
	sc.Scan()
	hoge := sc.Text()
	i, e := strconv.ParseInt(hoge, 0, 64)
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 1796
#include <bits/stdc++.h>
#define l_ength size
const int mod = 1000000007;
using ll = long long;
const ll infll = (1ll<<60);
using namespace std;

int main(){
	ll n; cin >> n;
	ll ans = infll;
	for( ll k = 1; k*k <= n; ++k ){
		if( n%k == 0 ) ans = min( k+n/k-2, ans );
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
//sieu nhan
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inp "test.inp"
#define out "test.out"
#define oo 3004
#define inf 1e15
#define mod 1000000007
#define pii pair<int,int>
#define reset(x,y) memset(x,y,sizeof(x))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define y1 hungdzno1
int n;
double res,p[oo],f[oo];
void nhap(){
  cin>>n;
  for(int i=1;i<=n;++i) cin>>p[i];
}
void xuly(){
  f[0]=double(1);
  for(int i=1;i<=n;++i) for(int j=n+1;j>=0;--j) f[j]=(j==0 ? double(0) : f[j-1]*p[i])+f[j]*(1-p[i]);
  for(int i=n/2+1;i<=n;++i) res+=f[i];
  cout<<fixed<<setprecision(10)<<res;
}
main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 // freopen(inp,"r",stdin);
 // freopen(out,"w",stdout);
  nhap();
  xuly();
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = []

for i in range(N):
  a, b = map(int, input().split())
  A.append((a, b))

A.sort()
res = 0
bought = 0

for a, b in A:
  if bought == M:
    break
  if bought + b <= M:
    res += a * b
    bought += b
  else:
    res += (M - bought) * a
    break

print(res)


Measured memory_bytes: 16892
#include <array>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

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

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

constexpr int EMBLEM_SIZE = 2;
bool out(int x, int y, int w, int h) {
	return x < 0 || y < 0 || x >= w || y >= h;
}

bool check(int x, int y, const vector<string> &flag, const array<string, 2> &emblem) {
	rep(i, EMBLEM_SIZE) {
		rep(j, EMBLEM_SIZE) {
			if(flag[y + i][x + j] != emblem[i][j]) return false;
		}
	}
	return true;
}

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

	constexpr int dx[] = {-1, 0, -1, 0};
	constexpr int dy[] = {-1, -1, 0, 0};
	const string JOI = "JOI";

	int h, w;
	cin >> h >> w;

	vector<string> flag(h);
	for(auto &e : flag) cin >> e;

	array<string, EMBLEM_SIZE> emblem;
	for(auto &e : emblem) cin >> e;

	vector<vector<bool>> match(h - 1, vector<bool>(w - 1, 0));
	int sum = 0;

	rep(y, h - 1) {
		rep(x, w - 1) {
			if(check(x, y, flag, emblem)) {
				match[y][x] = true;
				++sum;
			}
		}
	}

	int ans = sum;
	rep(y, h) {
		rep(x, w) {
			for(const auto &c : JOI) {
				const char tmp = flag[y][x];
				flag[y][x] = c;

				int num = sum;
				rep(d, 4) {
					const int nx = x + dx[d];
					const int ny = y + dy[d];
					if(out(nx, ny, w, h) || out(nx + 1, ny + 1, w, h)) continue;
					num += check(nx, ny, flag, emblem) - match[ny][nx];
				}

				chmax(ans, num);
				flag[y][x] = tmp;
			}
		}
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2456
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;

int main()
{
  char s[101];
  cin >> s;

  cout<< s[0] << strlen(s)-2 << s[strlen(s)-1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  double ans=0;
  rep(i,0,n){
    double x;
    string u;
    cin>>x>>u;
    if(u=="JPY") ans+=x;
    else ans+=x*380000;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5; int n; lli k;
lli a[maxN], acc[maxN + 1];

int main()
{
  while (scanf("%d %lld", &n, &k) != EOF)
  {
    for (int i = 0; i < n; i ++)
    {
      scanf("%lld", &a[i]);
      acc[i + 1] = (acc[i] + a[i] - 1) % k;
    }

    map<lli, lli> cnt;
    cnt[0] = 1;
    lli ans = 0;
    for (int i = 1; i <= n; i ++)
    {
      if (i >= k) cnt[acc[i - k]] --;
      if (!cnt.count(acc[i]))
        cnt[acc[i]] = 0;
      ans += cnt[acc[i]] ++;
    }

    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int main()
{
  //flash;
  int x,y;
  cin>>x>>y;
  if(x>9||y>9)cout<<-1;
  else cout<<x*y;
  return 0;
}
//code the AC sol !
// BS/queue/map


Measured memory_bytes: 256
N,K=map(int,input().split())
 
a=list(map(int,input().split()))
tentou1=0
for i in range(N):
  for j in range(i+1,N):
    if(a[i]>a[j]):
      tentou1+=1
stentou=0
for i in range(N):
  for j in range(N):
    if(a[i]>a[j]):
      stentou+=1
answer=int(tentou1*K + stentou*K*(K-1)//int(2))
print(answer%1000000007)


Measured memory_bytes: 3188
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>

using namespace std;
typedef long long int ll;

ll n,a[300010],r=0;

int main(){
    scanf("%lld",&n);
    for(int i=0;i<3*n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a,a+3*n,greater<long long int>());
    for(int i=0;i<n;i++){
        //printf("%d\n",a[i]);
        r+=a[i*2+1];
    }
    printf("%lld\n",r);
    
}

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

using namespace std;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 5003;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int a[N];
ll sum;
bitset < N > pf[N], sf[N];

int get (vector < int > &f, int l, int r) {
	if (l <= 0) return f[r];
	return f[r] - f[l-1];
}

int main () {
	SpeedForce;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	pf[0][0] = 1;
	sf[n+1][0] = 1;

	for (int i = 1; i <= n; ++i) {
		pf[i] |= pf[i-1];
		if (a[i] < k)
			pf[i] |= pf[i] << a[i];
	}

	for (int i = n; i >= 1; i --) {
		sf[i] |= sf[i+1];
		if (a[i] < k) {
			sf[i] |= sf[i] << a[i];
		}
	}

	int ans = 0;
	for (int p = 1; p <= n; p ++) {
		vector < int > f(N);
		vector < int > b(N);
		for (int i = 0; i < k; i++) {
			f[i] = pf[p-1][i];
			b[i] = sf[p+1][i];
			if (i) {
				f[i] += f[i-1];
				b[i] += b[i-1];
			}
		}

		bool need = 0;

		for (int i = 0; i < k; i ++) {
			if ((pf[p-1][i] || sf[p+1][i]) && i >= k - a[p]) need = 1;
			if (pf[p - 1][i] && get(b, k - i - a[p], k - 1 - i)) need = 1;
      		if (sf[p + 1][i] && get(f, k - i - a[p], k - 1 - i)) need = 1;
		}

		ans += !need;
	}

	cout << ans << '\n';

	return Accepted;
}

// B...a

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  LLI h;
  while(cin >> h){
    LLI ans = 0;

    LLI t = 1;

    while(h){
      ans += t;
      t *= 2;

      h /= 2;
    }

    cout << ans << endl;
  }

  return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int k;

ll digits(ll n)
{
    ll d = 0;
    while (n > 0)
    {
        n /= k;
        d++;
    }
    return d;
}

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

    OP(digits(n));

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <cmath>
#include <climits>
#include <functional>
#include <bitset>
using namespace std;

long long N, K, mask, i, j, A, B, ans = 0;
vector<pair<long, long> > AB(100010);
vector<long long> ptrn;

int main()
{
    cin >> N >> K;
    for (i = 0; i < N; i++) {
        cin >> A >> B;
        if (A > K) continue;
        AB[i] = make_pair(A, B);
    }
    ptrn.push_back(K);
    for (i = 1; i <= 30; i++) {
        mask = 1 << i;
        if (K & mask) {
            long long tmp = K ^ mask;
            tmp |= mask - 1;
            ptrn.push_back(tmp);
        }
    }
    for (i = 0; i < ptrn.size(); i++) {
        long long tmp = 0;
        for (j = 0; j < N; j++) {
            if (ptrn[i] == (ptrn[i] | AB[j].first))
                tmp += AB[j].second;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1920
/// author: Mr.Hakimov

#include <bits/stdc++.h>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define pf push_front
#define Pb pop_back
#define Pf pop_front
#define all(x) (x).begin(), (x).end()
#define fin(s) freopen(s, "r", stdin);
#define fout(s) freopen(s, "w", stdout);

using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
typedef long double ld;

int TN = 1;

void solve() {
	int n;
	cin >> n;
	
	int m;
	cin >> m;
	
	vector<pair<int, int>> conds;
	vector<int> a(n, -1);
	for (int i = 0; i < m; ++i) {
		int s;
		int c;
		cin >> s >> c;
		
		--s;
		
		conds.pb({s, c});
		
		a[s] = c;
	}
	
	for (int i = 0; i < m; ++i) {
		if (a[conds[i].fi] != conds[i].se) {
			cout << -1;
			return;
		}
	}
	
	if (n > 1 && a[0] == 0) {
		cout << -1;
		return;
	}
	
	for (int i = 0; i < n; ++i) {
		if (i == 0 && a[i] == -1 && n > 1) {
			a[i] = 1;
		} else if (a[i] == -1) {
			a[i] = 0;
		}
	}
	
	for (int i : a) {
		cout << i;
	}
}

int main() {
    auto start = chrono::steady_clock::now();
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    /// =========================================
    /// fin("input.txt"); fout("output.txt");
    /// fin("file.in"); fout("file.out");
    /// cin >> TN;
    /// =========================================

    while (TN--) {
        solve();
    }

    auto finish = chrono::steady_clock::now();
    auto elapsed_ms = chrono::duration_cast<chrono::milliseconds>(finish - start);
    cerr << endl << "Time: " << elapsed_ms.count() << " ms\n";

    return 0;
}


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

using  namespace std;
int n;
void solve(){
  int inputMin=10001, inputMax=-1;
  int score,ans = 0;
  for(int input = 0; input < n ; input ++){
    cin >> score;
    ans += score;
    inputMin = min(inputMin , score);
    inputMax = max(inputMax , score);
  }
  ans = (ans - inputMin -inputMax)/ (n-2);
  cout << ans << endl;
}
int main(){

  while(cin >> n){
    if(n == 0) break;
    solve();
  }


  return 0;
}



Measured memory_bytes: 3028
#include <stdio.h>
#include <string.h>
#define LEM 100005
typedef struct qq{
  char name[100];
  int t;
}Q;

Q QQ[LEM];

int head,tail,n,x;

void enqueue(Q);
Q dequeue(void);
int min(int,int);

int main(){

  int elaps=0,c;
  int i,q;
  Q u;
  scanf("%d %d",&n,&q);

  for(i=1;i<=n;i++){
    scanf("%s",QQ[i].name);
    scanf("%d",&QQ[i].t);
  }
  head=1;
  tail=n+1;
  
  while(head !=tail){

   u=dequeue();
   c=min(q,u.t);
   u.t-=c;
   elaps+=c;
   if(u.t>0) enqueue(u);

   else{
     printf("%s %d\n",u.name,elaps);
   }
     }
  return 0;

}



void enqueue(Q x){


  QQ[tail]=x;
  tail = (tail+1)%LEM;
}

Q dequeue(){
  Q x;
  x=QQ[head];
  head =(head+1)%LEM;
  return x;

}

 int min(int x1,int x2){

   return x1 < x2 ? x1:x2;
  
 }



Measured memory_bytes: 11884
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
#endif

struct Node{
    vector<Node*> dests;
    ll a;
    void add(Node* n){
        dests.push_back(n);
    }
    void add2(Node* n){
        add(n);
        n->add(this);
    }
    int dfs(Node* from = nullptr){
        vector<int> ret;
        int sum = 0, maxi = 0, cnt = 0;
        for(Node* d : dests){
            if(d == from){ continue; }
            ret.push_back(d -> dfs(this));
            sum += ret.back();
            maxi = max(maxi, ret.back());
            cnt++;
        }
        if(!cnt){ return a; }
        if(sum < a || a - (sum - a) < 0){
            cout << "NO" << '\n';
            exit(0);
        }
        int lim = M;
        if(sum - maxi < maxi){
            lim = sum - maxi;
        }
        if(lim < sum - a){
            cout << "NO" << '\n';
            exit(0);
        }
        prints(a - (sum - a));
        return a - (sum - a);
    }
    // pair<ll, ll> dfs(Node* from = nullptr){
    //     vector<pair<ll, ll>> vp;
    //     int cnt = 0;
    //     bool even = true;
    //     for(Node* d : dests){
    //         if(d == from){ continue; }
    //         cnt++;
    //         vp.push_back(d -> dfs(this));
    //     }
    //     if(!cnt){ return {a, a}; }
    //     ll mini = 0, maxi = 0, mami = 0, mama = 0;
    //     for(auto p : vp){
    //         even ^= p.first % 2;
    //         mini += p.first;
    //         maxi += p.second;
    //         mami = max(mami, p.first);
    //         mama = max(mama, p.second);
    //     }
    //     if(a < mami || a < (mini + 1) / 2){
    //         cout << "NO" << '\n';
    //         exit(0);
    //     }
    //     ll rmi = a, rma = a;
    //     rmi = maxi - mama + 2 <= mama ? a - (maxi - mama) : a - maxi / 2;
    //     if(rmi < 0){
    //         rmi = 0;
    //     }
    //     // rma = mini <= a ? a : a - (mini + 1) / 2;
    //     rma = mini <= a ? a : a - (mini - a);
    //     prints(a, rmi, rma);
    //     return {rmi, rma};
    // }
};

int main(){
    int n; cin >> n;
    vector<Node> nodes(n);
    for(int i=0;i<n;i++){
        cin >> nodes[i].a;
    }
    for(int i=0;i<n-1;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        nodes[a].add2(&nodes[b]);
    }
    Node* leaf;
    for(Node& n : nodes){
        if(n.dests.size() == 1){
            leaf = &n;
            break;
        }
    }
    prints("leaf", leaf - &nodes[0]);
    auto p = leaf->dests[0]->dfs(leaf);
    // cout << (p.first <= leaf->a && leaf->a <= p.second ? "YES" : "NO") << '\n';
    cout << (p == leaf->a ? "YES" : "NO") << '\n';
    return 0;
}


Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  set<string> S;
  for(int i = 0; i < N; i++){
    string s; cin >> s;
    if(S.count(s))
      continue;
    else
      S.insert(s);
  }
  
  cout << S.size() << endl;
}

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


int main(){
    ll N;cin>>N;
    if(N%2 == 1){
        cout<<0<<endl;
        return 0;
    }else{
        ll x=5;
        ll ans=0;
        while(N>=x){
            ans += N/x/2;
            x *= 5;
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const long long MOD = 1e9 + 7;
const int N = 1e5 + 5;
long long f[N];

long long power(long long a , long long b){
    long long x = 1 , y = a;
    while(b > 0){
        if(b & 1){
            x = (x * y);
            if(x >= MOD)
                x %= MOD;
        }

        y = y*y;
        if(y >= MOD)
            y %= MOD;

        b >>= 1;
    }
    return x;
}


long long nCr(long long n , long long r){
    if(r > n)return 0;
    return (f[n] * power(f[r] * f[n-r] %MOD , MOD - 2))% MOD;
}

int idx[N];

int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    f[0] = 1;
    for(int i = 1 ; i < N ;i++)
        f[i] = (f[i-1] * i) % MOD;

    memset(idx,-1,sizeof idx);
    int lst = -1 , frst = -1;
    int n;
    cin >> n;
    n++;
    vi v(n);
    for(int &x : v)cin >> x;
    loop(i,n){
        if(idx[v[i]] == -1)idx[v[i]] = i;
        else lst = i , frst = idx[v[i]];
    }

    int len = lst - frst + 1;
    //cout << frst << " " << lst << " " << v[lst] << endl;
    cout << n - 1 << endl;
    range(i,2,n){
        ll cur = nCr(n,i);
        //cout << "**" << nCr(n-len,i-1) << endl;
        cur -= nCr(n-len,i-1);
        cur += MOD;
        cur %= MOD;
        cout << cur << endl;
    }



    return 0;
}


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

int main() {
    string s;
    cin>>s;
    for (int i=s.size()-1; i>=0; i--) {
        string res=s.substr(0,i);
        int n=res.size();
        if (n%2==0&&res.substr(0,n/2)==res.substr(n/2,n/2)) {
            cout<<n<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int f[1010][1010],n,m;
char a[1010][1010];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	f[1][1]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]=='.' && a[i-1][j]=='.')
				f[i][j]=(f[i][j]+f[i-1][j])%mod;
			if(a[i][j]=='.' && a[i][j-1]=='.')
				f[i][j]=(f[i][j]+f[i][j-1])%mod;
		}
	}
	cout<<f[n][m]<<endl;
	return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    if(n==m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    } 

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <climits>
using namespace std;

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

const int dx[] = {1,-1,0,0};
const int dy[] = {0,0,1,-1};
int w,h,sx,sy,gx,gy,cx,cy;
int memo[7][7][7][7]; //ツ篠ゥツ閉ェ

bool inside(int x, int y){
  return !(x>=w || y>=h || x<0 || y<0 );
}

class state{
public:
  int x,y,cx,cy,cost;
  state(int _x, int _y, int _cx, int _cy, int _cost){
    x=_x; y=_y;
    cx=_cx; cy=_cy;
    cost = _cost;
  }
  bool operator<(const state &a)const{
    return cost > a.cost;
  }
};

int main(){
  int field[7][7];

  while(scanf("%d%d",&w,&h),w|h){
    rep(i,7)rep(j,7)rep(k,7)rep(l,7)memo[i][j][k][l]=INT_MAX;
    rep(i,h){
      rep(j,w){
	scanf("%d",&field[i][j]);
	if( field[i][j]==2 ){ //cargo
	  cx=j; cy=i;
	}else if( field[i][j]==3 ){
	  gx=j; gy=i;
	}else if( field[i][j]==4 ){
	  sx=j; sy=i;
	}
      }
    }

    int ans = -1;
    bool f = false;
    priority_queue<state> q;
    q.push(state(sx,sy,cx,cy,0));
    memo[sy][sx][cy][cx] = 0;

    while( !q.empty() ){
      state r = q.top();
      q.pop();
      int c = memo[r.y][r.x][r.cy][r.cx];
      rep(k,4){
	int tx = r.x + dx[k];	
	int ty = r.y + dy[k];
	if( !inside(tx,ty) || field[ty][tx]==1 ){
	  continue;
	}
	if( tx==r.cx && ty==r.cy ){
	  int ttx = tx + dx[k];
	  int tty = ty + dy[k];
	  if( inside(ttx, tty) ){
	    if( field[tty][ttx]!=1 && field[tty][ttx]!=3 ){
	      if( memo[ty][tx][tty][ttx] > c+1 ){
		memo[ty][tx][tty][ttx] = c+1;
		q.push(state(tx, ty, ttx, tty, c+1));
#if DEB
		printf("1 : (%d,%d)--> (%d,%d),(%d,%d),%d\n",r.x,r.y,tx,ty,ttx,tty,c+1);
#endif
	      }
	    }else if( field[tty][ttx]==3 ){
	      ans = c+1;
	      f = true;
	      break;
	    }
	  }
	}else{
	  if( memo[ty][tx][r.cy][r.cx] > c ){
	    memo[ty][tx][r.cy][r.cx] = c;
	    q.push(state(tx, ty, r.cx, r.cy, c));
#if DEB
	    printf("2 : (%d,%d)--> (%d,%d),(%d,%d),%d\n",r.x,r.y,tx,ty,r.cx, r.cy,c);
#endif
	  }
	}
      }
      if( f ) break;
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 0
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    S = SI()
    l = len(S)
    ans = 0
    for case in range(2**(l-1)):
        j = 0
        N = int(S)
        ans += N % 10
        for i in range(l-1):
            if (case >> i) & 1:
                j = 0
            else:
                j += 1
            ans += int(S[-(i+2)]) * 10**j

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
import java.util.Scanner;

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

        double r = sc.nextDouble();
        double pi = Math.PI;

        double area = r * r * pi;
        double length = 2 * pi * r;

        System.out.printf("%f %f\n", area, length);
    }
}


Measured memory_bytes: 28248
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  cout<<s.substr(0,s.size()-8)<<endl;

  return 0;
}

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

typedef pair<int, int> P;
int check[1 << 10][10];

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

	int N;
	string s;
	while(cin >> N, N) {
		//cout << N << endl;
		memset(check, 0, sizeof check);
		cin >> s;

		bool ok = true;
		vector<P> v;
		int x = 0;
		for(int i = 0; i < N; i++) {
			if(s[i] == 'u') {
				x = 0;
			}
			else {
				int y = s[i] - '0';
				if(!check[x][y]) {
					v.push_back({ x, y });
					check[x][y] = 1;
				}

				if(x >> y & 1) {
					ok = false;
					break;
				}
				x |= 1 << y;
			}
		}

		if(!ok) {
			cout << "UNSAFE" << endl;
			continue;
		}

		int n = 0;

		while(1) {
			vector<P> add;
			for(int i = 0; i < v.size() && ok; i++) {
				for(int j = 0; j < v.size() && ok; j++) {
					if(i == j) continue;
					int s1 = v[i].first, t1 = v[i].second;
					int s2 = v[j].first, t2 = v[j].second;
					if(s1 & s2) continue;
					int ns = s1 | s2;
					if((s1 >> t2 & 1) && (s2 >> t1 & 1)) {
						ok = false;
						break;
					}
					if((s1 >> t2 & 1) && !(s2 >> t1 & 1)) {
						if(!check[ns][t1]) {
							add.push_back({ ns, t1 });
							check[ns][t1] = 1;
						}
					}
					if(!(s1 >> t2 & 1) && (s2 >> t1 & 1)) {
						if(!check[ns][t2]) {
							add.push_back({ ns, t2 });
							check[ns][t2] = 1;
						}
					}
				}
			}

			if(!ok || add.size() == 0) break;

			n = v.size();
			for(auto p : add) {
				v.push_back(p);
			}
		}

		if(ok) cout << "SAFE" << endl;
		else cout << "UNSAFE" << endl;
	}
}

Measured memory_bytes: 3216
function Main(input) {
    var N = parseInt(input[0], 10);
    var M = parseInt(input[1], 10);
    var A = input.slice(2).map(a => parseInt(a, 10));

    var sum = 0;

    for (var i = 0; i < M; i++) {
        sum += A[i];
    }

    console.log(N - sum >= 0 ? N - sum : -1);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 30772
#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 ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    string s;
    cin>>s;
    int n = s.size();
    int l = n / 2 - 1;
    int r = (n + 1)/2;
    int ans = 0;
    while(l >= 0) {
        if(s[l] != s[r]) ans++;
        l--, r++;
    } 
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int N; cin >> N;
    vector <ll> A(N);
    
    ll sum1=0;
    rep(i,N){
        cin >> A[i];
        sum1+=A[i];
    }
    
    ll sum2=0;
    ll ans=1001001001001;
    for (int i=N-1; i>0; i--){
        sum2+=A[i];
        sum1-=A[i];
        ans=min(ans,abs(sum1-sum2));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792