akhauriyash/Code-Regression huggingface dataset:
def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    _ = int(input())
    A = [int(i) for i in input().split()]

    ans = 0
    c = Counter(A)
    B = sorted(c.keys(), reverse=True)
    # print(type(c.keys()))
    for b in B:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b]//2
        else:
            if a in c:
                cur = min(c[a], c[b])
            else:
                cur = 0
        ans += cur
        # c[b] -= cur
        c[a] -= cur

    print(ans)


if __name__ == '__main__':
    main()


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

int n;
int m;
typedef long long int LLI;
LLI ans;

int main() {
  scanf("%d%d", &n, &m);
  for (int i=0; i<n; i++) {
    printf("lst %d\n", i);
    fflush(stdout);

    LLI k;
    scanf("%lld", &k);

    for (int j=0; j<k; j++) {
      int v;
      scanf("%d", &v);
    }
    ans += k*(k-1);
  }

  printf("ans %lld\n", ans);
    fflush(stdout);
}

Measured memory_bytes: 1280
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func createNewSheet(a, b int) (sheet [][]string) {
	sheet = make([][]string, a+1)
	for i := 0; i < a+1; i++ {
		sheet[i] = make([]string, b+1)
	}
	return
}

func outputArray(sheet []string) {
	fmt.Println(strings.Join(sheet[:], " "))
}

func main() {
	s := nextLine()

	res := strings.Split(s, " ")

	a, _ := strconv.Atoi(res[0])
	b, _ := strconv.Atoi(res[1])

	// 多重配列の初期化
	sheet := createNewSheet(a, b)

	for i := 0; i < a; i++ {
		line := nextLine()
		lines := strings.Split(line, " ")

		r := sheet[i]

		total := 0
		for j := 0; j < b; j++ {
			v, _ := strconv.Atoi(lines[j])

			r[j] = strconv.Itoa(v)

			total = total + v
		}
		r[b] = strconv.Itoa(total)
		outputArray(r)
	}

	for j := 0; j <= b; j++ {
		total := 0
		for i := 0; i <= a; i++ {
			v, _ := strconv.Atoi(sheet[i][j])
			total = total + v
		}
		sheet[a][j] = strconv.Itoa(total)
	}
	outputArray(sheet[a])
}



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

int main(){
  int H,N;
  cin>>H>>N;
  vector<int> h(N);
  int sum=0;
  for(int i=0;i<N;i++){
    cin>>h.at(i);
    sum+=h.at(i);
  }
  if(H-sum<=0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

int main() {
  string S;
  cin>>S;
  long K;
  cin>>K;
  int l=S.size();
  long ans=0;
  int i=0;
    while(i<l-1){
      int con=1;
      int power=1;
      for(int j=i+1;j<l;j++){
        if(S[i]==S[j]){
          power++;
          con++;
          if(j==l-1){
            int b=power/2;
            ans+=b;
          }
        }
        else{
          int b=power/2;
          ans+=b;
          break;
        }
      }
      i+=con;
    }
  ans*=K;
 if(S[0]==S[l-1]){
    int boxa=1;
    for(int i=1;i<l;i++){
      if(S[0]==S[i]) boxa++;
      else break;
    }
    int boxb=1;
    for(int i=l-2;i>=0;i--){
      if(S[l-1]==S[i]) boxb++;
      else break;
    }
    int box=(boxa/2)+(boxb/2)-((boxa+boxb)/2);
    ans-=box*(K-1);
    if(boxa==l) ans=l*K/2 ;
 }
  cout<<ans<<endl;  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const int mod=1e9+7;

struct Unionfind{
  vector<int>d;
  Unionfind(int n):d(n,-1){}
  int root(int x){
    if(d[x]<0){return x;}
    return d[x]=root(d[x]);
  }
  bool unite(int x,int y){
    x=root(x);y=root(y);
    if(x==y){return false;}
    if(d[x]>d[y]){swap(x,y);}
    d[x]+=d[y];
    d[y]=x;
    return true;
  }
  bool same(int x,int y){return root(x)==root(y);}
  int size(int x){return -d[root(x)];}
};

int main(){
  int N,M,K;
  cin>>N>>M>>K;
  Unionfind uf(N);
 
  vector<int>fre(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    fre[a]++;
    fre[b]++;
    uf.unite(a,b);
  }
  vector<int>block(N);
  for(int i=0;i<K;i++){
    int c,d;
    cin>>c>>d;
    c--;d--;
    if(uf.same(c,d)){block[c]++;block[d]++;}
  }
  for(int i=0;i<N;i++){
    int sum=uf.size(i)-1-fre[i]-block[i];
    cout<<sum<<endl;
  }
  return 0;                       
}

Measured memory_bytes: 4232
import java.util.*;
import static java.lang.Math.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char a[] = new char[s.length()];
        a = s.toCharArray();
        int cnt = 0;
        for(int i=0; i<s.length()-1; i++){
            if(a[i] != a[i+1]){
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

long long n, a, b, c, d;
map<long long, long long> mp;

long long go(long long x) {
    if (mp.count(x))
        return mp[x];

    if (x == 1)
        return d;
    if (x == 0)
        return 0;

    long long res = LLONG_MAX / 2;
    if (res / d >= x)
        res = min(res, 1ll * x * d);

    // x * d <= res
    // x <= res / d

    // cerr << x << " D " << res << endl;

    long long two = 2ll * (x / 2);
    res = min(res, a + go(two / 2) + d * (x - two));
    if (x != 2)
        res = min(res, a + go(two / 2 + 1) + d * (two + 2 - x));
    // cerr << x << " 2 " << res << endl;

    long long three = 3ll * (x / 3);
    res = min(res, b + go(three / 3) + d * (x - three));
    res = min(res, b + go(three / 3 + 1) +  d * (three + 3 - x));
    // cerr << x << " 3 " << res << endl;

    long long five = 5ll * (x / 5);
    res = min(res, c + go(five / 5) + d * (x - five));
    res = min(res, c + go(five / 5 + 1) + d * (five + 5 - x));
    // cerr << x << " 5 " << res << endl;

    mp[x] = res;

    // cerr << x << " " << res << endl;

    return res;
}

void solve() {
    cin >> n >> a >> b >> c >> d;
    mp.clear();
    cout << go(n) << endl;
}

int main() {

    int tests;
    scanf("%d\n", &tests);
    while (tests--) {
      solve();
    }

    return 0;
}


Measured memory_bytes: 4828
#include <cstdio>
#include <cmath>
struct point{
	double x, y;
	point(double _x = 0, double _y = 0){ x = _x, y = _y; }
	void read(){ scanf("%lf%lf", &x, &y); }
	void print(char ch = '\n'){ printf("%.10lf %.10lf", x, y), putchar(ch); }
	point operator + (const point &rhs) const { return point(x + rhs.x, y + rhs.y); }
	point operator - (const point &rhs) const { return point(x - rhs.x, y - rhs.y); }
}A, B, C, D;
int q;
double dot_product(point a, point b){
	return a.x * b.x + a.y * b.y;
}
double cross_product(point a, point b){
	return a.x * b.y - a.y * b.x;
}
bool parallel(point p1, point p2, point p3, point p4){
	return cross_product(p1 - p2, p3 - p4) == 0;
}
bool orthogonal(point p1, point p2, point p3, point p4){
	return dot_product(p1 - p2, p3 - p4) == 0;
}
int main(){
	scanf("%d", &q);
	for (register int i = 1; i <= q; ++i){
		A.read(), B.read(), C.read(), D.read();
		if (parallel(A, B, C, D)) printf("2\n");
		else if (orthogonal(A, B, C, D)) printf("1\n");
		else printf("0\n");
	}
}


Measured memory_bytes: 2764
#include<iostream>
using namespace std;
int main(){
    int count,infon,tou,kai,heya,hito;
    int info[4][3][10]={{0},{0},{0}};
    cin>>infon;
    for(count=0;count<infon;count++){
        cin>>tou>>kai>>heya>>hito;
        info[tou-1][kai-1][heya-1]+=hito;
    }
    for(tou=1;tou<=4;tou++){
        for(kai=1;kai<=3;kai++){
            for(heya=1;heya<=10;heya++){
                cout<<' '<<info[tou-1][kai-1][heya-1];
            }
            cout<<endl;
        }
        if(tou!=4){
            cout<<"####################"<<endl;
        }
    }
}

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

int main() {
  int n;
  std::cin >> n;
  std::vector<std::int64_t> a(n);
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  
  for (int i = 0; i < n; ++i) {
    if (a[i] == 0) {
      std::cout << 0 << std::endl;
      return 0;
    }
  }

  std::int64_t p = 1;
  for (auto x : a) {
    if (x > 1'000'000'000'000'000'000 / p) {
      std::cout << -1 << std::endl;
      return 0;
    }
    p *= x;
  }
  std::cout << p << std::endl;
  return 0;
}

Measured memory_bytes: 4056
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val n = in.readLine().toInt
    val nodes = (0 until n).map { _ =>
      in.readLine().split("\\s+").map(_.toInt)
    }.toArray

    val lengths = for {
      n1 <- nodes.indices
      n2 <- nodes.indices
      if n1 < n2
    } yield {
      val node1 = nodes(n1)
      val node2 = nodes(n2)

      Math.sqrt(Math.pow(node2(0) - node1(0), 2.0) + Math.pow(node2(1) - node1(1), 2.0))
    }


    System.err.println(
      lengths
    )

//    val result = lengths.sum * factorial(n-2) * (n-1) * 2 / factorial(n)
    val result = lengths.sum / n * 2
    System.out.println(
      f"$result%2.10f"
    )
  }

  def factorial(n: Int): Long = {
    def inner(n: Int, cur: Long): Long = {
      if (n == 0) {
        cur
      } else {
        inner(n - 1, cur * n)
      }
    }

    inner(n, 1)
  }
}


Measured memory_bytes: 27196
#include<iostream>
using namespace std;
int main(){
  long long int n;
  while(cin >>n,n){
    int ans = 0;
    for(long long int i=5; i<=n; i*=5) for(long long int j=i; j<=n; j+=i) ans++;
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import sys, math
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()
    CSF = [LI() for _ in range(N-1)]

    for i in range(N-1):
        arrival_time = 0
        for j in range(i, N-1):
            arrival_time = math.ceil(max(arrival_time, CSF[j][1])/CSF[j][2])*CSF[j][2] + CSF[j][0]
        print(arrival_time)
    print(0)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3188
import java.util.Scanner;
import java.util.Arrays;

public class Main{

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

		int a=sc.nextInt();
		int b=sc.nextInt();
		int k=sc.nextInt();

		for(int i=a;i<=b;i++){
			if(i<a+k || i>b-k){
				System.out.println(i);
			}
		}

	}
}


Measured memory_bytes: 21844
n = int(input())
a = list(map(int, input().split()))
answer = sorted(a)[1]
if n == 2:
    pass
else:
    for b in reversed(range(answer)):
        cnt = 2
        flag = True
        for i in range(n):
            if a[i] % answer != 0:
                cnt -= 1
            if cnt == 0:
                flag = False
                break
        if flag:
            break
        answer -= 1
print(answer)

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

int main(){
    int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    int x, y; cin >> x >> y;

    cout << (a[x] == a[y] ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n: i64 = read();
    let m: i64 = read();
    let s: Vec<char> = read::<String>().chars().collect();
    let t: Vec<char> = read::<String>().chars().collect();
    let l = n * m / gcd(n, m);
    let k = l / n;
    let p = l / m;
    let mut ok = true;
    for i in 0..(n as usize) {
        if i as i64 * k % p == 0 {
            let j = (i as i64 * k / p) as usize;
            if s[i] != t[j] {
                ok = false;
            }
        }
    }
    println!("{}", if ok { l } else { -1 });
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define w(x)            int x; cin>>x; while(x--)
#define fr(i,a,b)       for(int i = a; i < b; i++)

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void vacation(vector<vector<int>>&arr, int n)
{
	vector<vector<int>>dp(n, vector<int>(3, 0));
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];
  
	fr(i, 1, n)
	{
		fr(j, 0, 3)
		{
			int op1 = dp[i - 1][(j + 1) % 3];
			int op2 = dp[i - 1][(j + 2) % 3];
			dp[i][j] = arr[i][j] + max(op1, op2);
		}
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
	return;
}

void solve()
{
	int n;
	cin >> n;
	vector<vector<int>>arr(n, vector<int>(3));
	fr(i, 0, n)
	fr(j, 0, 3)
	cin >> arr[i][j];
	vacation(arr, n);
}

int32_t main()
{
	c_p_c();
	solve();
	return 0;
}

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

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

  vector<int> ans(N);
  vector<bool> is_fix(N);

  rep(i, M) {
    int keta, num;
    cin >> keta >> num;

    keta--;
    if (keta == 0 && num == 0 && N > 1) {
      cout << "-1" << endl;
      return 0;
    }
    if (!is_fix[keta]) {
      is_fix[keta] = true;
      ans[keta] = num;
    } else if (ans[keta] != num) {
      cout << "-1" << endl;
      return 0;
    }
  }



  rep(i, N) {
    if (!is_fix[i]) {
      if (i == 0) {
        if (N == 1) {
          ans[i] = 0;
        } else {
          ans[i] = 1;
        }
      } else {
        ans[i] = 0;
      }
    }
    cout << ans[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
n, m = map(int,input().split())
lsl = []
lsr = []
for i in range(m):
    l, r = map(int,input().split())
    lsl.append(l)
    lsr.append(r)
lmax = max(lsl)
rmin = min(lsr)

if lmax > rmin:
    print(0)
else:
    ans1 = set(range(1,n + 1))
    ans2 = set(range(lmax,rmin + 1))
    ans = ans1 & ans2
    print(len(ans))


Measured memory_bytes: 35432
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

bool kansu(const pair<int, int>a, const pair<int, int>b)
{
	return a.first*a.second < b.first*b.second;
}

int main()
{
	int n, w, d;
	while (cin >> n >> w >> d, w)
	{
		vector<pair<int, int>>data;
		data.push_back(pair < int, int > {w, d});
		int a, b;
		for (size_t i = 0; i < n; i++)
		{
			cin >> a >> b;
			a--;
			b %= (data[a].first + data[a].second);
			if (b>data[a].first)
			{
				b -= data[a].first;
				if (b < data[a].second - b)
				{
					data.push_back(pair < int, int > {data[a].first, b});
					data.push_back(pair < int, int > {data[a].first, data[a].second - b});
				} else
				{
					data.push_back(pair < int, int > {data[a].first, data[a].second - b});
					data.push_back(pair < int, int > {data[a].first, b});
				}
			} else
			{
				if (b < data[a].first-b)
				{
					data.push_back(pair < int, int > {b, data[a].second});
					data.push_back(pair < int, int > {data[a].first - b, data[a].second});
				} else
				{
					data.push_back(pair < int, int > {data[a].first - b, data[a].second});
					data.push_back(pair < int, int > {b, data[a].second});
				}
				//data.push_back(pair < int, int > {b, data[a].second});
				//data.push_back(pair < int, int > {data[a].first - b, data[a].second});
			}
			data.erase(data.begin() + a);
		}
		sort(data.begin(), data.end(), kansu);
		auto ite = data.begin();
		for (; ite != data.end() - 1; ite++)
		{
			cout << ((*ite).first)*((*ite).second) << " ";
		}
		cout << ((*ite).first)*((*ite).second) << endl;
	}
}

Measured memory_bytes: 1200
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    A[i] -= i + 1

sortA = sorted(A)

if(N>1):
    b1 = sortA[(N-1)//2]
    b2 = sortA[(N-1)//2+1]

    ans1 = 0
    ans2 = 0
    for i in range(N):
        ans1 += abs(b1-A[i])
        ans2 += abs(b2-A[i])

    print(min(ans1, ans2))
else:
    print(0)


Measured memory_bytes: 25156
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(1){
    if(x -> left == NIL) break;
    x = x->left;
  }
  return x;

}

Node treeMaximum(Node x){
  while(1){
    if(x -> right == NIL) break;
    x = x-> right;
  }
  return x;


}

Node treeSearch(Node u, int k){
  Node a,b;

  if(u == NIL) return u;
  if(k == u -> key) return u;

  a = treeSearch(u->left,k);
  b = treeSearch(u->right,k);
  if(k < u->key) return a;
  else return b;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(1){
    if(y == NIL && x != y->right) break;
    x = y;
    y = y->parent;
  }

  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL) y = z;
  if(x->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(x != NIL){
    x->parent = y->parent;
  }

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(1){
    if(x == NIL) break;
    y = x;

    if(z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else (y->right = z);
}




void inorder(Node u){
  if(u == NIL) return;
  inorder(u -> left);
  printf(" %d", u -> key);
  inorder(u -> right);

}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d", u -> key);
  preorder(u -> left);
  preorder(u -> right);

}

Node find(Node u,int k){
  while(u != NIL && k != u-> key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else break;
    
  }

  return 0;
}



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

namespace CsTest
{
    public class Program
    {
        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');
            int N = int.Parse(line[0]), L = int.Parse(line[1]);
            int result = ((L - 1) * N) + ((N + 1) * N / 2);
            if (L > 0) result -= L;
            else if (Math.Abs(L) >= N) result -= (L + N - 1);
            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 13140
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from functools import reduce, lru_cache
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
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)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N = I()
    X = S()
    original_popcount = X.count("1")

    upper_popcount = original_popcount + 1
    lower_popcount = original_popcount - 1

    if original_popcount == 0:
        for i in range(N):
            print(1)
        return

    if original_popcount == 1:
        for i in range(N):
            if X[-1] == "1":
                if i != N-1:
                    print(2)
                else:
                    print(0)
            else:
                if X[i] == "1":
                    print(0)
                elif i == N-1:
                    print(2)
                else:
                    print(1)
        return

    # Xが0の可能性
    upper = [0] * N
    lower = [0] * N
    upper[-1] = 1 % upper_popcount
    lower[-1] = 1 % lower_popcount

    for i in range(1, N)[::-1]:
        upper[i-1] = (2 * upper[i]) % upper_popcount
        lower[i-1] = (2 * lower[i]) % lower_popcount

    mu = 0
    ml = 0
    for i in range(N):
        if X[i] == "1":
            mu = (mu + upper[i]) % upper_popcount
            ml = (ml + lower[i]) % lower_popcount

    for i in range(N):
        if X[i] == "0":
            m = (mu + upper[i]) % upper_popcount
        else:
            m = (ml - lower[i]) % lower_popcount

        ans = 1
        while m:
            tmp = m
            ones = 0
            while tmp:
                if tmp & 1 == 1:
                    ones += 1
                tmp //= 2
            m %= ones
            ans += 1

        print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 90524
n=int(input())
#a,b=map(int,input().split())
hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
mx=hl[0]
flag=True
for i in range(n):
    mx=max(mx,hl[i])
    if hl[i]>=mx-1:
        pass
    else:
        flag=False
        break
if flag:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 15020
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

const ll INF = 1e18;

ll a, b, c, d;
map<ll, ll> mp;

ll dfs(ll x){
    if(x == 0) return 0;
    if(mp[x] > 0) return mp[x];
    ll res = INF;
    if(INF/d > x) res = x * d;
    auto f2 = [&](ll y){
        if(y >= x) return INF;
        return dfs(y);
    };
    {
        ll l = x/2*2, r = l+2;
        chmin(res, f2(l/2)+a+(x-l)*d);
        chmin(res, f2(r/2)+a+(r-x)*d);
    }
    {
        ll l = x/3*3, r = l+3;
        chmin(res, f2(l/3)+b+(x-l)*d);
        chmin(res, f2(r/3)+b+(r-x)*d);
    }
    {
        ll l = x/5*5, r = l+5;
        chmin(res, f2(l/5)+c+(x-l)*d);
        chmin(res, f2(r/5)+c+(r-x)*d);
    }
    return mp[x] = res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    rep(_,t){
        ll n;
        cin >> n >> a >> b >> c >> d;
        mp = map<ll, ll>();
        ll ans = dfs(n);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4816
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,c[100005],i,ans1,ans2;
char s[10];
bool ok[100005];
int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d%s",&i,s);
		if(s[0]=='A')
			ok[i]=true;
		else if(!ok[i])
			++c[i];
	}
	for(i=1;i<=n;++i)
		if(ok[i])
			++ans1,ans2+=c[i];
	printf("%d %d",ans1,ans2);	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>

using namespace std;

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

  int a[n];

  int max = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];

    max += a[i];
  }

  sort(a, a + n);

  double c = max / 4.0 / m;

  if(a[n - m] >= c){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}

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

const long long INF = 1LL << 60;

ll gcd_ori(ll a, ll b){
    if(b == 0){
        return a;
    }

    return gcd_ori(b, a % b);
}

int main() {
    ll N; cin >> N;
    vector<ll> A(N, -1);
    rep(i, N) cin >> A.at(i);

    sort(A.begin(), A.end());
    ll ans = gcd_ori(A.at(1),A.at(0));

    for(ll i=0;i<N; i++){
        if(A.at(i) % ans != 0) break;
        if(i == N-1){
            cout << ans << endl;
            return 0;
        }
    }

    cout << 1 << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){

char str[2];
char *pt = &str[0];

scanf("%s",str);

  if('A' <= *pt && *pt <= 'Z'){
    printf("A\n");
  }
  else if('a' <= *pt && *pt <= 'z'){
    printf("a\n");
  }

return 0;
}



Measured memory_bytes: 1632
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int n = 0;
            for(int i = 0; i < N.Length; i++)
            {
                n += int.Parse(N[i].ToString());
            }
            if(n % 9 == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    } 
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 32956
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

int MOD = (ll)1000000000 + 7;
ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
const int MAX = 500050;
typedef pair<int, int>P;

struct con {
	int s, t, x;
};
bool operator<(const con& p1, const con& p2) {
	return p1.x < p2.x;
}
vector<con>v;
int q[200020];
set<int>st;
map<int, int>mp;
signed main() {
	int N, Q; cin >> N >> Q;
	//v.resize(N);
	REP(i, N) {
		int s, t, x; cin >> s >> t >> x;
		t--;
		s -= x, t -= x;
		v.push_back(con({ s,t,x }));
	}
	REP(i, Q) {
		cin >> q[i];
		st.insert(q[i]);
	}
	VSORT(v);
	for (auto x : st) {
		mp[x] = -1;
	}
	st.insert(-INF); st.insert(INF);
	REP(i, v.size()) {
		int l = v[i].s, r = v[i].t;
		
		auto itr1 = st.lower_bound(l);
		auto itr2 = st.upper_bound(r);

		vector<int>pos;
		while (itr1 != itr2) {
			pos.pb(*itr1);
			mp[*itr1] = v[i].x;
			itr1++;;
		}
		REP(j, pos.size()) {
			auto x = st.erase(pos[j]);
		}
	}
	REP(i, Q) {
		print(mp[q[i]]);
	}
}

Measured memory_bytes: 33644
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ss(x) (int) x.size()
#define cat(x) cerr << #x << " = " << x << endl

using ll = long long;

using namespace std;

int n, a, b;	

int main() {
	scanf ("%d%d%d", &n, &a, &b);
	printf (((b - a - 1) & 1) ? "Alice\n" : "Borys\n");	
	return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#define INF 1000000001

using namespace std;

struct Card{char suit; int value;};

int partition(Card c[],int p,int r){
  int x=c[r].value;
  int i=p-1;
  for(int j=p;j<=r-1;j++){
    if(c[j].value<=x){
      i++;
      Card t=c[i];
      c[i]=c[j];
      c[j]=t;
    }
  }
  Card t=c[++i];
  c[i]=c[r];
  c[r]=t;
  return i;
}

void quicksort(Card c[],int p,int r){
  if(p<r){
    int q=partition(c,p,r);
    quicksort(c,p,q-1);
    quicksort(c,q+1,r);
  }
}

void merge(Card c[],int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  Card L[n1+1],R[n2+1];
  for(int i=0;i<n1;i++) L[i]=c[left+i];
  for(int i=0;i<n2;i++) R[i]=c[mid+i];
  L[n1].value=INF; R[n2].value=INF;
  int i=0,j=0;
  for(int k=left;k<right;k++){
    if(L[i].value<=R[j].value){
      c[k]=L[i++];
    }else{
      c[k]=R[j++];
    }
  }
}

void mergeSort(Card c[],int left,int right){
  if(left+1<right){
    int mid=(left+right)/2;
    mergeSort(c,left,mid);
    mergeSort(c,mid,right);
    merge(c,left,mid,right);
  }
}

bool compare(Card c1[],Card c2[],int n){
  for(int i=0;i<n;i++){
    if(c1[i].suit!=c2[i].suit) return false;
  }
  return true;
}

int main(){
  int n; cin >> n;
  Card c1[n],c2[n];
  for(int i=0;i<n;i++){
    cin >> c1[i].suit >> c1[i].value;
    c2[i]=c1[i];
  }
  quicksort(c1,0,n-1);
  mergeSort(c2,0,n);
  bool isStable=compare(c1,c2,n);
  if(isStable) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  for(int i=0;i<n;i++)
    cout << c1[i].suit << " " << c1[i].value << endl;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define assign(x,val) memset(x,val,sizeof(x))
void solve(){
    ll a;float b;
    cin>>a>>b;
    double d=b*100;
    ll p=round(d);
    cout<<(a*p)/100;
}
int main() {
    crap;
	int t=1;
	//cin>>t;
	while(t--){
	    solve();
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int res = 0;
  for(int i = 1; i <= n; ++i) {
    if((i&1) && (a[i - 1] & 1)) res++;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

int main() {
  int N; cin >> N;
  vector<ll> x(N), y(N);
  REP(i, N){
    cin >> x[i] >> y[i];
  }
  map<pair<ll,ll >, int> diff;

  REP(i, N) REP(j, N){
    if(i == j) continue;
    diff[{x[i]-x[j], y[i]-y[j]}]++;
  }

  int ans = N;
  FOREACH(a, diff){
    ans = min(ans, N - a.second);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,j,k) for(ll i=(ll)j;i<(ll)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF INT_MAX
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
	char string[10000];
	int i,JOIcount,IOIcount,strlong;
	while(scanf("%s",&string) != EOF){
		JOIcount = 0;
		IOIcount = 0;
		strlong = strlen(string);
		for(i=0;i<strlong-2;i++){
			if(string[i] == 'J'){
				if(string[i+1] == 'O'){
					if(string[i+2] == 'I'){
						JOIcount += 1;
					}
				}
			}
			else if(string[i] == 'I'){
				if(string[i+1] == 'O'){
					if(string[i+2] == 'I'){
						IOIcount += 1;
					}
				}
			}
		}
		printf("%d\n%d\n",JOIcount,IOIcount);
	}
	return 0;
}

Measured memory_bytes: 0
S=int(input())
S1=S//100
S2=S%100
if 1<=S1<=12:
    m1=1
else:
    m1=0
if 1<=S2<=12:
    m2=1
else:
    m2=0
if m1==0 and m2==0:
    print("NA")
elif m1==0 and m2==1:
    print("YYMM")
elif m1==1 and m2==0:
    print("MMYY")
else:
    print("AMBIGUOUS")

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    while(1){
        cin>>a>>b;
        if(a==0&&b==0){
            break;
        }
        if(a>=b){
            swap(a,b);
        }
        cout<<a<<" "<<b<<endl;
    }
}


Measured memory_bytes: 2984
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  string s,p;
  cin>>s>>p;
  int ans = 0;
  for(int i = 0;i<3;i++){
    if(s.at(i) == p.at(i)){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 5010

ll dp[SIZE][SIZE];

int main(){
  int N, A, B;
  int p[SIZE];

  cin >> N >> A >> B;

  for(int i=0;i<N;i++)
    cin >> p[i];

  for(int i=0;i<=N;i++)
    for(int j=0;j<=N;j++)
      dp[i][j] = LLINF * (i != 0);


  for(int i=0;i<N;i++){
    ll minVal = LLINF;

    for(int j=0;j<p[i];j++)
      minVal = min(minVal, dp[i][j]);

    for(int j=0;j<=N;j++){
      if(j < p[i]) dp[i+1][j] = dp[i][j] + A;
      if(j > p[i]) dp[i+1][j] = dp[i][j] + B;
    }

    dp[i+1][p[i]] = minVal;
  }

  ll ans = LLINF;

  for(int i=0;i<=N;i++)
    ans = min(ans, dp[N][i]);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 195968
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	vector<int>a(N);
	rep(i, N) {
		cin >> a[i];
		a[i]--;
	}
	int ans = 0;
	rep(i, N)if (a[a[i]] == i)ans++;
	ans /= 2;
	cout << ans << endl;
}

Measured memory_bytes: 1024
until (n = gets.to_i) == 0 do

    ascore = 0
    bscore = 0
    
    for i in 1..n do
        acard, bcard = gets.split(" ").map(&:to_i)
        
        if acard > bcard then
            ascore += acard + bcard
        elsif bcard > acard then
            bscore += acard + bcard
        else
            ascore += acard
            bscore += bcard
        end
    end
    
    printf("#{ascore} #{bscore}\n")

end

Measured memory_bytes: 8760
import sys
import math
from collections import deque
from collections import Counter

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 make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]

def make_cumulative(A):
    C = [0] * (len(A) + 1)
    for i, a in enumerate(A):
        i += 1
        C[i] = C[i - 1] + a
    return C


def main():
	N, M = NMI()
	A = NLI()
	C = make_cumulative(A)
	C = [c%M for c in C]
	C = Counter(C)
	ans = 0
	for c, x in C.items():
		if x >= 2:
			ans += x * (x-1) // 2
	print(ans)
	

if __name__ == "__main__":
	main()

Measured memory_bytes: 16412
P = [(1,1,1), (1,1,-1), (1,-1,1), (1,-1,-1), (-1,1,1), (-1,1,-1), (-1,-1,1), (-1,-1,-1)]
N, M = map( int, input().split())
X = [0]*N
Y = [0]*N
Z = [0]*N
ans = 0
for i in range(N):
    X[i], Y[i], Z[i] = map( int, input().split())
for i in range(8):
    a, b, c = P[i]
    W = [0]*N
    for j in range(N):
        W[j] = a*X[j] + b*Y[j] + c*Z[j]
    W.sort(key=None, reverse = True)
    ans = max( ans, sum(W[:M]))
print(ans)


Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n==0) break;
			int [][] info = new int[n][n];
			for(int i=0;i<n;i++) {
				for(int j=0;j<n;j++) {
					info[i][j] = 0;
				}
			}
			int [] leak = new int[n];
			for(int i=0;i<n;i++) {
				int m = sc.nextInt();
				for(int j=0;j<m;j++) {
					info[i][j] = sc.nextInt();
				}
				Arrays.sort(info[i]);
			}
			int k = sc.nextInt(); 
			for(int i=0;i<k;i++) {
				leak[i] = sc.nextInt();
			}
			int count1 = 0;
			int count2 = 0;
			int ans = -1;
			for(int i=0;i<n;i++) {
				for(int j=0;j<k;j++) {
					if(Arrays.binarySearch(info[i], leak[j])>=0) count1++;
				}
				if(count1 == k) {
					count2++;
					ans = i+1;
				}
				count1 = 0;
			}
			if(count2 == 1 || count2 == 0) {
				System.out.println(ans);
			}else {
				System.out.println("-1");
			}
		}				
	}
}



Measured memory_bytes: 78408
// 2_m-solutions2019_b
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt = 0;
    int k = s.length();
    rep(i, k){
        if(s[i] == 'x') cnt++;
    }

    if(cnt <= 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


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

int main() {
    string S, T;
    cin >> S >> T;
    int mx = 0;
    for (int i = 0; i <= S.size() -  T.size(); i++){
        int common = 0;
        for (int j = 0; j < T.size(); j++){
            if (S[i+j] == T[j]){
                common++;
            }
        }
        mx = max(mx, common);
    }
    cout << T.size() - mx << "\n";
    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;
class Main{
public static void main(String[] args)
{
Scanner scan =new Scanner(System.in);
String str1=scan.next();
String str2=scan.next();
int a=Integer.parseInt(str1);
int b=Integer.parseInt(str2);
System.out.println(a*b+" "+(a*2+b*2));
}
}

Measured memory_bytes: 26140
while True:
    n=int(input())
    x=1
    y=[]
    z=0
    if n==0:
        break
    
    
    for i in range(1,n+1):
        x*=i
        #print(x)
    #print(str(x))


    for j in str(x):
        y+=[j]
    
    
    #print(y)
    y.reverse()
    #print(y)
    
    for k in y:
        if k=='0':
            z+=1
        elif k!=0:
            break
    print(z)


Measured memory_bytes: 6492
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n;
	cin >> n;
	for(int i = 0; i <= n; ++i){
		if(i + i * 8 / 100 == n){
			cout << i << endl;
			return;
		}
	}
	cout << ":(\n";
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,b; bool f;
char s[51][51],t[51][51];
using namespace std;
int main()
{
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;++i)
	for(int j=1;j<=a;++j)
	cin>>s[i][j];
	for(int i=1;i<=b;++i)
	for(int j=1;j<=b;++j)
	cin>>t[i][j];
	for(int i=1;i<=a-b+1;++i)
	for(int j=1;j<=a-b+1;++j)
	if(s[i][j]==t[1][1])
	{
		f=true;
		for(int i1=i;i1<=i+b-1;++i1)
		{
			for(int j1=j;j1<=j+b-1;++j1)
			if(s[i1][j1]!=t[i1-i+1][j1-j+1])
			{
				f=false;
				break;
			}
			if(!f)break;
		}
		if(f)
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
}

Measured memory_bytes: 256
n = int(input())
arr = []
for i in range(n):
  a,b = map(int,input().split())
  arr.append([a,b])
time = 0
k = 1
arr = sorted(arr,key=lambda x: x[1])
for i in range(n):
  time += arr[i][0]
  if time > arr[i][1]:
    k = 0
    break
if k == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 39708
#include <iostream>

using namespace std;

int getDigitsSum(int number) {
  int sum = 0;
  while(1) {
    int rest = number % 10;
    sum += rest;
    number /= 10;
    //cout << i << "," << sum << "," << rest << "," << number << endl;
    if (number == 0) {
      break;
    }
  }
  return sum;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int total = 0;
  for (int i = 1; i <= n; i++) {
    int sum = getDigitsSum(i);
    if (sum >= a && sum <= b) {
      //cout << "get" << endl;
      total += i;
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 256