akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] hn = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[] a = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int sum = 0;
        for(int i=0; i<hn[1]; i++) {
            sum += a[i];
        }
        String ans = "";
        if (hn[0] > sum) ans = "No";
        else ans = "Yes";

        System.out.println(ans);
    }
}

Measured memory_bytes: 47256
from collections import defaultdict as dd
N = int(input())
# 以下の形の数が75個の約数を持つ
# 素数^4 * 素数^4 * 素数^2
# 素数^14 * 素数^4
# 素数^24 * 素数^2
# 素数^74
primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
ct = dd(int)
for i in range(1, N+1):
  for j in primes:
    x = i
    while x % j == 0:
      ct[j] += 1
      x //= j

over74 = []
over24 = []
over14 = []
over4 = []
over2 = []
for k, v in ct.items():
  if v >= 74:
    over74.append(k)
  elif v >= 24:
    over24.append(k)
  elif v >= 14:
    over14.append(k)
  elif v >= 4:
    over4.append(k)
  elif v >= 2:
    over2.append(k)

l2 = len(over2)
l4 = len(over4)
l14 = len(over14)
l24 = len(over24)
l74 = len(over74)
print(
  l2 * (l4+l14+l24+l74) * ((l4+l14+l24+l74) - 1) // 2 +
  (l4+l14+l24+l74) * ((l4+l14+l24+l74) - 1) * ((l4+l14+l24+l74) - 2) // 2 +
  l4 * (l14+l24+l74) +
  (l14+l24+l74) * ((l14+l24+l74) - 1) +
  (l2+l4+l14) * (l24+l74) +
  (l24+l74) * ((l24+l74) - 1) +
  l74
)

Measured memory_bytes: 3316
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

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

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

    sort(c.begin(), c.end(), greater<int>());

    long long res = 0;
    for (int i = 0; i < n; i++) {
        res -= b[i];
        if (i % 2 == 0) {
            res += c[i];
        }
    }

    cout << res << endl;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int a, b; cin>>a>>b;
    if(a>0) cout << "Positive" << endl;
    else if(a<=0 && b>=0) cout << "Zero" << endl;
    else{
        if((b-a)%2==0) cout << "Negative" << endl;
        else cout << "Positive" << endl;
    }
}

Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0

#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main() {

    double N, K;
    cin >> N >> K;

    vector<double> p(N, 0);
    for (int i = 0; i < N; ++i) {
        double tmp;
        cin >> tmp;
        p[i] = (tmp + 1.0) / 2.0;
    }


    double maximum = 0;
    for (int i = 0; i < K; ++i) {
        maximum += p[i];
    }
    double sum = maximum;
    for (int i = 1; i < N - K + 1; ++i) {
        sum = sum - p[i - 1] + p[i + (K - 1)];
        maximum = max(maximum, sum);
    }

    printf("%lf", maximum);

    return 0;
}


Measured memory_bytes: 1792
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val ss = mutableMapOf<String, Int>()

    var max = 0
    repeat(n) {
        val s = readLine()!!
        val i = (ss[s] ?: 0) + 1
        ss[s] = i

        if (i > max) {
            max = i
        }
    }

    ss.entries.filter { it.value == max }.sortedBy { it.key }.forEach {
        println(it.key)
    }
}

Measured memory_bytes: 85836
#include<iostream>
#include<cmath>
 
using namespace std;
 
int main()
{
    int count = 0;
    long n, d;
    cin >> n >> d;
    for(int i = 0; i < n; i++)
    {
        double x, y;
        cin >> x >> y;
        double dis = hypot(x,y);
        if(dis <= d)
        {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);

		int result[] = new int[3];
		result[0] = in.nextInt();
		result[1] = in.nextInt();
		result[2] = in.nextInt();

		Arrays.sort(result);


		for(int i = 0; i < 2; i++){
			System.out.print(result[i] + " ");
		}

		System.out.println(result[2]);

	}

}



Measured memory_bytes: 26204
def main(input = input = STDIN.gets)
  input.chomp!

  y = 0
  stack = []

  input.chars.each_with_index do |ch, x|
    # puts "#{ch} (#{x}, #{y})"

    case ch
    when '\\' # DOWN
      y -= 1
      stack << [x, y]
    when '/'  # UP
      area = 0

      until stack.empty? || stack.all?{|e| e.is_a?(Integer)}
        case stack[-1]
        when Integer
          area += stack.pop
        when Array
          last_x, _ = stack.pop
          area += x - last_x
          break
        end
      end
      stack << area unless area.zero?

      y += 1
    when '_'
      # skip
    end
  end

  areas = stack.select{|e| e.is_a?(Integer) }

  puts areas.sum
  puts [areas.length, *areas].join ' '
end

main


Measured memory_bytes: 8872
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        if(N>=30){
            out.println("Yes");
        }else{
            out.println("No");
        }
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);
    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define sort(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

int main(){
int x,a,b;
cin>>x>>a>>b;
int A=abs(x-a);
int B=abs(x-b);
if(A>B){
	cout<<"B"<<endl;
  }
  else{
	  cout<<"A"<<endl;
	}
}


Measured memory_bytes: 256
INF = 10 ** 9 + 7

n = gets.to_i
s = gets.chomp
hs = Hash.new(0)

n.times do |i|
  hs[s[i]] += 1
end

res = 1
hs.values.each do |v|
  res = (res * (v + 1)) % INF
end
res = (res - 1) % INF
puts res

Measured memory_bytes: 14564
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()

if n == 0:
    print(0)
else:
    s = ""
    while n != 0:
        if n % 2 != 0:
            n -= 1
            s = "1" + s
        else:
            s = "0" + s
        n //= -2
    print(s)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int i;
        
        for(i=0; i<2; i++){
            if(N % 10 == 9){
                break;
            }
            N /= 10;
        }

        if(i == 2){
            Console.WriteLine("No");
        }else{
            Console.WriteLine("Yes");
        }
    }
}



Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#define INF 100000000
#define dis first
#define x second.first
#define y second.second
using namespace std;
typedef pair < int ,pair < int,int > > P;
int mp[1001][1001];
int D[1001][1001];
int w,h,tx,ty;
int dx[] = {1,-1,0,0},dy[] = {0,0,1,-1};
int dijkstra(){
  priority_queue <P, vector<P>, greater<P> > Q;
  for(int i=0;i<=h;i++)
    for(int j=0;j<=w;j++) D[i][j] = INF;
  D[0][0] = 0;
  P t,a;
  t.dis = t.x = t.y = 0;
  Q.push(t);
  while(!Q.empty()){
    t = Q.top();Q.pop();
    if(t.x == tx && t.y == ty) return t.dis;
    for(int i=0;i<4;i++){
      int nx = t.x+dx[i];
      int ny = t.y+dy[i];
      if(nx<0 ||ny<0 ||nx>=w ||ny>=h || mp[ny][nx] == INF)continue;
      int ndis = max(t.dis,mp[ny][nx]);
      if(ndis < D[ny][nx]){
	a.dis = ndis , a.x = nx , a.y = ny;
	Q.push(a);
	D[ny][nx] = ndis;	
      }
    }
  }
  return -1;
}

int main(){
  while(cin >>w >>h){
    string str;
    for(int i=0;i<h;i++){
      cin >> str;
      for(int j=0;j<w;j++)
	if(str[j] == '.') mp[i][j] = 0;
	else if(str[j] =='#') mp[i][j] = INF;
	else if(str[j] == 't') mp[i][j] = 0,tx =j,ty = i;
    }
    int q;
    cin >> q;
    for(int i=1;i<=q;i++){
      int a,b;
      cin >> a >> b;
      if(mp[b][a] == INF)  mp[b][a] = i;
    }
    cout << dijkstra() <<endl;
  }
  return 0;
}

Measured memory_bytes: 9080
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) when x < y -> Node (y, doit l, r)
    | Node (y, l, r) -> Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  let f e = print_string " "; print_int e in
  inorder f t;
  print_newline ();
  preorder f t;
  print_newline ()

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let rec read i t =
    if i < m then
      match split_on_char ' ' (read_line ()) with
      | ["insert"; n] -> read (i + 1) (insert (int_of_string n) t)
      | _ -> print t; read (i + 1) t in
  read 0 (create ())

Measured memory_bytes: 31824
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        s: chars
    }

    print!("{}", s[0]);
    print!("{}", s[1]);
    println!("{}", s[2]);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2208
#include <iostream>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int m[4][3][10] = {0};

    int b, f, r, v;
    for (int i=0; i<n; ++i) {
        cin >> b >> f >> r >> v;
        m[b-1][f-1][r-1] += v;
    }

    for (int i=0; i<4; ++i) {
        for (int j=0; j<3; ++j) {
            for (int k=0; k<10; ++k) {
                cout << " " << m[i][j][k];
            }
            cout << "\n";
        }
        if (i != 3) {
            cout << "####################\n";
        }
    }

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;
const double PI = acos(-1.0);

double DEG_to_RAD(double d) { return d * PI / 180.0; }

int n;

int main(){
    //freopen("test.txt","r",stdin);
    cin >> n;
    int ans = 0;
    while ( n  ) {
        if ( n % 10 == 1) ans++;
        n /= 10;
    }
    cout << ans << endl;
}


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

int main(){
  int k, a[3];
  cin >> a[0] >> a[1] >> a[2] >> k;
  sort(a, a + 3);
  for(int i = 0; i < k; i++) a[2] = a[2] * 2;
  cout << a[2] + a[1] + a[0] << endl; 
  return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = IR(5)
    k = I()
    if max(s)-min(s) > k:
        print(":(")
    else:
        print("Yay!")
    return

#B
def B():
    s = IR(5)
    s.sort(key = lambda x:-x%10)
    ans = 0
    i = 0
    k = 0
    while 1:
        if i%10 == 0:
            ans = i+s[k]
            i += s[k]-1
            k += 1
            if k == 5:break
        i += 1
    print(ans)
    return

#C
def C():
    n = I()
    a = IR(5)
    ans = 5+n//min(a)
    if n%min(a) == 0:ans -= 1
    print(ans)
    return

#D
def D():
    x,y,z,k = LI()
    a = LI()
    b = LI()
    c = LI()

    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 39152
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
typedef long long int ll; 
typedef long double ld; 

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    string s,t;
    cin>>s>>t;
    ll ans = 0;
    for(ll i=0;i<s.size();i++)
    {
        if(s[i]==t[i])
        {
            ans++;
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner num = new Scanner(System.in);
		int a = num.nextInt();
		int b = num.nextInt();
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}
}



Measured memory_bytes: 26176
import sys, itertools
input = sys.stdin.readline

n = int(input())
ll = []
for i in range(n):
  a = int(input())
  for j in range(a):
    x, y = map(int, input().split())
    ll.append([i, x-1, y])

ans = 0

for p in itertools.product([1,0], repeat=n):
  ok = 1
  for l in ll:
    if p[l[0]] == 1 and p[l[1]] != l[2]:
      ok = 0
      break
  if ok:
    ans = max(ans, sum(p))

print(ans)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
	int mhr[20],i,j,c;
	for(i=1; i<=10; i++)
	{
		cin >> mhr[i];
	}
	for(i=1; i<=10; i++)
	{
		for(j=i+1; j<=10; j++)
		{
			if(mhr[i]<mhr[j])
			{
				c=mhr[i];
				mhr[i]=mhr[j];
				mhr[j]=c;
			}

		}
	}
	for(i=1; i<=3; i++)
	{
		cout << mhr[i] << endl;
	}

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> mochi(N);
  for (int i=0; i<N; i++){
    cin >> mochi.at(i);
  }
  int count = 0;
  for (int i=0; i<N; i++){
    for (int j=0; j<N; j++){
      if (mochi.at(i) == 0){
        break;
      }
      else if (i != j && mochi.at(i) == mochi.at(j)){
        mochi.at(j) = 0;
      }
    }
    if (mochi.at(i) > 0){
      count +=1;
    }
  }
  cout << count << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N;
    cin >> N;

    vector<ll> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    map<ll,ll> mp;
    for (int i = 0; i < N; i++) {
        mp[a[i]]++;
    }

    ll idx = 0;
    for (int i = 1; i < N; i++) {
        if (mp[a[0] ^ a[i]]) {
            idx = i;
            break;
        }
    }

    if (idx == 0) {
        cout << "No" << endl;
        return;
    }

    int cnt = 0;
    ll x0 = a[0];
    ll x1 = a[idx];
    mp[x1]--;
    ll x2 = x0 ^ x1;
    while (mp[x2]) {
        cnt++;
        x0 = x1;
        x1 = x2;
        mp[x2]--;
        x2 = x0 ^ x1;
    }

    if (cnt == N-1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 7808
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    ll n;cin>>n;
    if(n==2){
        cout<<1<<endl;
        return 0;
    }
    map<ll,ll>m;
    ll ans=0;//k==n k==n-1
    for(ll k=2;k*k<=n;k++){
        ll in=n;
        while(in>=k){
            if(in%k==0)in/=k;
            else in%=k;
        }
        if(in==1){
            if(m[k]==0)
                ans++;
            m[k]++;
            ll tri=n/k;
            ll iin=n;
            while(iin>=tri){
                if(iin%tri==0)iin/=tri;
                else iin%=tri;
            }
            if(iin==1&&k*k<n){
                if(m[tri]==0)ans++;
                m[tri]++;
            }
        }
    }
    if(m[n]==0)ans++;
    if(m[n-1]==0)ans++;
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------













































Measured memory_bytes: 256
parseInt(x) = parse(Int, x)

function main()
	n = parseInt(readline())
	a = map(parseInt, split(readline()))
	b = Array{Int}(n)
	b[1] = a[1]
	for i in 2:n
		b[i] = b[i-1] + a[i]
	end
	d = Dict{Int, Int}()
	for i in 1:n
		if haskey(d, b[i])
			d[b[i]] += 1
		else
			d[b[i]] = 1
		end
	end
	total = 0
	for i in keys(d)
		if i == 0
			total += d[i]+div(d[i]*(d[i]-1),2)
		else
			total += div(d[i]*(d[i]-1),2)
		end
	end
	print(total)
end

main()

Measured memory_bytes: 155112
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <string.h>
#include <map>
#include <iomanip>
#include <time.h>
#include <complex>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>

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

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i < b) {
                if (j < a) cout << 0;
                else cout << 1;
            }
            else {
                if (j < a) cout << 1;
                else cout << 0;
            }
        }
        cout << endl;
    }

}


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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s == "Y") {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define all(v) v.begin(),v.end()
// vector
template<class T> istream&
operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

template<typename T>
T gcd(T a,T b){
    T c=a,d=b,r;
    do{r=c%d;c=d;d=r;}while(r);
    return c;
}

bool does_win_first(vector<int> &A) {
    ll sum = accumulate(all(A), 0ll) - A.size();
    
    if(sum % 2 == 1) return true;
    
    vector<int> odd_indices;
    rep(i, A.size()) if(A[i] % 2) odd_indices.push_back(i);
    
    if(odd_indices.size() == 1 and A[odd_indices[0]] > 1) {
        A[odd_indices[0]]--;
        ll g = accumulate(all(A), A[0], gcd<ll>);
        rep(i, A.size()) A[i] /= g;
        return not does_win_first(A);
    }
    return false;
}

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

    int N; cin >> N;
    vector<int> A(N); cin >> A;

    cout << (does_win_first(A) ? "First" : "Second") << endl;
    
    return 0;
}


Measured memory_bytes: 1276
loop do
    n = gets.to_i
    break if n == 0
    a = (1..n).map { gets.split.map(&:to_i) }
    limit = gets.split.map(&:to_i)
    ans = a.select {|s, p, q, r| p <= limit[0] and q <= limit[1] and r <= limit[2] and 4 * p + 9 * q + 4 * r  <= limit[3]}
    if ans.empty?
        puts 'NA'
    else
        puts ans.map {|r| r[0]}
    end
end


Measured memory_bytes: 7168
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n) {rep(i, n)par[i]=i;}
    
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
 
int main(){
    ll n, m;
    cin >> n >> m;

    ll p[n];
    rep(i, n)cin >> p[i];
    
    UnionFind tree(n+1);
    rep(i, m){
        ll x, y;
        cin >> x >> y;
        tree.merge(x, y);
    }
    ll ans = 0;
    rep(i, n)if(tree.issame(i+1, p[i]))ans++;
    cout << ans << endl;
 
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int n;
    cin >> n;
    double t, a;
    cin >> t >> a;

    int ans = 1;
    double min_abs = INF;
    REP(i, n) {
        int h;
        cin >> h;
        double temp = t - h * 0.006;
        if (min_abs > abs(a-temp)) {
            min_abs = abs(a-temp);
            ans = i+1;
        }
    }
    P(ans);

    return 0;
}


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

void swap(char *x, char *y) {
    char tmp; tmp = *x;
    *x = *y;
    *y = tmp;
}

void *reverse(char *s) {
    char *p = s, *q = s + strlen(s) - 1;
    int t = p - q;
    while ((p - q) * t >= 0) {
        swap(p, q);
        *p++; *q--;
    }
    return s;
}

int main() {
    char str[21];

    fgets(str, sizeof(str), stdin);
    printf("%s\n", reverse(str));

    return 0;
}


Measured memory_bytes: 2020
#include <bits/stdc++.h>
using namespace std;
int64_t ncr[4005][4005]={1},n,k,md=998244353;
int main(){
	cin>>k>>n;
	for(int i=1,j;i<4005;++i) for(ncr[i][0]=j=1;j<=i;++j)
		ncr[i][j]=(ncr[i-1][j]+ncr[i-1][j-1])%md;
	for(int t=2;t<=2*k;++t){
		int64_t p = 0, ans = 0, o = 0;
		for(int j=1;j<=k;++j) if(j*2!=t)
			p += t-j<=k && t-j >= 1, o += !(t-j<=k && t-j >= 1);
		p/=2;
		for(int q=0,pwr=1;q<=p && q<=n;++q,(pwr*=2)%=md){
				(ans += ncr[p][q]*pwr%md*ncr[n+(o)-1][q+o-1])%=md;
			if(t%2==0)
				(ans += ncr[p][q]*pwr%md*ncr[n+(o)-2][q+o-1])%=md;
		}
		cout<<ans<<'\n';
	}
}

Measured memory_bytes: 77952
import java.util.*;

public class Main {

	private void doIt(){
		Scanner sc = new Scanner(System.in);
		final int START = 540;
		final int END = 1260;
		int [][] data = new int[END + 1][10000 + 1];
		int N,M,r;
		int t,m,s,p;
		while(true){
			N = sc.nextInt();
			M = sc.nextInt();
			if(N == 0 && M == 0){
				break;
			}
			r = sc.nextInt();
			for(int i = START ; i <= END; i++){
				Arrays.fill(data[i], 0);
			}
			
			ArrayList<int []> al = new ArrayList<int []>();
			for(int i = 0; i < r; i++){
				t = sc.nextInt();
				p = sc.nextInt();
				m = sc.nextInt();
				s = sc.nextInt();
				if(s == 1){
					int [] input = {t,p,m,s};
					al.add(input);
				}
				else{
					for(int j = 0; j < al.size(); j++){
						int [] now = al.get(j);
						if(now[1] == p && now[2] == m){
							for(int k =now[0]; k < t; k++){
								data[k][m] = 1;
							}
							al.remove(j);
							break;
						}
					}
				}
			}
			int q = sc.nextInt();
			for(int i =0 ;i < q; i++){
				int ts = sc.nextInt();
				int te = sc.nextInt();
				int mm = sc.nextInt();
				int ans = 0;
				for(int j=ts; j < te; j++){
					ans += data[j][mm];
				}
				System.out.println(ans);
			}
		}
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();

	}

}

Measured memory_bytes: 66000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl
#define rep(i, a, n) for(int i=a; i<(n); i++)

int main(){
    int n, m; cin>>n>>m;
    int sum=0;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
        sum+=a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    if (sum % (4*m) ==0) sum /= 4*m;
    else sum = sum / (4*m) +1;
    rep(i, 0, m){
        if(a[i] < sum){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3608
if __name__ == '__main__':
    N = int(input())
    v = sorted(list(map(float, input().split())), reverse=True)
    while (len(v) > 1):
        pops = v[-2:]
        del v[-2:]
        ave = sum(pops) / 2
        v.append(ave)
    print(v.pop())

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

int main(){
    int h,w;
    cin >> h >> w;
    char maze[h][w];
    int count=0;
    int d[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> maze[i][j];
            if(maze[i][j]=='.') count++;
            
            d[i][j]=100000000;
        }
    }

    typedef pair<int, int> P;

    queue<P> que;
    que.push(P(0,0));
    d[0][0]=0;

    int x[4]={1,0,-1,0};
    int y[4]={0,1,0,-1};

    while(que.size()){
        P p=que.front();
        que.pop();
        for(int i=0;i<4;i++){
            int nx=p.first+x[i];
            int ny=p.second+y[i];
        
            if(nx>=0 && ny>=0 && nx<h && ny<w && maze[nx][ny]=='.' && d[nx][ny]==100000000){
                que.push(P(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    //cout << count << d[h-1][w-1] << endl;
    int ans=count-d[h-1][w-1]-1;
    if(d[h-1][w-1]==100000000) ans=-1;
    printf("%d\n",ans);

}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scanf("%s", &s)
	parts := strings.Split(s, "")
	ans := 0
	for _, p := range parts {
		switch p {
		case "+":
			ans++
		case "-":
			ans--
		}
	}
	fmt.Printf("%d\n", ans)
}


Measured memory_bytes: 640
nums={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}
while True:
    try:
        s=input()
    except:
        break
    ans=nums[s[0]]
    for i in range(1,len(s)):
        if nums[s[i-1]]<nums[s[i]]:
            ans+=nums[s[i]]-2*nums[s[i-1]]
        else:
            ans+=nums[s[i]]
    print(ans)
        

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


int main() {
  int N ; 
  cin >> N ; 
  
  unordered_map<string , int> M ; 
  
  for(int i = 0 ; i < N ; i++){
    string S ; 
    cin >> S ; 
    sort(S.begin(),S.end()) ; 
    M[S]++ ;   
  }
  int64_t T = 0 ; 
    
for (auto p : M) {
  auto v = p.second;
    for( int i = 0 ; i < v ;i++){
      T += i ; 
    }
   
  
}

  cout << T << endl ; 
}

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

using namespace std;

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

#define N 100010
#define M 200010
#define A 110
#define endl "\n"
#define mod 1000000007 

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	int a, b, c, d;
	
	cin >> a >> b >> c >> d;
	
	for(int i = 1; ; i++){
		if(i % 2){
			c -= b;
			
			if(c <= 0){
				cout << "Yes" << endl;
				return 0;
			}
		}
		else{
			a -= d;
			
			if(a <= 0){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	
	return 0;
}

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

void print( vector<pair<char, char>> &C, int N )
{
	for( int k = 0; k < N; k++ ) {
		cout << C[k].first << C[k].second;
		if( k < N - 1 ) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}
}

void bubble( vector<pair<char, char>> &C, int N )
{
	for( int i = 0; i < N; i++ ) {
		for( int j = N - 1; j > i; j-- ) {
			if( C[j].second < C[j - 1].second ) {
				swap( C[j], C[j - 1] );
			}
		}
	}
}

void selection( vector<pair<char, char>> &C, int N )
{
	for( int i = 0; i < N; i++ ) {
		int minj = i;
		for( int j = i; j < N; j++ ) {
			if( C[j].second < C[minj].second ) {
				minj = j;
			}
		}
		swap( C[i], C[minj] );
	}
}

bool check( vector<pair<char, char>> &in, vector<pair<char, char>> &out, int N )
{
	for( int i = 0; i < N; i++ ) {
		for( int j = i + 1; j < N; j++ ) {
			for( int a = 0; a < N; a++ ) {
				for( int b = a + 1; b < N; b++ ) {
					if( in[i].second == in[j].second && in[i] == out[b] && in[j] == out[a] ) {
						return false;
					}
				}
			}
		}
	}
	return true;
}

int main()
{
	int N;
	cin >> N;
	vector<pair<char, char>> C( N );
	vector<pair<char, char>> C1( N );
	vector<pair<char, char>> C2( N );
	for( int i = 0; i < N; i++ ) {
		string s;
		cin >> s;
		C[i] = make_pair( s[0], s[1] );
		C1[i] = C[i];
		C2[i] = C[i];
	}

	bubble( C1, N );
	selection( C2, N );

	print( C1, N );
	string res = "Stable";
	if( check( C, C1, N ) == false ) {
		res = "Not stable";
	}
	cout << res << endl;

	print( C2, N );
	res = "Stable";
	if( check( C, C2, N ) == false ) {
		res = "Not stable";
	}
	cout << res << endl;
}



Measured memory_bytes: 3168
from math import sqrt

a,b = map(int,input().split())
 
L = []
 
if a < b: a,b = b,a
while b!=0:
    r = a%b
    a,b = b,r
 
G = a
 
for i in range(2,int(sqrt(G))+1):
    if G%i==0:
        L.append(i)
        while G%i==0:
            G/=i

if G!=1:
    L.append(G)

print(len(L)+1) 

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        int cnt = 0, ans = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'A' || s.charAt(i) == 'C' || s.charAt(i) == 'G' || s.charAt(i) == 'T') {
                cnt++;
                ans = Math.max(ans, cnt);
            } else {
                cnt = 0;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  int n ;
  cin >> n;
  int count = 0 ;
  vector<int> swi(n) ;
  REP(i,n){
    cin >> swi.at(i) ;
  }
  int i = 0 ;
  while(count<n){
    i = swi.at(i) -1  ;
    count++ ;
    if(i==1){
      cout << count<<endl ;
      return 0 ;
    }
    
  }
  
  cout << -1 <<endl ;
    
    

  return 0 ;
}




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

int main(){
    int n;
    cin >> n;
    vector<string> answer(n);
    for(int i = 0; i < n; i++){
        cin >> answer.at(i);
    }
    int C0 = 0;
    int C1 = 0;
    int C2 = 0;
    int C3 = 0;
    for(int i = 0; i< n; i++){
        if(answer.at(i) == "AC"){
            C0 += 1;
        }else if(answer.at(i) == "WA"){
            C1 += 1;
        }else if(answer.at(i) == "TLE"){
            C2 += 1;
        }else if(answer.at(i) == "RE"){
            C3 += 1;
        }
    }

    cout << "AC x " << C0 << endl;
    cout << "WA x " << C1 << endl;
    cout << "TLE x " << C2 << endl;
    cout << "RE x " << C3 << endl;
}

Measured memory_bytes: 6428
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define pii pair<int,int>
#define MOD 1000000007
#define int long long
using namespace std;
#define s second
#define f first

int32_t main()
{
    fastio;
    int i,n,m,ans,a;
    
    string s;
    cin>>s;
    n=s.length();

    unordered_map<int,int> mp;
    m=0;
    ans=0;
    mp[0]++;
    a=1;
    for(i=0;i<n;i++)
    {
        m = (m+a*(s[n-i-1]-'0'))%2019;
        a = (a*10)%2019;
        ans+=mp[m];
        mp[m]++;
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
/*
░░░░░░░░░░░░░░░░░░░░░░░░░
░░█▀▀▄░░░░░░░░░░░▄▀▀█░░░░
░░█░░░▀▄░▄▄▄▄▄░▄▀░░░█░░░░
░░░▀▄░░░▀░░░░░▀░░░▄▀░░░░░
░░░░░▌░▄▄░░░▄▄░▐▀▀░░░░░░░
░░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█░
░░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█░
░▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█░
░█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀░
░░▀▄░░▀░░▀▀▀░░▀░░░▄█▀░░░░
░░░░█░░░░░░░░░░░▄▀▄░▀▄░░░
░░░░█░░░░░░░░░▄▀█░░█░░█░░
░░░░█░░░░░░░░░░░█▄█░░▄▀░░
░░░░█░░░░░░░░░░░████▀░░░░
░░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░
*/
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 1e5 + 10;
ll rankk[MAXN];
ll parent[MAXN];

ll pare(ll x){
    while(parent[x] != x){
        parent[x] = parent[parent[x]];
        x = parent[x];
    }
    return parent[x];
}

void unionn(ll x,ll y){
    x = pare(x),y = pare(y);

    if(x == y) return;

    if(rankk[x] > rankk[y]){
        rankk[x] += rankk[y];
        parent[y] = x;
    }else {
        rankk[y] += rankk[x];
        parent[x] = y;
    }
}

bool visit[MAXN];

vector<pair<ll,ll>> doub;
void solve(){
    ll n,m,q; cin>>n>>m>>q;

    FOR(i,1,n) parent[i] = i,rankk[i] = 1;

    FOR(i,1,q){
        ll a,b,c; cin>>a>>b>>c; a++,b++;

        if(c == 0) unionn(a,b);
        else doub.push_back({a,b});
    }

    if(m == n-1){
        if(doub.size()) cout<<"No\n";
        else cout<<"Yes\n";
        return;
    }

    for(auto x:doub){
        if(pare(x.first) == pare(x.second)){
            cout<<"No\n";
            return;
        }
    }   

    ll k = 0;
    
    FOR(i,1,n){
        if(!visit[pare(i)]){
            visit[pare(i)] = 1;
            k++;
        }
    }

    if(m <= n - k + (k*(k-1))/2){
        cout<<"Yes\n";
    }else cout<<"No\n";
}   

signed main(){
 
   FastRead;    


    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // clog<<"DEBUGGING ----> "<<i<<endl; 
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
const int N = 3*1e5, M = 7 + 1e9;
ll a[N], b[N];
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << ' ' << b << ' ' << c;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn dfs(v: usize, a: i64, b: i64, g: &[Vec<(usize, i64)>],
       vis: &mut [bool], coef: &mut [(i64, i64)],
       cand: &mut Vec<i64>) -> bool {
    if vis[v] {
        if coef[v].0 == a {
            return coef[v].1 == b;
        }
        if (coef[v].1 - b) % (coef[v].0 - a) != 0 {
            return false;
        }
        cand.push(-(coef[v].1 - b) / (coef[v].0 - a));
        return true;
    }
    vis[v] = true;
    coef[v] = (a, b);
    for &(w, s) in g[v].iter() {
        if !dfs(w, -a, s - b, g, vis, coef, cand) {
            return false;
        }
    }
    return true;
}

const INF: i64 = 1 << 61;

fn solve() {
    let n = get();
    let m = get();
    let mut g = vec![Vec::new(); n];
    for _ in 0 .. m {
        let u = get::<usize>() - 1;
        let v = get::<usize>() - 1;
        let s: i64 = get();
        g[u].push((v, s));
        g[v].push((u, s));
    }
    let mut vis = vec![false; n];
    let mut coef = vec![(0, 0); n];
    let mut cand = Vec::new();
    if !dfs(0, 1, 0, &g, &mut vis, &mut coef, &mut cand) {
        println!("0");
        return;
    }
    cand.sort();
    cand.dedup();
    //println!("cand = {:?}", cand);
    if cand.len() >= 2 {
        println!("0");
        return;
    }
    let mut lo = 1; let mut hi = INF;
    for i in 0 .. n {
        if coef[i].0 == 1 {
            lo = max(lo, -coef[i].1 + 1);
        } else {
            hi = min(hi, coef[i].1 - 1);
        }
    }
    if cand.len() == 1 {
        let x = cand[0];
        println!("{}", if lo <= x && x <= hi { 1 } else { 0 });
        return;
    }
    println!("{}", if lo <= hi { hi - lo + 1 } else { 0 });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

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

fn main() {
    let n = read::<i32>();
    let k = read::<i32>();

    let mut ans = 1;
    for _ in 0..n {
        if ans <= k {
            ans *= 2;
        } else {
            ans += k;
        }
    }
    println!("{}", ans);
}

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

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


Measured memory_bytes: 4352