akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000
 
using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
 
int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0,0 };
 
 
int main(void) {
    int n;

    cin>>n;
    vector<int> c(n),v(n);
    vector<int> value(n);
    int total=0;

    FOR(i,0,n-1){
        cin>>v[i];
    }
    FOR(i,0,n-1){
        cin>>c[i];
    }
    FOR(i,0,n-1){
        value[i]=v[i]-c[i];
    }
    sort(value.begin(),value.end());

    RFOR(i,n-1,0){
        if(value[i]>0){
            total+=value[i];
        }else{
            break;
        }
    }
    cout<<total<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    n, m = LI()
    if n == m:
        print("Yes")
    else:
        print("No")

    return


# B
def B():
    a, b = LI()
    if a <= b:
        ans = str(a) * b
    else:
        ans = str(b) * a
    print(ans)
    return


# C
def C():
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


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


Measured memory_bytes: 38256
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ld = long double;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vector<string> S(N);
  ll a = 0, b = 0, c = 0, d = 0;
  REP(i, 0, N) {
    cin >> S[i];
    if (S[i] == "AC") {
      a++;
    } else if (S[i] == "WA") {
      b++;
    } else if (S[i] == "TLE") {
      c++;
    } else {
      d++;
    }
  }

  cout << "AC x " << a << endl;
  cout << "WA x " << b << endl;
  cout << "TLE x " << c << endl;
  cout << "RE x " << d << endl;

  return 0;
}


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

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

fn main() {
    let n: i32 = read();
    let x: i32 = read();
    let mut ans10000 = -1;
    let mut ans5000 = -1;
    let mut ans1000 = -1;
    'found: for i in 0..n + 1 {
        for j in 0..n - i + 1 {
            let k = n - i - j;
            if i * 10000 + j * 5000 + k * 1000 == x {
                ans10000 = i;
                ans5000 = j;
                ans1000 = k;
                break 'found;
            }
        }
    }
    println!("{} {} {}", ans10000, ans5000, ans1000);
}

Measured memory_bytes: 4352
#pragma region 宣言部分
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;

#pragma endregion



int main(){
    int n;
    cin >> n;
    ll a[100010] = {};
    ll res = 0;
    REP(i,n){
        ll x;
        cin >> x;
        a[x]++;
        res += x;
    }
    int q;
    cin >> q;

    REP(i,q){
        ll b,c;
        cin >> b >> c;
        res -= b * a[b];
        res += c * a[b];
        a[c] += a[b];
        a[b] = 0;
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 4396
#import <stdio.h>
typedef long long INT;
int main(){
    INT a,b;
    scanf("%lld %lld",&a,&b);
    if(a>0){
        puts("Positive");
        return 0;
    }
    if(b<0){
        puts((b-a+1)%2==0?"Positive":"Negative");
        return 0;
    }
    puts("Zero");
}


Measured memory_bytes: 7244
#include<stdio.h>
int main(void) {
int n, k, p,i;
scanf("%d",&n);
for(i=0;i<n;i++) {
scanf("%d%d",&k,&p);
if(k%p) printf("%d\n",k%p);
else printf("%d\n",p);
}
return(0);
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();



		switch(N){
		case 1:
			System.out.println("Hello World");
			break;
		case 2:
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			System.out.println(a+b);
		}




	}

}

Measured memory_bytes: 21844
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	a = input()
	print(a[:3]+'8'+a[4:])

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()


Measured memory_bytes: 63980
module Main (main) where

import Control.Monad
import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.List

main :: IO ()
main = replicateM 2 readStrings >>= print . solve

solve [[xs], [ys]] = foldl' f 0 $ zipWith (==) xs ys
  where
    f acc = (acc +) . bool 0 1

readStrings :: IO [String]
readStrings = map C8.unpack . C8.words <$> C8.getLine

Measured memory_bytes: 380
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        List<Integer> l = new ArrayList<>();

        for (int i=0; i < 3; i++) {
            l.add(sc.nextInt());
        }

        l.sort((Comparator.comparingInt(o -> o)));

        System.out.println(l.get(0) + l.get(1));

    }

}


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

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

    string s;
    cin >> s;
    vector<int> v;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '0'){
            v.push_back(0);
        }else if(s[i] == '1'){
            v.push_back(1);
        }
    }
    v.push_back(2);
    v.push_back(2);

    int ans = 0;
    int check = 0;

    while(1){
        check = 0;
        if(v.size() == 2)break;
        for(int i = 0; i < v.size()-3; i++){
            if(v[i] != v[i+1]){
                v.erase(v.begin() + i, v.begin() + i + 2);
                ans += 2;
                check = 1;
                /*for(int j = 0; j < v.size()-1; j++){
                    cout << v[j];
                }
                cout << endl;*/
                break;
            }
            check = 0;
        }
        if(check == 0)break;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 1020
#include <iostream>
#include <map>
using namespace std;
int main(){
  int N, M, a, b;
  cin >> N >> M;
  map<int,int> C;
  for(int i = 0; i < M; ++i){
    cin >> a >> b;
    ++C[a];
    ++C[b];
  }
  for(int i = 0; i < N; ++i){
    if(C[i+1]%2){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 4992
import sys
import math


def main(X=None):
    """
    >>> main(90)
    4
    >>> main(120)
    3
    >>> main(45)
    8
    >>> main(1)
    360
    >>> main(70)
    36
    """
    if not X:
        X = int(input())
    # q, r = divmod(360, X)
    # if r == 0:
    #     print(q)
    # ret = q
    # q, r = (X, r)
    # if r == 0:
    #     ret = ret * q + 1
    ret = 0
    cur = 0
    while True:
        ret += 1
        cur += X
        if cur % 360 == 0:
            print(ret)
            return


def _test():
    import doctest
    doctest.testmod()


USE_NUMBA = False
if USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE' or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', 'void(i8,i8)')(main)
    # b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
    cc.compile()
    exit()
else:
    if USE_NUMBA and sys.argv[-1] != '-p':
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import main  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline

    # read parameter
    main()


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

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; }

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  ll N;
  cin>>N;
  vector<ll> v(N);
  rep(i,N) cin>>v[i];
  vector<ll> d(N);
  rep(i,N) {
    if(i==0) d[i] = v[i];
    else d[i] = v[i]-v[i-1];
  }
  vector<ll> s(N);
  rep(i,N) s[i] = i;
  ll M,K;
  cin>>M>>K;
  rep(i,M){
    ll a;
    cin>>a;
    a--;
    swap(s[a],s[a+1]);
  }
  vector<vector<ll>> db(61,vector<ll>(N));
  rep(i,61){
    if(i==0) db[i] = s;
    else {
      rep(j,N){
        db[i][j] = db[i-1][db[i-1][j]];
      }
    }
  }
  vector<ll> ans(N);
  rep(i,N) ans[i] = i;
  rep(i,61){
    if(K&(1LL<<i)){
      rep(j,N){
        ans[j] = db[i][ans[j]];
      }
    }
  }
  ll p = 0;
  rep(i,N){
    p+=d[ans[i]];
    cout<<p<<endl;
  }
}

Measured memory_bytes: 54136
#include<iostream>
#include<string>
using namespace std;
int N_MAX = 100000;
int p = 1000000007;
int main()
{
  int n;
  string s;
  cin >> n;
  cin >> s;
  int cc[N_MAX];
  fill(cc,cc+n,1);
  int cn=0;
  string t;
  string::size_type pos;
  long long res=1;
  while(!s.empty()){
    t=s.front();
    pos=s.find(t);
    while(pos!=string::npos){
      s.erase(pos,1);
      pos=s.find(t,pos);
      cc[cn]++;
    }
    cn++;
  }
  for(int i=0;i<cn;i++){
    res=(res*cc[i])%p;
  }
  res--;
  if(res==-1) res=1000000006;
  cout << res << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

int main()
{
  string s; cin >> s;
  int ans = 0;
  int length = 0;
  REP(i, SIZE(s)) {
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') length++;
    else {
      ans = max(ans, length);
      length = 0;
    }
    if (i == SIZE(s) - 1) ans = max(ans, length);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[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 , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{r:i64,g:i64,b:i64};
    println!("{}", if (r*100+g*10+b) % 4 == 0 {"YES"} else {"NO"});
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

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

    int N, result = 0;
    scanf("%d", &N);

    vector<int> B(N -1);
    for(int i = 0; i < N -1; i++)
        scanf("%d", &B[i]);

    for(int i = 0; i < N - 2; i++)
        result += min(B[i], B[i + 1]);
    result += B[0];
    result += B[N - 2];

    cout << result << endl;

    return 0;
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int main(){
  int N,M;cin >> N >> M;
  vector<pair<int,int>> BRIDGES(M);
  for(int i = 0;i < M;i++){
    cin >> BRIDGES[i].second >> BRIDGES[i].first;
  }
  sort(BRIDGES.begin(),BRIDGES.end());
  for(int i = 0;i < M;i++){
    swap(BRIDGES[i].first,BRIDGES[i].second);
  }
  int memo = -1,ans = 0;
  for(int i = 0;i < M;i++){
    if(memo >= BRIDGES[i].first){
      continue;
    }else{
      memo = BRIDGES[i].second - 1;
      ans++;
    }
  }
  cout << ans << endl;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

#define int ll

const int inf = 1ll<<62;
const int mod = 1e9+7;

main(){
  int n; cin >> n;
  int ans = 0, tmp = 0;
  rep(i, n){
    int a; cin >> a;
    if(a) tmp += a;
    else{
      ans += tmp / 2;
      tmp = 0;
    }
  }
  ans += tmp / 2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int i, n, m;
  vector<int> data;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    for(i=0; i<n; ++i)
      data.push_back(i+1);

    i = 0;
    while(data.size() != 1){
      i = i + m - 1;
      i %= data.size();
      data.erase(data.begin()+i);
    }

    cout << data[0] << endl;
    data.clear();
  }

  return 0;
}

Measured memory_bytes: 0
package main

import (
	"fmt"
)

//2で割れる回数を返す
func DivideBy2(i int)int {
	cnt := 0
	num := i
	for num % 2 == 0 {
		cnt++
		num /= 2
	}
	return cnt
}

func main() {
	var n  int
	fmt.Scan(&n)
	
	//2で割れる回数が最も多い数字を格納する変数を初期化
	max_num := 0
	
	//2で割れる最大の回数を格納する変数を初期化（仮に-1とする）
	max_cnt := -1
	for i := 1; i <= n; i++ {
		if DivideBy2(i) > max_cnt {
			max_cnt = DivideBy2(i)
			max_num = i
		}
	}
	fmt.Println(max_num)
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif
#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;
const int MO=1e9+7; 
int dx[]={-1,-1,-1,0,0,1,1,1};
int dy[]={-1,0,1,-1,1,-1,0,1};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<endl;;}
inline int powerexp(int a,int b,int m){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
void solve(){
  int h,w;
  cin>>h>>w;
  vector<string> grid(h),ans(h);
  for(auto& it:grid)cin>>it;
  for(int i=0;i<h;i++){
  	for(int j=0;j<w;j++){
       if(grid[i][j]=='#')ans[i]+='#';
       else{
           ans[i]+='0';
           for(int x=0;x<8;x++){
           	int nx=i+dx[x];
           	int ny=j+dy[x];
           	if(nx<0 or ny<0 or nx>=h or ny>=w)continue;
            if(grid[nx][ny]=='#')ans[i][j]++;
           }
       }
  	} 	
  }
  print(ans);
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
    IOS;
    solve();
    #ifdef LOCAL_DEFINE
    cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
    #endif
}

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

int q;
int len[1005][1005];

int common(string a,string b,int m,int n){
    int i,j;
    for(i=0;i<=m;i++)len[i][0]=0;
    for(i=0;i<=n;i++)len[0][i]=0;
    for(i=0;i<m;i++){
        for(j=0;j<n;j++){
            if(a[i]==b[j])len[i+1][j+1]=len[i][j]+1;
            else len[i+1][j+1]=max(len[i+1][j],len[i][j+1]);
        }
    }
    return len[m][n];
}

int main()
{
    cin>>q;
    int i;
    for(i=0;i<q;i++){
        string a,b;
        cin>>a>>b;
        int m=a.length();
        int n=b.length();
        cout<<common(a,b,m,n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 7068
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		String ph = new String();

		
			while(sc.hasNext()) {
				ph = sc.nextLine();
				if  (ph.equals("0")) break; 
				System.out.printf("%d\n", CalcScore(ph));
			}

	}
	
	public static int CalcScore(String dk) {
		int[] score = {0, 11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10};
		int max = 0;
		int min = 0;
		String[] plh = new String[5];
		ArrayList<Integer> ph = new ArrayList<Integer>();
		int cntAce = 0;
		
			plh = dk.split(" ");
				for (String s : plh) {
					ph.add(Integer.parseInt(s));
						if (Integer.parseInt(s) == 1) {
							++cntAce;
						}
				}
			
			for (int cd : ph) {
				max += score[cd];
				
					if (cd == 1) {
						min += 1;
					} else {
						min += score[cd];
					}
			}
			
			int tmp = min;
			
			for (int i = 0; i < cntAce; i++) {
				tmp += 10;
					if (tmp > 21)  {
						break;
					} else {
						min = tmp;
					}
				
			}
			
		if (max > 21) max = 0;
		if (min > 21) min = 0;
			
		return Math.max(max, min);
	}
}


Measured memory_bytes: 26972
#include <stdio.h>
int main(void)
{
  int n,d1,d2,max,a[10000][2],i,j;
  while(1){
    scanf("%d",&n);
    if(n==0)
      break;
    for(i=0;i<n;i++){
      scanf("%d %d %d",&a[i][0],&d1,&d2);
      a[i][1]=d1+d2;
    }

    max=a[0][1];
    j=0;
    for(i=0;i<n;i++){
      if(a[i][1]>max){
	max=a[i][1];
	j=i;
      }
    }
    printf("%d %d\n",a[j][0],a[j][1]);
  }

  return 0;
}

Measured memory_bytes: 676
#include <iostream>
#define int long long
using namespace std;
int32_t main() {
  string s;
  cin >> s;
  int p = 0;
  for(char c : s) {
  	int dig = c - '0';
    p += dig;
  }
  if(p % 9) cout << "No\n";
  else cout << "Yes\n";
  return 0;
}


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


int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int d, s, t;
    cin >> d >> s >> t;
    if((s*t) >= d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

using namespace std;
constexpr int NMAX = 1000010;

char curPar[NMAX];

int signum(int i) {
	return (0 < i) - (i < 0);
}

void answer(bool b) {
	if (b) printf("Yes\n");
	else printf("No\n");
	exit(0);
}

int main() {
	int n; scanf("%d", &n);
	vector<pair<int, int>> parBalance(n);
	for (int i = 0; i < n; ++i) {
		scanf("%s", curPar);
		int cBal = 0;
		for (int k = 0; curPar[k]; ++k) {
			cBal += (curPar[k] == '(' ? 1 : -1);
			parBalance[i].first = min(parBalance[i].first, cBal);
//			printf("%d char %d bal %d\n", i, k, cBal);
		}
		parBalance[i].first *= -1;
		parBalance[i].second = cBal;
//		printf("pbal %d\n", parBalance[i].first);
	}
	sort(begin(parBalance), end(parBalance), [] (pair<int, int> i, pair<int, int> j) {
//		printf("sorting %d %d %d %d\n", i.first, i.second, j.first, j.second);
		if (signum(i.second) != signum(j.second)) return signum(i.second) > signum(j.second);
		else if (signum(i.second) == 1) return i.first < j.first;
		else if (signum(i.second) == -1) return i.first + i.second > j.first + j.second;
		else return i.first < j.first;
	});
	// now we can attempt to construct the string
	int cCoeff = 0;
	for (auto req_d : parBalance) {
		//printf("order %d %d\n", req_d.first, req_d.second);
		if (cCoeff < req_d.first) {
			answer(false);
		}
		cCoeff += req_d.second;
	}
	if (cCoeff == 0) answer(true);
	else answer(false);
	return 0;
}


Measured memory_bytes: 11504
my $a_500 = <>;
my $b_100 = <>;
my $c_50 = <>;
my $x = <>;
my $result = 0;

for my $i (0..$a_500) {
    for my $j (0..$b_100) {
        for my $k (0..$c_50) {
            my $sum = $i * 500 + $j * 100 + $k * 50;
            $result++ if $sum == $x;
        }
    }
}
print $result;


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

const int MAXN = 500010;
typedef double db;
int n, L, vs[MAXN];
db ts[MAXN], tov;
int b, e;
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(8);
	std::cin >> n >> L; int tl = 0;
	for (int i = b = 1, v; i <= n; ++i) {
		db t; std::cin >> t >> v; tl += v; tov += v * t;
		while (tl > L) {
			int res = std::min(tl - L, vs[b]);
			tov -= ts[b] * res; vs[b] -= res; tl -= res;
			if (!vs[b]) ++b;
		}
		std::cout << tov / L << '\n';
		while (b <= e && t <= ts[e])
			t = (t * v + ts[e] * vs[e]) / (v + vs[e]), v += vs[e], --e;
		++e; ts[e] = t, vs[e] = v;
	}
	return 0;
}


Measured memory_bytes: 15488
#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int,int>
#define ppb pop_back
#define orta ((bas+son)>>1)
#define st first
#define nd second
#define ll long long
#define N 200005
#define inf 1000000005
#define MOD 1000000007
#define LOG 20
#define EPS 0.000000001
#define M 305
using namespace std;

int n,k;
double a[N];

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);	

	cin>>n>>k;
	for(int i=1;i<=n;i++) {
		int x;
		cin>>x;
		a[i]=(x+1)/2.0;
		a[i]+=a[i-1];
	}
	double ans=0;
	for(int i=k;i<=n;i++) {
		ans=max(ans,a[i]-a[i-k]);
	}
	cout<<fixed<<setprecision(12)<<ans;

}

Measured memory_bytes: 1792
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    using namespace std;
    #define INF 10000000;
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

  
  
    int main(){
      string s;
      cin >> s;
      int size = s.size()-1;
      long sum = 0;
      for(int i=0;i<(1<<size);i++){
        long cur = 0;
        rep(j,size+1){
          if(i & (1<<j-1) && j){
            sum += cur;
            cur = 0;
          }
          cur = cur*10 + (s[j]-'0');
          
        }
        sum += cur;
        
      }
      cout << sum <<endl;
      }


    


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

 
int main(){
	string s;
	cin>>s;
	int k;
	cin>>k;
	int n=s.size();
	rep(i,n){
		int dis='z'-s[i];
		if(dis<k&&s[i]!='a'){
			s[i]='a';
			k-=dis+1;
		}
		if(i==n-1&&k>0){
			int m=s[i]-'a';
			m+=k;
			m%=26;
			s[i]='a'+m;
		}
		//cout<<k<<endl;
	}
	cout<<s<<endl;
}


Measured memory_bytes: 512
import javax.swing.DefaultBoundedRangeModel

object Main extends App {
  import scala.io.StdIn._

  val MOD = 1000000007L
  val Array(n, k) = readLine.trim.split(' ').map(_.toInt)
  val factorial = Array.fill(2000){1L}
  val inv = Array.fill(2000){1L}
  val invF = Array.fill(2000){1L}
  for (i <- 2 until factorial.length) {
    factorial(i) = i * factorial(i - 1) % MOD
    inv(i) = (MOD - MOD / i) * inv((MOD % i).toInt) % MOD
    invF(i) = inv(i) * invF(i - 1) % MOD
  }
  for (i <- 1 to k) {
    val blue = split(k, i)
    val red = (split(n - k, i - 1) + split(n - k, i) * 2 + split(n - k, i + 1)) % MOD
    println(blue * red % MOD)
  }
  def split(n: Int, k: Int): Long = {
    if (n == 0 && k == 0) 1L
    else if (k < 1 || n < k) 0L
    else combination(n - 1, k - 1)
  }
  def combination(n: Int, r: Int): Long = {
    factorial(n) * invF(r) % MOD * invF(n - r) % MOD
  }
}

Measured memory_bytes: 25544
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>
#include <map>
using namespace std;


vector<int> v;
map<int, int> d;

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

   unsigned int sz = 1e+6 + 5;
   v.assign(sz, 0);

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

   }

   for (const auto p : d)
   {
      int cur = p.first;
      v[cur]--;
      for (int i = cur; i < sz; i += cur)
      {
         v[i] += p.second;
      }
   }

   int ans = 0;
   for (const auto p : d)
   {
      //cout << p.first << " " << p.second << " " << v[p.first] << "\n";
      if (v[p.first] == 0)
      {
         ans += p.second;
      }
   }

   cout << ans;

   return 0;
}

Measured memory_bytes: 16356
int main(void)
{
  int a,b,c,d;
  int flag = 0;
  
  scanf("%d%d%d%d",&a,&b,&c,&d);  
  
  while(a>0){
    c -= b;
	a -= d;
	if(c<=0){
      flag=1;
      break;
    }
  }
  
  if(flag == 1)
  printf("Yes\n");
  
  else 
    printf("No\n");
  
  return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+9;
ll n,k,a[N],ans[N];

int main()
{   
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
    cin>>s;
    cin>>t;
    t.pop_back();
    cout<<(s==t?"Yes":"No");
    
    return 0;
}


Measured memory_bytes: 3648
using System;
using System.Linq;

namespace ABC072
{
    class A
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int X = input[0];
            int t = input[1];

            if (X <= t) Console.WriteLine(0);
            else Console.WriteLine(X - t);

        }
    }
}


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

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)



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


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

    //freopen("1.txt","rt",stdin);
    //freopen("output.txt","wwt",stdout);

    ll t;
    t=1;
    //cin>>t;
    //ll t1=0;
    while(t--)
    {
       ll h,w;
       cin>>h>>w;
       string s[h];
       for(ll i=0;i<h;i++)
        cin>>s[i];
       ll ans=0; 
       for(ll i=0;i<h;i++)
       {
           for(ll j=0;j<w;j++)
           {
               if(s[i][j]=='.')
               {
                   queue<pair<ll,pair<ll,ll>> >q;
                   vector<vector<ll> >visited(h,vector<ll>(w,0));
                   q.push({0,{i,j}});
                   ll mx=0;
                   while(!q.empty())
                   {
                     pair<ll,pair<ll,ll> >q1=q.front();
                     q.pop();  
                     ll d=q1.first;
                     ll x=q1.second.first;
                     ll y=q1.second.second;
                     if(visited[x][y] == 1) {
                         continue;
                     }

                     visited[x][y] = 1;


                     mx=max(mx,d);

                     if(y<w-1&&s[x][y+1]=='.')
                      q.push({d+1,{x,y+1}});
                     if(y>0&&s[x][y-1]=='.')
                      q.push({d+1,{x,y-1}});
                     if(x<h-1&&s[x+1][y]=='.')
                      q.push({d+1,{x+1,y}});
                     if(x>0&&s[x-1][y]=='.')
                      q.push({d+1,{x-1,y}});   
                   }
                   ans=max(ans,mx);   
               }
           }
       }
       cout<<ans;
    }
}


Measured memory_bytes: 3548
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    string s;
    cin>>s;
    rep(i,s.size()){
        if(s[i]=='?'){
            s[i]='D';
        }

    }
    cout<<s<<endl;
return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#include <iostream>
#include <string>

#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define phi 3.1415926535
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
 
using namespace std;

const ll mod = 1000000007;    

ll tc, cnt = 0, number, many, total = 0, query;
// vector <vector <int> > adjList;
int rmove[8] = {-1, 0, 1, 0, -1, 1, -1, 1};
int cmove[8] = {0, 1, 0, -1, 1, -1, -1, 1};

ll power(ll x, ll y, ll mod)
{
    if(y == 0)
        return 1;
    else if(y % 2 == 0)
        return (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod;
    else
        return x * (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod;
}

int main()
{
    fastio();
        
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    // g++ -std=c++11 Default.cpp  -o test
    // g++ -Wl,--stack=268435456 -std=c++11 Default.cpp  -o test

    cin >> many >> number;

    int arr[many];
    for(int i = 0; i < many; i++)
        cin >> arr[i];

    int dp[many];
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;

    for(int i = 0; i < many; i++)
    {
        for(int j = i + 1; j <= i + number && j < many; j++)
        {
            if(dp[j] == -1)
                dp[j] = dp[i] + abs(arr[j] - arr[i]);
            else
                dp[j] = min(dp[i] + abs(arr[j] - arr[i]), dp[j]);
        }
    }

    // for(int i = 0; i < many; i++)
    //     cout << dp[i] << " ";
    // cout << endl;

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

    //
    return 0;
}

Measured memory_bytes: 4388
#include <iostream>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    for(int i = 1; i < s.size(); ++i){
        vector<bool> f(255, false);
        for(int j = 0; j < i; ++j){
            f.at(s.at(j)) = true;

        }
        ll tmp = 0;
        for(int j = i; j < s.size(); ++j){
            if(f.at(s.at(j))){
                tmp++;
                f.at(s.at(j)) = false;
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N, ans = LONG_LONG_MAX;
    cin >> N;
    
    for (ll i = 1; (i * i) <= N; i++) {
        if ((N % i) != 0) {
            continue;
        }
        
        ans = min(ans, (N / i) + i - 2);
    }
    
    cout << ans << endl;
    return 0;
}

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

const int N = 110;
const long long inf = 1e18;

int n, W;
int w[N], v[N], base;
long long dp[N][N][3 * N];
long long ans;

void mxm(long long &a, long long b) {
	if (a < b) a = b;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> W;
	for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i];

	base = w[1];
	for (int i = 1; i <= n; ++i) w[i] -= base;

	for (int i = 0; i < N; ++i) {
		for (int choose = 0; choose < N; ++choose) {
			for (int add = 0; add <= choose * 3; ++add) {
				dp[i][choose][add] = -inf;
			}
		}
	}
	
	dp[0][0][0] = 0;
	for (int i = 1; i <= n; ++i) {
		for (int choose = 0; choose < i; ++choose) {
			for (int add = 0; add <= 3 * choose; ++add) {
				if (dp[i-1][choose][add] == -inf) continue;
				// don't choose a[i]
				mxm(dp[i][choose][add], dp[i-1][choose][add]);
				// choose a[i]
				long long real_sum = 1LL * (choose + 1) * base + add + w[i];
				if (real_sum <= W) {
					mxm(dp[i][choose + 1][add + w[i]], dp[i-1][choose][add] + v[i]);
				}
			}
		}
	}

	for (int choose = 0; choose <= n; ++choose) {
		for (int add = 0; add <= 3 * choose; ++add) {
			ans = max(ans, dp[n][choose][add]);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 31488
import sys

n = int(input())
print(0)
sys.stdout.flush()
ls = input()
if ls == 'Vacant':
    exit()
print(n - 1)
sys.stdout.flush()
if input() == 'Vacant':
    exit()
l = 0
r = n - 1
while l != r - 1:
    mid = (l + r) // 2
    if mid % 2 == 1:
        mid += 1
    if mid == r:
        mid -= 1
    print(mid)
    sys.stdout.flush()
    nex = input()
    if nex == 'Vacant':
        exit()

    if ls == nex:
        l = mid
    else:
        r = mid

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

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#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(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

template <int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod)
            x -= mod;
    }
    ModInt &operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod)
            x -= mod;
        return *this;
    }
    ModInt &operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0)
            x += mod;
        return *this;
    }
    ModInt &operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt &operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
    friend ostream &operator<<(ostream &s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream &operator>>(istream &s, ModInt<mod> &a) {
        s >> a.x;
        return s;
    }
};
using mint = ModInt<MOD>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<int> v(n);
    map<int, int> mp;
    mint ans = 0;
    REP(i, n) cin >> v[i];
    REP(i, n) {
        FOR(j, i + 1, n) {
            if (v[i] > v[j]) {
                ans += (k + 1) * k / 2;
            } else if (v[i] < v[j]) {
                ans += (k - 1) * k / 2;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    string s;
    cin >> s;
    SORT(s);
    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <vector>
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

const int inf = 1e9 + 7;
const long long INF = 1e18 + 7;
const int maxn = 2e5 + 7;

int sx, sy, tx, ty, curx, cury;
map < pair < int, int >, bool > m;
string s;

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cout.tie(0);
	cin >> sx >> sy >> tx >> ty;
	curx = sx;
	cury = sy;
	while (cury < ty){
		cury++;
		s += 'U';
	}
	while (curx < tx){
		curx++;
		s += 'R';
	}
	while (cury > sy){
		cury--;
		s += 'D';
	}
	while (curx > sx){
		curx--;
		s += 'L';
	}
	curx--;
	s += 'L';
	while (cury < ty){
		cury++;
		s += 'U';
	}
	cury++;
	s += 'U';
	while (curx < tx){
		curx++;
		s += 'R';
	}
	cury--;
	s += 'D';
	curx++;
	s += 'R';
	while (cury > sy){
		cury--;
		s += 'D';
	}
	cury--;
	s += 'D';
	while (curx > sx){
		curx--;
		s += 'L';
	}
	cury++;
	s += 'U';
	cout << s;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N;string s;cin>>N>>s;
  std::vector<int> v(N+1,0);
  for(int i=0;i<N;i++)v[i+1]=v[i]+(s[i]=='#');
  int ans=LINF;
  for(int i=0;i<=N;i++)ans=min(ans,v[i]-v[0]+N-i-(v[N]-v[i]));
  cout<<ans<<endl;
}


Measured memory_bytes: 2180
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

struct UnionFind {
  vector<int> par, siz;

  UnionFind(int n) : par(n), siz(n, 1) {
    for (int i = 0; i < n; ++i) par[i] = i;
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);

    if (x == y) return false;

    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x) {
    return siz[root(x)];
  }
};

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n, m; cin >> n >> m;
  UnionFind uf(n);

  rep(i, m) {
    int a, b; cin >> a >> b;
    uf.unite(a-1, b-1);
  }

  int ans = 0;
  rep(i, n) chmax(ans, uf.size(i));

  cout << ans << endl;
  
  return (0);
}

Measured memory_bytes: 4776
#include<iostream>
using namespace std;
int main(void){
	int x,y,t;
	while(1){
		int i=0;
		cin >> x >> y;
		if(x == 0 && y == 0) break;
		else if(x < y){
			t = x;
			x = y;
			y = t;
		}while(y !=0){
			x %=y;
			t = x;
			x = y;
			y = t;
			i +=1;
		}cout << x << " " << i << endl;
		
	}
}

Measured memory_bytes: 1164
package main

import (
	"fmt"
)

func main() {
	var M int
	fmt.Scan(&M)
	var D int
	fmt.Scan(&D)
	var count int
	for i := 1; i <= M; i++ {
		for j := 1; j <= D; j++ {
			d1 := j % 10
			d10 := j / 10
			mm := d1 * d10
			if d1 >= 2 && d10 >= 2 && (i == mm) {
				count++
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#include<stdio.h>

int m,n;
int thickness[100];

int ok(int x){
	int i,j=0,w;
	for(i=0;i<m;i++){
		w=x;
		while(j<n&&thickness[j]<=w)w-=thickness[j++];
		if(j==n)break;
	}
	return j==n;
}
int main(){
	int i,l,mid,r;
	while(scanf("%d%d",&m,&n)==2&&(m||n)){
		for(i=0;i<n;i++)scanf("%d",&thickness[i]);
		l=1;r=1500000;
		while(1<r-l){
			mid=(l+r)/2;
			if(ok(mid))r=mid;
			else l=mid;
		}
		printf("%d\n",r);
	}
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,m;
    cin >> n >> m;
    vector<int32> h(n);
    REP(i,n)cin >> h[i];
    vector<bool> good(n,true);
    REP(i,m){
        int32 a,b;
        cin >> a >> b;
        a--;b--;
        if(h[a] == h[b]){
            good[a] = good[b] = false;
        }else if(h[a] > h[b]){
            good[b] = false;
        }else{
            good[a] = false;
        }
    }
    int32 ans = 0;
    REP(i,n)if(good[i])ans++;
    ANS(ans);
    return 0;
}

Measured memory_bytes: 3992