akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define N 1005
#define INF 0x3f3f3f3f 
#define mod 1000000007
using namespace std;
typedef long long ll;
ll ans;
 
int main(){
    ll n, t;
    cin >> n >> t;
    ll arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];
    ans = n*t;
    for(int i=1; i<n; i++){
        if(t-(arr[i]-arr[i-1]) > 0) ans-=t-(arr[i]-arr[i-1]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5152
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n = ii()
    s = 0
    anslist = []
    for i in range(1,10000000):
        s+=i
        if s > n:
            s-=i
            break
        anslist.append(i)

    
    dif = n - s

    ans = list(reversed(anslist))
    for i in range(dif):
        ans[i] += 1

    for i in ans:
        print(i)

main()


Measured memory_bytes: 3700
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (s.length() == 26) {
			boolean[] arr = new boolean[26];
			for (int i = s.length() - 1; i >= 0; i--) {
				if (i != s.length() - 1) {
					if (s.charAt(i) < s.charAt(i + 1)) {
						char c = '\0';
						for (int j = s.charAt(i) - 'a' + 1; j < arr.length; j++) {
							if (arr[j]) {
								c = (char)('a' + j);
								System.out.println(s.substring(0, i) + c);
								return;
							}
						}
					}
				}
				arr[s.charAt(i) - 'a'] = true;
			}
			System.out.println(-1);
		} else {
			boolean[] arr = new boolean[26];
			for (int i = 0; i < s.length(); i++) {
				arr[s.charAt(i) - 'a'] = true;
			}
			for (int i = 0; i < arr.length; i++) {
				if (!arr[i]) {
					System.out.println(s + (char)('a' + i));
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 22228
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, X;
	cin >> N >> X;

	vector<int> L(N);
	for (int i = 0; i < N; i++) cin >> L[i];

	lint bo = 0,ans = 1;
	for (int i = 0; i < N; i++) {

		bo += L[i];
		if (bo <= X) ans++;
		else break;

	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
cnt = [0] * (m + 1)
cur = [0] * n
done = [0] * (m + 1)
for i in range(n):
	cnt[a[i][0]] += 1
	cur[i] = a[i][0]
ans = max(cnt)
for _ in range(m - 1):
	col = cnt.index(max(cnt))
	done[col] = 1
	for i in range(n):
		if cur[i] == col:
			j = 0
			while done[a[i][j]]:
				j += 1
			t = a[i][j]
			cur[i] = t
			cnt[t] += 1
	cnt[col] = 0
	ans = min(ans, max(cnt))
print(ans)


Measured memory_bytes: 43260
package main

import "fmt"

func main() {
	var n, m uint
	fmt.Scan(&n, &m)

	lightBulbs := make([][]int, m)
	var k int
	for i := range lightBulbs {
		fmt.Scan(&k)
		lightBulbs[i] = make([]int, k)
		for j := range lightBulbs[i] {
			fmt.Scan(&lightBulbs[i][j])
		}
	}

	ps := make([]int, m)
	for i := range ps {
		fmt.Scan(&ps[i])
	}

	var (
		match int
		flag  bool
		onOff string
		ans   int
	)
	for i := 0; i < (1 << n); i++ {
		flag = true
		onOff = fmt.Sprintf("%010b", i)
		for j, l := range lightBulbs {
			match = 0
			for k := range l {
				if onOff[len(onOff)-l[k]] == '1' {
					match++
				}
			}
			if match%2 == ps[j] {
				continue
			} else {
				flag = false
				break
			}
		}
		if flag == false {
			continue
		} else {
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100000 + 5;



int main(){
    string x;
    string y;
    cin >> x >> y;
    int ans=0;
    for(int i=0;i<x.length();i++){
        if(x[i]!=y[i]){
            ans++;
        }
    }
    cout << ans  <<endl;
    return 0;
}

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

using namespace std;
using ll=long long;

void solve() {
    ll n; cin >> n;
    if (n&1){
        cout << 0;return;
    }

    n/=2;
    ll x = 5;
    ll res = 0;
    while (x <= n) {
        res += n/x;
        x *= 5;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp15
{
    class Class404
    {
        static void Main()
        {
            var AB = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = AB[0], B = AB[1];
            int count = 0;
            for (int i = A; i <= B; i++)
            {
                string n1 = i.ToString();
                string n2 = string.Join("", n1.Reverse());
                if (n1 == n2) count++;
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 23344
#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<lb,lb>;
using graph = vector<vector<int>>;

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,L,T;
  cin>>N>>L>>T;
  vector<ll> l,r;
  ll s;
  rep(i,N){
    ll X,W;
    cin>>X>>W;
    if(i==0) s = W;
    if(W==1LL) r.push_back(X);
    if(W==2LL) l.push_back(X);
  }
  vector<ll> last;
  for(auto x:r){
    last.push_back((x+T)%L);
  }
  for(auto x:l){
    ll p = (x-T)%L;
    if(p<0) p+=L;
    last.push_back(p);
  }
  sort(last.begin(),last.end());
  vector<ll> ans(N);
  if(s==1){
    ll c = (T*2LL)/L,d=(T*2LL)%L;
    ll total = c*(ll)l.size();
    total += (ll)(upper_bound(l.begin(),l.end(),(r[0]+d)%L)-l.begin());
    total %= N;
    ll u = lower_bound(last.begin(),last.end(),(r[0]+T)%L)-last.begin();
    if(u!=N-1&&last[u]==last[u+1]) u++;
    rep(i,N){
      ans[(total+i)%N] = last[(u+i)%N]; 
    }
  }
  else{
    ll c = (T*2LL)/L,d=(T*2LL)%L;
    ll total = c*(ll)r.size();
    ll q = (l[0]-d)%L;
    q+=L;
    total += (ll)(r.end()-lower_bound(r.begin(),r.end(),q));
    total %= N;
    q=(l[0]-T)%L;
    if(q<0) q+=L;
    ll u = lower_bound(last.begin(),last.end(),q)-last.begin();
    rep(i,N){
      ans[i] = last[(u+total+i)%N]; 
    }
  }
  for(auto x:ans) {
    printf("%lld\n",x);
  }
}

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

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

const double F = 0.006;

int main() {
  int N, T, A;
  cin >> N >> T >> A;
  double mn = 10000000;
  int ans = -1;
  int x;
  for(int i = 1; i <= N; ++i) {
    cin >> x;
    double t = T - x * F;
    if(chmin(mn, abs((double)A - t))) {
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
i = 0
sousa = 0
while i <= n-1:
  j = 0
  while j == 0:
    if a[i]%2 == 0:
      a[i] = a[i]/2
      sousa += 1
      j = 0
    else:
      j = 1
  i += 1
print(sousa)

Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N,U[105],D[105];
  cin>>N;
  for(int t=1;t<=N;t++)cin>>U[t];
  for(int t=1;t<=N;t++)cin>>D[t];

  int SU[105]={},SD[105]={};
  int sumu=0,sumd=0;
  for(int t=1;t<=N;t++){
    sumu+=U[t];
    sumd+=D[t];
    SU[t]=sumu;
    SD[t]=sumd;
  }

  int max=0;
  for(int t=1;t<=N;t++){
    int temp=SU[t]+(SD[N]-SD[t-1]);  //S[0]=0;
    if(max<temp)max=temp;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for(int i=0;i<(int)(n);++i)
#define FOR(i, b, n)  for(int i=b;i<(n);++i)
#define ALL(c) (c).begin(),(c).end()
#define SS size()
#define PB push_back
#define ST first
#define ND second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;

typedef vector<vi> vvi;

template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }


int main() {
    // freopen("./aaa.txt", "r", stdin);
    int a, b; cin >> a >> b; 
    cout << ((b>=a) ? a : a-1) << endl;
}


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


def main():
    A = list(map(int, list(input()[:-1])))
    for i in range(2**3):
        f = str(A[0])
        ans = A[0]
        for j in range(3):
            if (i>>j) & 1:
                f += '+' + str(A[j+1])
                ans += A[j+1]
            else:
                f += '-' + str(A[j+1])
                ans -= A[j+1]
        if ans==7:
            f += '=7'
            print(f)
            return


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

int main() {
    ll a; string c;cin>>a>>c;
    a=a*((c[0]-'0')*100+(c[2]-'0')*10+(c[3]-'0'));
    cout<<a/100;
    return 0;
}

Measured memory_bytes: 3600
<?php
$members = trim(fgets(STDIN));
list($days, $choco) = explode(' ', trim(fgets(STDIN)));

$ate = 0;
for ($i = $members; $i > 0; $i--) {
    $step = trim(fgets(STDIN));
    $j = 0;
    while (true) {
        if ($j * $step + 1 > $days) {
            break;
        }
        $ate++;
        $j++;
    }
}

$total = $ate + $choco;
echo($total."\n");


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

int main(){

	double a,b,c,d,e,f;
	double x,y;
	register double alpha;

	while(cin>>a>>b>>c>>d>>e>>f){

		alpha =  1.0 / (a*e-b*d);
		x = alpha*(e*c-b*f);
		y = alpha*(a*f-d*c);

		if(x == -0.00)x=0.0;
		if(y == -0.00)y=0.0;

		cout<<fixed<<setprecision(3)<<x<<" "<<y<<endl;

	}

	return 0;

}

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

ll n,k;
const int MAXN = 2000*2000;
long long kai[MAXN+1];
long long inv[MAXN+1];
long long mod = 1e9+7;
long long mp(long long a, long long b) {
    long long res = 1;
    for (; b; b >>= 1) {
        if (b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
void init() {
    kai[0] = 1;
    for (long long i = 1; i <= MAXN; i++) kai[i] = kai[i - 1] * i % mod;
    inv[MAXN] = mp(kai[MAXN], mod-2);
    for (long long i = MAXN; i >= 1; i--) inv[i - 1] = inv[i] * i % mod;
}
long long calc(long long n, long long k) {
    if (n < k) return 0;
    return (kai[n] * inv[k]) % mod * inv[n - k] % mod;
}

ll dp[2010][2010];
bool ok[2010][2010];

ll dfs(int a, int b) {
    if (ok[a][b]) return dp[a][b];
    ll ret = 0;
    if (a - 1 >= 0) ret += dfs(a-1,b);
    if (b - 1 >= a) ret += dfs(a, b-1) * calc(a + b * (k - 1) - 1, k - 2) % mod;
    ok[a][b] = 1;
    return dp[a][b] = ret % mod;
}

int main() {
    cin >> n >> k;
    init();
    if (k == 1) {
        cout << 1 << endl;
        return 0;
    }
    dp[0][0] = 1;
    ok[0][0] = 1;
    ll ret = dfs(n,n);
    for (ll i = 1; i <= n; i++) ret = ret * i % mod;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 92788
///
// File:  c.go
// Author: ymiyamoto
//
// Created on Sun May 13 15:43:50 2018
//
package main

import (
	"fmt"
	"sort"
)

var s string
var K int

type strArray []string

func (s strArray) Len() int {
	return len(s)
}

func (s strArray) Less(i, j int) bool {
	return s[i] < s[j]
}

func (s strArray) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	fmt.Scan(&s, &K)

	set := map[string]struct{}{}
	for i := range s {
		for k := 1; k <= K && i+k <= len(s); k++ {
			str := s[i : i+k]
			set[str] = struct{}{}
		}
	}

	arr := make(strArray, 0)
	for k, _ := range set {
		arr = append(arr, k)
	}
	sort.Sort(arr)

	fmt.Println(arr[K-1])
}


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

void dfs(int digit, long now, vector<long> &runrun) {
  runrun.push_back(now);
  if (digit == 10) return;
  for (int i = -1; i < 2; i++) {
    int add = now % 10 + i;
    if (0 <= add && add <= 9) dfs(digit + 1, now * 10 + add, runrun);
  }
}

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

  vector<long> runrun;
  for (int i = 1; i < 10; i++) dfs(1, i, runrun);
  sort(runrun.begin(), runrun.end());

  cout << runrun.at(K - 1) << "\n";
}

Measured memory_bytes: 2420
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=0;
    String s=sc.next(),t=sc.next();
    for(int i=n-1;i>=0;i--){
      if(s.substring(n-1-i,n).equals(t.substring(0,i+1))){
        System.out.println(2*n-i-1);
        f++;
        break;
      }
    }
    if(f==0){
      System.out.println(2*n);
    }
  }
}


Measured memory_bytes: 21972
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

using namespace std;

void a_takoyaki(void) {
	int x, t, n;
	cin >> n >> x >> t;

	int ans = n % x == 0 ? (n / x) : ((int)(n / x) + 1);
	ans = ans * t;

	cout << ans << endl;
}

int main()
{
    a_takoyaki();

    return 0;
}

Measured memory_bytes: 3628
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
//import static java.lang.System.*; はしばらく使わなそう(使うとしてもexit(0)のためだけ)←return;でよさそう
最後にout.flush()またはout.close()をするのを忘れずに！
Point2D p2d=new Point2D.Double(d1,d2);
*/
//入力終了→Ctrl+D
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
//import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        int n=sc.nextInt();
        int k=sc.nextInt();
        String s=sc.next();
        int c=s.charAt(0);
        int count=0;
        ArrayList<Integer> list=new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if(s.charAt(i)==c){
                count++;
            }else {
                list.add(count);
                c=s.charAt(i);
                i--;
                count=0;
            }
        }
        if(count>0){
            list.add(count);
        }
        int[] a=new int[list.size()+1];
        count=1;
        for (Integer e:list){
            a[count++]=e;
        }
        int l=a.length;
        for (int i = 1; i < l; i++) {
            a[i]+=a[i-1];
        }
        int ans=0;
        if(s.charAt(0)=='0'){
            for (int i = 2;i < l; i+=2) {
                ans=max(ans,a[min(l-1,i+2*k)]-a[i-1]);
            }
            ans=max(ans,a[min(2*k,l-1)]-a[0]);
            if(l/2<=k)ans=n;
        }else {
            for (int i = 1; i<l; i+=2) {
                ans=max(ans,a[min(l-1,i+2*k)]-a[i-1]);
            }
            if((l-1)/2<=k)ans=n;
        }
        out.println(ans);
        out.close();
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc     {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }

        static boolean hasNext() {
            return s.hasNext();
        }
    }
}
/*
4
1
0100
2
 */

Measured memory_bytes: 27940
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int n, c, k; cin >> n >> c >> k;
    vector<int> T(n); rep(i, n) cin >> T[i];

    sort(all(T));
    int res = 1, cnt = 1, last = T[0] + k;
    for(int i=1; i<n; i++){
        if(T[i] <= last && cnt < c){
             cnt++;
        }else{
            res++; cnt = 1;
            last = T[i] + k;
        }
    }
    cout << res << ln;
}


Measured memory_bytes: 640
// stdin
macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

// input
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

// Test
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

#[allow(dead_code)]
fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        return x;
    }
    gcd(y, x % y)
}

#[test]
fn test_primes() {
    assert_eq!(primes(1), vec![1]);
    assert_eq!(primes(140), vec![1, 2, 2, 5, 7])
}

#[allow(dead_code)]
fn primes(num: i64) -> Vec<i64> {
    let mut ans = vec![1];
    let mut cur = num;
    for i in 2.. {
        if i * i > num { break; }
        if cur % i == 0 {
            while cur % i == 0 {
                ans.push(i);
                cur /= i;
            }
        }
    }
    if cur > 1 {
        ans.push(cur);
    }
    return ans;
}


test! {
r"10
" => r"Yes",

r"50
" => r"No",

r"81
" => r"Yes"
}

fn solve(src: &str) -> String {
    input! {
        source=src,
        n:i32,
//        a:[i32;n],
    }
    let n: i32 = n;
    let mut ans = "No";
    for i in 1..10 {
        for ii in 1..10 {
            if i * ii == n {
                ans = "Yes"
            }
        }
    };


    format!("{}", ans)
}


fn main() {
    println!("{}", solve(&stdin!()));
}



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

int main() {
    string s;
    cin >> s;

    int cnt = 0;
    for (int i = 1; i < s.size(); i++) {
        if (s.at(i-1) == s.at(i)) {
            cnt++;
            if (s.at(i) == '0') {
                s.at(i) = '1';
            } else {
                s.at(i) = '0';
            }
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3736
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#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 REP(i, n) for (int i = 0; i < n; ++i)

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

const int kMaxH = 300;
const int kMaxW = 300;
const int kMaxQ = 100000;
const int kInf = 1000000000;

int H, W, D;
int A[kMaxH][kMaxW];
int Q;
int L[kMaxQ], R[kMaxQ];
int ans;

int nxt[kMaxH*kMaxW+1];
int cost[kMaxH*kMaxW+1];

int main() {
  cin >> H >> W >> D;
  REP(i, H) { REP(j, W) { cin >> A[i][j]; } }
  cin >> Q;
  REP(i, Q) { cin >> L[i] >> R[i]; }

  map<int, Pair> m;
  REP(i, H) {
    REP(j, W) {
      auto k = m.find(A[i][j]-D);
      if (k != m.end()) {
        Pair p = k->second;
        nxt[A[i][j]-D] = ABS(i - p.first) + ABS(j - p.second);
      }

      auto k2 = m.find(A[i][j]+D);
      if (k2 != m.end()) {
        Pair p2 = k2->second;
        nxt[A[i][j]] = ABS(p2.first - i) + ABS(p2.second - j);
      }

      m.insert(make_pair(A[i][j], Pair(i, j)));
    }
  }
  FOR(i, 1, D+1) {
    cost[i] = 0;
    int j = i;
    while (j+D <= H*W) {
      cost[j+D] = cost[j] + nxt[j];
      j += D;
    }
  }

  REP(i, Q) {
    ans = cost[R[i]] - cost[L[i]];
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 8576
#include <iostream>

static int has_fib[44];
static int fib[44];

int fibonacci(int n) {
    if (has_fib[n] == 1) {
        return fib[n];
    }
    fib[n] = fibonacci(n - 1) + fibonacci(n - 2);
    has_fib[n] = 1;
    return fib[n];
}

int main() {
    int N;
    fib[0] = 1;
    has_fib[0] = 1;
    fib[1] = 1;
    has_fib[1] = 1;
    std::cin >> N;
    std::cout << fibonacci(N) << std::endl;
}



Measured memory_bytes: 3088
#include<cstdio>
#include<algorithm>

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

using namespace std;

typedef long long ll;

int main(){
	for(int r,c,q;scanf("%d%d%d",&r,&c,&q),r;){
		static int row[50000][2],col[50000][2];
		rep(i,r){
			row[i][0]=-1;
			row[i][1]=-2;
		}
		rep(j,c){
			col[j][0]=-3;
			col[j][1]=-4;
		}

		rep(t,q){
			int a,b,ord; scanf("%d%d%d",&a,&b,&ord);
			if(a==0) row[b][ord]=t;
			else     col[b][ord]=t;
		}

		static int v0[50000],v1[50000];
		rep(j,c){
			if(col[j][0]<col[j][1]){
				v0[j]=col[j][1];
				v1[j]=-5;
			}
			else{
				v0[j]=-5;
				v1[j]=col[j][0];
			}
		}
		sort(v0,v0+c);
		sort(v1,v1+c);

		ll ans=0;
		rep(i,r){
			if(row[i][1]<row[i][0]){
				ans+=(v0+c)-lower_bound(v0,v0+c,row[i][0]);
			}
			else{
				ans+=lower_bound(v1,v1+c,row[i][1])-v1;
			}
		}
		printf("%lld\n",ans);
	}

	return 0;
}

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

int main(){
	int n;
	cin >> n;
	int a[n+1], maxv=0, minv=0x7ff, ans=0x7ffff;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		maxv=max(maxv,a[i]);
		minv=min(minv,a[i]);
	}
	for(int i=minv; i<=maxv; i++){
		int sum=0;
		for(int j=1; j<=n; j++)
			sum+=(a[j]-i)*(a[j]-i);
		ans=min(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
s=[list(map(int,input().split()))for i in range(3)]
a=[0]*3
b=[0]*3
for i in range(3):
    b[i]=s[0][i]-a[0]
for i in range(3):
    a[i]=s[i][0]-b[0]
for i in range(3):
    for j in range(3):
        if a[i]+b[j]!=s[i][j]:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  
  int ans = 0;
  
  for(int i = 1; i <= N; i++){
    for(int j = i; j <= N; j++){
      for(int k = j; k <= N; k++){
        int gcd = 0;        
        for(int l = j; l > 0; l--){
          if(i % l == 0 && j % l == 0 && k % l == 0){
            if(i==j && j==k){
              ans += l;
            }
            else if(i == j || j == k){
              ans += l*3;
            }
            else{
              ans += l*6;
            }
            l = 0;
          }
        }
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()	
using namespace std;
typedef long long ll;
const ll MOD=1000000007;
const ll INF=1000000010;
int main(){
    ll n,x;cin>>n>>x;
    ll a[110];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=0;
    ll sum=0;
    ll y=x;
    for(int i=0;i<n;i++){
        if(x>=a[i]){
            x-=a[i];
            ans++;
        }
        sum+=a[i];
    }
    if(sum<y){
        ans--;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
s = input()

judge = 0
for i in range(len(s)):
	try:
		if s[i] == s[i + 1]:
			print("{0} {1}".format(i + 1, i + 2))
			judge = 1
		if s[i] == s[i + 2]:
			print("{0} {1}".format(i + 1, i + 3))
			judge = 1
	except:
		pass
	if judge == 1:
		exit()

print(-1, -1)

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

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

int dp[100005];

void Main() {
    for (auto& x : dp)
    {
        x = INF;
    }

    int n;
    cin >> n;

    vint h(n);
    for (auto& x : h)
    {
        cin >> x;
    }

    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        chmin(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]));
        if (i >= 2) {
            chmin(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
        }
    }
    cout << dp[n - 1] << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
string kei[] = {".,!? ","abc","def","ghi",
		"jkl","mno","pqrs","tuv","wxyz",};

int main(){
  string str;
  int n;
  cin >> n;
  while(n--){
    cin >> str;
    int cnt = 0;
    for(int i = 0 ; i < str.size()-1 ; i++ ){
      if(str[i] == str[i+1] && str[i] != '0')cnt++;
      if(str[i] == '0' && str[i+1] == '0')continue;
      if(str[i]!='0' && str[i+1] == '0'){
	cout << kei[(str[i]-'0')-1][cnt%(kei[(str[i]-'0')-1].size())];  
	cnt = 0;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 1212
import math

N = int(input())
pts = [[int(i) for i in input().split()] for _ in range(N)]
tot = 0
for i in range(N):
  tot += sum([math.sqrt((pts[i][0]-pts[j][0])**2+(pts[i][1]-pts[j][1])**2) for j in range(i+1, N)])
print(tot / math.factorial(N) * math.factorial(N-1) * 2)

Measured memory_bytes: 3064
n=int(input())
lipp = []
lipm = []
limm = []
allcnt = 0
for _ in range(n):
    s = input()
    cnt = 0
    mi = 0
    for x in s:
        if x == ')':
            cnt -= 1
            mi = min(mi,cnt)
        else:
            cnt += 1
    if mi == 0:
        lipp.append(cnt)
    elif cnt >= 0:
        lipm.append([mi,cnt])
    else:
        limm.append([cnt - mi, mi,cnt])
    allcnt += cnt
if allcnt != 0:
    print('No')
    exit()

now = sum(lipp)
lipm.sort(reverse = True)
limm.sort()

for mi, cnt in lipm:
    if mi + now < 0:
        print('No')
        exit()
    now += cnt

cnt2 = 0
for sa, mi, cnt in limm:
    if sa > cnt2:
        print('No')
        exit()
    cnt2 += -cnt
print("Yes")

Measured memory_bytes: 177020
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int gcd(int a,int b){
    if(!b)return a;
    return gcd(b,a%b);
}
main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(C % gcd(A,B))cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, q;
    
    cin >> N;
    int S[N];
    for(int i = 0; i < N; ++i){
        cin >> S[i];
    }
    
    cin >> q;
    int T[q];
    for(int i = 0; i < q; ++i){
        cin >> T[i];
    }
    
    int n = 0;
    for(int i = 0; i < q; ++i){
        int l = 0, r = N;
        while(r > l){
            int j = (l + r) / 2;
            if(T[i] == S[j]){
                n++;
                break;
            }else if(T[i] < S[j]){
                r = j;
            }else{
                l = j + 1;
            }
        }
    }
    
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 3684
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		String s = in.next();
		int n = s.length();
		int ans = -1;

		for (int i = 0; i < n - 1; i++) {
			if (s.substring(i, i + 1).equals(s.substring(i + 1, i + 2))) {
				ans = i + 1;
				break;
			}
		}
		if (ans != -1) {
			System.out.println(ans + " " + (ans + 1));
		} else {
			for (int i = 0; i < n - 2; i++) {
				if (s.substring(i, i + 1).equals(s.substring(i + 2, i + 3))) {
					ans = i + 1;
					break;
				}
			}
			if (ans != -1) {
				System.out.println(ans + " " + (ans + 2));
			} else {
				System.out.println("-1 -1");
			}
		}

		in.close();

	}

}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

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

  LL bis = 1;
  if (b - a <= 1) {
    cout << k + 1 << endl;
  } else {
    while (k > 0) {
      if (bis < a || k == 1) {
        bis++;
        k--;
      } else {
        bis += b - a;
        k -= 2;
      }
    }
    cout << bis << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iomanip>
#define ll long long int
#define ld long double
#define f first
#define inf 100000000000000000
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define s second
#define pb push_back
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define Sort(a) sort(a.begin(),a.end());
using namespace std;
ll const mod=1000000007;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
// ordered_set os.find_by_order os.order_of_key
// b/w l and r os.order_of_key(r+1)-order_of_key(l)

// ll arr1[1000009];
// //ll parent[1000009];
// set<ll> sieve;
// void sievefun(ll n){
//     for(ll i=2;i<=n;i++){
//         if(arr1[i]==0){
//  //              parent[i]=i;
//             for(ll j=i*i;j<=n;j+=i){
//    //         	if(arr1[j]==0)parent[j]=i;
//                 arr1[j]=1;
//             }
//         }
//     }
//     for(int i=2;i<=n;i++){
//     	if(arr1[i]==0)sieve.insert(i);
//     }
// }
ll power(ll x, ll y,ll m) {
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2,m)%m;
	if (y%2 == 0)
		return ((temp)*(temp))%m;
	else
		return (((x)%m)*((temp*temp)%m))%m;
}

// ll fac[1000009];
// void factorial(){
// 	fac[0]=1;
// 	for(int i=1;i<=1000000;i++)fac[i]=(i*fac[i-1])%mod;
// }
// ll ncr(ll n,ll r){
// 	return (fac[n]*((power(fac[r],mod-2)*power(fac[n-r],mod-2))%mod))%mod;
// }
bool Q;
struct Line {
    mutable ll k, m, p;
    bool operator<(const Line& o) const {
        return Q ? p < o.p : k < o.k;
    }
};
struct LineContainer : multiset<Line> {
    // const ll inf = LLONG_MAX;
    ll div(ll a, ll b){
        return a / b - ((a ^ b) < 0 && a % b);
    }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    ll query(ll x) {
        assert(!empty());
        Q = 1; auto l = *lower_bound({0,0,x}); Q = 0;
        return l.k * x + l.m;
    }
};
int const N=200009;
ll arr[N];
int main()
{	//sievefun(1000000);
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll n,c;
	cin>>n>>c;
	forn(i,n)cin>>arr[i+1];
	LineContainer cht;
	cht.add(2*arr[n],-(c+arr[n]*arr[n]));
	for(int i=n-1;i>=1;i--){
		ll temp=arr[i]*arr[i]+-1*cht.query(arr[i]);
		// cout<<temp<<"\n";
		cht.add(2*arr[i],-(c+arr[i]*arr[i]+temp));
		if(i==1)cout<<temp;
	}

}

Measured memory_bytes: 14336
#include<stdio.h>
#include<stdlib.h>
#define N 100010
#define NIL -1

typedef struct{int parent, left, right; }Node;

Node T[N];
int depth[N];

void Print(int x){
	int i,a;
	printf("node %d: parent = %d, depth = %d, ",x,T[x].parent,depth[x]);
	if(T[x].parent == NIL)printf("root, ");
	else if(T[x].left == NIL)printf("leaf, ");
	else printf("internal node, ");

	printf("[");
	for(i=0,a=T[x].left;	a!=NIL;		i++,a=T[a].right){
		if(i)printf(", ");
		printf("%d",a);
	}
	printf("]\n");
}

void getDepth(int x, int d){
	depth[x] = d;
	if(T[x].right != NIL)getDepth(T[x].right, d);
	if(T[x].left != NIL)getDepth(T[x].left, d+1);
}

int main(){
	int i,j,n,id,k,c,l,r;	scanf("%d",&n);
	for(i = 0 ; i < n ; i++)T[i].parent = T[i].left = T[i].right = NIL;

	for(i = 0 ; i < n ; i++){
		scanf("%d%d",&id,&k);
		for(j = 0 ; j < k ; j++){
			scanf("%d",&c);
			if(j == 0)T[id].left = c;
			else T[l].right = c;
			l = c;

			T[c].parent = id;
		}
	}

	for(i = 0 ; i < n ; i++){
		if(T[i].parent == NIL){
			getDepth(i,0);
			break;
		}
	}

	for(i = 0 ; i < n ; i++)Print(i);

	return 0;
}



Measured memory_bytes: 6404
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

const ll INF = LLONG_MAX;
const int MAX_V = 100100;

struct edge{
  int to;
  ll cost;
};
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(int V,int s){
  priority_queue<P,vector<P>,greater<P>> que;
  fill(d,d+V,INF);
  d[s] = 0;
  que.push(P(0,s));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.se;
    if(d[v] < p.first)continue;
    rep(i,sz(G[v])){
      edge e = G[v][i];
      if(d[e.to] > d[v]+e.cost){
        d[e.to] =  d[v]+e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
}

int main() {
  int n;
  cin >> n;
  rep(i,n-1){
    int a,b;
    ll c;
    cin >> a  >> b >> c;
    a--;
    b--;
    edge e1,e2;
    e1.to = b;
    e1.cost = c;
    e2.to = a;
    e2.cost =c;
    G[a].push_back(e1);
    G[b].push_back(e2);
  }
  int q,k;
  cin >> q >> k;
  k--;
  dijkstra(n,k);
  vl ans;
  rep(i,q){
    int x,y;
    cin  >> x>> y;
    x--;y--;
    ans.push_back(d[x]+d[y]);
  }
  for(auto e : ans){
    cout<<e<<endl;
  }
  return 0;
}

Measured memory_bytes: 10976
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    vector<int> a(3); rep(i,3) cin >> a[i];
    sort(a.begin(),a.end());
    int ans = a[1]-a[0] + a[2]-a[1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int main(){
 string s,t;
 cin >> s >> t;
 sort(s.begin(),s.end());
 sort(t.begin(),t.end());
 reverse(t.begin(),t.end());
 if(s < t){
   cout << "Yes" << endl;
 }
else {
  cout << "No" << endl;
}
}

Measured memory_bytes: 256
H,W = list(map(int,input().split()))
S = H*W

out = H*W

for Hi in range(1,H):
    S1 = W*Hi
    Hr = H-Hi
    S2a = (W//2)*Hr
    S3a = (W-W//2)*Hr
    S2b = W*(Hr//2)
    S3b = W*(Hr - (Hr//2))
    Da = max(S1,S2a,S3a)-min(S1,S2a,S3a)
    Db = max(S1,S2b,S3b)-min(S1,S2b,S3b)
    cand = min(Da,Db)
    if cand<out:
        out=cand
for Wi in range(1,W):
    S1 = Wi*H
    Wr = W-Wi
    S2a = (H//2)*Wr
    S3a = (H-H//2)*Wr
    S2b = H*(Wr//2)
    S3b = H*(Wr - (Wr//2))
    Da = max(S1,S2a,S3a)-min(S1,S2a,S3a)
    Db = max(S1,S2b,S3b)-min(S1,S2b,S3b)
    cand = min(Da,Db)
    if cand<out:
        out=cand
print(out)


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

int main() {
  int N, X, P=0, Sum=1;
  cin >> N >> X;
  vector<int> L(N);
  rep(i, N) cin >> L.at(i);
  rep(i, N){
    P=P+L.at(i);
    if(P>X) break;
    Sum++;
  }
  cout << Sum << endl;
}

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

int main() {
  double x1, y1, x2, y2, ans = 0;
  scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  cout << fixed << setprecision(5);
  ans = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
  cout << sqrt(ans) << "\n";
}


Measured memory_bytes: 3332
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(){
        int n = int.Parse(Console.ReadLine());
        int[] X = {111,222,333,444,555,666,777,888,999};
        var q = from x in X
            where x >= n
            select x;
        Console.WriteLine(q.Min());
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
const int INF = 1001001001;

int main()
{
    ll k; cin >> k;
    vector<ll> a(k);
    rep(i, k){
        cin >> a[i];
        if(a[i]==0) {cout << 0 << endl; return 0;}
    }
    ll sum=1,mx=1000000000000000000;
    rep(i,k){
        if(sum <= mx/a[i]) sum *= a[i];
        else {cout << "-1" << endl; return 0;}
    }
    if(sum <= mx) cout << sum << endl;
    else cout << "-1" << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/


Measured memory_bytes: 4044
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
int main() {
	double N;
	cin >> N;
	double M = N / 1.08;
	m = (int)(M + 0.000001);
	//cout << m << " " << M << " " << N << endl;
	if ((int)(m * 1.08) ==(int)N) {
		cout << m << endl;
	}
	else if ((int)((m + 1) * 1.08) == (int)N) {
		cout << m + 1 << endl;
	}
	else {
		cout << ":(" << endl;
	}
}

Measured memory_bytes: 256
from bisect import bisect_left


def solve():
    S = input()
    T = input()
    if not set(T) <= set(S):
        return -1

    pos = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
    for i, c in enumerate(S):
        pos[c].append(i)
    ans = 0
    cur_pos = 0
    for t in T:
        nxt_idx = bisect_left(pos[t], cur_pos)
        if nxt_idx == len(pos[t]):
            ans += len(S)
            cur_pos = 0
            nxt_idx = bisect_left(pos[t], cur_pos)
            cur_pos = pos[t][nxt_idx] + 1
        else:
            cur_pos = pos[t][nxt_idx] + 1

    return ans + cur_pos


print(solve())


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

int sort(int* &num, int size)
{
    for(int i = 0; i < size; i++)
    {
        int j = i;
        int temp = num[j];
        for(j = i - 1; j >= 0 && temp < num[j]; j--)
        {
            num[j + 1] = num[j];
        }
        num[j + 1] = temp;
        for(int t = 0; t < size; t++)
        {
            if(t != 0)
                cout << " ";
            cout << num[t];
        }
        cout << endl;
    }
    return 0;
}

int main()
{
    int count = 0;
    cin >> count;
    int *num = new int[count];
    for(int i = 0; i < count; i++)
    {
        cin >> num[i];
    }
    sort(num, count);
    return 0;
}


Measured memory_bytes: 3096
N, K = gets.split.map(&:to_i)
nums = Array.new(10**5+1, 0)
N.times do |i|
    a, b = gets.split.map(&:to_i)
    nums[a] += b
end

sum = 0
nums.length.times do |i|
    sum += nums[i]
    if sum >= K
        puts i
        exit
    end
end


Measured memory_bytes: 2684
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int a, b; cin >> a >> b;
    if (a == b) {
        cout << "0\n";
        return 0;
    }
    if ((a + b) % 2 == 0) {
        cout << (a + b) / 2 << "\n";
        return 0;
    }
    cout << "IMPOSSIBLE\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lb long double
#define pb push_back
#define l first
#define r second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < int , int >

using namespace std;

const int N = 5000005;
const int M = 1000000007;
const lb PI = acos(-1);

ll a , b;

ll f(ll x)
{
    ll zero = (x & 1);
    ll last = ((x >> 1) & 1);

    if(last == 0 && zero == 1)
        return 1;
    else if(last == 1 && zero == 1)
        return 0;
    else if(last == 1 && zero == 0)
        return x + 1;
    else return x;
}

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

    cin >> a >> b;
    cout << (f(b) ^ f(a - 1));

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
	int n;
	cin >> n;
	int tmp=0, x=0;
	while(n/pow(10,tmp)>=1) tmp++;
	int m = n/pow(10, tmp-1);
	while(x-n<0){
		x=0;
		REP(i, tmp) x+=m*pow(10, i);
		++m;
	}
	cout << x << '\n';
	
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>

using namespace std;

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

int main(){
  char s[4];
  scanf("%s", s);

  int ans = 0;
  rep(bit, 0, 1 << 3) {
    int tmp = s[0] - '0';
    string stmp;
    stmp += s[0];
    rep(j, 0, 3) {
      if ((bit >> j) & 1) {
        tmp -= s[j+1] - '0';
        stmp += '-';
      } else {
        tmp += s[j+1] - '0';
        stmp += '+';
      }
      stmp += s[j+1];
    }
    if (tmp == 7) {
      printf("%s=7\n", stmp.c_str());
      exit(0);
    }
  }
}

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

using ll = long long;
using boost::irange;

int main(){

    int N;
    cin >> N;

    vector<pair<int, int>> A(N);
    
    int num;
    for (int i: irange(0, N)){
        cin >> num;
        A[i].first = num;
        A[i].second = i;
    }
    sort(A.begin(), A.end());

    for (auto a: A){
        cout << a.second + 1 << " ";
    }
    cout << endl;

    return 0;
}

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

using namespace std;

#define inf 1<<30
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> P;


int main(){
	int N;
	int rate[9] = {};
	cin >> N;
	for(int i = 0; i < N; i++){
		int in;
		cin >> in;
		if(in < 400)
			rate[0]++;
		else if(in < 800)
			rate[1]++;
		else if(in < 1200)
			rate[2]++;
		else if(in < 1600)
			rate[3]++;
		else if(in < 2000)
			rate[4]++;
		else if(in < 2400)
			rate[5]++;
		else if(in < 2800)
			rate[6]++;
		else if(in < 3200)
			rate[7]++;
		else
			rate[8]++;
	}

	int cnt = 0;
	for(int i = 0; i < 8; i++){
		if(rate[i] > 0){
			cnt++;
		}
	}

	cout << max(1,cnt) << " " << cnt+rate[8] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	vector<ll> A(n), B(n);
	for (int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		int a = x + y;
		int b = x - y;
		A[i] = a;
		B[i] = b;
	}
	ll ans = *max_element(A.begin(), A.end()) - *min_element(A.begin(), A.end());
	ans = max(ans, *max_element(B.begin(), B.end()) - *min_element(B.begin(), B.end()));
	printf("%lld\n", ans);
}


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

int selectionSort(vector<int>&, int);

int main(){
vector<int> A(100);
    int n, sw;
    cin >> n;

    for(int i = 0; i < n; i++) cin >> A.at(i);

    sw = selectionSort(A, n);

    for(int i = 0; i < n; i++){
        if(i) cout << " ";
        cout << A.at(i);
    }
    cout << endl;
    cout << sw << endl;
}

int selectionSort(vector<int>& A, int n){
    int sw = 0;
    for(int i = 0; i < n - 1; i++){
        int minj = i;
        for(int j = i; j < n; j++){
            if(A.at(j) < A.at(minj)) minj = j;
        }
        int t = A.at(i);
        A.at(i) = A.at(minj);
        A.at(minj) = t;
        if(i != minj) sw++;
    }
    return sw;
}



Measured memory_bytes: 3068
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
typedef long long ll;
using namespace std;

int main(){
    int x;
    cin >> x;
    int ans = 0;
    int sum = 0;
    for(int i = 1;sum<x;i++){
        sum += i;
        ans = i;
    }
        cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, sum = 0;
  int n[9], div[9];
  bool harshad;

  cin >> N;
  
  for ( int i = 0; i < 9; i++ ) {
    div[i] = 10; 
    for ( int j = 0; j < i; j++ ) {
      div[i] *= 10;
    }
  }
  
  for ( int i = 0; i < 9; i++ ) {
    n[i] = ( N - (N / div[i]) * div[i] ) / ( div[i] / 10 );
    sum += n[i];
    //cout << n[i] << endl;
  }
  
  if ( (N % sum) == 0 ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256