akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
  int a,b,sum,diff,pro,max;
  scanf("%d %d",&a,&b);
  sum=a+b;
  diff=a-b;
  pro=a*b;
  
  max=sum;
  if(max<diff)max=diff;
  if(max<pro)max=pro;
  
  printf("%d",max);
  return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;

public class Main {
	public static void main(String[] args) {
		int N = nextInt();
		int M = nextInt();

		int[] x = new int[N];// x座標でソートした時の宝物の座標
		int[] y = new int[N];// y座標でソートした時の宝物の座標

		int[][] map = new int[N + 1][N + 1];
		Treasure[] treasure = new Treasure[N];

		for (int i = 0; i < N; i++) {
			treasure[i] = new Treasure(nextInt(), nextInt());
		}

		// x座標でソートしてindexをつける
		Arrays.sort(treasure, new ComparatorX());
		for (int i = 0; i < N; i++) {
			x[i] = treasure[i].x * 2;
			treasure[i].xindex = i;
		}

		// y座標でソートしてインデックスをつける
		Arrays.sort(treasure, new ComparatorY());
		for (int i = 0; i < N; i++) {
			y[i] = treasure[i].y * 2;
			treasure[i].yindex = i;
		}

		for (int i = 0; i < N; i++) {
			map[treasure[i].xindex + 1][treasure[i].yindex + 1]++;
		}

		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				map[i][j] += map[i - 1][j];
			}
		}

		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				map[i][j] += map[i][j - 1];
			}
		}
		for (int i = 0; i < M; i++) {
			int x1 = nextInt() * 2;
			int y1 = nextInt() * 2;
			int x2 = nextInt() * 2;
			int y2 = nextInt() * 2;
			x1 = binarySearch(x, x1 - 1) + 1;
			y1 = binarySearch(y, y1 - 1) + 1;
			x2 = binarySearch(x, x2 + 1) + 1;
			y2 = binarySearch(y, y2 + 1) + 1;
			System.out.println(map[x2][y2] - map[x2][y1] - map[x1][y2] + map[x1][y1]);
		}
	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

	static int binarySearch(int[] array, int num) {
		int first = 0;
		int last = array.length - 1;
		int center = (first + last) / 2;
		while (first <= last) {
			if (center < array.length - 1) {
				if (array[center] < num) {
					if (num < array[center + 1]) {
						return center;
					} else {
						// num >= array[center + 1]なので前端をcenter+1にする
						first = center + 1;
					}
				} else {
					// array[center] >= numなので後端をcenter-1にする
					last = center - 1;
				}
			} else {
				return array.length - 1;
			}
			center = (first + last) / 2;
		}
		return -1;
	}

}

class Treasure {
	int x = 0;
	int y = 0;
	int xindex = 0;
	int yindex = 0;

	public Treasure(int x, int y) {
		this.x = x;
		this.y = y;
	}
}

class ComparatorX implements Comparator<Treasure> {
	public int compare(Treasure t1, Treasure t2) {
		return t1.x - t2.x;
	}
}

class ComparatorY implements Comparator<Treasure> {
	public int compare(Treasure t1, Treasure t2) {
		return t1.y - t2.y;
	}
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int a,b,c,sum;
	cin >> a >> b >> c;
	sum = a+b+c;
	if(sum>=22)cout << "bust" << endl;
	else  cout << "win" << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> P;
#define Mod 1000000007


int main(){
    ll i,j;


    ll n,k;
    cin>>n>>k;
    ll h[n];
    for(i=0;i<n;i++) cin>>h[i];

    ll dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++){
        dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        for(j=1;j<=k;j++) {
        if(i-j>=0) dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }

    cout<<dp[n-1]<<endl;
    

    
    return 0;
}

Measured memory_bytes: 1792
n,m = map(int,input().split())
C = [[i]+list(map(int,input().split())) for i in range(m)]
C.sort(key=lambda c:c[1:])
prev = 0
count = 0
for c in C:
    if prev==c[1]: count+=1
    else: count=1
    c.append(format(c[1],'0>6')+format(count,'0>6'))
    prev=c[1]

for c in sorted(C, key=lambda c:c[0]):
    print(c[3])

Measured memory_bytes: 105628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll,ll> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 

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



Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		if (n % 2 == 1) {
		    System.out.println(0);
		} else {
		    long count = 0;
		    while (n > 0) {
		        count += n / 5 / 2;
		        n /= 5;
		    }
		    System.out.println(count);
		}
	}
}


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

int main()
{
    int n, x, sum=0;
    vector<int> v;
    cin>>n;
    for(int i=0; i<n; ++i)
    {
        cin>>x;
        v.push_back(x);
    }
    for(int i=0; i<n; ++i)
    {
        if(((i+1)%2!=0)&&((v[i]%2)!=0))
        sum=sum+1;
    }
    cout<<sum;
}

Measured memory_bytes: 3620
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = iss()
    print('Yes' if '9' in N else 'No')



if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <cstdio>
#define s(i) ((int)S[i] - (int)'a')

int main(){
    char S[4];
    scanf("%s", S);
    if(s(0)+s(1)+s(2)==3 && s(0)*s(1)*s(2)==0) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

int main(){
  string s;
  cin>>s;
  int point=0;
  ll tmp=0;
  ll ans=0;
  for(int i=0;i<s.length()-1;i++){
    if(s[i]=='A'){
      tmp++;
    }else if(s[i]=='B'&&s[i+1]=='C'){
      ans+=tmp;
      i++;
    }else{
      tmp=0;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  int n,a,b;
  cin >> n >> a >> b;

  string s;
  cin >> s;

  int tuuka=0;
  int oversea=0;
  rep(i,n){
    if(s.at(i)=='a'){
      if(tuuka<a+b) {cout<<"Yes"<<endl; tuuka++;}
      else cout << "No"<< endl;
    }else if(s.at(i)=='b'){
      oversea++;
      if(tuuka<a+b&&oversea<=b) {cout<<"Yes"<<endl; tuuka++;}
      else cout << "No"<< endl;
    }else{cout << "No" << endl;}
  }
}


Measured memory_bytes: 3732
h, w, k = gets.split.map(&:to_i)
c = h.times.map{ gets.chop.chars }
kcount = 0
(2 ** h).times do |hi|
  (2 ** w).times do |wi|
    count = 0
    c.each.with_index do |ch, chidx|
      next if (hi >> chidx)[0] == 1

      ch.each.with_index do |cw, cwidx|
        next if (wi >> cwidx)[0] == 1

        count += 1 if cw == '#'
      end
    end
    kcount += 1 if count == k
  end
end
puts kcount

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


const ll MAX = 1000000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
	// おまじない
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll X,Y;
	// 出入力
	cin>>X>>Y;
    if((2*X-Y)<0||(2*Y-X)<0||(2*X+2*Y)%3!=0){
        cout<<0<<"\n";
        return 0;
    }
    ll a,b;
    a = (2*X-Y)/3;
    b = (2*Y-X)/3;
    COMinit();
    ll ans = COM(a+b,a);
    
    
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 23680
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($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, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        n: usize,
        s: chars,
    }

    let mut count = std::collections::HashMap::new();
    let rev = s[n..].iter().rev().cloned().collect::<Vec<_>>();

    for i in 0..1 << n {
        let mut a = vec![];
        let mut b = vec![];

        for j in 0..n {
            if (i >> j) & 1 == 1 {
                a.push(rev[j]);
            } else {
                b.push(rev[j]);
            }
        }
        *count.entry((a, b)).or_insert(0) += 1;
    }

    let mut ans = 0usize;
    for i in 0..1 << n {
        let mut a = vec![];
        let mut b = vec![];

        for j in 0..n {
            if (i >> j) & 1 == 1 {
                a.push(s[j]);
            } else {
                b.push(s[j]);
            }
        }
        ans += *count.get(&(a, b)).unwrap_or(&0);
    }
    println!("{}", ans);
}


Measured memory_bytes: 75940
S = [int(i) for i in input()]
S1 = [i % 2 for i in range(len(S))]
S2 = [(i + 1) % 2  for i in range(len(S))]

s1 = 0
s2 = 0

for i in range(len(S)):
  if S[i] == S1[i]:
    s1 += 1
  if S[i] == S2[i]:
    s2 += 1
print(min(s1,s2))

Measured memory_bytes: 5532
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		if(a+b==c|b+c==a|c+a==b){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 23252
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	m := getNextInt(scanner)

	nn := make([]int, n)
	mm := make([]int, m)

	for i := 0; i < n; i++ {
		nn[i] = i
	}

	for i := 0; i < m; i++ {
		mm[i] = -1
	}

	for i := 0; i < n; i++ {
		k := getNextInt(scanner)
		for ii := 0; ii < k; ii++ {
			l := getNextInt(scanner) - 1
			if mm[l] == -1 {
				mm[l] = i
				continue
			}

			r1 := root(i, nn)
			r2 := root(mm[l], nn)
			if r1 != r2 {
				nn[r2] = r1
			}
		}
	}

	counter := 0
	prev := -1

	ans := "YES"
	for i := 0; i < n; i++ {
		r := root(i, nn)
		if prev != r {
			prev = r
			counter++
			if counter > 1 {
				ans = "NO"
				break
			}
		}
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

func root(i int, nodes []int) int {
	if i == nodes[i] {
		return i
	}
	r := root(nodes[i], nodes)
	nodes[i] = r
	return nodes[i]
}


Measured memory_bytes: 18688
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define P(x) cout << (x) << "\n"
#define D(x) cerr << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

using i64=long long int; // 10^18

int n,w;
const int SIZE= 101;
const int WEIGHT = 100001;
i64 we[SIZE],v[SIZE],dp[SIZE][WEIGHT];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>w;
    // 1-indexed
    REP(i,n){
        cin>>we[i+1]>>v[i+1];
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<WEIGHT;++j){
            if(j-we[i] >= 0){
                dp[i][j] = max(
                    dp[i-1][j],
                    dp[i-1][j-we[i]] + v[i]
                );
            }else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    P(dp[n][w]);
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int const N = 3e3 + 3;

int h, w;
char grid[N][N];

int result[N][N];

int moveA[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int moveB[20][2] = {{-2, -2}, {-2, -1}, {-2, 0}, {-2, 1}, {-2, 2}, {-1, -2}, 
					{-1, -1}, {-1, 1}, {-1, 2}, {0, -2}, {0, 2}, {1, -2}, {1, -1}, 
					{1, 1}, {1, 2}, {2, -2}, {2, -1}, {2, 0}, {2, 1}, {2, 2}};

bool valid(int r, int c)
{
	return 0 <= r && r < h && 0 <= c && c < w;
}

bool wall(int r, int c)
{
	for (auto m : moveA)
	{
		int nr = r + m[0];
		int nc = c + m[1];

		if (valid(nr, nc) && grid[nr][nc] == '#')
		{
			return true;
		}
	}
	return false;
}

bool blank(int r, int c)
{
	for (auto m : moveA)
	{
		int nr = r + m[0];
		int nc = c + m[1];

		if (valid(nr, nc) && grid[nr][nc] == '.')
		{
			return true;
		}
	}
	return false;
}

struct cstcmp
{
	bool operator()(const ii& lhs, const ii& rhs)
	{
		return result[lhs.f1][lhs.s2] < result[lhs.f1][lhs.s2];
	}
};


void bfs(int r, int c)
{
	memset(result, -1, sizeof(result));

	result[r][c] = 0;
	//priority_queue<ii, vector<ii>, cstcmp> qA; //move A
	//priority_queue<ii, vector<ii>, cstcmp> qB; //move B
	queue<ii> qA;
	queue<ii> qB;

	if (blank(r, c)) qA.push(mp(r, c));
	if (wall(r, c)) qB.push(mp(r, c));

	while (!qA.empty() || !qB.empty())
	{
		while (!qA.empty())
		{
			r = qA.front().f1;
			c = qA.front().s2;
			
			qA.pop();

			for (auto m : moveA)
			{
				int nr = r + m[0];
				int nc = c + m[1];

				if (valid(nr, nc) && grid[nr][nc] == '.' && (result[nr][nc] == -1 || result[nr][nc] > result[r][c]))
				{
					result[nr][nc] = result[r][c];
					if (blank(nr, nc)) qA.push(mp(nr, nc));
					if (wall(nr, nc)) qB.push(mp(nr, nc));
				}
			}
		}

		if (!qB.empty())
		{
			r = qB.front().f1;
			c = qB.front().s2;
			qB.pop();

			for (auto m : moveB)
			{
				int nr = r + m[0];
				int nc = c + m[1];

				if (valid(nr, nc) && grid[nr][nc] == '.' && (result[nr][nc] == -1 || result[nr][nc] > result[r][c] + 1))
				{
					result[nr][nc] = result[r][c] + 1;
					if (blank(nr, nc)) qA.push(mp(nr, nc));
					if (wall(nr, nc)) qB.push(mp(nr, nc));
				}
			}
		}
	}
}

int main()
{
	fastio;

	int cx, cy;
	int dx, dy;

	cin >> h >> w;
	cin >> cx >> cy;
	cin >> dx >> dy;

	for (int i = 0; i < h; ++i)
		cin >> grid[i];

	cx--; cy--; dx--; dy--;

	bfs(cx, cy);
	cout << result[dx][dy] << '\n';

	return 0;
}


Measured memory_bytes: 41796
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int pwr(int x,int y)
{
    int res=1;
    x%=mod;
    while(y>0)
    {
        if(y&1)
            res=(res*x)%mod;
        y>>=1;
        x=(x*x)%mod;
    }
    return res;
}

string s;

void solve()
{
    cin>>s;
    int ans=0,cnt=0;
    for(int i=0;i<sz(s);++i)
    {
        if(s[i]=='1')
        {
            int sum=pwr(2,cnt)*pwr(3,sz(s)-1-i);
            sum%=mod;
            ans+=sum;
            ans%=mod;
            cnt++;
        }
    }
    ans+=pwr(2,cnt);
    ans%=mod;
    cout<<ans;
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

struct AF
{
    long long a;
    long long f;
    AF(const long long A, const long long F)
    {
        this->a = A;
        this->f = F;
    }
    long long score() const
    {
        return this->a * this->f;
    }
    bool operator<(const AF &af) const
    {
        if (this->score() == af.score())
        {
            return this->f < af.f;
        }
        return this->score() < af.score();
    }
};

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

    vector<long long> A(N);
    long long sum = 0;
    for (long long &a : A)
    {
        cin >> a;
        sum += a;
    }
    if (sum <= K)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(A.begin(), A.end());

    vector<long long> F(N);
    for (long long &f : F)
    {
        cin >> f;
    }
    sort(F.rbegin(), F.rend());

    vector<long long> X(N);
    for (int i = 0; i < N; i++)
    {
        X[i] = A[i] * F[i];
    }

    long long l = 0;
    long long r = 1e12 + 5;

    while (r - l > 1)
    {
        long long c = (l + r) / 2;
        long long k = 0;
        for (int i = 0; i < N; i++)
        {
            if (A[i] * F[i] > c)
            {
                k += (A[i] * F[i] - c) / F[i];
                if ((A[i] - (A[i] * F[i] - c) / F[i]) * F[i] > c)
                {
                    k++;
                }
            }
        }
        if (k <= K)
        {
            r = c;
        }
        else
        {
            l = c;
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 4992
//
//  main.cpp
//  D
//
//  Created by 曾憲揚 on 2020/8/21.
//  Copyright © 2020 曾憲揚. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

const int maxn = 4e3+5;

int main(int argc, const char * argv[]) {
    int n; cin>>n;
    string s; cin>>s;
    
    int r=0, g=0, b=0;
    for(int i=0; i<n; i++){
        if(s[i]=='R') r++;
        else if(s[i]=='G') g++;
        else if(s[i]=='B') b++;
    }
    long long ans = 1LL*r*g*b;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(s[i] == s[j]) continue;
            int k = j+(j-i);
            if(k>=n) break;
            if(s[k] != s[i] && s[k] != s[j]) ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<double> x(n),y(n);
	rep(i,n){
		cin>>x[i]>>y[i];
	}
	auto f=[&](double rx,double ry){
		double ret=0;
		rep(i,n){
			chmax(ret,sqrt((rx-x[i])*(rx-x[i])+(ry-y[i])*(ry-y[i])));
		}
		return ret;
	};
	auto g=[&](double rx){
		double l=0,r=1010;
		rep(i,100){
			double nl=(2*l+r)/3,nr=(l+2*r)/3;
			if(f(rx,nl)<f(rx,nr)) r=nr;
			else l=nl;
		}
		return f(rx,l);
	};
	double l=0,r=1010,ans=inf;
	rep(i,100){
		double nl=(2*l+r)/3,nr=(l+2*r)/3;
		if(g(nl)<g(nr)) r=nr;
		else l=nl;
	}
	cout<<setprecision(10)<<g(l)<<endl;
}

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

struct Node {
	int key;
	Node *prev, *next;
};

Node *nil;

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

Node* listSearch(int key) {
	Node *cur = nil->next;
	while (cur != nil && cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t) {
	if (t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deleteKey(int key) {
	deleteNode(listSearch(key));
}

void printList() {
	Node *cur = nil->next;
	int isf = 0;
	while (1) {
		if (cur == nil) break;
		if (isf++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

int main() {
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++) {
		scanf("%s%d", com, &key);
		if (com[0] == 'i') { insert(key); np++; size++; }
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F') deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}
			else {
				deleteKey(key); nd;;
			}
			size--;
		}
	}

	printList();

	return 0;
}

Measured memory_bytes: 34444
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define ll long long
using namespace std;
int P=1e9+7;
int gcd(int x,int y){ return y==0?x:gcd(y,x%y); }
int fpw(int x,ll y){
    int s=1; for (;y;y>>=1,x=(ll)x*x%P) if (y&1) s=(ll)s*x%P;
    return s;
}
int main(){
    int h,w,t; cin>>h>>w>>t;
    int gx=gcd(h,t),gy=gcd(w,t);
    int p=((ll)fpw(2,h/gx)+fpw(2,w/gy)+fpw(2,gcd(h/gx,w/gy)))%P;
    cout<<fpw(p+P-3,(ll)gx*gy)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, X;
  cin >> N >> X;
  int M[N];
  for (int i = 0; i < N; i++) {
    cin >> M[i];
  }
  sort (M, M + N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += M[i];
  }
  cout << ((X - sum) / M[0]) + N << endl;
}

Measured memory_bytes: 256
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();

    if n == 3 {
        return "2 5 63\n".to_string();
    }

    let mut ret = String::new();
    use std::fmt::Write;
    let aa = match n & 1 {
        0 => [2, 10, 3, 9, 4, 8, 12, 6],
        1 => [6, 2, 10, 3, 9, 4, 8, 12],
        _ => unreachable!(),
    };

    let mut c = 0;
    'lp: for i in 0.. {
        for j in 0..8 {
            write!(&mut ret, "{} ", 12 * i + aa[j]).unwrap();
            c += 1;
            if c == n {
                break 'lp;
            }
        }
    }
    ret.pop();
    ret.push('\n');
    ret
}

fn main() {
    let mut buf = String::new();
    use std::io;
    use std::io::{Read, Write};
    io::stdin().read_to_string(&mut buf).unwrap();
    io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}

struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
ll ara[200005];char st[200004];
ll a[200004]; ll b[200004];
int main()
{
    ll c,d,m,n,i,j,k,l,t,x,y,z;
    ll mul=1;
    cin>>n;
    for(i=0;i<n;i++) cin>>ara[i];
    for(i=0;i<n;i++)
    {
        if(ara[i]==0){ cout<<"0"<<endl;
        return 0;
        }
    }
    for(i=0;i<n;i++)
    {
        if(ara[i]<= 1000000000000000000/mul)
        mul*=ara[i];
        else
        {
            mul =-1;
            break;
        }

    }
    cout<<mul<<endl;



    return 0;
}






Measured memory_bytes: 4436
n = int(input())
C = input()
len_r, len_w = 0, 0
for c in C:
    if c == 'R':
        len_r += 1
    else:
        len_w += 1
c2 = 'R'*len_r + 'W'*len_w
cnt = 0
for a, b in zip(C, c2):
    if a != b:
        cnt += 1
print(cnt//2)

Measured memory_bytes: 9608
N, M, X, Y = map(int, input().split())

x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.append(X)
y.append(Y)

m = max(x)
n = min(y)


if n - m > 0:
    print('No War')
else:
    print('War')


Measured memory_bytes: 3060
N, M = map(int, input().split())
li = list(map(int,input().split()))
li = sorted(li)

if N >= M:
    print(0)
else:
    L=[]
    for i in range(M-1):
        L.append(li[i+1]-li[i])
    L = sorted(L, reverse=True)
    x=0
    for j in range(N-1):
        x+=L[j]
    answer = li[-1]-li[0]-x
    print(answer)

Measured memory_bytes: 58280
import sys
sys.setrecursionlimit(10**7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = map(int, input().split())
ab=[list(map(int, input().split())) for _ in range(m)]

uf = UnionFind(n)
tmp_ans = n*(n-1)//2
ans = []
for i in range(m):
    ans.append(tmp_ans)
    a=ab[m-1-i][0]
    b=ab[m-1-i][1]
    a-=1
    b-=1
    if not uf.is_same(a,b):
        tmp_ans-=uf.size(a)*uf.size(b)
    uf.union(a,b)

ans.reverse()
for i in ans:
    print(i)


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

int skor[100010], n, q, k, a;
int main()
{
    cin >> n >> k >> q;
    for (int i = 1; i <= n; i++)
    {
        skor[i] = k - q;
    }
    for (int i = 1; i <= q; i++)
    {
        cin >> a;
        skor[a]++;
    }
    for (int i = 1; i <= n; i++)
    {
        if (skor[i] > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
        
    }
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;

int main() {
  cout << fixed << setprecision(8);
  int N;
  cin >> N;
  vector<pair<int, int>> grid(N);
  vector<int> turn(N);
  int Nkai = 1;
  for (int i = 1; i<=N; i++) {
    Nkai *= i;
  }
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    grid[i] = make_pair(x, y);
    turn[i] = i;
  }
  double sum = 0; 
  do {
    for (int i = 0; i < N-1; i++) {
      sum += sqrt((grid[turn[i+1]].first-grid[turn[i]].first)*(grid[turn[i+1]].first-grid[turn[i]].first) +
                  (grid[turn[i+1]].second-grid[turn[i]].second)*(grid[turn[i+1]].second-grid[turn[i]].second));
    } 
  } while (next_permutation(turn.begin(), turn.end()));
  cout << sum / Nkai << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  char x,y;
  cin >> x >> y;
  if(x>y){cout << ">" << endl;}
  if(x==y){cout << "=" << endl;}
  if(x<y){cout << "<" << endl;}
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vll;
     
int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector <int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  int ans = 1;
  int mn = p[0];
  for (int i = 1; i < n; i++) {
    mn = min(mn, p[i]);
    if (p[i] <= mn) ans++;
  }
  cout << ans << '\n';
  return (0);
}


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

typedef long long ll;

int main(){
	ll n,h,w;
	cin>>n>>h>>w;
	vector<ll>a(n),b(n);
	ll ans=0;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		ans+=min(a[i]/h,b[i]/w);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
A = []
[A.extend(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]
for b in B:
    try:
        i = A.index(b)
        A[i] = 0
    except:
        pass
lines = [
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8],
    [0, 3, 6],
    [1, 4, 7],
    [2, 5, 8],
    [0, 4, 8],
    [2, 4, 6],
]
ans = "No"
for line in lines:
    a, b, c = line
    if A[a] == 0 and A[a] == A[b] and A[a] == A[c]:
        ans = "Yes"
print(ans)


Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
        int x[] = new int[n];
        int y[] = new int[n];
        double sum = 0;
        double ave = 0;
        for(int i = 0; i < n; i++){
        	x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        for(int i = 0; i < n - 1; i++){
        	for(int j = i + 1; j < n; j++){
            	double a = Math.sqrt(Math.pow((x[i] - x[j]), 2) + Math.pow((y[i] - y[j]), 2));
                sum += a;
            }
        }
        int num = 2;
        for(int i = 2; i <= n; i++){
        	 num = (i - 1) * num;	
        }
        int fac = n;
        for(int i = n - 1; i >= 1; i--){
        	fac = fac * i;
        }
        ave = (sum * (double)num) / fac;
        System.out.println(ave);
    }
}

Measured memory_bytes: 35848
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main
int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d}) << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  ll n,h;
  cin >> n >> h;
  vector <ll> a;
  vector <ll> b;

  REP(i,n){
    ll aa,bb;
    cin >> aa >> bb;
    a.pb(aa);
    b.pb(bb);
  }
  sort(a.begin(),a.end());
  ll anum = a[n-1];
  sort(b.begin(),b.end());
  ll pos = -1;
  int j = 0;
  while(b[j] < anum){
    j++;
    if(j == n)
      break;
  }
  ll sum = 0,num = 0;
  for(int i = n-1;i >= j;i--){
    sum += b[i];
    num++;
    if(sum >= h)
      break;
  }
  //cout << j << endl;
  if(sum < h)
    num += (h-sum)/anum;
  if(((h-sum)%anum != 0) && sum < h)
    num++;
  cout << num << endl;
  return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  if (a%1000%111 == 0)
    cout << "Yes" << endl;
  else if (a/10%111 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front

#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)

#define mp make_pair
#define ff first
#define ss second
#define null NULL

#define all(c) (c).begin(),(c).end()
#define nl "\n"

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;

const ll INF = 1e18L + 5;

void min_Self(ll& a,ll b){
    a = min(a,b);
}

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

    ll n,w;
    cin>>n>>w;

    vector<ll> weight(n) , value(n);

    for(ll i=0;i<n;i++){
        cin>>weight[i]>>value[i];
    }

    ll sum_value = 0;
    for(ll x:value){
        sum_value += x;
    }

    vector<ll> dp(sum_value + 1,INF);
        dp[0]=0;
        // dp[i] - the minimum total weight of itmes with the total value excatly i
    for(ll item=0;item<n;item++){
        for(ll value_already = sum_value - value[item];value_already>=0;--value_already){
            min_Self( dp[value_already+value[item]] , dp[value_already] + weight[item] );
        }
    }

    ll ans = 0;
    for(ll i=0;i<=sum_value;i++){
        if(dp[i]<=w){
            ans = max(ans,i);
        }
    }

    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

def main():

    N = int(input())
    d = list(map(int, input().split()))

    ans = 0

    for i in range(N - 1):
        for j in range(i + 1, N):
            ans += d[i] * d[j]

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9132
#include<stdio.h>
int main()
{
    int a[1001];
    int n,m,i,j,k,sum,temp;
    scanf("%d%d", &n,&m);
    for(i=0;i<n;i++){
        scanf("%d", &a[i]);
    }
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            if(a[i]>a[j]){
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    sum=0;
    for(k=0; k<m; k++){
            sum+=a[k];
    }
    printf("%d",sum);


}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int N, M;
  cin >> N >> M;
  auto b = vector<int>(N, 1);
  auto r = vector<bool>(N, false);
  r[0] = true;

  REP(i, M) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    b[x]--;
    b[y]++;
    if(r[x]) {
      r[y] = true;
    }
    if(b[x] == 0) {
      r[x] = false;
    }
  }

  int ans = 0;
  REP(i, N) {
    if(b[i] >= 1 && r[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
//#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define ff first
#define tcase int _; cin>> _; for( ; _; --_)
#define ss second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

void solve(){
    cin >> n;

    if(n % 2 == 0){
        cout<< -1 << endl;
        return;
    }
    
    int num = 7;
    for(int i = 1; i<=100000000 ; ++i){
        if(num % n == 0){
            cout<< i << endl;
            return;
        }
        num*= 10;
        num += 7;
        num %=n;
    }
    cout<< -1 << endl;
}

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



Measured memory_bytes: 3584
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int h, n;
  cin >> h >> n;
  vector<int> a(n);
  int s = 0;
  for (auto &i : a) {
    cin >> i;
    s += i;
  }
  if (s >= h) cout << "Yes" << '\n';
  else cout << "No" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3996
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 998244353;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
ll n, t,ans,v[200010];
int main() {
	cin >> n >> t;
	rep(i, n) {
		cin >> v[i];
		if (i == 0)continue;
		if (v[i] - v[i - 1] >= t)ans += t;
		else ans += v[i] - v[i - 1];
	}
	ans += t;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
# if __name__ == '__main__':
#     a = int(input())
#     if a == 1:
#         print(1)
#     else:
#         print(pow(a, 3))
if __name__ == '__main__':
    tmp = 0
    a = 0
    counter = 0
    li = []
    a = int(input())
    li_1 = list(map(int, input().split()))
    li_2 = list(map(int, input().split()))
    li_3 = list(map(int, input().split()))

    for x in range(0, len(li_1) - 1):
        if li_1[x + 1] - li_1[x] == 1:
            li.append(li_1[x] - 1)

    tmp = 0
    for y in li_2:
        tmp += y

    for z in li:
        tmp += li_3[z]

    print(tmp)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
using namespace std;
#define MAX 100000+5
int color[MAX];
vector<int> u[MAX];
int num;
void ranse(int p,int color_num){
	stack<int> s;
	int a;
	s.push(p);color[p]=color_num;
	while(!s.empty()){
		a=s.top();s.pop();
		for(int i=0;i<u[a].size();i++){
		if(color[u[a][i]]==-1){
			s.push(u[a][i]);color[u[a][i]]=color_num;
		}
	}
	}
}
int main(){
	int m;
	memset(color,-1,sizeof(color));
	cin>>num>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		u[a].push_back(b);u[b].push_back(a);
	}
	int color_num=0;
	for(int i=0;i<num;i++){
		if(color[i]==-1){
			ranse(i,color_num);color_num++;
		}
	}
	int order_num;
	cin>>order_num;
	for(int i=0;i<order_num;i++){
		int a,b;
		cin>>a>>b;
		if(color[a]==color[b]) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
} 


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

int main(){
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	
	int cnt = 0;
	
	for(int i = 0 ; i < s.size() ; i ++){
		if(i + 2 == s.size()) break;
		if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') cnt++;
	}
	
	cout << cnt << "\n";
	
	return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		for (int i = 0; i < m; i++) {
			int money = sc.nextInt();
			int year = sc.nextInt();
			int n = sc.nextInt();
			int[] result = new int[n];
			int max = 0;
			for (int j = 0; j < n; j++){
				int tmoney = money;
				int mer = 0;
				int v = sc.nextInt();
				double per = sc.nextDouble();
				int a = sc.nextInt();
				if (v == 0) {
					for (int k = 0; k < year; k++) {
						mer += tmoney * per;
						tmoney -= a;
					}
					result[j] = tmoney + mer;
				}
				if (v == 1) {
					for (int k = 0; k < year; k++) {
						tmoney += tmoney * per;
						tmoney -= a;
					}
					result[j] = tmoney;
				}
			}
			for (int j = 0; j < n; j++)
				if (max < result[j])
					max = result[j];
			System.out.println(max);
		}
		sc.close();
	}
}

Measured memory_bytes: 42168