akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
using namespace std;

int main(){
    long long n; cin >> n;
    for(long long i = (long long)sqrt(n); i>0LL; --i){
        if(n%i == 0LL){cout << (int)max(log10(i)+1LL, log10(n/i)+1LL) << endl; return 0;}
    }
}

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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (s == u) {
        cout << a - 1 << " " << b;
    } else {
        cout << a << " " << b - 1;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
dp = [0 for i in range(n+1)]

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            res = x**2+y**2+z**2+x*y+y*z+z*x
            if res<=n:
                dp[res]+=1

for i in range(1,n+1):
    print(dp[i])


Measured memory_bytes: 69616
# ARC080D - Grid Coloring (ABC069D)
def main():
    H, W = tuple(map(int, input().split()))
    N = int(input())
    A = tuple(map(int, input().split()))
    F = []  # flatten grid
    for color, cnt in enumerate(A, 1):
        F += [color] * cnt
    par = 1  # parity
    for i in range(1, H + 1):
        if par:
            print(*F[(i - 1) * W : i * W])
        else:
            print(*F[(i - 1) * W : i * W][::-1])
        par ^= 1


if __name__ == "__main__":
    main()

Measured memory_bytes: 3828
n = gets.to_i
nums = gets.split.map(&:to_i)

min = nil

nums.min.upto(nums.max) do |point|
  sum = 0
  nums.each do |num|
    sum += (point - num) ** 2
  end

  if min
	min = [min, sum].min
  else
    min = sum
  end
end
  
puts min



Measured memory_bytes: 3836
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector <ll>
#define vii vector <int>
#define vpii vector <pii>
#define vpll vector <pll>
#define ff first
#define ss second
#define vvll vector <vll>
#define vvii vector <vii>
#define all(v) v.begin(),v.end()
#define PQ priority_queue
using namespace std;
ll mod = 1000000007;
ll pow(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b&1) res*=a;
		b/=2;
		a*=a;
	}
	return res;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	int arr[n];
	int r_idx = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'R'){
			r_idx = i;
		}
		else arr[i] = r_idx;
	}
	int l_idx = n-1;
	for(int i = n-1; i >= 0; i--){
		if(s[i] == 'L') l_idx = i;
		else arr[i] = l_idx;
	}
	ll ans[n] = {0};
	for(int i = 0; i < n; i++){
		if((i-arr[i])%2 == 0){
			ans[arr[i]]++;
		}
		else{
			if(s[i] == 'L'){
				ans[arr[i]+1]++;
			}
			else ans[arr[i]-1]++;
		}
	}
	for(int i = 0; i < n; i++){
		cout << ans[i] << " ";
	}	
	cout << "\n";
	return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

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

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();

    return 0;
}

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

using namespace std;

int main() {
	long long X, K, D;
	cin >> X >> K >> D;

	long long answer, tmp;

	X = abs(X);
	tmp = X / D;

	if(tmp >= K) {
		answer = X - K*D;
	} else {
		if((K - tmp) % 2 == 0) {
			answer = X - tmp*D;
		} else {
			answer = min(abs(X - tmp*D + D), abs(X - tmp*D - D));
		}
	}	

	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 3616
def insert_sorted_array(a, i)
  (a << i; return 0) if a.size == 0
  (a << i; return 1) if a.size == 1 && a[0] < i
  (a.unshift(i); return 0) if a.size == 1
   l = 0; h = a.size - 1
  (a.unshift(i); return 0) if a[l] >= i
  (a << i; return a.size - 1) if a[h] <= i
  while(h - l > 1) do
    m = (h - l) / 2 + l
    (a[m] > i) ? h = m : l = m
  end
  a.insert(h, i)
  return h
end

Q = gets.to_i
query = []
Q.times{|q|
  query << gets.chomp.split(" ").map(&:to_i);
}

#←  l  →m←  h   →
#d = h - l
q = query.shift
a = [q[1]]
b = q[2]
d = 0
query.each{|q|
  if q[0] == 1 then
    b += q[2]
    m = (a.size - 1) / 2
    po = insert_sorted_array(a, q[1])
    if a.size.even? then
      if m >= po then
        d += a[m + 1] + a[m] - q[1]
      else
        d += q[1]
      end
    else
      if m >= po then
        d -= q[1]
      else
        d += q[1] -a[m + 1] - a[m]
      end
    end
  else
    m = (a.size - 1) / 2
    if a.size.even? then
      printf("#{a[m]} #{d - a[m] + b}\n")
    else
      printf("#{a[m]} #{d + b}\n")
    end
  end
}


Measured memory_bytes: 24700
import math
o, b = map(int, input().split())
def pi(a):
    s= 0
    a+=1
    p = math.log2(a)
    p = int(p)
    qq=1
    q = 2
    ans =0
    t = 0
    t = a//2
    ans += t%2

    for i in range(1,p+1):
        qq = q

        q*=2
        t = a%(q)
        ans += qq*(max(0,t-qq)%2)
    return ans
print((pi(b)^pi(o))^o)


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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<int> edges[200010];
vector<int> c(200010,0);

void dfs(int i,int p = -1) {
    for (int& j : edges[i]) if (j != p) {
        c[j] += c[i];
        dfs(j,i);
    }
}

int main() {
    int n,q;
    cin >> n >> q;
    for (int i = 0;i < n-1;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    for (int i = 0;i < q;++i) {
        int p,x;
        cin >> p >> x;
        c[p-1] += x;
    }
    dfs(0);
    for (int i = 0;i < n;++i) cout << c[i] << " \n"[i == n-1];
    return 0;
}

Measured memory_bytes: 23424
#include <bits/stdc++.h>
#include <math.h>
#include <iostream>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main(void){
    string S;
    cin >> S;
    if(S=="Sunny"){
        cout << "Cloudy" << endl;
    }
    else if(S=="Cloudy"){
        cout << "Rainy" << endl;
    }
    else{
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, M, X = gets.split.map &:to_i
A = $<.map{|s| s.split.map &:to_i }

ans = 1.0/0

(2**N).times{|bits|
  c = 0
  a = [0] * M
  N.times{|i|
    next if bits[i] == 0
    cc, *aa = A[i]
    c += cc
    a = a.zip(aa).map{|x, y| x + y }
  }
  next if c >= ans
  ans = c if a.all?{|x| x >= X }
}

p ans == 1.0/0 ? -1 : ans

Measured memory_bytes: 14376
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=II()
  l=LI()

  zcnt=l.count(0)
  c=0
  i=0

  while True:
    if zcnt==n:
      break
    if i>=n:
      i=0
    if l[i]>0:
      c+=1
      while True:
        if i<n and l[i]>=1:
          l[i]-=1

          if l[i]==0:
            zcnt+=1

          i+=1
        else:
          break
    else:
      i+=1

  return c

print(main())


Measured memory_bytes: 6308
n = int(input())
a= [input() for i in range(n)]

ca=a.count('AC')
cw=a.count('WA')
ct=a.count('TLE')
cr=a.count('RE')
print('AC x',ca)
print('WA x',cw)
print('TLE x',ct)
print('RE x',cr)

Measured memory_bytes: 16296
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main()
{
#ifndef LOCAL
	ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
	ll n, m; cin >> n >> m;
	string s, t; cin >> s >> t;
	ll l1 = n / __gcd(n, m), l2 = m / __gcd(n, m);
  	rep(i, 0, __gcd(n, m)){
		if(s[i * l1] != t[i * l2]){
			cout << "-1\n";
			return 0;
		}
	}
	cout << n * m / __gcd(n, m) << "\n";
    return 0;
}

Measured memory_bytes: 640
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader bf =new BufferedReader(new InputStreamReader(System.in));
		String s,t;
		char c;
		while((s=bf.readLine())!=null){
			t="";for(int i=0,j=s.length();i<j;i++){c=s.charAt(i);t+=(char)((c>=97&&c<=123)?(c-32):(c));}
			System.out.println(t);
		}
	}
}

Measured memory_bytes: 9256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n: usize,
        mut s: [chars; n],
    }
    let mut res = 0u64;
    let mut cnt = vec![0u64; 5];
    let P = vec![0, 0, 0, 0, 0, 0, 1, 1, 1, 2];
    let Q = vec![1, 1, 1, 2, 2, 3, 2, 3, 2, 3];
    let R = vec![2, 3, 4, 3, 4, 4, 3, 4, 4, 4];
    for c in s {
        let s_ = c[0];
        match s_ {
            'M' => cnt[0] += 1,
            'A' => cnt[1] += 1,
            'R' => cnt[2] += 1,
            'C' => cnt[3] += 1,
            'H' => cnt[4] += 1,
            _ => continue,
        }
    }
    for i in 0..10 {
        res += (cnt[P[i]] * cnt[Q[i]] * cnt[R[i]]);
    }
    println!("{}", res);
}


Measured memory_bytes: 12540
using System;

class Program
{
	static void Main()
	{
		var input = Console.ReadLine().Split();
		var a = int.Parse(input[0]);
		var b = int.Parse(input[1]);

		var result = a.CompareTo(b);

		if (result == -1)
			Console.WriteLine("a < b");

		if (result == 0)
			Console.WriteLine("a == b");

		if (result == 1)
			Console.WriteLine("a > b");
	}
}

Measured memory_bytes: 8916
import numpy as np
w,h,n = map(int, input().split())
d = np.array([[1]*w for _ in range(h)], dtype=int)
for _ in range(n):
  x,y,a = map(int, input().split())
  for i in range(w):
    for j in range(h):
      if a==1 and i<x:
        d[j][i] = 0
      elif a==2 and x<=i:
        d[j][i] = 0
      elif a==3 and j<y:
        d[j][i] = 0
      elif a==4 and y<=j:
        d[j][i] = 0
  #print(d)
print(sum(sum(x) for x in d))

Measured memory_bytes: 12508
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long ull;
typedef long long ll;

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

using namespace std;

typedef pair<int ,int > P;

int n,ans;

int main()
{
	while(cin>>n)
	{
		ans=0;
		rep(a,10) rep(b,10) rep(c,10) rep(d,10) if(a+b+c+d==n) ans++;
		cout<<ans<<endl;
	}


	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int qmax(int &x,int y) {if (x<y) x=y;}
int qmin(int &x,int y) {if (x>y) x=y;}
int read()
{
    char s;
    int k=0,base=1;
    while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
    if(s=='-')base=-1,s=getchar();
    while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
    return k*base;
}
inline void write(int x)
{
    static char cnt,num[15];cnt=0;
    if (!x)
    {
        putchar('0');
        return;
    }
    for (;x;x/=10) num[++cnt]=x%10;
    for (;cnt;putchar(num[cnt--]+48));
}
int n;
long long s,s2;
int a[10100];
int b[10100];
int main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int j=1;j<=n;j++) b[j]=read();
	for (int i=1;i<=n;i++)
	{
		if (a[i]<b[i]) s+=(b[i]-a[i])/2;
		if (b[i]<a[i]) s2+=a[i]-b[i];
	} 
	if (s2>s)
	{
		printf("No");
	} else
	{
		printf("Yes");
	}
	return 0;
} 

Measured memory_bytes: 384
while True:
    a, op, b = input().split()   # 3変数ともに文字列として読み込む
    a = int(a)                   # a を整数に変換
    b = int(b)                   # b を整数に変換

    if op=="?": # opが"?"の時は終了
        break
    else:    #opが"?"以外の時
        if op == '+':
            print(a+b)
        if op == '-':
            print(a-b)
        if op == '*':
            print(a*b)
        if op == '/':
            print(a//b)
      
        

        # ここ処理を書いてください
        # else のなかです。この通りのインデントを付けてください。




Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << "/n"
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    vector<vector<char>> g(h,vector<char> (w));
    rep(i,h) rep(j,w) cin >> g[i][j];

    rep(i,2*h){
        rep(j,w){
            cout << g[i/2][j];
        }
        cout << endl;
    }

}

Measured memory_bytes: 256
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
s=sorted(a,reverse=True)
M1=s[0]
M2=s[1]

if M1==M2:
  for i in range(n):
    
    print(M1)
else:
  key=a.index(M1)
  for i in range(n):
    if i==key:
      print(M2)
    else:
      print(M1)

Measured memory_bytes: 14112
def resolve():
    N, K = list(map(int, input().split()))
    AB = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[0])
    length = 0
    idx = 0
    val = None
    while True:
        if length >= K:
            break
        length += AB[idx][1]
        val = AB[idx][0]
        idx += 1
    print(val)
    

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 29912
a, b = input().split()

a = int(a)

c1 = a * int(b[0])
c2 = a * int(b[2])
c3 = a * int(b[3])

int_c2 = (c2 - c2 % 10) // 10
d2 = c2 % 10

int_c3 = (c3 - c3 % 100) // 100
d3 = c3 % 100

d = d2 * 0.1 + d3 * 0.01
d = int(d)

ans = c1 + int_c2 + int_c3 + d

print(int(ans))


Measured memory_bytes: 9124
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int a,b;
	cin>>a>>b;
	if(a<=5){
		cout<<0;
	}else if(a<=12){
		cout<<b/2;
	}else{
		cout<<b<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
//setprecision(10);
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
        return b != 0 ? gcd(b, a % b) : a;
    }

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int l; cin>>l;
    int cnt=0;
    int ans=inf;
    int g=0;
    for(int i=1; i<=n; i++)
    {
        if(ans>=abs(l+i-1))
        {
            g=i;
            ans=abs(l+i-1);
        }
        cnt+=l+i-1;
    }
    cout<<cnt-(l+g-1)<<endl;

    return  0;
}


Measured memory_bytes: 256
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    string s;cin>>s;
    ll n=s.size();

    if(n<26){
        char c='a';
        while(1){
            bool ok=true;
            rep(i,n){
                if(s[i]==c)ok=false;
            }
            if(ok){
                s+=c;
                cout<<s<<endl;
                return;
            }
            ++c;
        }
    }

    vector<char> a;
    rrep(i,n-1){
        a.push_back(s[i+1]);
        if(s[i]<s[i+1]){
            a.push_back(s[i]);
            sort(all(a));
            char nxt='z';
            for(char c1:a){
                if(c1>s[i]){
                    chmin(nxt,c1);
                    break;
                }
            }
            s[i]=nxt;
            cout<<s.substr(0,i+1)<<endl;
            return;
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 256
def calc(lst):
	if lst[0] == 7:
		if lst[1] == 5 and lst[2] == 5:
			return 'YES'
		else:
			return 'NO'
	elif lst[0] == 5:
		if lst[1] == 7:
			if lst[2] == 5:
				return 'YES'
			else:
				return 'NO'
		elif lst[1] == 5:
			if lst[2] == 7:
				return 'YES'
			else:
				return 'NO'
		else:
			return 'NO'
	else:
		return 'NO'

inpt = map(int, raw_input().split())

print calc(inpt)

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  int p = 0;
  for (int x = A; x <= B; x++){
    int x_4 = x / 10000;
    int x_3 = x / 1000 % 10;
    int x_1 = x / 10 % 10;
    int x_0 = x % 10;
    if (x_4 == x_0 && x_3 == x_1){
      p++;
    }
  }
  
  cout << p << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n;
  int i,x,y,a,b,p,w;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&x,&y,&a,&b);
    p=x*a+y*b;
    w=10000000;
    if(a>4&&b>1)p=p*4/5;
    else{
      w=p;
      if(a<5)w+=(5-a)*x;
      if(b<2)w+=(2-b)*y;
      w=w*4/5;
    }
    if(p>w)p=w;
    printf("%d\n",p);
  }
  return 0;
}
    

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
int main()
{

  int n;
  cin >> n;

  map<int, int> indices;
  int a[n];
  map<int, vector<int>> ax;
  map<int, vector<int>> ay;
  int x, y;

  for (int i = 0; i < n; i++) {
  	cin >> a[i];
  	int x = a[i]+(i+1);
  	int y = -a[i]+(i+1);

  	if (ax.count(x) == 0)
  		ax[x] = vector<int>();
  	if (ay.count(y) == 0)
  		ay[y] = vector<int>();
  	ax[x].push_back(i+1);
  	ay[y].push_back(i+1);
  }

  long long ans = 0;
  for (auto x: ax) {
  	if (ay.count(x.first)) {
  		ans += x.second.size()*ay[x.first].size();
  	}
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 44848
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
const int maxn = 1e5 + 5;
ll dp[maxn] , sum[maxn] , pre[maxn] , mu[maxn];
string a;
int main()
{
    ios::sync_with_stdio(false);
    cin >> a;
    int n = a.size();
    a = '#' + a;
    ll x = 0, y = 0;
    for (int i = 1 ; i <= n ; i++){
        int v = a[i] - '0';
        x = 10 * x + v;
        dp[i] = x;
        if (i != 1) {
            y = 10 * y + v;
            dp[i] += dp[1] + y;
        }
        if (i > 2){
            mu[i] = mu[i - 1] + (1 << (i - 2));
            sum[i] = (sum[i - 1]) * 10 + mu[i] * v;
            dp[i] += pre[i - 1] - pre[1] + sum[i];
        }
        pre[i] = pre[i - 1] + dp[i];
    }
    cout << dp[n] << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

struct UnionFind{
    ll par[201000];
    ll rank[201000];
    ll siz[201000];

    void init(){
        for (ll i = 0; i < 201000; i++){
            par[i] = i;
            rank[i] = 1;
            siz[i] = 1;
        }
    }

    ll find(ll x){
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    void unite(ll x, ll y){
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y]){
            par[x] = y;
            siz[y] += siz[x];
        }
        else{
            par[y] = x;
            siz[x] += siz[y];
            if (rank[y] == rank[x])rank[x]++;
        }
    }

    bool same(ll x, ll y){
        return find(x) == find(y);
    }

    ll size(ll x){
        return siz[find(x)];
    }
};

UnionFind uf;
ll n,m;

int main(){
    cin >> n >> m;
    vector<ll> f(m,-1);
    uf.init();
    rep(i,n){
        ll k;
        cin >> k;
        rep(j,k){
            ll l;
            cin >> l;
            l--;
            if(f[l] == -1)f[l] = i;
            else uf.unite(i,f[l]);
        }
    }
    set<ll> s;
    rep(i,n)s.insert(uf.find(i));
    if(s.size() == 1)cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 5760
from collections import defaultdict

def main():
    N,M = map(int, input().split())
    d = defaultdict(lambda: 0)
    A = list(map(int, input().split()))

    for a in A:
        d[a]+=1

    for _ in range(M):
        B,C = map(int, input().split())
        d[C]+=B

    d_sorted = sorted(d.items(), key=lambda x:x[0], reverse=True)
    ans = 0

    for i in range(len(d_sorted)):
        ans += d_sorted[i][0] * min(d_sorted[i][1],N)
        N -= min(d_sorted[i][1],N)
        if N == 0:
            break



    print(ans)







if __name__ == '__main__':
    main()

Measured memory_bytes: 47148
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a<b){
            System.out.println(0);
        }else{
            System.out.println(10);
        }
    }
    
}

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

typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

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

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n;
int main(){
    ll l,r;
    cin>>l>>r;
    ll smallest=2019;
    for(ll i=l;i<r;i++){
        for(ll j=i+1;j<=r;j++){
        if((!(i%2019))||(!(j%2019))){cout<<0<<endl;return 0;}
        else{
            ll temp=(i*j)%2019;
            if(smallest>temp){
                smallest=temp;
            }
        }
        }
    }
    cout<<smallest<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define sort(a) sort(a.begin(), a.end())
#define loop(n) for(ll i = 0; i<n; i++)
using namespace std;

int main(){
    int a, b; cin>>a>>b;
    cout<<6-a-b<<"\n";
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

int main(){
	
	int N;
	cin >> N;
	
	int ans = 0;
	
	for(int i = 0; i < N; i++){
		long long int num;
		cin >> num;
		while(num % 2 == 0){
			num /= 2;
			ans++;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

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

class Program
{



    static void Main(string[] args)
    {

        double[] a = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();

        double b = a[1];
        double c = a[2];
        double k = a[3];

        double tokuten = 0;

        if (a[0] < k)
        {
            tokuten += a[0];
            k -= a[0];
        }
        else
        {
            tokuten += k;
            k = 0;
        }

        if (b < k)
        {
            k -= b;
        }
        else
        {
            k = 0;
        }

        if (c < k)
        {
            tokuten -= c;
        }
        else
        {
            tokuten -= k;
        }

        Console.WriteLine(tokuten);


    }
}

Measured memory_bytes: 28332
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,A,ans,a,b,X[100000],Y[100000],rans;
vector<ll> v;
int main(void){
    cin>>n>>k;
    v.push_back(k);
    for(int i=29;i>0;i--){
        //cout<<((k>>i)&1);
        if(k>>i&1){
            A=(1<<i)-1;
            A+=ans;
            ans+=(1<<i);
            v.push_back(A);
        }
    }
    for(int i=0;i<n;i++)cin>>X[i]>>Y[i];
    //cout<<endl;
    for(auto x:v){
        ans=0LL;
        for(int i=0;i<n;i++){
            int ok=0;
            for(int j=29;j>=0;j--){
                if(X[i]>>j&1){
                    if((x>>j&1)==0){ok=1;break;}
                }
            }
            if(!ok)ans+=Y[i];
        }
        rans=max(rans,ans);
    }
    cout<<rans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s;
    cin >> s;
    bool fn = false, fs = false, fw = false, fe = false;
    for (auto c : s)
    {
        if (c == 'N')
            fn = true;
        if (c == 'S')
            fs = true;
        if (c == 'W')
            fw = true;
        if (c == 'E')
            fe = true;
    }
    if (fn ^ fs || fw ^ fe)
        puts("No");
    else
        puts("Yes");
}

Measured memory_bytes: 256
while True:
    try:
        (a,b,c,d,e,f)  =  map(int,input().split())
    except:
        break
    g = (a * e)  - (b * d)
    ans1= "{0:.3f}".format((( e * c) + ( -b * f)) / g + 0)
    ans2= "{0:.3f}".format(((-d * c) + (  a * f)) / g + 0)
    print (ans1,ans2)



Measured memory_bytes: 5616
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        temp1 = N * n * h
        temp2 = 4 * h * n - N * (n + h)
        if temp2 != 0:
            w = temp1 // temp2
            if w * temp2 == temp1 and w >= 1:
                ans = (h, n, w)
                break
h, n, w = ans
print(h, n ,w)

Measured memory_bytes: 44380
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main() {
    string s;
    cin >> s;
    if(s[0]==s[1]){
        cout << "Bad"<<endl;
    }
    else if(s[1]==s[2]){
        cout << "Bad"<<endl;
    }
    else if(s[2]==s[3]){
        cout << "Bad"<<endl;
    }
    else{
        cout << "Good"<<endl;
    }


}


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

int main(){
	int k,s,count=0;
  	cin >> k >> s;
  	for (int x=0;x<=k;x++){
    	for(int y=0;y<=k;y++){
            if (s-x-y<=k && s-x-y>=0) count++;
        }
    }
  	cout << count << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    As = [0]*(N+1)
    Bs = sum(B)
    As[0] = 0
    for i in range(1,N+1):
        As[i] = As[i-1] + A[i-1]
    T = K
    j = M 
    ans = 0
    for i in range(N+1):
        T = K - As[i]
        if T < 0:
            break
        while Bs > T:
            j -= 1
            Bs -= B[j]
        ans = max(ans, i+j)
    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
    int n, d, g = 0;
    cin >> n >> d;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        g ^= (a-1)%(d+1);
    }
    cout << (g ? "First" : "Second") << endl;
    return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int n, a[100];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    int diff = 0;
    for (int i = 0; i < n; i++) {
        int sign = (i % 2)? -1 : 1;
        diff += a[i] * sign;
    }
    cout << abs(diff) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>

using namespace std;


class DICE
{
private:
	void swapMap(string a, string b);
public:
	map<string,int> dice;
	DICE(vector<int> &v);
	~DICE();
	void turnDice(char c);
	void rotateDice(char c);
	void setDice(string s1, string s2, int a, int b);
	void printDice(string s);
	bool judgeSame(DICE &d);
};

DICE::DICE(vector<int> &v){
	dice["top"] = v[0];
	dice["front"] = v[1];
	dice["right"] = v[2];
	dice["left"] = v[3];
	dice["back"] = v[4];
	dice["bottom"] = v[5];
}

DICE::~DICE(){
	
}

void DICE::swapMap(string a, string b){
	if(dice.end() == dice.find(a) || dice.end() == dice.find(b)) return;
	int tmp;
	tmp = dice[a];
	dice[a] = dice[b];
	dice[b] = tmp;
}

void DICE::turnDice(char c){
	switch(c){
		case 'N':
			swapMap("top","back");
			swapMap("top","bottom");
			swapMap("top","front");
			break;
		case 'E':
			swapMap("top","right");
			swapMap("top","bottom");
			swapMap("top","left");
			break;
		case 'S':
			swapMap("top","front");
			swapMap("top","bottom");
			swapMap("top","back");
			break;
		case 'W':
			swapMap("top","left");
			swapMap("top","bottom");
			swapMap("top","right");
			break;
		default :
			break;
	}
}

void DICE::rotateDice(char c){
	switch(c){
		case 'R':
			swapMap("front","right");
			swapMap("front","back");
			swapMap("front","left");
			break;
		case 'L':
			swapMap("front","left");
			swapMap("front","back");
			swapMap("front","right");
			break;
		default :
			break;
	}
}

void DICE::setDice(string s1, string s2, int a, int b){
	int cnt = 0;
	while(dice[s1] != a && cnt < 6){
		if(cnt % 2 == 0) this->turnDice('E');
		else this->turnDice('N');
		cnt++;
	}
	cnt = 0;
	while(dice[s2] != b && cnt < 4){
		this->rotateDice('R');
		cnt++;
	}
}

void DICE::printDice(string s){
	cout << dice[s] << endl;
}

bool DICE::judgeSame(DICE &d){
	DICE tmp(d);
	int cnt = 0;
	while(cnt < 6){
		if(cnt % 2 == 0) tmp.turnDice('E');
		else tmp.turnDice('N');
		if(this->dice["top"] != tmp.dice["top"]){
		}
		else{
			for(int i = 0; i < 4; i++){
				tmp.rotateDice('R');
				if(	(this->dice["right"] == tmp.dice["right"]) &&
					(this->dice["left"] == tmp.dice["left"]) &&
					(this->dice["front"] == tmp.dice["front"]) &&
					(this->dice["back"] == tmp.dice["back"]) &&
					(this->dice["bottom"] == tmp.dice["bottom"])) 
					return true;
			}
		}
		cnt++;
	}
	return false;
}

int main(){
	int n;
	vector<DICE> data;
	cin >> n;
	for(int i = 0; i < n; i++){
		vector<int> v;
		for(int j = 0; j < 6; j++){
			int tmp;
			cin >> tmp;
			v.push_back(tmp);
		}
		DICE dice(v);
		data.push_back(dice);
	}

	bool flag = true;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			if(data[i].judgeSame(data[j])){
				flag = false;
				continue;
			}
		}
	}

	cout << (flag ? "Yes": "No") << endl;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc=Console.ReadLine().Split(' ').ToArray();
            Console.WriteLine(abc[0].Last()==abc[1].First()&&abc[1].Last()==abc[2].First()?"YES":"NO");
        }
    }
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

vector<int> prime;

void make_prime() {
    prime.push_back(2);
    FOR(i, 3, 55556) {
        bool isPrime = true;
        for (auto p : prime) {
            if (i % p == 0) {
                isPrime = false;
                break;
            }
        }
        if (isPrime) prime.push_back(i);
    }
}

int main() {
    int N;
    cin >> N;
    make_prime();
    int count = 0;
    for (auto p : prime) {
        if (p % 10 == 1) {
            cout << p << " " << endl;
            count++;
        }
        if (count == N) break;
    }

    return 0;
}

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

string grid[500];
int posy[26][2],posx[26][2];
int pos[26][2][2];
bool use[26];
int n,m;
int res;

bool cluck(int y,int x){
  int k;
  int cnt[26];
  for(int i=0;i<26;i++)cnt[i] = 0;

  k = 1;
  while(y+k<n && grid[y+k][x] == '.')k++;
  if(y+k<n)cnt[grid[y+k][x]-'A']++;
  
  k = 1;
  while(x+k<m && grid[y][x+k] == '.')k++;
  if(x+k<m)cnt[grid[y][x+k]-'A']++;

  k = 1;
  while(y-k>=0 && grid[y-k][x] == '.')k++;
  if(y-k>=0)cnt[grid[y-k][x]-'A']++;

  k = 1;
  while(x-k>=0 && grid[y][x-k] == '.')k++;
  if(x-k>=0)cnt[grid[y][x-k]-'A']++;   

  bool f = false;
  for(int i=0;i<26;i++){
    if(cnt[i]==2){
      res += 2;
      grid[posy[i][0]][posx[i][0]] ='.';
      grid[posy[i][1]][posx[i][1]] ='.';
      use[i] = false;
      f = true;
    }
  }
  return f;
}

int main(){
  cin >> n >> m;
  for(int i=0;i<n;i++)cin >> grid[i];

  for(int i=0;i<26;i++){
    posy[i][0] = -1;
    posx[i][0] = -1;
    posy[i][1] = -1;
    posx[i][1] = -1;
    use[i] = false;
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(grid[i][j] != '.'){
	if(posy[grid[i][j]-'A'][0]<0){
	  posy[grid[i][j]-'A'][0] = i;
	  posx[grid[i][j]-'A'][0] = j;
	  use[grid[i][j]-'A'] = true;
	}else{
	  posy[grid[i][j]-'A'][1] = i;
	  posx[grid[i][j]-'A'][1] = j;
	}
      }
    }
  }

  res = 0;
  while(1){
    bool f = false;
    for(int i=0;i<26;i++){
      if(use[i]){
	if(posy[i][0] == posy[i][1]){
	  for(int j=posx[i][0]+1;j<posx[i][1];j++){
	    if(grid[posy[i][0]][j]=='.')f |= cluck(posy[i][0],j);
	  }
	}else if(posx[i][0] == posx[i][1]){
	  for(int j=posy[i][0]+1;j<posy[i][1];j++){
	    if(grid[j][posx[i][0]]=='.')f |= cluck(j,posx[i][0]);
	  }
	}else{
	  if(grid[posy[i][0]][posx[i][1]] == '.')f |= cluck(posy[i][0],posx[i][1]);
	  if(grid[posy[i][1]][posx[i][0]] == '.')f |= cluck(posy[i][1],posx[i][0]);
	}
      }
    }
    if(!f)break;
  }

  cout << res << endl;
}

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

ll f1(ll n, ll p){
    if(n==0) return 0;
    else{
       ll x = n/p + f1(n/p, p);
       return x;
    }

}

ll f2(ll n, ll p){
    if(n%2==1){
        ll x = f1(n, p) - f2(n-1, p);
        return x;
    }
    else{
        ll x = f1(n/2, p);
        if(p==2) x+=n/2;
        return x;
    }
    
}
int  main(){
    ll n;
    cin >> n;
    ll ans = min(f2(n,2), f2(n,5));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n;
  int min;
  int max;
  long long int sum = 0;

  scanf("%d\n",&n);
  int num[n];

  for(int i = 0; i<n ; i++){
    scanf("%d ",&num[i]);
  }

  min = num[0];
  max = num[0];

  for(int i = 0; i<n ; i++){
    if(num[i] < min){
      min = num[i];
    }
    if(num[i] > max){
      max = num[i];
    }
    sum += num[i];
  }

  printf("%d %d %ld\n",min,max,sum);

  return 0;
}


Measured memory_bytes: 2140
from collections import defaultdict as dd
a=dd(int)
freq=0
while True:
    try:
        b=int(input())
    except:
        break
    a[b]+=1
    if freq<a[b]:
        freq=a[b]
ans=sorted([i for i,j in a.items() if j==freq])
for i in ans:
    print(i)

Measured memory_bytes: 8008
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N;
vector<int> A,B;

vector<pair<int,int>> v;

int main(){
  cin>>N;
  for(int i=0;i<N;i++){
      int x;
      cin>>x;
      A.push_back(x);
      v.push_back(make_pair(x,0));
  }
  for(int i=0;i<N;i++){
      int x;
      cin>>x;
      B.push_back(x);
      v.push_back(make_pair(x,1));
  }
  sort(v.begin(),v.end());

  ll ans=1;
  for(int i=0;i<v.size();i++){
      int start=v[i].second;
      int a=1,b=0;
      int rest=1;
      for(i=i+1;i<v.size();i++){
          if(v[i].second==start){
              a++;
              rest++;
          }else{
              ans=(ans*rest)%MOD;
              b++;
              rest--;
          }
          if(a==b) break;
      }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3056
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)

inf = 10 ** 15
mod = 10 ** 9 + 7
n,x = map(int, input().split())
a = list(map(int, input().split()))
ans = abs(a[0]-x)
for i in range(n):
    ans = fractions.gcd(ans, abs(a[i]-x))
print(ans)

Measured memory_bytes: 88172
//fifer a tak luboin
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define mp make_pair
#define pb push_back
#define s second
#define f first
#define endl "\n"

// using namespace __gnu_pbds;
using namespace std;
// template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 

const double eps = 1e-10;                                     
const double pi = acos(-1.0);

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
    // freopen("input.in.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    map <ll, ll> cnt;
    int n;
    cin >> n;
    vector <ll> a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        sum += x;
        cnt[x]++;
    }

    int q;
    cin >> q;
    while (q--) {
        ll b, c;
        cin >> b >> c;
        sum -= cnt[b] * b;
        sum += cnt[b] * c;
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << endl;
    }
    return 0;  
}


Measured memory_bytes: 10088
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
  string S;
  cin >> S;
  int a = 0, b = 0, c = 0;
  for(int i=0; i<S.size(); i++){
    if(S[i] == 'a') a++;
    else if(S[i] == 'b') b++;
    else if(S[i] == 'c') c++;
  }

  if(abs(a-b) > 1 || abs(b-c) > 1 || abs(c-a) > 1)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
	int N, X, D;
	scanf("%d", &N);
	scanf("%d %d", &D, &X);
	int a[100] = {};
	int i;
	int sum = X;
	for (i = 0; i < N; i++)
	{
		scanf("%d", &a[i]);
		sum += 1 + (D - 1) / a[i];
	}

	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <numeric>

#define repAll(n) (n).begin(), (n).end()
#define repConAll(n) (n).cbegin(), (n).cend()

using namespace std;

namespace {

}

int main()
{
	int N = 0;

	cin >> N;

	vector<int>t(N);
	vector<pair<int, int>> p(N);
	for (int i = 0; i < N; ++i){
		cin >> t[i] >> p[i].first >> p[i].second;
	}

	pair<int, int> p0(0, 0);

	int time0 = 0;

	for (int i = 0; i < N; ++i){
		int timeSpan = t[i] - time0;
		int dx = std::abs(p[i].first - p0.first);
		int dy = std::abs(p[i].second - p0.second);

		int restTime = timeSpan - (dx + dy);
		if (dx + dy > timeSpan
			|| (restTime % 2 != 0))
		{
			cout << "No" << endl;
			return 0;
		}
		p0 = p[i];
		time0 = t[i];
	}

	cout << "Yes" << endl;
	return 0;
}

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

l, m, n = map(int, "-1 -1 -1".split())

for x in range(a + 1):
    for y in range(a + 1):
        z = a - x - y
        if z >= 0 and x*10000 + y*5000 + z*1000 == b:
            l = x
            m = y
            n = z
print(l,m,n)


Measured memory_bytes: 2940
import java.util.*;

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

	void run() {
		solver();
	}

	int[][] cost;
	char[][] map;
	int[][] dp;

	void solver() {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		map = new char[H][W];
		cost = new int[H][H];
		dp = new int[H][H];
		for (int i = 0; i < H; i++) {
			map[i] = sc.next().toCharArray();
		}
		int ans = 0;
		for (int i = 0; i < W - 1; i++) {
			for (int j = 0; j < H; j++) {
				for (int k = 0; k < H; k++) {
					dp[j][k] = -1;
					cost[j][k] = -1;
				}
			}
			ans += dfs(i, H - 1, H - 1);
		}
		System.out.println(ans);
	}

	int dfs(int x, int lh, int rh) {
		if (lh < 0 || rh < 0)
			return 0;
		if (dp[lh][rh] >= 0)
			return dp[lh][rh];
		return dp[lh][rh] = Math.min(dfs(x, lh - 1, rh) + calc(x, lh, rh), dfs(x, lh, rh - 1) + calc(x, lh, rh));
	}

	int calc(int x, int lh, int rh) {
		if (lh < 0 || rh < 0)
			return 0;
		if (cost[lh][rh] >= 0)
			return cost[lh][rh];
		return cost[lh][rh] = calc(x, lh - 1, rh - 1) + (map[lh][x] == map[rh][x + 1] ? 1 : 0);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 17032
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

int main() {
  // freopen("input.txt", "r", stdin);
  ll N;
  cin >> N;
  if (N == 0) {
    cout << "0" << endl;
    return 0;
  }

  string ans = "";
  while (N != 0) {
    if (N % 2 != 0) {
      N--;
      ans = "1" + ans;
    } else {
      ans = "0" + ans;
    }
    N /= -2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int[] a = new int[N];
        boolean[] pushFlg = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        int lightButton = 1;
        boolean relightFlg = false ;
        int count = 0;
        while(!relightFlg){
            if (lightButton == 2) {
                break;
            }
            pushFlg[lightButton - 1] = true;
            lightButton = a[lightButton - 1];
            count ++;
            if(pushFlg[lightButton - 1]){
                relightFlg = true;
            }
        }
        System.out.println(relightFlg ? -1 : count);

    }

}


Measured memory_bytes: 51164