akhauriyash/Code-Regression huggingface dataset:
Table=[0,0,0,6,42,192,732,2538,8334,26484]
N=int(input())
K=len(str(N))
ans=Table[K-1]

import itertools
U=['3','5','7']
PRD = list(itertools.product(U, repeat=K))
for i in PRD:
    T=''.join(i)
    if int(T)>N:
        break
    if '3' in T and '5' in T and '7' in T:
        ans+=1

print(ans)

Measured memory_bytes: 5492
def main():
    import sys
    #input = sys.stdin.readline
    s = input()
    n = len(s)
    s_l = s[:int((n-1)/2)]
    s_r = s[int((n+1)/2):]
    if s == s[::-1] and s_l == s_l[::-1] and s_r == s_r[::-1]:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int T = sc.nextInt();
    int t [] = new int [N];
    
    for(int i=0; i<N; i++){
      t[i] = sc.nextInt();
    }
    
    int ans = 0;
    for(int i=1; i<N; i++){
      if(t[i]-t[i-1]>=T){
        ans += T;
      }else{
        ans += t[i]-t[i-1];
      }
    }
   System.out.println(ans+T); 
  }
}

Measured memory_bytes: 84804
import java.util.*;
public class Main {
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] a = new int[M];
    int[] b = new int[M];
    boolean[] at = new boolean[200001];
    boolean[] nt = new boolean[200001];
    for(int i = 0 ; i < M; i++){
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
      if(a[i]==1){
        at[b[i]]=true;
      }
      if(b[i]==N){
        nt[a[i]]=true;
      }
    }
    
    if(M < 2){
      System.out.println("IMPOSSIBLE");
      return;
    }
    
    for(int i = 0 ; i < 200001; i++){
        if(at[i] && nt[i]){
          System.out.println("POSSIBLE");
          return; 
        }
    }
    System.out.println("IMPOSSIBLE");
  }
}

Measured memory_bytes: 61156
list = []
while True:
    a = []
    a = [int(i) for i in input().split()]
    if a[0] == 0 and a[1] == 0:
        break
    else:
        list.append(a)

for i in range(len(list)):
    if list[i][0] >= list[i][1]:
        print(list[i][1],list[i][0])
    else:
        print(list[i][0],list[i][1])



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

using namespace std;

struct Node
{
    int parent;
    int child;
    int sibling;

    Node() : parent(-1), child(-1), sibling(-1) {}
};

enum NodeType
{
    Root,
    Internal,
    Leaf,
};

int depth(vector<Node>& G, int id)
{
    int dep = 0;
    int vid = id;
    while (G[vid].parent != -1) {
        vid = G[vid].parent;
        ++dep;
    }
    return dep;
}

NodeType node_type(vector<Node>& G, int id)
{
    if (G[id].parent == -1)
        return Root;
    else if (G[id].child == -1)
        return Leaf;
    else
        return Internal;
}

int get_childs(vector<Node>& G, int id, vector<int>& childs)
{
    int count = 0;
    int child_id = G[id].child;
    while (child_id != -1) {
        childs[count] = child_id;
        child_id = G[child_id].sibling;
        ++count;
    }
    return count;
}

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

    vector<Node> G(n);

    for (int i = 0; i < n; ++i) {
        int id, k;
        cin >> id >> k;

        int last_sibling;
        for (int j = 0; j < k; ++j) {
            int c;
            cin >> c;
            if (j == 0) // if c is a first child of id
                G[id].child = c;
            else
                G[last_sibling].sibling = c;
            G[c].parent = id;
            last_sibling = c;
        }
    }

    vector<int> childs(100000);
    for (int i = 0; i < n; ++i) {
        cout << "node " << i << ": parent = " << G[i].parent;
        cout << ", depth = " << depth(G, i);
        switch (node_type(G, i)) {
            case Root:
                cout << ", root, [";
                break;
            case Internal:
                cout << ", internal node, [";
                break;
            case Leaf:
                cout << ", leaf, [";
                break;
        }
        int nchild = get_childs(G, i, childs);
        if (nchild > 0)
            cout << childs[0];
        for (int j = 1; j < nchild; ++j)
            cout << ", " << childs[j];
        cout << "]\n";
    }
}



Measured memory_bytes: 4344
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::cmp::max;
use std::cmp::min;
use std::collections::BinaryHeap;

fn main() {
    input! {
        _K: usize,
        T: usize,
        As: [i64; T],
    }

    // As.iter().sum() == K

    // O(KT)くらいまでならいける

    // (残り数, ind)
    let mut max_heap: BinaryHeap<(i64, usize)> = BinaryHeap::new();

    for (i, &a) in As.iter().enumerate() {
        let tpl = (a, i);
        max_heap.push(tpl);
    }

    let mut ans = 0;


    // 一番多いものから減らしていく
    while !max_heap.is_empty() {
        let (biggest_cnt, biggest_ind) = max_heap.pop().unwrap();

        let snd_biggest_op = max_heap.pop();

        if snd_biggest_op.is_some() {
            let (snd_biggest_cnt, _snd_biggest_ind) = snd_biggest_op.unwrap();

            // 違う種類のものを食べる。2個目は0個になるのでpushしない
            if biggest_cnt > snd_biggest_cnt {
                max_heap.push((biggest_cnt - snd_biggest_cnt, biggest_ind));
            }
            continue;
        } else {
            // 違う種類のものが食べられない
            ans = biggest_cnt - 1;
            break;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2168
n = int(input())
a, b = map(int, input().split())
P = list(map(int, input().split()))

fst, snd, thr = 0, 0, 0

for p in P:
    if p <= a:
        fst += 1
    elif a + 1 <= p <= b:
        snd += 1
    else:
        thr += 1

print(min([fst, snd, thr]))

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())

using namespace std;

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
typedef vector<ll> vecll;
const ll inf =1000000007;

void solve(){
    ll n,k,c;
    cin >> n >> k >>c;
    string s;
    cin >> s;
    ll t=inf;
    ll mae[n];
    ll ushiro[n];
    rep(i,n){
        mae[i]=0;
        ushiro[i]=0;
    }

    //mae
    ll l=0;
    vecll L;
    for(ll i=0;i<n;i++){
        if(s[i]=='o' && t>=c){
            mae[i]=1;
            L.pb(i);
            t=0;
            l++;
            if(l==k) break;
        }
        else{
            t++;
        }
    }
    l=0;
    t=inf;
    vecll R;
    for(ll i=n-1;i>=0;i--){
        if(s[i]=='o' && t>=c ){
            ushiro[i]=1;
            R.pb(i);
            t=0;
            l++;
            if(l==k) break;
        }
        else{
            t++;
        }
    }
    reverse(R.begin(),R.end());
    for(ll i=0;i<k;i++){
        if(L[i]==R[i]){
            kaku(L[i]+1);
        }
    }

}

int main(){
    solve();
}

Measured memory_bytes: 8180
while True:
    m, n = map(int, input().split())
    if n+m == 0:
        break
    else:
        book_list = [int(input()) for _ in range(n)]
        left = min(book_list)
        right = 10**7
        while left < right:
            w = (left+right)//2
            cnt_m = 1
            tmp_w = 0
            for book in book_list:
                if book > w:
                    cnt_m = m + 1
                else:
                    tmp_w += book
                    if tmp_w > w:
                        tmp_w = book
                        cnt_m += 1
            if cnt_m > m:
                left = w + 1
            else:
                right = w
        print(left)



Measured memory_bytes: 5604
import itertools
import math

def dist(c1, c2):
    dist = math.sqrt((c2[0]-c1[0])**2 + (c2[1]-c1[1])**2)
    return dist

def solve():
    N = int(input())
    c = []
    for _ in range(N):
        x_tmp, y_tmp = list(map(int, input().split()))
        c.append([x_tmp, y_tmp])
    l = [i for i in range(N)]

    sum_dist = 0
    ave_dist = 0
    for p in itertools.permutations(l):
        for i in range(len(p)-1):
            sum_dist += dist(c[p[i]], c[p[i+1]])
    ave_dist = sum_dist/len(list(itertools.permutations(l)))
    print(ave_dist)

if __name__ == "__main__":
    solve()

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

int main() {
	int N;
	cin >> N;
	if (N / 10 == 9 || N % 10 == 9) cout << "Yes";
	else cout << "No";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

n進数におけるある整数xの1の位を取得する時はx%nで求まる
同様にnの位を取得する時には(x/n)%nを取得すると良いし、
n^2の位を取得する時には(x/n/n)%nを……と行えば良い
*/

Measured memory_bytes: 256
sx, sy, tx, ty = gets.split.map(&:to_i)
print "U" * (ty - sy) + "R" * (tx - sx)
print "D" * (ty - sy) + "L" * (tx - sx)
print "L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) + "D"
print "R" + "D" * (ty - sy + 1) + "L" * (tx - sx + 1) + "U"


Measured memory_bytes: 1788
N,M=gets.chomp.split(" ").map { |e| e.to_i  }

const = 0
val = Math.sqrt(M)

if M%N == 0
  puts M/N
  exit
end
a=[]
indx = 0
for i in 1..val+1 do
  if M % i == 0
    a[indx] = i
    a[indx+1] = M/i
    indx += 2
  end
end

for i in a do
  if  M % i == 0 && N*i <= M
     const = i > const ? i : const
  end
end

puts const



Measured memory_bytes: 1788
n,k = map(int, input().split())
a = list(map(lambda x : int(x) -1,  map(int, input().split())))

s = {0}
loop = [0]

while a[loop[-1]] not in s:
    loop.append(a[loop[-1]])
    s.add(loop[-1])

    
idx = loop.index(a[loop[-1]])

if k < len(loop):
    print(loop[k]+1)
else:
    print(loop[(k - idx)% (len(loop) - idx) + idx] + 1)


Measured memory_bytes: 126248
#include<iostream>
#include<map>
using namespace std;
int main(){
        string s;
        cin>>s;
        map<char,int> char_map;
        map<char,int>::iterator iter;
        int cnt;
        for(int i=0;i<s.length();i++){
                //cnt = char_map.count(s[i]);
                iter = char_map.find(s[i]);
                if(iter != char_map.end()){
                //if(cnt!=0){
                        cout<<"no"<<endl;
                        return 0;
                }
                char_map[s[i]] = 1;
        }
        cout<<"yes"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public  class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int N = scan.nextInt();
      	int a = N / 1000;
      	int b = N / 100 - 10 * a;
      	int c = N / 10 - 100 * a - 10 * b;
      	int d = N % 10;
     	if(a == b && b == c && c == d){
        	System.out.print("Yes");
        }	
      	else if(a == b && b == c){
        	System.out.print("Yes");
        }
      	else if(b == c && c == d) {
         	System.out.print("Yes"); 
        }
      	
      	else {
        	System.out.print("No");
        }
    
    }
 
}

Measured memory_bytes: 21844
def main():
    N = int(input().strip())
    ss = [
        int(input().strip())
        for _ in range(N)
    ]
    total = sum(ss)
    if total % 10 == 0:
        for s in sorted(ss):
            if s % 10 == 0:
                continue
            total -= s
            if total % 10 != 0:
                break
    if total % 10 == 0:
        print(0)
    else:
        print(total)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
N = int(input())
li = []
w = input()
li.append(w)
k = 0
ans = "Yes"
for i in range(N-1) :
    word = input()
    for j in range(len(li)) :
        if li[j] == word :
            k = 1
            break
    last_word = li[-1]
    if last_word[-1] != word[0] :
        k = 1
    if k == 1 :
        ans = "No"
        break
    li.append(word)
print(ans)

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 5000000000000000;
constexpr auto MOD = 1000000007;

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

	ll ans = 0;

	ans +=(x / 11)*2;

	ll s = x % 11;

	if (s >= 7) { ans += 2; }
	else if(s >= 1) { ans++; }

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
using namespace std;
using ll = unsigned long long;

int main() {

    int x,n,p;

    bool bucket[102];

    for(int i = 0 ; i < 102 ; i++){
        bucket[i] = true;
    }
    cin >> x >> n;

    for(int i = 0; i < n ; i++){
        cin >> p;
        bucket[p] = false;
    }

    int i = 0;

    for(; x-i >= 0 & x+i < 102 ;i++){

        if(bucket[x-i]){
            cout << x-i;
            return 0;
        }
        if(bucket[x+i]){
            cout << x+i;
            return 0;
        }
    }

    while(x-i >= 0){
        if(! bucket[x-i]){
            cout << x-i;
            return 0;
        }
        i++;
    }

    while(x+i < 102){
        if(! bucket[x+i]){
            cout << x+i;
            break;
        }
        i++;
    }

    return 0;
}



Measured memory_bytes: 3620
#include<stdio.h>
int main(void) {
	int m = 0, f = 0, b = 0,h,k;
	scanf("%d %d %d", &m, &f, &b);
	h = (f + m)-b;
	if (b == f + m) {
		printf("%d\n", f);
	}
	else if (h < 0) {
		printf("NA\n");
	}
	else if (b<= m) {
		printf("0\n");
	}
	else {
		printf("%d\n", f - h);
	}
	return 0;
}


Measured memory_bytes: 2132
#include<stdio.h>
int main(){
    int a,b,c;
    int cnt=0;
    scanf("%d%d%d",&a,&b,&c);
    for(;a<=b;a++){
        if(c % a == 0){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 2752
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  ll n, m;
  cin >> n >> m;
  vector<ll> x(n), y(m);
  for (auto &z: x) cin >> z;
  for (auto &z: y) cin >> z;

  vector<ll> multimex(n-1);
  for (int i = 0; i < n-1; i++) multimex[i] = (i + 1) * (n - i - 1);
  ll areax = 0;
  for (int i = 0; i < n-1; i++) {
    areax = (areax + ((x[i+1] - x[i]) * multimex[i]) % mod) % mod;
  }
  vector<ll> multimey(m-1);
  for (int i = 0; i < m-1; i++) multimey[i] = (i + 1) * (m - i - 1);
  ll areay = 0;
  for (int i = 0; i < m-1; i++) {
    areay = (areay + ((y[i+1] - y[i]) * multimey[i]) % mod) % mod;
  }

  ll ans = (areax * areay) % mod;

  cout << ans << endl;

  return 0;
}


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

typedef long long ll;

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

    string s;
    cin >> s;

    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << "\n";
    else
        cout << "No" << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
    	bool ok = true;
    string s;
    cin>>s;
    for(int i=0; i<s.size(); i++)
    {
    	if(s[i]=='7')
    	{
    		ok = false;
    		break;
		}
	}
	if(ok == false)
	{
		cout<<"Yes \n";
	}
	else
	{
		cout<<"No \n";
	}
      return 0;
    }

Measured memory_bytes: 3628
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String n = String.valueOf(sc.nextLong()+1);
      String m = n.substring(0,1);
      System.out.println(Integer.parseInt(m)-1+(n.length()-1)*9);
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
	cin >> n >> m;
  	if(m == n)cout << "Yes";
  	else
      cout << "No";

    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
     sc.Scan()
     i, e := strconv.Atoi(sc.Text())
     if e != nil {
     	panic(e)
     }
     return i
}

func main() {
     sc.Split(bufio.ScanWords)
     n := nextInt()
     a := 0

     for i := 1; i <= n; i++ {
     	 if !(i % 3 == 0) && !(i % 5 == 0){
	    a += i
	 }
     }

     fmt.Println(a)
}  

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

using namespace std;

int H, W;
char maps[51][51];
int load[51][51];
int white = 0;

int dy[4] = {0,  0,  1, -1};
int dx[4] = {1, -1,  0,  0};

void bfs() {
  queue<pair<int, int> > q;
  q.push(make_pair(0, 0));
  load[0][0] = 1;

  while(!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    if (p.first == H -1 && p.second == W - 1) {
      return;
    }
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W && maps[nx][ny] == '.' && load[nx][ny] == -1) {
        load[nx][ny] = load[p.first][p.second] + 1;
        q.push(make_pair(nx, ny));
      }
    }
  }
}

int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> maps[i][j];
      if (maps[i][j] == '.') {
        white++;
      }
    }
  }

  memset(load, -1, sizeof(load));
  bfs();

  if (load[H-1][W-1] == -1) {
    cout << "-1" << endl;
  } else {
    cout << white - load[H -1][W -1] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  string s;
  cin>>s;
  FOR(i, 0, 26) {
    char al = 'a' + i;
    bool next = false;
    rep(i, s.size()) {
      if(s[i] == al) {
        next = true;
        break;
      }
    }
    if(next) {
      continue;
    } else {
      char min = al;
      cout << min << endl;
      return 0;
    }
  }
  cout << "None" << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    char front=s.at(0);
    char back=s.at(s.size()-1);
    string tmp=s.substr(1,s.size()-2);
    cout<<front<<tmp.size()<<back<<endl;
}


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

using namespace std;
typedef long long ll;
const int MAX = 100000;
int inn[MAX+1];
int n,m;

int main(){

  inn[1] = 0;

  while(cin >> n >> m && n+m){
    ll ans = 0;

    for(int i = 2; i <= n; i++){
      cin >> inn[i];
      inn[i] += inn[i-1];
    }
    
    int pos = 1;

    for(int i = 0; i < m; i++){
      int next;
      cin >> next;
      ans += abs(inn[pos]-inn[pos+next]);
      pos+=next;
    }
    cout << ans%MAX << endl;
  }
  return 0;
}

Measured memory_bytes: 1544
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
char s[N];int cnt[3],n,mx;
int main(){
	scanf("%s",s+1),n=strlen(s+1);
	fp(i,1,n)++cnt[s[i]-'a'];
	mx=max(cnt[0],max(cnt[1],cnt[2]));
	if(!cnt[0]||!cnt[1]||!cnt[2])return puts(mx<=1?"YES":"NO"),0;
	fp(i,0,2)if(cnt[i]<mx-1)return puts("NO"),0;
	puts("YES");
	return 0;
}

Measured memory_bytes: 384
//I love Nanami Chiaki
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fst first
#define snd second
const int maxn=1e5+7;
const ll linf=1e18+7;
ll mx[maxn<<3],lazy[maxn<<3];
int le[maxn<<3],ri[maxn<<3];
vector<pii> hve[maxn];
void push_up(int id){
	mx[id]=max(mx[id<<1],mx[(id<<1)|1]);
}
void push_down(int id){
	if (lazy[id]!=-1){
		mx[id<<1]=min(mx[id<<1],lazy[id]);
		mx[(id<<1)|1]=min(mx[(id<<1)|1],lazy[id]);
		if (lazy[id<<1]==-1) lazy[id<<1]=lazy[id];
		else lazy[id<<1]=min(lazy[id<<1],lazy[id]);
		if (lazy[(id<<1)|1]==-1) lazy[(id<<1)|1]=lazy[id]; 
		else lazy[(id<<1)|1]=min(lazy[(id<<1)|1],lazy[id]);
		lazy[id]=-1;
	}
}
void build(int l,int r,int id){
	le[id]=l;ri[id]=r;
	lazy[id]=-1;
	if (l==r){
		if (l==1) {mx[id]=0;}
		else {mx[id]=linf;}
		return;
	}
	int mid=(l+r)>>1;
	build(l,mid,id<<1);
	build(mid+1,r,(id<<1)|1);
	push_up(id);
}
void changeit(int l,int r,int id,ll v){
	int l1=le[id],r1=ri[id];
	if (l>r || l1>r || l>r1) return;
	if (l<=l1 && r1<=r){
		mx[id]=min(mx[id],v);
		if (lazy[id]==-1) lazy[id]=v;
		else lazy[id]=min(lazy[id],v);
		return;
	}
	push_down(id);
	changeit(l,r,id<<1,v);
	changeit(l,r,(id<<1)|1,v);
	push_up(id);
}
ll query(int p,int id){
	int l1=le[id],r1=ri[id];
	if (l1==r1){
		return mx[id];
	}
	push_down(id);
	int mid=(l1+r1)>>1;
	ll re;
	if (p<=mid) re=query(p,id<<1);
	else re=query(p,(id<<1)|1);
	push_up(id);
	return re;
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int x,y,c;
	for (int i=0;i<m;i++){
		scanf("%d%d%d",&x,&y,&c);
		hve[x].push_back(mp(c,y));
	}
	build(1,n,1);
	ll v;
	int prep,p;
	for (int i=1;i<=n;i++){
		v=query(i,1);
		prep=i+1;
		sort(hve[i].begin(),hve[i].end());
		for (int j=0;j<hve[i].size();j++){
			p=hve[i][j].snd;c=hve[i][j].fst;
			if (p>=prep){
				changeit(prep,p,1,v+c);
				prep=p+1;
			}
		}
	}
	ll ans=query(n,1);
	if (ans==linf) puts("-1");
	else printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 19712
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

import static java.util.stream.Collectors.toList;

public class Main {
    public static long process(TestCase testCase) {
        int N = testCase.N;
        List<Integer> A = testCase.A;

        List<Integer> differences = IntStream.range(0, N)
                .map(i -> i - A.get(i))
                .sorted()
                .boxed()
                .collect(toList());

        int mid = N / 2;
        final int midDiff = differences.get(mid);

        return sadness(differences, midDiff);
    }

    private static long sadness(Collection<Integer> differences, int midDiff) {
        return differences.stream()
                .mapToLong(i -> Math.abs(i - midDiff))
                .sum();
    }

    // Util func

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final long result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        List<Integer> A = new ArrayList<>();
        for (int i = 0; i < N; ++i) {
            A.add(sc.nextInt());
        }

        sc.close();
        return new TestCase(N, A);
    }

    private static void output(long result) {
        System.out.println(result);
    }

    public static class TestCase {
        final int N;
        final List<Integer> A;

        public TestCase(int N, List<Integer> A) {
            this.N = N;
            this.A = A;
        }
    }

}


Measured memory_bytes: 94552
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i = n;i >= 0;--i)
#define FOR(i,m,n) for(int i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    int n;
    double sum = 0;
    cin >> n;
    vector<pair<double,double>> p(n);
    REP(i,n){
        cin >> p[i].first >> p[i].second;
    }

    FOR(i,0,n-1){
        FOR(j,i+1,n){
            sum += sqrt(pow(p[i].first-p[j].first,2)+pow(p[i].second-p[j].second,2));
        }
    }

    printf("%.8lf\n",2*sum/n);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
#define MAX 1005

char JOI[MAX][MAX];
int h,w,n;
int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};

pair<int, int> goal[10];
bool check(int a,int b){
    return (a>=1&&a<=h&&b>=1&&b<=w);
}

int step[MAX][MAX];
int bfs(pair<int, int> st,pair<int, int> en){
    queue<pair<int,int> > q;
    q.push(st);
    memset(step, -1, sizeof(step));
    step[st.first][st.second]=0;
    int stp=0;
    while(!q.empty()){
        pair<int, int> S=q.front(); q.pop();
        int x=S.first;  int y=S.second;
        stp=step[x][y];
        for(int i=0; i<4; i++){
            int cx=x+dx[i]; int cy=y+dy[i];
            if(check(cx, cy)){
                if(JOI[cx][cy]!='X'&&step[cx][cy]==-1){
                    if(cx==en.first&&cy==en.second) return stp+1;
                    q.push(make_pair(cx, cy));
                    step[cx][cy]=stp+1;
                }
            }
        }
    }
    return stp;
}
int main(){
    cin>>h>>w>>n;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cin>>JOI[i][j];
            if(JOI[i][j]=='S') goal[0]=make_pair(i, j);
            else if(JOI[i][j]>='0'&&JOI[i][j]<='9'){
                int x=JOI[i][j]-'0';
                goal[x]=make_pair(i, j);
            }
        }
    }
    int ans=0;
    for(int i=0; i<n; i++){
        ans+=bfs(goal[i],goal[i+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8080
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
// constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VI a(n),b(n);
    REP(i,0,n) cin >> a[i];
    REP(i,0,n) cin >> b[i];
    VI ca(n+1),cb(n+1);
    REP(i,0,n) ca[a[i]]++;
    REP(i,0,n) cb[b[i]]++;
    REP(i,0,n+1) {
        if (ca[i] + cb[i] > n) {
            cout << "No" << endl;
            return;
        }
    }
    
    int r = 0, re = 0;
    REP(i,0,n) {
        if (a[i] != b[i]) continue;
        chmax(r,i+1);
        while (r < n) {
            if (a[r] != b[r] || a[r] == a[i]) {
                ++r;
                continue;
            }
            break;
        }
        // dump(r);
        if (r == n) {
            // dump(i);
            while (re < n) {
                if (a[i] != b[re] && b[i] != a[re]) {
                    swap(b[i],b[re]);
                    ++re;
                    break;
                }
                ++re;
            }
        } else {
            swap(b[i], b[r]);
            ++r;
        }
    }

    cout << "Yes" << endl;
    REP(i,0,n) cout << b[i] << " ";
    cout << endl;
    // REP(i,0,n) cerr << a[i] <<" ";
    // cerr << endl;
}

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

Measured memory_bytes: 6404
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <string>
#include <iostream>
using namespace std;

int main() {
	string S;
	cin >> S ;
 
	if (S == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (S == "Cloudy") {
		cout << "Rainy" << endl;
	}

	else {
		cout << "Sunny" << endl;
	}
	}

	    

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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 912345678;


int main()
{
    vi a;
    int n;
    cin >> n;
    REP(i,n){
        int c;
        cin >> c;
        a.push_back(c);
    }
    int ret = 0;
    REPS(1,i,n-1){
        if((a[i-1] < a[i] && a[i] < a[i+1])||(a[i-1] > a[i] && a[i] > a[i+1])){
            ret++;
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
/* 3???????????£???????????????????????± */

#include <cstdio>
using namespace std;

int t, h, s;

int main() {
  while (1) {
    scanf("%d%d%d", &t, &h, &s);
    if (t == -1 && h == -1 && s == -1) return 0;

    int rem_sec = 7200 - (t*3600 + h*60 + s);
    printf("%02d:%02d:%02d\n", rem_sec/3600, rem_sec%3600/60, rem_sec%60);
    rem_sec *= 3;
    printf("%02d:%02d:%02d\n", rem_sec/3600, rem_sec%3600/60, rem_sec%60);
  }
}

Measured memory_bytes: 2676
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    T1, T2, R1, R2 = LI()
    if (R1 == -1 or R2 == -1) :
        if (T1 < T2):
            print("Alice")
        elif (T2 < T1) :
            print("Bob")
        else :
            print("Draw")
    else :
        if (R1 > R2):
             print("Alice")
        elif (R2 > R1) :
             print("Bob")
        else :
             print("Draw")
    return


if __name__ == "__main__":
    solve()



Measured memory_bytes: 8172
from sys import stdin, setrecursionlimit


def main():
    h, n = map(int, stdin.readline().split())
    a = list(map(int, stdin.readline().split()))
    print('Yes') if sum(a) >= h else print('No')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Measured memory_bytes: 52316
import math

N, K = map(int, input().split())

naru = 0

for i in range(1, N+1):
    if i >= K:
        naru += 1
    else:
        kaisuu = math.ceil(math.log2(K / i))
        naru += 0.5 ** kaisuu

print("{:.12f}".format(naru / N))


Measured memory_bytes: 2940
package main

import (
	"bufio"
	"fmt"
	"os"
)

const (
	initialBufSize = 10000
	maxBufSize     = 100000000
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	return sc
}()

// var sc = bufio.NewScanner(os.Stdin)
// var buff []byte
//
// func init() {
// 	sc.Split(bufio.ScanWords)
// 	sc.Buffer(buff, 100000000)
// 	log.SetFlags(log.Lshortfile)
// }

func main() {
	input := nextString()
	remSumArray := make([]int, 2019)
	remSumArray[0] = 1
	var num int
	digit := 1
	for i := len(input) - 1; i >= 0; i-- {
		num += int(input[i]-48) * digit
		digit *= 10
		digit %= 2019
		remSumArray[num%2019]++
	}
	var result int
	for _, num := range remSumArray {
		result += num * (num - 1) / 2
	}
	fmt.Println(result)
}

func nextString() (s string) {
	sc.Scan()
	return sc.Text()
}


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

#define F first
#define S second
#define int long long
#define pb push_back
#define endl '\n'

using namespace std;

const int mod = 1e+9 + 7 ; 
const int maxn = 1001 ; 

char a[maxn][maxn] ;
int dp[maxn][maxn] ; 

int mul(int x , int y){
	return (x + y) % mod ; 
}

int32_t main()
{
	ios_base :: sync_with_stdio(false) ;
	cin.tie(0); cout.tie(0) ;
	int h , w ;
	cin >> h >> w ;
	for(int i = 1 ; i <= h ; i++){
		for(int j = 1 ; j <= w ; j++){
			cin >> a[i][j] ; 
		}
	}
	dp[1][1] = 1 ; 
	for(int i = 1 ; i <= h ; i++){
		for(int j = 1 ; j <= w ; j++){
			if(i == 1 and j == 1 or (a[i][j] == '#')) continue ; 
			dp[i][j] = mul(dp[i-1][j] , dp[i][j-1]) ; 
		}
	}
	cout << dp[h][w] << endl ; 
}



Measured memory_bytes: 9088
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int n; cin>>n;
  cout<<(24-n)+24<<endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;



int main() {
    ll x; cin>>x;
    int ans=0;
    for(ll i=2; i*i<=x; ++i) {
        while(x%i==0) {
            int j=0;
            while(x%i==0) x/=i, j++;
            int p=0;
            for(int t=1; ; ++t) {
                if(t*(t+1)/2>j) { p=t; break; }
            }
            ans+=p-1;
        }
    }
    if(x>1) ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
//#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
//#define int long long
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}


int32_t main(){
 fastio;
 int a,b;
 cin>>a>>b;
 cout<<a*b<<endl; 
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<int> data(n);
    for(int i=0;i<n;i++){
        cin >> data.at(i);
    }
    sort(data.begin(),data.end());
    long long sum=0;
    for(int i=0;i<n;i++){
        sum += data.at(i);
    }
    cout << data.at(0) << " " << data.at(n-1) << " " << sum << endl;
}


Measured memory_bytes: 3152
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1e9 + 100;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 105;
int n, m;
int dp[maxn][maxn], row[maxn][maxn][maxn], col[maxn][maxn][maxn];
char a[maxn][maxn];

bool read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%s", a[i]);
  }
  return true;
}

void solve() {
  int sx, sy;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 'E') {
        sx = i;
        sy = j;
      }
    }
  }
  if (sx < n - sx - 1) {
    for (int i = 0; 2 * i < n; i++) {
      for (int j = 0; j < m; j++) {
        swap(a[i][j], a[n - i - 1][j]);
      }
    }
    sx = n - sx - 1;
  }
  if (sy < m - sy - 1) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; 2 * j < m; j++) {
        swap(a[i][j], a[i][m - j - 1]);
      }
    }
    sy = m - sy - 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      row[i][j][j] = (a[i][j] == 'o');
      for (int k = j + 1; k < m; k++) {
        row[i][j][k] = row[i][j][k - 1] + (a[i][k] == 'o');
      }
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      col[i][j][j] = (a[j][i] == 'o');
      for (int k = j + 1; k < n; k++) {
        col[i][j][k] = col[i][j][k - 1] + (a[k][i] == 'o');
      }
    }
  }
  int ans = 0;
  for (int x = 0; x + sx < n; x++) {
    for (int y = 0; y + sy < m; y++) {
      dp[sx][sy] = (a[x + sx][y + sy] == 'o');
      for (int i = sy - 1; i >= 0; i--) {
        dp[sx][i] = dp[sx][i + 1] + (a[x + sx][y + i] == 'o');
      }
      for (int i = sx - 1; i >= 0; i--) {
        dp[i][sy] = dp[i + 1][sy] + (a[x + i][y + sy] == 'o');
        for (int j = sy - 1; j >= 0; j--) {
          dp[i][j] = max(dp[i][j + 1] + col[y + j][x + i][min(x + sx, x + i + n - sx - 1)],
                         dp[i + 1][j] + row[x + i][y + j][min(y + sy, y + j + m - sy - 1)]);
        }
      }
      ans = max(ans, dp[0][0]);
    }
  }
  printf("%d\n", ans);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time: %.18f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

vector<int> stuff;
vector<int> store;
ll ans = 0;

void kaj(vector<int> tmp2)
{
    ll num;
    int i = 0;

        for (int j = 0; j < (int)tmp2.size(); j++) {
            num = 0;
            while (i != tmp2[j]) {
                num = num * 10 + store[i];
                i++;
            }
            ans += num;
        }

        num = 0;
        while (i != (int)store.size()) {
            num = num * 10 + store[i];
            i++;
        }

        ans += num;
}

void power_set(int pos, vector<int> tmp2)
{

    if (pos == (int)store.size()) { ///storesize not stuffsize
        if (tmp2.size()) kaj(tmp2);
        return;
    }

    tmp2.push_back(pos);
    power_set(pos+1, tmp2);

    tmp2.pop_back();
    power_set(pos+1, tmp2);
}

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

    ll tmp = num;
    while (tmp) {
        int rem = tmp % 10;
        store.push_back(rem);
        tmp /= 10;
    }

    reverse(store.begin(), store.end());
    for (int i = 0; i < (int)store.size() - 1; i++) {
        stuff.push_back(i+1);
    }

    vector<int> tmp2;
    power_set(1, tmp2);


    ans += num;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		int ans = (A - 1) * (B - 1 );
   		System.out.println(ans);
		
   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 24532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int A,B,C,X; cin>>A>>B>>C>>X;
	// ote(A);//
	// ote(B);//
	// ote(C);//
	// ote(X);//
	ll ans = 0;
	rp(a,0,A+1){
		rp(b,0,B+1){
			rp(c,0,C+1){
				if(X==500*a+100*b+50*c) ans++;
			}
		}
	}
	ote(ans);
}


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

const int MAXN = 2 * 100000 + 1;
int A[MAXN];
long long ans;
int N;

int main() 
{
    // freopen("./input.txt", "r", stdin);
    // freopen("./output.txt", "w", stdout);
    
    scanf("%d", &N);
    ans = 0;    
    for (int i = 1; i <= N; i++) {
        scanf("%d", &A[i]);
    }
    if (A[1] != 0) {
        ans = -1;
    }    
    else {
        for (int i = 1; i <= N; ) {
            int j;
            for (j = i + 1; j <= N; j++) {
                if (A[j] == A[j - 1] + 1) {
                    continue;
                } else if (A[j] > A[j - 1] + 1) {
                    ans = -1;
                    break;
                } else {
                    break;
                }
            }
            if (ans == -1) {
                break;
            } else {
                ans += A[j - 1];
                i = j;
            }            
        }
    }
    printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 1024
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる
# 全ての｢辺｣についてループする

from collections import deque

N = int(input())

edge = [[] for _ in range(N)]

for _ in range(N-1):
    u, v, w = map(int, input().split())
    edge[u-1].append([v-1, w])
    edge[v-1].append([u-1, w])

color = [0] + [-1]*(N-1)
d = deque([0])

while d:
    current_point = d.popleft()
    for current_edge in edge[current_point]:
        if color[current_edge[0]] == -1:
            color[current_edge[0]] = (color[current_point] + current_edge[1]) % 2
            d.append(current_edge[0])

for idx in range(N):
    print(color[idx])

Measured memory_bytes: 82976
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
  int n, m;
  while(cin>>n>>m) {
    UnionFind uf(100000);
    REP(i,m) {
      int x,y,z;
      input(x,y,z);
      x--;y--;
      uf.unionSet(x,y);
    }
    set<int> S;
    REP(i,n) {
      S.insert(uf.root(i));
    }
    cout << S.size() << endl;
  }
}


Measured memory_bytes: 5376