akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N,K;
ll A[100010];

int main() {
    cin >> N >> K;
    rep(i,N) cin >> A[i];
    if (N <= K) {
        cout << 1 << endl;
        return 0;
    }
    ll p = -1;
    rep(i,N){
        if (A[i] == 1) {
            p = 1;
            break;
        }
    }
    ll ans = 0;
    N -= K;
    ans ++;
    if (p <= K-1 || p>=N-K){
        while (N > 0){
            N -= (K-1);
            ans++;
        }
    }
    else{
        ll left = p;
        ll right = N-K-p;
        while (left > 0){
            left -= (K-1);
            ans++;
        }
        while (right > 0){
            right -= (K-1);
            ans++;
        }
    }
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    ll a=n-1;
    ll res=1;
    for(int i=2;i<=sqrt(a);i++){
        ll cnt=1;
        while(a%i==0){
            cnt++;
            a/=i;
        }
        res*=cnt;
    }
    if(a>=2)res*=2;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i!=0)continue;
        a=n;
        ll b=n,c=n/i;
        while(a%i==0)a/=i;
        while(b%c==0)b/=c;
        if(a%i==1)res++;
        if(b%i==1)res++;
        if(i==c)res--;
    }
    
    cout<<res<<endl;
}

Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9
struct Puzzle {
  int f[N2];
  int space;
  string path;

  bool operator < (const Puzzle &p) const {
    for(int i = 0;i < N2;i++) {
      if(f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = {-1,0,1,0};
static const int dy[4] = {0,-1,0,1};
static const char dir[4] = {'u','l','d','r'};

bool isTarget(Puzzle p) {
  for (int i = 0;i < N2;i++)
    if(p.f[i] != (i + 1)) return false;
  return true;
}

string bfs(Puzzle s) {
  queue<Puzzle> Q;
  map<Puzzle,bool> V;
  Puzzle u,v;
  s.path = "";
  Q.push(s);
  V[s] = true;

  while(!Q.empty()) {
    u = Q.front(); Q.pop();
    if(isTarget(u)) return u.path;
    int sx = u.space / N;
    int sy = u.space % N;
    for(int r = 0;r < 4;r++) {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if(tx < 0 || ty < 0 || tx >=N || ty >= N) continue;
      v = u;
      swap(v.f[u.space],v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if(!V[v]) {
	V[v] = true;
	v.path += dir[r];
	Q.push(v);
      }
    }
  }

  return "unsolvable";
}

int main() {
  Puzzle in;
  
  for(int i = 0;i < N2;i++) {
    cin >> in.f[i];
    if(in.f[i] == 0) {
      in.f[i] = N2;
      in.space = i;
    }
  }

  string ans = bfs(in);
  cout << ans.size() << endl;

  return 0;
}



Measured memory_bytes: 30572
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_B
#include <iostream>
#include <string>
using namespace std;

int count(string x){
  //string?????°???????????????????¶????????????????
  int sum = 0;
  for(int i=0; i<x.length(); i++){
    string key = x.substr(i, 1);
    //cout << key << endl;
    sum += stoi(key);
  }
  return sum;
}

int main(){
  string x;
  while(cin >> x){
    if(x == "0") break;
    else cout << count(x) << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
a,b = map(int,input().split())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

s = set([i for i,k in factorization(a)])
t = set([i for i,k in factorization(b)])
if a==1 and b==1:
  print(1)
else:
  print(len(s&t)+1)

Measured memory_bytes: 3188
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m = i_map()
    n_list = i_row_list(n)
    m_list = i_row_list(m)

    for num in n_list:
        min_dist = INF
        min_point = 0
        for i, check in enumerate(m_list):
            dist = abs(num[0]-check[0]) + abs(num[1]-check[1])
            if min_dist > dist:
                min_dist = dist
                min_point = i + 1
        print(min_point)

if __name__ == '__main__':
    main()


Measured memory_bytes: 77328
(defun all-even-p (a)
  (every #'evenp a))

(defun solve (a &optional (c 0))
  (if (all-even-p a)
      (let ((a-next (mapcar #'(lambda (x) (floor x 2)) a)))
           (solve a-next (1+ c)))
      c))

(let ((n (read))
      (a (read-from-string (concatenate 'string "(" (read-line) ")"))))
     (princ (solve a)))

Measured memory_bytes: 6632
def resolve():
    X, K, D = list(map(int, input().split()))
    k = min(abs(X) // D, K)
    x = min(abs(X - D*k),abs(X + D*k))
    l = K-k
    if l % 2 == 1:
        x = min(abs(x-D), abs(x+D))
    print(x)
    
resolve()

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

using namespace std;

const int N = 51;
long long a[N];

main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	long long ans = 0;
	bool ok = false;
	while (!ok) {
		for (int i = 0; i < n; i++)
			if (a[i] >= n) {
				long long x = a[i] / n;
				a[i] %= n;
				ans += x;
				for (int j = 0; j < n; j++)
					if (i - j)
						a[j] += x;
			}
		ok = true;
		for (int i = 0; i < n; i++)
			if (a[i] >= n)
				ok = false;
	}
	cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> P(N);
  int min = 0;
  int count = 0;
  for(int i = 0; i < N; ++i) {
    cin >> P.at(i);
    
    if(i == 0) {
      min = N;
    }
    
    if(min >= P.at(i)) {
      min = P.at(i);
      count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 1024
<?php
  fscanf(STDIN, "%d%d",$h,$w);
  if($h ==1 && $w==1){
      echo "#";
      exit;
  }
  $dot = [];
  for($i=0; $i<$h; $i++){
      $a = trim(fgets(STDIN));
      $flag = false;
      for($j=0; $j<$w; $j++){
          if($a[$j] == "#") $flag = true;
          else $dot[$j]++;
      }
      if($flag){
          $a_li[] = $a;
      }
  }
  if(count($dot) == 0){
      foreach($a_li as $s){
          echo $s."\n";
      }
  }
//   print_r($dot);
//   print_r($a_li);
  
  foreach ($a_li as $s){
      for($i=0; $i<count($dot); $i++){
          if($dot[$i] < $h){
              echo $s[$i];
          }
      }
      echo "\n";
  }
  


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  string S; cin >> S;
  int N = S.length();
  int K; cin >> K;
  for (int i = 0; i < N; i++){
    if (S[i] == 'a') continue;
    int now = 'z' - S[i] + 1;
    if (K >= now){
      K -= now;
      S[i] = 'a';
    }
  }
  S[N - 1] += K % 26;
  if (S[N - 1] > 'z'){
    S[N - 1] -= 26;
  }

  cout << S << endl;

  return 0;
}


Measured memory_bytes: 3740
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    vector <vector <int> > dist;
    vector <int> r(n+1);
    dist.resize(n+1,r);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            cin>>dist[i][j];
    bool f=1;
    ll t=0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            bool x=1;
            for(int k=1;k<=n;k++)
            {
                if(k==j||k==i)
                    continue;
                if(dist[i][k]+dist[k][j]<dist[i][j])
                {
                    f=0;
                    break;
                }
                if(dist[i][k]+dist[k][j]==dist[i][j])
                {
                    x=0;
                    break;
                }
            }
            if(!f)
                break;
            if(x)
                t+=dist[i][j];
        }

    if(!f)
        break;
    }   
    if(!f)
        cout<<"-1\n";
    else
        cout<<t<<endl;
    
    
    return 0;   
}




 
 


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

using namespace std;

int main() {
	
	int n;
	cin >> n;
	int t, a;
	cin >> t >> a;
	
	double minn = 1000;
	int minno = 0;
	int h;
	for (int i = 0; i < n; i++) {
		cin >> h;
		if (minn > abs(t - h * 0.006-a)) {
			minn = abs(t - h * 0.006-a);
			minno = i + 1;
		}
	}
	cout << minno << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
s = input()

ans = 0
count = k
ans = 0
for i in range(1,n-1):
    if s[i+1] in s[:i] and s[i] != s[i+1] and count > 0:
        count -=1
        j = i
        while s[j] != s[i+1]:
            if s[j] == 'R':
                s = s[:j] + 'L' + s[j+1:]
                j -=1
            elif s[j] == 'L':
                s = s[:j] + 'R' + s[j+1:]
                j-=1

if count > 0 and s != 'L'*n and s != 'R'*n:
    ans += 1

for i in range(1,n):
    if s[i] == s[i-1]:
        ans += 1

print(ans)

Measured memory_bytes: 3484
using System;

class Program
{
    static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        double x1 = double.Parse(s[0]);
        double y1 = double.Parse(s[1]);
        double x2 = double.Parse(s[2]);
        double y2 = double.Parse(s[3]);

        double disx = x2 - x1;
        double disy = y2 - y1;
        double z = disx * disx + disy * disy;
        z = Math.Sqrt(z);
        Console.WriteLine("{0:f4}",z);
        
    }
}

Measured memory_bytes: 9144
def main():
    n = int(input())
    abl = []
    for _ in range(n):
        a, b = map(int, input().split()) 
        abl.append([a,b])

    abl.sort(key=lambda x:x[1])
    curr_time = 0
    for curr_ab in abl:
        # print(curr_time)
        a,b = curr_ab
        curr_time += a
        if curr_time > b:
            print('No')
            return
    print('Yes')


if __name__ == "__main__":
    main()

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

int main() {
  int N,cnt=1;
  cin >> N;
  vector<int>d(N);
  for(int i=0;i<N;i++){
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  for(int i=0;i<N-1;i++){
    if(d.at(i)!=d.at(i+1)){
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

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

    final int M = 1_000_000_007;
    int N = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    long res = 1;
    Arrays.sort(s);
    int cnt = 1;
    for (int i = 1; i < N; i++) {
      if (s[i] == s[i - 1]) {
        cnt++;
      } else {
        res *= cnt + 1;
        res %= M;
        cnt = 1;
      }
    }
    res *= cnt + 1;
    res %= M;
    System.out.println(res - 1);
  }
}


Measured memory_bytes: 25980
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>
//#include "mylibrary.hpp"



using namespace std;

int main(){
    int N;
    cin >> N;
    int i;
    int p;
    vector<int> X;
    for(i=0;i<N;i++){
        int temp;
        cin >> temp;
        X.push_back(temp);
    }
    long long sum=0;
    for(i=0;i<N;i++){
        sum+=((X.at(i)-1)*(X.at(i)-1));
    }
    
    for(p=1;p<=100;p++){
        long long temp_sum=0;
        for(i=0;i<N;i++){
            temp_sum += (X.at(i)-p)*(X.at(i)-p);
        }
        sum = min(temp_sum,sum);
    }
    cout << sum << endl;
    return 0;
 
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_macros)]
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 ) * } } ; }
#[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 ) * } } ; }
#[allow(unused_macros)]
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 , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
#[allow(dead_code)]
struct Writer {
    s: String,
}
#[allow(unused_imports)]
use std::fmt::Display;
#[allow(dead_code)]
impl Writer {
    #[allow(dead_code)]
    pub fn new() -> Writer {
        Writer { s: String::new() }
    }
    #[allow(dead_code)]
    pub fn flush(&mut self) {
        print!("{}", self.s);
        self.s.clear();
    }
    pub fn write<T: Display>(&mut self, x: T) {
        self.s.push_str(&format!("{}", x));
    }
    pub fn writeln<T: Display>(&mut self, x: T) {
        self.s.push_str(&format!("{}", x));
        self.s.push('\n');
    }
    #[allow(dead_code)]
    pub fn write_vec<T: Display>(&mut self, xs: &Vec<T>) {
        if xs.len() == 0 {
            self.writeln("");
            return;
        }
        self.write(&format!("{}", xs[0]));
        for i in 1..xs.len() {
            self.write(&format!(" {}", xs[i]));
        }
        self.writeln("");
    }
}
#[allow(dead_code)]
fn main() {
    input!{
        a: u64,
        b: u64,
        x: u64,
    }
    let mut ans: u64 = 0;
    if a % x == 0 {
        ans += 1;
    }
    let left = a / x;
    let right = b / x;
    ans += right - left;
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int a[109],B[109];
int dp[300009][19];
main(){
    int n;
    cin>>n;
    if(n==1) {cout<<0; return 0;}
    for(int i =0; i < n; i++){
        cin >> a[i] ;
        dp[(1<<i)][i] = 0;
    }
    for(int i =0 ; i < n; i++)
        cin>>B[i];
    int ans = 1e9;
    for(int b = 0; b < (1<<n); b++){
        int t = 0;
          for(int j = 0; j < n; j++)
            if((1<<j)&b)
        t++;
        if(t <= 1) continue;
        for(int j = 0; j < n; j++){
            if((1<<j)&b){
                dp[b][j] = 1e9;
                int M = 1e9, inv = 0;
                for(int k = 0;k  < n; k++){
                    if(!((1<<k) &b)) continue;
                    if(k == j) continue;
                    if(j < k) inv++;
                    int x=a[j],y=a[k];
                    if(t%2 == j%2) x=B[j];
                    if(t%2 != k%2) y=B[k];
                    if(y > x) continue;
                    M= min(M, dp[b^(1<<j)][k]);

                }
                dp[b][j] = M + inv;
            }
            if(b == (1<<n)-1) ans = min(ans, dp[b][j]);
        }

    }
    if(ans == 1e9)ans=-1;
    cout<<ans<<endl;

}


Measured memory_bytes: 20736
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF LLONG_MAX / 2;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;

const ll INF = LLONG_MAX;

#define ARRAY_MAX 100005
#define INF 1e9+7


int main(){

    int h,w;
    cin >> h >> w;
    int cost[10][10];
    vector<int> num(10);
    int mini[10];

    REP(i,10){
        mini[i] = INF;
    }
    mini[1] = 0;/*1は変える必要がない*/
    REP(i,10){
        num[i] = i;
    }
    REP(i,10){
        REP(j,10){
            cin >> cost[i][j];
        }
    }

    do{
        int magic_power = 0;
        if(num[0] == 1){
            continue;
        }

        for(int i = 0;i < 9;i++){
            magic_power += cost[num[i]][num[i+1]];
            if(num[i+1] == 1){
                /*1になったのでもう変える必要がない*/
                break;
            }
        }
        mini[num[0]] = min(mini[num[0]],magic_power);/*num[0]から1に変えるのに必要な最小コストの更新*/

    }while(next_permutation(num.begin(),num.end()));

    /*REP(i,10){
        cout << mini[i] << " ";
    }
    cout << endl;
*/
    int ans = 0,tmp;
    REP(i,h){
        REP(j,w){
            cin >> tmp;
            if(tmp != -1){
                ans += mini[tmp];
            }
        }
    }
    cout << ans << endl;




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  ll n,k;
  cin >> n >> k;
  ll res = 0;
  if(n > k){
    n -= (n / k) * k;
  }
  res = min(k - n,n);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 10

int main(void){
  int i, j, a[N];
  char num[N+1];

  while(scanf("%s", num) != EOF){
    for(i = 0; i < N; i++){
      a[i] = (num[i]-'0');
    }
    for(i = N; i > 0; i--){
      for(j = 1; j < i; j++){
	a[j-1] = (a[j]+a[j-1]) % 10;
      }
    }
    printf("%d\n", a[0]);
  }
  return 0;
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long

double n, a, ans;
int32_t main() {
	cin >> n;
	for(int i = 0; i < n; ++i) {
		cin >> a;
		ans += (1/a);
	}
	cout << 1/ans;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define rep1(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

template<class T> inline bool chmax(T &a, T b) {
    if(a<b) {
        a=b; return 1;
    } 
    return 0;
}

template<class T> inline bool chmin(T &a, T b) {
    if(a>b) {
        a=b; return 1;
    } 
    return 0;
}

const ll INF = 1LL << 60;

int N;

//DPテーブル
vector<ll> dp(100010);

int main() {
    int n,m;
    cin >> n >> m;
    vi a(m);
    rep(i,m) cin >> a.at(i);
    ll sum=0;
    rep(i,m) sum+=a.at(i);
    if(sum>n) cout << -1 << endl;
    else cout << n-sum << endl;
}

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

#define MAX 1000000


int main(){

  bool prime[MAX];
  int a,d,n;
  int head=2;
  int sum,k;
  
  prime[0]=true;

  while(head<=MAX){

    while(prime[head-1]!=false && head<MAX){ head++; }

    for(int i=2; head*i<=MAX; i++){ prime[head*i-1]=true; }

    head++;

  }

 

  while(cin >> a >> d >> n){
    if(a==0 && d==0 && n==0){ break; }

    k=0;
    sum=a;

    while(k<n){
      if(prime[sum-1]==false){ k++; }

      sum+=d;
    }

    cout << sum-d << endl;

  }

  

  return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

void dfs(const ll N, const ll A, const ll B, const ll C, const vector<ll>& l, vector<ll>& v, ll& ans)
{
    ll n = v.size();
    if (n == N)
    {
        ll a = 0, b = 0, c = 0;
        ll countA = 0, countB = 0, countC = 0;
        REP(i, N)
        {
            if (v[i] == 1)
            {
                a += l[i];
                countA++;
            }
            else if (v[i] == 2)
            {
                b += l[i];
                countB++;
            }
            else if (v[i] == 3)
            {
                c += l[i];
                countC++;
            }
        }
        if (a == 0 || b == 0 || c == 0)
        {
            return;
        }
        else
        {
            ll mp = 10 * (countA + countB + countC - 3);
            mp += abs(A - a) + abs(B - b) + abs(C- c);
            ans = min(ans, mp);
            return;
        }
    }
    else
    {
        REP(i, 4)
        {
            v.push_back(i);
            dfs(N, A, B, C, l, v, ans);
            v.pop_back();
        }
    }

    return;
}

int main()
{
    ll N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<ll> l(N);
    REP(i, N) 
    {
        cin >> l[i];
    }

    ll ans = LONG_MAX;
    vector<ll> v;
    dfs(N, A, B, C, l, v, ans);

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    map<int, int> os, es;
    for(int i = 0; i < n; i++){
        int v; cin >> v;
        (i & 1 ? os : es)[v]++;
        printde(os, es);
    }
    vector<pair<int, int>> os2, es2;
    for(auto& o : os){
        os2.emplace_back(o.second, o.first);
    }
    for(auto& e : es){
        es2.emplace_back(e.second, e.first);
    }
    sort(os2.rbegin(), os2.rend());
    sort(es2.rbegin(), es2.rend());
    if(os2[0].second != es2[0].second){
        cout << n - os2[0].first - es2[0].first << '\n';
    }else{
        printde(os2, es2);
        int n1 = os2[0].first + (es2.size() > 1 ? es2[1].first : 0);
        printde(os2, es2);
        int n2 = es2[0].first + (os2.size() > 1 ? os2[1].first : 0);
        printde(os2, es2);
        cout << n - max(n1, n2) << '\n';
    }
}


Measured memory_bytes: 6140
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<LL> A(N),B(N);
	for(int i=0;i<N;++i){
		cin >> A[i] >> B[i];//比
	}
	////////
	LL L,R;
	L = 1;
	R = 1;
	/*
	L/R = A/B
	L*B = R*A
	LはAの倍数
	RはBの倍数
	xAB ? yAB
	x,yの最小値を求めて
	L = max(x,y) * A
	R = max(x,y) * B
	*/
	for(int i=0;i<N;++i){
		LL X,Y;
		//L*A*B ? R*A*Bを作って
		//係数を大きいほうへ一致させる
		X = (L+A[i]-1)/A[i];
		Y = (R+B[i]-1)/B[i];
		
		L = max(X,Y) * A[i];
		R = max(X,Y) * B[i];
		//cout << L << " " << R << endl;
	}
	cout << L + R << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


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


Measured memory_bytes: 22612
# coding: utf-8
# Your code here!
import math

N = int(input())
S = ["" for i in range(N)]
for i in range(N):
    S[i] = input()
    
S.sort()

if N==1:
    print(1)
else:
    count = 1
    for i in range(N-1):
        if S[i] != S[i+1] :
            count += 1
    print(count)

Measured memory_bytes: 23820
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
ll inv(ll a);
ll fastpow(ll a, ll n);
ll C(ll n, ll m);
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = fastpow(2, n) - 1 - C(n, a) - C(n, b);
	cout << (ans + 2 * MOD) % MOD << endl;
	return 0;
}
ll fastpow(ll a, ll n)
{
	if (n < 0)return 0;
	ll res = 1;
	a %= MOD;
	while (n) {
		if (n & 1)res = (res * a) % MOD;
		a = (a * a) % MOD;
		n >>= 1;
	}
	return res % MOD;
}
ll inv(ll a)
{
	return a == 1l ? 1l : (ll)(MOD - MOD / a) * inv(MOD % a) % MOD;
}
ll C(ll n, ll m)
{
	if (m < 0)return 0;
	if (n < m)return 0;
	if (m > n - m)m = n - m;
	ll up = 1, down = 1;
	for (ll i = 0; i < m; i++)
	{
		up = up * (n - i) % MOD;
		down = down * (i + 1) % MOD;
	}
	return up * inv(down) % MOD;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,c,i,m;
	float t;
	while(~scanf("%d %d", &a, &b)){
		m=1;
		c=b;
		while(c!=0)
		{
			m*=10;
			c/=10;
		}
		m=m*a+b;
		t = sqrt(m);
		if(ceil(t)==t)
	    {
	        printf("Yes\n");
	    }
	    else
	    	printf("No\n");
	}
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, k, s, ans;

int main() {
	cin >> n >> k >> s;
	vector<ll> ans(n);
	REP(i, n) {
		if (s <= 1000000)ans[i] = 10000000;
		else ans[i] = 1;
	}
	REP(i, k)ans[i] = s;
	REP(i, n) {
		if (i != 0)cout << " ";
		cout << ans[i];
	}
	cout << endl;
}


Measured memory_bytes: 2048
#include <iostream>
#include<sstream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define  mem memset(a,0,sizeof(a))

const int mo=1000000007;
const int inf=0x3f3f3f3f;

typedef long long ll;
using namespace std;

int gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int main()
{
    ll x,y,ans;
    cin>>x>>y;
    if(x%y!=0)
    {
        cout<<x<<endl;
    }
    else
        cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    string s; cin>>s;
    ll n = s.size();
    vector<ll> cnt(26, 0);
    if((n%2==0) ^ (s[0] == s[n-1])) cout << "Second" << endl;
    else cout << "First" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; std::vector<std::string> s(n * 2);
	for(int i = 0; i < n; i++){
		cin >> s[i]; s[i] += s[i];
		s[i + n] = s[i];
	}
	
	int c = 0;
	for(int a = 0; a < n; a++){
		bool f = true;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(s[i + a][j] != s[j + a][i]) f = false;
			}
		}
		
		if(f) c += n;
	}
	
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;

int k[1000][1000], n, a, b, c, t, x[1000];
queue<int>Q;
queue<int>R;

int main() {
	memset(x, -1, sizeof(x));
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a >> b;
		for (int j = 0; j < b; j++) {
			cin >> c;
			k[i][c] = 1;
		}
	}
	Q.push(1);
	x[1] = 0;
	while (!Q.empty()) {
		t++;
		while (!Q.empty()) {
			for (int i = 1; i <= n; i++) {
				if (x[i] == -1 && k[Q.front()][i] == 1) {
					x[i] = t;
					R.push(i);
				}
			}
			Q.pop();
		}
		while (!R.empty()) {
			Q.push(R.front());
			R.pop();
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << i << ' ' << x[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1596
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var eo = 0L;
            for (var i = 0; i < N; ++i)
                eo |= Sarray()[0];
            if ((eo & 1) == 0)
                WriteLine("second");
            else
                WriteLine("first");
            //Out.Flush();
        }
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main() {
    ll ans=0;
    ll n;cin >>n;
    string s;cin >>s;
    ans++;
    char key=s[0];
    for (int i = 0; i < n; ++i) {
     if(key!=s[i]){
         ans++;
         key=s[i];
     }
    }
    cout <<ans <<endl;
    return 0;
}



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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var np = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = np[0];
        var p = np[1];
        var s = Console.ReadLine().Trim();

        var k = 0L;
        if (p == 2 || p == 5)
        {
            for (int i = 0; i < s.Length; ++i)
            {
                if ((s[i] - '0') % p != 0)
                {
                    continue;
                }

                k += i + 1;
            }
        }
        else
        {
            var m = 0;
            var pow = 1;
            var bucket = new int[p];
            bucket[0] = 1;
            for (int i = 0; i < s.Length; ++i)
            {
                int ii = s.Length - i - 1;
                m += (s[ii] - '0') * pow; m %= p;
                pow *= 10; pow %= p;

                k += bucket[m]++;
            }
        }

        Console.WriteLine(k);
    }
}


Measured memory_bytes: 13920
N=int(input())
A=input()
B=input()
C=input()
count=[0]*N
for i in range(N):
  if A[i]!=B[i]:
    count[i]+=1
  if C[i]!=A[i] and C[i]!=B[i]:
    count[i]+=1
print(sum(count))

Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 順列のループは https://maku77.github.io/java/numstr/permutation.html を参考
 */
public class Main {

	/** 数字の数 */
	private static final int N = 3;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int[] a = new int[N];
			IntStream.range(0, N).forEach(i -> a[i] = scanner.nextInt());
			System.out.println(permutation(a));
		}
	}

	/**
	 * 与えられた配列で順列のループを実施する
	 * 
	 * @param seed 順列のもととなる配列
	 */
	private static int permutation(int[] seed) {
		int[] perm = new int[seed.length];
		boolean[] used = new boolean[seed.length];
		return buildPerm(seed, perm, used, 0);
	}

	/**
	 * 与えられた配列で順列のループを実施し、最小値を計算する
	 * 
	 * @param seed  順列のもととなる配列
	 * @param perm  作成された順列
	 * @param used  個々の要素が使用したかどうかを記録用配列
	 * @param index 現在処理しているインデックス
	 */
	private static int buildPerm(int[] seed, int[] perm, boolean[] used, int index) {
		if (seed.length == index) {
			return procPerm(perm);
		}

		int min = Integer.MAX_VALUE;
		for (int i = 0; i < seed.length; ++i) {
			if (!used[i]) {
				perm[index] = seed[i];
				used[i] = true;
				min = Math.min(min, buildPerm(seed, perm, used, index + 1));
				used[i] = false;
			}
		}
		return min;
	}

	/**
	 * できた順列に対して、コストを計算する
	 * 
	 * @param perm 順列
	 * @return コスト
	 */
	private static int procPerm(int[] perm) {
		return IntStream.range(1, perm.length).map(i -> Math.abs(perm[i] - perm[i - 1])).sum();
	}

}


Measured memory_bytes: 35780
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 55;
const int mod = 1000000007;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  string s;
  cin>>s;
  cout<<string(s.size(), 'x')<<endl;
  return 0;
}

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

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;

int main(void){
  ll N;
  cin >> N;
  
  N %= 10;
  
  if(N==2 || N==4 || N==5 || N==7 || N==9){
    cout << "hon";
  }else if(N==0 || N==1 || N==6 || N==8){
    cout << "pon";
  }else{
    cout << "bon";
  }

  return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct node{
  int key;
  struct node *next;
  struct node *prev;
};

struct node *NIL;

void init(void){
  NIL = (struct node *)malloc(sizeof(struct node));
  NIL->next = NIL;
  NIL->prev = NIL;
}

void insert(int key){
  struct node *x;

  x = (struct node*)malloc(sizeof(struct node));
  x->key = key;
  x->next = NIL->next;
  NIL->next->prev = x;
  NIL->next = x;
  x->prev = NIL;
}

struct node* listSearch(int key){
  struct node *goal = NIL->next;
  while(goal != NIL && goal->key != key){
    goal = goal->next;
  }
  return goal;
}

void delete(struct node *y){
  if (y == NIL) return;
  y->prev->next = y->next;
  y->next->prev = y->prev;
  free(y);
}

void deleteF(void){
  delete(NIL->next);
}

void deleteL(void){
  delete(NIL->prev);
}

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

void print(void){
  struct node *z = NIL->next;
  int flag = 1;

  while(1){
    if (z == NIL) break;
    if (flag == 0) printf(" ");
    printf("%d",z->key);
    z = z->next;
    flag = 0;
  }
  printf("\n");
}

int main(){
  int i;
  int n,key;
  char word[12];

  scanf("%d",&n);

  init();

  for(i=0; i<n; i++){
    scanf("%s",&word);
    if (strcmp(word,"insert") == 0){
      scanf("%d",&key);
      insert(key);
    }
    else if(strcmp(word,"delete") == 0){
      scanf("%d",&key);
      deleteKey(key);
    }
    else if(strcmp(word,"deleteFirst") == 0){
      deleteF();
    }
    else if(strcmp(word,"deleteLast") == 0){
      deleteL();
    }
  }

  print();

  return 0;
}


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

int main(){
  int a;
  int count5 = 0,count7=0;
  bool judge = false;
  while(cin >> a){
    if(a == 5){
      count5++;
    }else if(a == 7){
      count7++;
    }else{
      judge = false;
    }
  }
  if(count5 == 2 and count7 == 1){
    judge = true;
  }
  if(judge){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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

int main() {
	int n;cin>>n;
	string s;cin >>s;
	int k;cin >>k;
	string out = "";
	string target = s.substr(k-1,1);
	for(int i=0;i<n;++i){
		auto tmp = s.substr(i,1);
		if(tmp == target){
			out +=tmp;
		} else {
			out +="*";
		}
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
ex=0
for i in range(1,100):
    ex+=26**i
    if(n<=ex):
        digit=i
        break
x=n-ex+26**digit-1
sum=''
for i in range(digit):
    q,mod=divmod(x,26)
    sum+=chr(ord('a')+mod)
    if(q==0):
        for j in range (digit-i-1):
            sum+='a'
        break
    x=q
    
    
print(sum[::-1])

Measured memory_bytes: 8860
#include <stdio.h>
int main(){
	int a,b,c,d,e,f;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	e=a*b;
	f=c*d;
	if(e>f){
		printf("%d",e);
	}else if(e<=f){
		printf("%d",f);
	}	
	return 0;
}

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


int main(){
    int N,K,Q;
    int A[100000];
    cin >> N >> K >> Q;
    for(int i=0; i<Q; i++){
        cin >> A[i];
    }

    int point[100000] = {0};

    for(int j=0; j<Q; j++){
        point[A[j]-1] += 1;
    }

    for(int k=0; k<N; k++){
        point[k] = point[k] - Q + K;
    }

    for(int a=0; a<N; a++){
        if(point[a] <= 0){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1408
import sys
input=sys.stdin.readline

n = input().strip()

a = ""
b = ""

import math

for c in n:
    d = int(c)
    a += str(math.ceil(d/2))
    b += str(math.floor(d/2))

ans = 0
if int(n) % 10 == 0:
    ans += 9
for c in a:
    ans += int(c)
for c in b:
    ans += int(c)

print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>

int main(void) {
    int A,B,C,X;
    int ans = 0;

    std::cin >> A >> B >> C >> X;

    for(int a = 0; a <= A; a++) {
        for(int b = 0; b <= B; b++) {
            for(int c = 0; c <= C; c++) {
                if(a*500 + b*100 + c*50 == X)
                    ans++;
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	defer flush()

	H := readInt()
	W := readInt()
	Ch := readInt() - 1
	Cw := readInt() - 1
	Dh := readInt() - 1
	Dw := readInt() - 1
	S := make([]string, H)
	for i := 0; i < H; i++ {
		S[i] = readString()
	}

	t := make([][]int, H)
	for i := 0; i < H; i++ {
		t[i] = make([]int, W)
		for j := 0; j < W; j++ {
			if S[i][j] == '#' {
				t[i][j] = -1
			} else {
				t[i][j] = math.MaxInt64
			}
		}
	}

	a := 0
	t[Ch][Cw] = a
	q := make([][2]int, 0, 1024)
	q = append(q, [2]int{Ch, Cw})

	warpq := make([][2]int, 0, 1024)
	for len(q) != 0 {
		for len(q) != 0 {
			h, w := q[0][0], q[0][1]
			warpq = append(warpq, [2]int{h, w})
			q = q[1:]
			if h-1 >= 0 && t[h-1][w] > a {
				q = append(q, [2]int{h - 1, w})
				t[h-1][w] = t[h][w]
			}
			if h+1 < H && t[h+1][w] > a {
				q = append(q, [2]int{h + 1, w})
				t[h+1][w] = t[h][w]
			}
			if w-1 >= 0 && t[h][w-1] > a {
				q = append(q, [2]int{h, w - 1})
				t[h][w-1] = t[h][w]
			}
			if w+1 < W && t[h][w+1] > a {
				q = append(q, [2]int{h, w + 1})
				t[h][w+1] = t[h][w]
			}
		}

		if t[Dh][Dw] != math.MaxInt64 {
			break
		}

		a++
		for i := 0; i < len(warpq); i++ {
			h, w := warpq[i][0], warpq[i][1]
			for i := max(0, h-2); i <= min(H-1, h+2); i++ {
				for j := max(0, w-2); j <= min(W-1, w+2); j++ {
					if t[i][j] <= a {
						continue
					}
					t[i][j] = a
					q = append(q, [2]int{i, j})
				}
			}
		}
		warpq = warpq[:0]
	}

	if t[Dh][Dw] == math.MaxInt64 {
		println(-1)
	} else {
		println(t[Dh][Dw])
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


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

struct UnionFind{
    vector<long long> root;
    vector<long long> sizes;
    UnionFind(long long n): root(n + 1), sizes(n + 1,1){
        for(long long i = 0; i <= n; i++) root[i] = i;
    }
    long long find(long long x){
        if(x == root[x]) return x;
        return root[x] = find(root[x]);
    }
    void unite(long long x, long long y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sizes[x] < sizes[y]) swap(x,y);
        root[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(long long x, long long y){
        return find(x) == find(y);
    }
};

int main(){
    //input
    long long N, M;
    cin >> N >> M;
    long long i,j,a[M+1],b[M+1];
    for(i=1; i<=M; i++){
        cin >> a[i] >> b[i];
    }

    //calc
    long long ans=0;
    bool bridge;
    for(i=1; i<=M; i++){
        UnionFind uf(N);
        set<long long> ss;
        for(j=1; j<=M; j++){
            if(j!=i){
                uf.unite(a[j],b[j]);
            }
        }
        for(j=1; j<=N; j++){
            ss.insert(uf.find(j));
        }
        if(ss.size()>1){
            ans++;
        }

    }
    
    //answer
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 504
def gcd( x, y ):
	if 1 < y < x:
		return gcd( y, x%y )
	else:
		if y == 1:
			return 1
		return x

a, b = [ int( val ) for val in input( ).split( " " ) ]
if a < b:
	a, b = b, a
print( gcd( a, b ) )

Measured memory_bytes: 6724
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int min = 6;
		int max = 0;
		HashMap<String,Integer> hm = new HashMap<>();
		String[] st = new String[n];
		int aa = 0;
		while(n--!=0) {
			String str = sc.next();
			min = Math.min(min, str.length());
			max = Math.max(max, str.length());
			int a = sc.nextInt();
			if(!hm.containsKey(str)) {
				st[aa] = str; aa++;
				hm.put(str, a);
			}	
			else
				hm.put(str, hm.get(str)+a);
		}
		String[] stt= Arrays.copyOfRange(st, 0, aa);
		Arrays.sort(stt);
		for(int i=min;i<=max;i++) {
			for(int j=0;j<aa;j++) {
				if(stt[j].length()!=i) continue;
				System.out.println(stt[j]+" "+hm.get(stt[j]));
			}
		}
	}
}


Measured memory_bytes: 47308