akhauriyash/Code-Regression huggingface dataset:
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        for (int i=1; i < s.length(); i++) {
            String a = s.substring(0, (s.length()-i)/2);
            String b = s.substring((s.length()-i)/2,s.length()-i);
            if(a.equals(b)){
                System.err.println(a);
                System.out.println(s.length()-i);
                return;
            }
        }
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 21844
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main(args: Array<String>) {

    val str = readLn()
    if (str.length % 2 == 0 && str == "hi".repeat(str.length / 2)) {
        println("Yes")
    } else {
        println("No")
    }

}

/*
1 1 5 -> 3
1 5 1 -> 2
5 1 1 -> 1
 */


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, k;
  std::cin >> n >> k;
  std::vector<int64_t> a(n);
  std::cin >> a;

  std::vector<int64_t> c(n, 0), d(n, 0);

  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = 0; j < n; j++) {
      if (a[j] < a[i]) {
        d[i]++;
        if (i < j) {
          c[i]++;
        }
      }
    }
  }

  constexpr int64_t mod = 1000000007;

  const int64_t nn = ((k - 1) * k) / 2 % mod;

  int64_t ans = 0;

  for (int64_t i = 0; i < n; i++) {
    ans += d[i] * nn % mod;
    ans %= mod;
    ans += c[i] * k % mod;
    ans %= mod;
  }

  std::cout << ans << std::endl;
  return 0;
}

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

using namespace std;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}
int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i =0; i<N ; i++){
    cin >> d[i];
  }
  sort( d.begin(), d.end()  );
  int count =0 , ans =0;
  if(d[N/2 -1] != d[N/2]){
    ans = d[N/2]-d[N/2-1];
  }
  cout << ans <<endl;
}

Measured memory_bytes: 640
use std::io::stdin;
use std::iter::Iterator;
use std::collections::VecDeque;
use std::collections::HashMap;

fn solve(cin: &mut ConsoleInputWrapper) {
    let n: usize = cin.input().parse().unwrap();

    let mut b: Vec<i32> = Vec::new();

    for i in 0..n - 1 {
        b.push(cin.input().parse().unwrap());
    }

    let mut i = n - 2;
    let mut sum = b[n - 2] + b[0];
    while i > 0 {
        sum += [b[i - 1], b[i]].iter().min().unwrap().clone();
        i -= 1;
    }
    println!("{}", sum);
    ()
}

//Other Functions Here

fn main() {
    let mut cin = ConsoleInputWrapper::new();
    solve(&mut cin);
}

fn factorization(value: i64) -> HashMap<i64, usize> {
    let sqrt = f64::sqrt(value.clone() as f64);
    let mut value = value;
    let mut map = HashMap::new();
    let mut p = 2;
    while p.clone() as f64 <= sqrt {
        let mut count = 0;
        while (value % p.clone()) == 0 {
            count += 1;
            value /= p.clone();
        }
        if count > 0 {
            map.insert(p.clone(), count);
        }
        p += 1;
    }
    if value != 1 {
        map.insert(value, 1);
    }
    map
}

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

fn min(a: i32, b: i32) -> i32 {
    if a < b { a } else { b }
}

fn max(a: i32, b: i32) -> i32 {
    if a > b { a } else { b }
}

struct ConsoleInputWrapper {
    queue: VecDeque<String>
}

impl ConsoleInputWrapper {
    fn new() -> ConsoleInputWrapper {
        ConsoleInputWrapper {
            queue: VecDeque::new()
        }
    }
    fn input(&mut self) -> String {
        if self.queue.len() <= 0 {
            let mut s = String::new();
            stdin().read_line(&mut s).unwrap();
            let list: Vec<&str> = s.split_whitespace().collect();
            for string in list {
                self.queue.push_back(String::from(string));
            }
        }
        self.queue.pop_front().unwrap()
    }
}

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

int main() {
	int a, b;
	scanf("%d", &a);
	scanf("%d", &b);
	if(a == b) cout << a+b;
	else if(a > b) cout << 2*a - 1;
	else cout << 2*b - 1;
	return 0;
}

Measured memory_bytes: 256
import scala.math._

// longでrangeの作り方

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
  val s = sc.next
//  val list = List.fill(3)(sc.next)

  val ans = s.replace(',', ' ')

  println(ans)


  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

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

int main()
{
	for (;;) {
		int a, b;
		cin >> a >> b;
		if (a == 0 && b == 0) {
			break;
		}
		else {
			for (int i = 0; i < a / 2; i++) {
				for (int i = 0; i < b / 2; i++) {
					cout << "#.";
				}
				if (b % 2 == 1) {
					cout << "#";
				}
				cout << endl;
				for (int j = 0; j < b / 2; j++) {
					cout << ".#";
				}
				if (b % 2 == 1) {
					cout << ".";
				}
				cout << endl;
			}
			if (a % 2 == 0) {
				cout << endl;
			}
			if (a % 2 == 1) {
				for (int k = 0; k < b / 2; k++) {
					cout << "#.";
				}
				if (b % 2 == 1) {
					cout << "#";
				}
				cout << endl;
				cout << endl;
			}
		}
	}
}


Measured memory_bytes: 3088
import sys
sys.stdin.readline

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
sa = []
sa_a = 0
sa_b = []
sa_c = 0
count = 0

for i in range(N):
    sa.append(A[i]-B[i])

sa.sort()

if sum(sa) <= 0:
    print(-1)
    sys.exit()
else:
    for i in range(N):
        if sa[i] < 0:
            count += 1
            sa_a += abs(sa[i])
        else:
            sa_b.append(sa[i])

while sa_a > sa_c:
    sa_c += sa_b.pop()
    count += 1

print(count)


Measured memory_bytes: 18356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
 
struct UnionFind{
  vi data;
 
  UnionFind(int N): data(N,-1){}
 
  int find(int x){
    if(data[x]<0) return x;
    return find(data[x]);
  }
 
  void unite(int x, int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(data[x]>data[y]) swap(x,y);
    data[x]+=data[y];
    data[y]=x;
  }
 
  int size(int x){return -data[find(x)];}
 
  bool same(int x, int y){return find(x)==find(y);}
};
 
ll num_pairs(int n){return (ll)n*(n-1)/2;}
 
int main(){
  int N, M;cin>>N>>M;
  vi A, B;
  for (int i=0;i<M;++i){
    int a, b;cin>>a>>b;A.push_back(a-1);B.push_back(b-1);
  }
 
  vll num_connected;
  num_connected.push_back(0);
 
  UnionFind tree(N);
 
  ll tmp=0;
 
  for (int i=M-1;i>=0;--i){
    if(tree.same(A[i], B[i])) {num_connected.push_back(tmp);}
    else{
      ll tmp1=num_pairs(tree.size(A[i])), tmp2=num_pairs(tree.size(B[i]));
      tree.unite(A[i], B[i]);
      ll tmp3=num_pairs(tree.size(A[i]));
      tmp+=tmp3-tmp1-tmp2;
      num_connected.push_back(tmp);
    }
  }
 
  for (int i=M-1;i>=0;--i){ 
    cout << num_connected[M]-num_connected[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3440
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main(){
	int n, m;
	while (cin >> n, n){
		bool ex[21][21];
		for (int i = 0; i < 21; i++) for (int j = 0; j < 21; j++) ex[i][j] = false;
		for (int i = 0; i < n; i++){
			int x,y;
			cin >> x >> y;
			ex[x][y] = true;
		}
		cin >> m;
		map<string, pair<int, int> > dd;
		dd["N"] = make_pair(0, 1);
		dd["E"] = make_pair(1, 0);
		dd["W"] = make_pair(-1, 0);
		dd["S"] = make_pair(0, -1);

		int x = 10, y = 10;

		for (int i = 0; i < m; i++){
			string dir;
			int dis;
			cin >> dir >> dis;
			for (int i = 0; i < dis; i++){
				x += dd[dir].first;
				y += dd[dir].second;
				if (ex[x][y]) ex[x][y] = false;
			}
		}
		int count = 0;
		for (int i = 0; i < 21; i++){
			for (int j = 0; j < 21; j++){
				if (ex[i][j]) count++;
			}
		}
		if (count != 0) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
	return 0;
}

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

int main(){
        ll s, m=1e9;
        scanf("%lld", &s);
        printf("0 0 %lld 1 %lld %lld\n", m, (m-s%m)*(s%m!=0), s/m+(s%m!=0));
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
ll f(ll b, ll n)
{
    ll ans = 0;
    while(n)
    {
        ans += n % b;
        n /= b;
    }
    ans += n;
    return ans;
}
int main()
{
   // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, s;
    cin >> n >> s;
    ll b = -1;
    if(s > n)
    {
        cout << -1 << endl;
    }
    else if(s == n)
    {
        cout << n + 1 << endl;
    }
    else
    {
        for(ll i = 2; i <= sqrt(n) + 1; i++)
        {
            if(f(i, n) == s)
            {
                b = i;
                break;
            }
        }
        if(b != -1)
        {
            cout << b << endl;
            return 0;
        }
        if(b == -1)
        {
            for(ll i = 1; i <= sqrt(n - s) + 1; i++)
            {
                if((n - s) % i == 0)
                {
                    ll x1 = i;
                    ll x0 = s - x1;
                    ll tmpb = (n - s) / i + 1;
                    if(x1 < tmpb && x0 < tmpb && x0 >= 0 && tmpb >= 2)
                    {
                        if(b == -1) b = tmpb;
                        else
                        b = min(b, tmpb);
                    }
                    
                }
            }
            cout << b << endl;           
        }
        
    }
    

}

Measured memory_bytes: 256
import math

def main():
    N = int(input())
    rN = math.ceil(math.sqrt(N))
    minDist = float('inf')
    for a in range(1, rN+1):
        if N % a == 0:
            minDist = min(minDist, a+N/a-2)
    print(int(minDist))


main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int maxn=2*1e5+5;
int arr[4];
int main()
{
    FAST

    int a,b;
    cin>>a>>b;

    arr[a]=a;
    arr[b]=b;
    for(int i=1;i<=3;i++)
        if(arr[i]==0)
        return cout<<i,0;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
   public static void main(String[] args)
   {
      Scanner scan = new Scanner(System.in);
      long    A    = scan.nextInt();
      long    B    = scan.nextInt();
      long    K    = scan.nextInt();
      long    u    = 0;

      if((B - A) <= K){
         for(long i = A; i <= B; i++){
             System.out.println(i);
             }
         }
      else{
          for(long i = A; i < A + K; i++){
              System.out.println(i);
              }
          for(long i = Math.max(A + K, B - K + 1); i <= B; i++){
              System.out.println(i);
              }
          }
   }
}


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

int N;
char S[100010] = {0};

int main()
{
    scanf("%s",S);
    for(int i = 0; i < strlen(S); i++)
    {
        if(i == 0);
        else if(i == 1)
        {
            if(S[i] == S[i - 1])
            {
                printf("%d %d\n",1,2);
                return 0;
            }
        }
        else
        {
            if(S[i] == S[i - 1])
            {
                printf("%d %d\n",i,i + 1);
                return 0;
            }
            if(S[i] == S[i - 2])
            {
                printf("%d %d\n",i - 1, i + 1);
                return 0;
            }
        }
    }
    printf("%d %d\n",-1,-1);
    return 0;
}


Measured memory_bytes: 384
using System;

namespace ITP1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
            int[][] set = new int[1000000][];

            while (true)
            {
                set[i] = new int[2];
                string[] input = Console.ReadLine().Split(' ');
                set[i][0] = int.Parse(input[0]);
                set[i][1] = int.Parse(input[1]);
                if (set[i][0] == 0 & set[i][1] == 0) break;
                i++;
            }
            for (int k = 0; k < i; k++)
            {


                for (int t = 0; t < set[k][0]; t++)
                {

                    if (t % 2 == 0)
                    {
                        for (int p = 0; p < set[k][1]; p++)
                        {
                            if (p % 2 == 0) Console.Write("#");
                            else Console.Write(".");
                        }
                        Console.WriteLine();
                    }
                    else
                    {
                        for (int p = 0; p < set[k][1]; p++)
                        {
                            if (p % 2 != 0) Console.Write("#");
                            else Console.Write(".");
                        }
                        Console.WriteLine();
                    }

                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 16764
#pragma region

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define MOD 1000000007
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  REP(i, vec.size())
  i == 0
      ? os << vec[i]
      : os << ", " << vec[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &deq) {
  os << "deq[ ";
  REP(i, deq.size())
  i == 0
      ? os << deq[i]
      : os << ", " << deq[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}

#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int M;
  cin >> M;
  ll digits = 0, sum = 0;
  REP(i, M) {
    ll d, c;
    cin >> d >> c;
    digits += c;
    sum += d * c;
  }
  cout << digits - 1 + (sum - 1) / 9 << "\n";
}


Measured memory_bytes: 256
n, m = map(int,input().split())
ans = [0]*n
WA_li = [0]*n
AC = 0
WA = 0
for i in range(m):
    temp = list(map(str, input().split()))
    if ans[int(temp[0])-1] == 0:
        if temp[1] == "AC":
            ans[int(temp[0])-1] = 1
            AC += 1 
        else:
            WA_li[int(temp[0])-1] += 1
for i in range(n):
    if ans[i] == 1:
        WA += WA_li[i]
print(AC, WA)

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

int main() {
    int L, R;
    cin >> L >> R;

    int ans = 2018;
    if (R - L >= 2019)
    {
        for (int i = L; i < L + 2019; i++)
        {
            for (int j = i + 1; j <= L + 2019; j++)
            {
                ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
            }
            
        }
        
    } else
    {
        for (int i = L; i < R; i++)
        {
            for (int j = i + 1; j <= R; j++)
            {
                ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
            }
            
        }
    }
    
    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;


public  class Main 
{

	   
	   static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 

  

	  // Complete the hurdleRace function below.
//    public static void solve() {
//    	FastReader s=new FastReader();

   
    public static void main(String[] args) throws IOException {
    	FastReader s=new FastReader();
        String S = s.next();  	
        String T = s.next();
        
        int a =s.nextInt();
        int b =s.nextInt();
        String U = s.next();
        if(U.equals(S)) {
        	System.out.println((a-1)+" "+b);
        	
        }
        else System.out.println(a+" "+(b-1));
       	
    }	
}





        
    

      
 

Measured memory_bytes: 36668
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int[] cost = new int[n];
        cost[0] = 0;
        cost[1]= Math.abs(h[1]-h[0]);

        for(int i = 2;i<n;i++){
            int tmp1 = Math.abs(h[i-1]-h[i])+ cost[i-1];
            int tmp2 = cost[i-2]+ Math.abs(h[i-2]-h[i]);
            cost[i] = Math.min(tmp1,tmp2);
        }
        System.out.println(cost[n-1]);


    }

}


Measured memory_bytes: 59552
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;


void solve(long long a, long long b){
    cout << (a < b ? string(b, '0' + a) : string(a, '0' + b)) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

input_n = lambda: int(readline())
input_nn = lambda: map(int, readline().split())
input_s = lambda: readline().rstrip().decode('utf-8')
input_ss = lambda: readline().rstrip().decode('utf-8').split()

mod = 10 ** 9 + 7


def judge(a, b, c, k):

    ret = False
    ret |= (b == 0 and c == 2 and k == 1)
    ret |= (b == 0 and c == 1 and k == 2)
    ret |= (b == 2 and c == 0 and k == 1)
    ret |= (a == 0 and b == 2 and k == 1)
    ret |= (a == 0 and c == 2 and k == 1)

    return not ret


def main():

    N = input_n()
    dp = np.full((4, 4, 4), 1, np.int32)
    dp[0, 2, 1] = 0
    dp[0, 1, 2] = 0
    dp[2, 0, 1] = 0

    for n in range(N - 3):
        next_dp = np.zeros((4, 4, 4), np.int32)
        for a in range(4):
            for b in range(4):
                for c in range(4):
                    for k in range(4):
                        if judge(a, b, c, k):
                            next_dp[b, c, k] += dp[a, b, c]
                            next_dp[b, c, k] %= mod
        dp = next_dp

    print(dp.sum() % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12452
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MAXN 100507
#define mo 19930726
#define ll long long
using namespace std;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
int head[MAXN],fa[MAXN],a[MAXN],b[MAXN],c[MAXN],n,m,vis[MAXN],id[MAXN],cnt,num;
ll s[MAXN],f[MAXN];
struct po{
	int nxt,to;
}edge[MAXN<<1];
vector<int> v[MAXN];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline bool cmp(int x,int y) {return c[x]<c[y];}
inline void add_edge(int from,int to){
	edge[++num].nxt=head[from];edge[num].to=to;head[from]=num;
}
void dfs(int u){
	s[u]=b[u];
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		dfs(v);
		s[u]+=s[v];
	}
	f[u]=s[u]+c[u];
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		f[u]=min(f[u],s[u]-s[v]+max(f[v],1ll*c[u]));
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		c[i]=max(0,a[i]-b[i]);
		fa[i]=id[i]=i;
	}
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y); v[y].push_back(x);
	}
	sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;i++){
		int x=id[i];vis[x]=1;
		for(int j=0;j<v[x].size();j++) {
			int y=v[x][j];
			if(!vis[y]) continue;
			y=find(y);
			if(x!=y){
				fa[y]=x;add_edge(x,y);
			}
		}
	}
	dfs(id[n]);
	cout<<f[id[n]];
}

Measured memory_bytes: 13948
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

int main() {
    int a[3], b[3], c[3][3];
    rep(i, 3) {
        rep(j, 3) {
            cin >> c[i][j];
        }
    }
    bool flag;
    for (int i = -100; i <= 100; i++) {
        a[0] = i;
        for (int j = 0; j < 3; j++) {
            b[j] = c[0][j] - a[0];
        }
        flag = true;
        for (int j = 1; j < 3; j++) {
            for (int k = 1; k < 3; k++) {
                if (c[j][k] - b[k] != c[j][k-1] - b[k-1]) {
                    flag = false;
                }
            }
        }
        if (flag) break;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
//using ll = long long;
using P = pair<int, int>;
#define chmin(x, y) x = min(x, y)

const int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> key;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    int s = 0;
    rep(j,b) {
      int c;
      cin >> c;
      --c;
      s |= 1<<c;
    }
    key.emplace_back(P(s, a));
  }

  vector<int> dp(1<<n, INF);
  dp[0] = 0;
  rep(s,1<<n) {
    rep(i,m) {
      int t = s | key[i].first;
      int cost = dp[s] + key[i].second;
      chmin(dp[t], cost);
    }
  }
  int ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
int calc(const string &s){
	int sum=0;
	for(int i=0;i<11;i++){
		sum+=(s[10-i]-'0')*(i%6+2);
	}
	sum=11-sum%11;
	if(sum>=10)sum=0;
	return sum;
}
int main(){
	string S;
	cin>>S;
	for(int i=0;i<12;i++){
		if(S[i]=='?'){
			if(i==11)printf("%d\n",calc(S.substr(0,11)));
			else{
				int r=-1;
				for(int j=0;j<=9;j++){
					S[i]=j+'0';
					if(calc(S.substr(0,11))==S[11]-'0'){
						if(r>=0){r=-2;break;}
						r=j;
					}
				}
				if(r==-1)puts("NONE");
				else if(r==-2)puts("MULTIPLE");
				else printf("%d\n",r);
			}
		}
	}
}

Measured memory_bytes: 3324
n = int(input())
p = list(map(int, input().split()))

count = 0
for i in range(n-1):
  if int(i+1) == p[i]:
    p1 = p[i]
    p[i] = p[i+1]
    p[i+1] = p1
    count += 1
else:
  if n == p[n-1]:
    count += 1
print(count)

Measured memory_bytes: 14008
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, N = MAP()
A, B = [0]*N, [0]*N

for i in range(N):
	A[i], B[i] = MAP()

max_A = max(A)
dp = [INF]*(H+max_A+1)
dp[0] = 0
for i in range(N):
	for j in range(A[i], H+max_A+1):
		dp[j] = min(dp[j], dp[j-A[i]]+B[i])

print(min(dp[H:]))


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

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs

const int MAXN = 105000;

string s;
int st[MAXN];
int sLen = 0;
int ans;

int main() { 

  getline(cin, s);

  for (int i = 0; i < sz(s); i++) {
    sLen++;
    st[sLen - 1] = s[i] - '0';
    while (sLen >= 2) {
      int a = st[sLen - 2], b = st[sLen - 1];
      if (a != b) {
        sLen -= 2;
        ans += 2;
      } else {
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

#define ll long long int

using namespace std;

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

    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<vector<int>> input(H, vector<int>(W, 0));
    char temp;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> temp;
            if (temp == '#') {
                input[i][j] = 9;
                for (int k = -1; k <= 1; ++k) {
                    for (int l = -1; l <= 1; ++l) {
                        if (i + k < 0 || i + k >= H) continue;
                        if (j + l < 0 || j + l >= W) continue;
                        ++input[i + k][j + l];
                    }
                }
            }
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (input[i][j] >= 9) {
                cout << '#';
            } else {
                cout << input[i][j];
            }
        }
        cout << endl;
    }
}

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

#define int long long
#define MOD 1000000007
#define maxlen 9223372036854775807
#define minlen -9223372036854775807
#define fin(n) for(int i=0;i<n;i++)

int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
vector<int> primeFact(int n){vector<int> ans;for(int t=2;t<=sqrt(n);t++){if(n%t==0){ans.push_back(t);while(n%t==0){n=n/t;}}}if(n>2)ans.push_back(n);return ans;}
vector<int> fact(int n){vector<int> ans;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if( i*i == n ){ans.push_back(i);}else{ans.push_back(i);ans.push_back(n/i);}}}return ans;}
int powerr(int base,int exp,int mod) { if(exp==0)return 1;int t = powerr(base,exp/2,mod)%mod;if(exp%2==0){return (t%mod*t%mod)%mod;}else{return (t%mod*t%mod*base%mod)%mod;}} 
void fastio(){ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}



int32_t main(){
	fastio();

	double x;
	cin >> x;

	int p = 100;

	int ans = 0;
	while(p<x){
		p=p*(1.01);
		ans++;
	}	

	cout << ans << "\n";
	return 0;
}






Measured memory_bytes: 3768
x, y = map(int, input().split())

if x >= 0 and y >= 0:
    if y >= x:
        print(y - x)
    else:
        if y == 0:
            print(1 + x - y)
        else:
            print(x - y + 2)
elif x < 0 and y < 0:
    if y >= x:
        print(y - x)
    else:
        print(2 + x - y)
else:
    if y == 0:
        print(abs(abs(x) - abs(y)))
    else:
        print(abs(abs(x) - abs(y)) + 1)

Measured memory_bytes: 3064
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())

for i in range(1, 11):
    acc = 1000 * i - N
    if acc < 0:
        continue
    else:
        print(acc)
        break


Measured memory_bytes: 27100
s=[list(map(int,input().split())) for i in range(3)]
t=int(input())
u=[int(input()) for i in range(t)]
for i in range(t):
  for j in range(3):
    for k in range(3):
      if s[j][k]==u[i]:
        s[j][k]=0
b=0
if s[0][0]==0 and s[1][0]==0 and s[2][0]==0:
  b=1
elif s[0][1]==0 and s[1][1]==0 and s[2][1]==0:
  b=1
elif s[0][2]==0 and s[1][2]==0 and s[2][2]==0:
  b=1
elif s[0][0]==0 and s[0][1]==0 and s[0][2]==0:
  b=1
elif s[1][0]==0 and s[1][1]==0 and s[1][2]==0:
  b=1
elif s[2][0]==0 and s[2][1]==0 and s[2][2]==0:
  b=1
elif s[0][0]==0 and s[1][1]==0 and s[2][2]==0:
  b=1
elif s[0][2]==0 and s[1][1]==0 and s[2][0]==0:
  b=1
if b==1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3188
#![allow(dead_code, unused_imports, unused_variables)]

use proconio::*;
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        a: usize,
    }
    let ans = if n % 500 <= a {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


Measured memory_bytes: 2132
import Control.Applicative
import Control.Monad

main :: IO ()
main = solve <$> replicateM 5 readLn >>= print

solve :: [Int] -> Int
solve = (-) <$> (sum . map f) <*> (maximum . (0:) . filter (< 10) . map ((10 -) . (flip mod 10)))
  where
    f x = let (q, r) = divMod x 10
          in if r > 0 then (q + 1) * 10 else x


Measured memory_bytes: 508
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>

using namespace std;
const long long INF = (long long) (1e18)+1;

int gcd(int a, int b) {
  int next_a;
  while (b != 0) {
    next_a = b;
    b = a % b;
    a = next_a;
  }
  // cout << next_a << endl;
  return next_a;
}
int main() {
  int k;
  cin >> k;
  long long ans = 0;
  for (int i=1; i<=k; ++i) {
    for (int j=1; j<=k; ++j) {
      int first = gcd(i,j);
      for (int l=1; l<=k; ++l) {
        int second = gcd(first, l);
        // cout << second << endl;
        ans += second;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
fun main(args: Array<String>) {
    val n = readLine()?.toLong() ?: return
    val c = listOf(
        "a",
        "b",
        "c",
        "d",
        "e",
        "f",
        "g",
        "h",
        "i",
        "j",
        "k",
        "l",
        "m",
        "n",
        "o",
        "p",
        "q",
        "r",
        "s",
        "t",
        "u",
        "v",
        "w",
        "x",
        "y",
        "z"
    )
    var r = n
    val s = StringBuilder()
    while (r > 0) {
        val a = (r % 26).toInt()
        if (a == 0) {
            s.append("z")
        } else {
            s.append(c[a - 1])
        }
        r /= 26
        if (a == 0) {
            r--
        }
    }
    println(s.reverse().toString())
}

Measured memory_bytes: 37992
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;
int main(){
  ll n, a;cin>>n>>a;
  vector<int> x(n);
  for(int i=0;i<n;i++){
    ll s;cin>>s;x[i]=s-a;
  }
  vector<vector<ll>> dp(n+1, vector<ll>(2*n*50+1, 0));
  dp[0][n*50]=1;
  for(int i=1;i<=n;i++){
    for(int j=0;j<=2*n*50;j++){
      if(0<=j-x[i-1] && j-x[i]<=2*n*50){
      	dp[i][j]=dp[i-1][j-x[i-1]]+dp[i-1][j];
      }else{
	    dp[i][j]=dp[i-1][j];
      }
    }
  }
  cout<<dp[n][n*50]-(ll)1<<endl;
}

Measured memory_bytes: 2304
#include<iostream>
using namespace std;
int main()
{
    int a,b,i,s1,s2;
    cin>>a>>b;
    s1=0;
    s2=0;
    for(i=a-1;i>0;i--){
        s1=s1+i;
    }
    for(i=b-1;i>0;i--){
        s2=s2+i;
    }
    cout<<s1+s2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
const int MOD = 1000000007;
using pint = pair<ll, ll>;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N), b(N);
  for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
  bool check = false;
  for (int i = 0; i < N-2; i++) {
      if(a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2])
        check = true;
  }
  if(check){
      cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        String[] strArray = br.readLine().split(" ");

        int result = 0;

        for(int i = 0; i < N; i++) {
            for(int j = i +1; j < N; j++) {
                for(int k = j +1; k < N; k++) {
                    int a = Integer.parseInt(strArray[i]);
                    int b = Integer.parseInt(strArray[j]);
                    int c = Integer.parseInt(strArray[k]);

                    if(a + b > c && b + c > a && c + a > b &&
                        a != b && b != c && c != a) result++;
                }    
            }
        }
        

        pw.println(result);
        br.close();
        pw.close();
    }
}

Measured memory_bytes: 35936
#include <iostream>
#include <cstdio>
#include <cstring>

int seq[100005];
#define INF 0x3f3f3f3f
inline long long abs(long long x){
    return x > 0 ? x : -x;
}
inline long long min(long long x,long long y){
    return x > y ? y : x;
}
long long n,a,b,c;
long long dfs(int cur, int x,int y, int z){
    if (cur == n + 1){
        if (min(x,min(y,z)) != 0) return (abs(x - a) + abs(y - b) + abs(z - c) ) - 30;
        else return INF;
    }
    long long ret1,ret2,ret3,ret4;
    ret1 = dfs(cur + 1, x, y, z);
    ret2 = dfs(cur + 1, x + seq[cur], y,z) + 10;
    ret3 = dfs(cur + 1, x, y + seq[cur], z) + 10;
    ret4 = dfs(cur + 1, x , y, z + seq[cur]) + 10;
    return min(ret1,min(ret2,(min(ret3,ret4))));
}
int main(){
    std::cin >> n >> a >> b >> c;
    for(int i = 1; i <= n; i++){
        std::cin >> seq[i];
    }
    long long res = dfs(1,0,0,0);
    std::cout << res << std::endl;
}

Measured memory_bytes: 256
par  =[]
V, E = [int(s) for s in input().split()]
for i in range(V+1):
    par.append(i)

graph = []

for _ in range(E):
    x, y, w = [int(s) for s in input().split()]
    graph.append((x,y,w))

def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def same(x,y):
    return find(x) == find(y)

def union(x,y):
    x = find(x)
    y = find(y)
    if x != y:
        par[x] = y

graph = sorted(graph, key=lambda x: x[2])
ans = 0
for g in graph:
    if not same(g[0], g[1]):
        union(g[0], g[1])
        ans += g[2]
print(ans)






Measured memory_bytes: 25412
#include<bits/stdc++.h>
     
    using namespace std;
     
    #define all(x) x.begin(), x.end()
    typedef vector<int> vi;
    typedef pair<int,int> ii;
    typedef long long ll;
     
    const ll inf = 3e18 + 5;
     
    const int MAXN = 1 << 19;
    int N = 400000;
    int seg[2 * MAXN], A[MAXN];
    typedef vector<vi> vvi;
    
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
    
        int h,w;
        cin >> h >> w;
        vector<string> a(h);
        for(int i=0; i<h; i++)
            cin >> a[i];
        for(string x : a){
            cout << x << endl;
            cout << x << endl;
        }
        
    }

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<vector>

using namespace std;

double MapData[101][101];
int XbyId[101], YbyId[101], N;
vector<int> Path;

const int INF = 1000000;


void Init() {
	for (int i = 0; i < 100; i++) {
		XbyId[i] = YbyId[i] = INF;
		for (int j = 0; j < 100; j++) {
			MapData[i][j] = INF;
		}
	}
}

void createMap() {
	double dis;

	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			if (i == j || XbyId[i] == INF || XbyId[j] == INF) {
				continue;
			}
			dis = sqrt( pow(XbyId[i]-XbyId[j], 2) + pow(YbyId[i]-YbyId[j], 2) );
			if (dis > 50) {
				continue;
			}
			MapData[i][j] = dis;
		}
	}
}

void solve(int start, int end) {
	double dist[100];
	bool used[100];
	int preNode[100], current;

	fill(dist, dist + N, INF);
	fill(used, used + N, false);
	fill(preNode, preNode + N, -1);
	dist[start] = 0;

	while (true) {
		current = -1;

		for (int i = 0; i < N; i++) {
			if (!used[i] && (current == -1 || dist[i] < dist[current])) {
				current = i;
			}
		}
		if (current == -1) {
			break;
		}
		used[current] = true;

		for (int next = 0; next < N; next++) {
			if (dist[next] > dist[current] + MapData[current][next]) {
				dist[next] = dist[current] + MapData[current][next];
				preNode[next] = current;
			}
		}
	}

	if (dist[end] == INF) {
		cout << "NA";
		return;
	}

	current = end;
	while (current != -1) {
		Path.push_back(current);
		current = preNode[current];
	}
	reverse(Path.begin(), Path.end());
}

int main() {
	int m,start,end;

	while (cin >> N, N) {
		Init();
		for (int i = 0; i < N; i++) {
			cin >> m;
			--m;
			cin >> XbyId[m] >> YbyId[m];
		}
		createMap();

		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> start >> end;
			Path.clear();
			solve(--start, --end);
			for (int i = 0; i < Path.size(); i++) {
				cout << Path[i] + 1;
				if (i != Path.size()-1) {
					cout << " ";
				}
			}
			cout << endl;
		}
	}

	return 0;
}



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

int main() {
    ll n, k;
    cin >> n >> k;
    ll x{n % k};
    x = min(x, abs(x - k));
    cout << x << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define endl "\n"    
typedef long long ll;
#define double long long
//#define int unsigned long long

const int maxn=1e2+10;
int arr[maxn][maxn];
int n,m;

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

   string a,b;
   cin>>a>>b;
   int cnt=0;
   for(int i=0;i<a.length();i++)
   {
       if(a[i]==b[i])
       ++cnt;
   }
   cout<<cnt;
}    

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(void) {
    char a, b;
    cin >> a >> b;
    bool p;
    if(a == 'H') {
        if(b == 'H') {
            p = true;
        } else {
            p = false;
        }
    } else {
        if(b == 'H') {
            p = false;
        } else {
            p = true;
        }
    }
    
    if(p) {
        cout << 'H' << endl;
    } else {
        cout << 'D' << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define llong long long
const int mod=1e9+7;
int add(int x,int y){return x+y<mod?x+y:x+y-mod;}
void ade(int& x,int y){x+=y;if(x>=mod)x-=mod;}
int qpow(int x,int k)
{
	int r=1;
	while(k)
	{
		if(k&1)r=1ll*r*x%mod;
		k>>=1;x=1ll*x*x%mod;
	}
	return r;
}
int n,m;
llong X;
struct Edge{
	int u,v,w;
	bool operator < (const Edge &o)const{
		return w<o.w;
	}
}ed[2020];
struct data{
	int to,nxt,w;
}mp[2020];
int head[1010],cnt;
void link(int x,int y,int w)
{
	mp[++cnt].to=y;
	mp[cnt].nxt=head[x];
	mp[cnt].w=w;
	head[x]=cnt;
}
struct UFS{
	int fa[1010];
	void reset(){for(int i=1;i<=n;++i)fa[i]=i;}
	int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
	int merge(int x,int y,int w)
	{
		int fx=find(x),fy=find(y);
		if(fx==fy)return 0;
		link(x,y,w);link(y,x,w);
		fa[fx]=fy;
		return w;
	}
}ufs;
bool ot[2020];

int fa[1010],fw[1010];
int dep[1010];
void dfs(int x)
{
	int v;
	dep[x]=dep[fa[x]]+1;
	for(int i=head[x];i;i=mp[i].nxt)
		if(mp[i].to!=fa[x])
		{
			v=mp[i].to;
			fa[v]=x;
			fw[v]=mp[i].w;
			dfs(v);
		}
}
int mxv(int x,int y)
{
	if(dep[x]>dep[y])swap(x,y);
	int res=0;
	while(dep[y]!=dep[x]) res=max(res,fw[y]),y=fa[y];
	if(x==y)return res;
	while(x!=y)res=max(res,fw[x]),res=max(res,fw[y]),x=fa[x],y=fa[y];
	return res;
}
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%lld",&X);
	for(int i=1;i<=m;++i)
		scanf("%d%d%d",&ed[i].u,&ed[i].v,&ed[i].w);
	sort(ed+1,ed+m+1);
	int x,y,w;
	llong mst=0;
	ufs.reset();
	for(int i=1;i<=m;++i)
	{
		w=ufs.merge(ed[i].u,ed[i].v,ed[i].w);
		mst+=w;
		if(w)
//		{
			ot[i]=1;
//			cout<<"x: "<<ed[i].u<<" y: "<<ed[i].v<<" w: "<<ed[i].w<<endl;
//		}
	}
//	cout<<"mst: "<<mst<<" X: "<<X<<endl;
	if(mst>X)
	{
		puts("0");
		return 0;
	}
	int ans=0;
	if(mst==X)ans=1ll*add(qpow(2,n-1),mod-2)*qpow(2,m-n+1)%mod;
	dfs(1);
	int sum=0,ta;
	int tot=0;
	for(int i=1;i<=m;++i)
	{
		if(ot[i])continue;
		x=mxv(ed[i].u,ed[i].v);
		ed[i].w-=x;
		ed[++tot]=ed[i];
	}
	sort(ed+1,ed+tot+1);
	for(int i=tot;i;--i)
		if(ed[i].w==X-mst)ade(sum,qpow(2,tot-i));
	ade(ans,add(sum,sum));
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3920
#include<iostream>
#include<queue>
using namespace std;
typedef pair<int, int> P;

int main()
{
  int N;

  cin >> N;
  priority_queue<int, vector<int>, greater<int> > que1;
  priority_queue<int> que2;
  queue<pair<int, int> > que3;
  int max = 0; 

  for (int i = 0; i < N; i++)
  {
    int a;

    cin >> a;
    if(a >= 0){
      que1.push(a);
    }
    else{
      que2.push(a);
    }
  }

  while (que1.size() > 1)
  {
    
   if (que2.empty())
   {
      int a, b;
      a = que1.top();que1.pop();
      b = que1.top();que1.pop();
      P p = make_pair(a, b);
      a = a - b;
      que2.push(a);
      que3.push(p);
      continue;
    }

    int a, b;
    a = que2.top();que2.pop();
    b = que1.top();que1.pop();
    que2.push(a - b);
    P p = make_pair(a, b);
    que3.push(p);
      
  }

  if(que1.empty()){
    max = que2.top();
    que2.pop();
  }
  else{
    max = que1.top();
    que1.pop();
  }

  while (!que2.empty())
  {
    int a;
    a = que2.top();
    P p = make_pair(max, que2.top());
    que3.push(p);
    max = max - a;
    que2.pop();
  }

  cout << max << endl;

  while (!que3.empty())
  {
    P p = que3.front();
    int x = p.first;
    int y = p.second;
    cout << x << ' ' << y << endl;
    que3.pop();
  }





  return 0;
}

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

namespace ABC129
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            int[] s = new int[n];
            var w = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var ws = w.Sum();
            int tmpMin = ws;
            int ws1 = 0;
            foreach(var tmpw in w)
            {
                ws1 += tmpw;
                tmpMin = Math.Min(Math.Abs(ws1 * 2 - ws), tmpMin);
            }
            Console.WriteLine(tmpMin);
        }
    }
}


Measured memory_bytes: 13396
import static java.lang.System.*;
import java.util.*;

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

        int n = sc.nextInt();
		int max = 0;
		
		int ans = 0;
		for(int i=0; i<n; i++) {
			int h = sc.nextInt();
			if(h >= max) {
				ans++;
				max = h;
			}
		}

        out.println(ans);
    }
}


Measured memory_bytes: 22612