akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define ff first
#define ss second
ll ans=0,n;
string s;
void solve(ll idx, ll sum){
	if(idx==n){
		ans+=sum;
		return;
	} 
	ll curr=0;
	for(ll i=idx;i<n;++i){
		curr=10*curr+(s[i]-'0');
		solve(i+1,sum+curr);
	}
}
int main(){
	cin>>s;
	s=' '+s;
	n=s.length();
	solve(1,0);
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int Window;
  int Curtain;

  
  cin >> Window ;
  cin >> Curtain ;
  
  int Ans = Window - Curtain*2; 
  if (Ans <= 0) Ans = 0;
  cout << Ans << endl;

  
  return 0;
}


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

int main(){
int a,b,c;
cin>>a>>b>>c;

if(a>b) swap(a,b);
if(b>c) swap(b,c);
if(a>b) swap(a,b);

cout<<a<<" "<<b<<" "<<c<<endl;

return 0;
}



Measured memory_bytes: 3120
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int n;
bool ask(vector<int>v)
{
	printf("?");
	for (int i = 0; i < v.size(); i++)printf(" %d", v[i] % (n + n) + 1);
	printf("\n");
	fflush(stdout);
	char s[10];
	scanf("%s", s);
	return s[0] == 'R';
}
vector<int>make(int t, int len)
{
	vector<int>v;
	for (int i = 0; i < len; i++)v.push_back(i + t);
	return v;
}
bool ans[1000];
int main()
{
	scanf("%d", &n);
	bool s = ask(make(0, n));
	int beg = 0, end = n - 1;
	if (s)beg = n, end = n + n - 1;
	for (;;)
	{
		if (beg == end)break;
		int med = (beg + end + 1) / 2;
		if (ask(make(med, n)))end = med - 1;
		else beg = med;
	}
	ans[beg % (n + n)] = false, ans[(beg + n) % (n + n)] = true;
	for (int i = 0; i < n - 1; i++)
	{
		vector<int>z = make(beg + 1, n - 1);
		z.push_back(beg + n + i + 1);
		ans[(beg + n + i + 1) % (n + n)] = ask(z); 
		z = make(beg + n + 1, n - 1);
		z.push_back(beg + i + 1);
		ans[(beg + i + 1) % (n + n)] = ask(z);
	}
	printf("! ");
	for (int i = 0; i < n + n; i++)printf(ans[i] ? "R" : "B");
	printf("\n");
	fflush(stdout);
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

int n;
string str;

map<tuple<int, bool>, long long> dp;

long long dfs(int p, bool black) {
	if (p == n) return 0;
	auto status = make_tuple(p, black);
	if (dp.count(status)) return dp[status];
	if (!black) {
		if (str[p] == '#') {
			return dp[status] = min(dfs(p + 1, false) + 1, dfs(p + 1, true));
		}
		return dp[status] = dfs(p + 1, str[p] == '#');
	}
	if (str[p] == '.') {
		return dp[status] = dfs(p + 1, true) + 1;
	}
	return dp[status] = dfs(p + 1, true);
}

void hawawa()
{
	cin >> n;
	cin >> str;
	cout << dfs(0, 0) << "\n";
}


void sieve_of_eratosthenes( vector<long long> &pm, long long n ) {
	vector<bool> is_pm( n + 1, true );
	is_pm[ 0 ] = is_pm[ 1 ] = false;
	for ( long long i = 2; i * i <= n; i += 2 ) {
		if ( is_pm[ i ] ) {
			for ( long long j = i * i; j <= n; j += i ) {
				is_pm[ j ] = false;
				if ( i != 2 ) {
					j += i;
				}
			}
			if ( i == 2 ) {
				--i;
			}
		}
	}
	for ( long long i = 2; i <= n; i += 2 ) {
		if ( is_pm[ i ] ) {
			pm.push_back( i );
			if ( i == 2 ) {
				--i;
			}
		}
	}
}

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


Measured memory_bytes: 38036
# -*- coding: utf-8 -*-
from fractions import Fraction
from collections import Counter, defaultdict, deque
import math

import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def f(a, b):
    if a == 0 and b == 0:
        return (0, 0)
    if b == 0:
        return (1, 0)
    f = Fraction(a, b)
    a = f.numerator
    b = f.denominator
    return a, b


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, AB):
    adb = Counter()
    for a, b in AB:
        a, b = f(a, b)
        adb[(a, b)] += 1
    M = Mod(1000000007)
    ans = 1
    done = set()
    for k, v in adb.items():
        if k in done:
            continue
        if k == (0, 0):
            continue
        a, b = k
        if a < 0:
            s = 1
            a = abs(a)
        elif a == 0:
            s = 1
        else:
            s = -1
        n = adb[(s*b, a)]
        done.add(k)
        done.add((s*b, a))
        t = M.sub(M.pow(2, v) + M.pow(2, n), 1)
        ans = M.mul(ans, t)

    return M.add(M.sub(ans, 1), adb[(0, 0)])


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 172472
#include <iostream>
using namespace std;
int d[1001][1001];
int e[1001][1001][3]={};
int f[1001][1001][3]={};
int main(){
	int m,n;
	char c;
	
	int k;
	int x1,y1,x2,y2;
	int tmp;
	cin>>m>>n;
	cin>>k;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			cin>>c;
			if(c=='J')d[j][i]=0;
			if(c=='O')d[j][i]=1;
			if(c=='I')d[j][i]=2;
		}
	}
	
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			for(int l=0;l<3;l++){
				if(d[j][i]==l)tmp=1;
				else tmp=0;
				e[j][i][l]=e[j-1][i][l]+tmp;
				f[j][i][l]=e[j-1][i][l]+f[j][i-1][l]+tmp;
			}
		}
	}
	/*
	for(int l=0;l<3;l++){
		for(int i=1;i<=m;i++){
			for(int j=1;j<=n;j++){
				if(f[j][i][l]<10)cout<<" ";
				cout<<f[j][i][l];
			}
			cout<<endl;
		}
		cout<<endl;
	}
	*/
	for(;k>0;k--){
		cin>>y1>>x1>>y2>>x2;
		
		for(int i=0;i<3;i++){
			cout<<f[x2][y2][i]+f[x1-1][y1-1][i]-f[x2][y1-1][i]-f[x1-1][y2][i];
			if(i==2)cout<<endl;
			else cout<<" ";
		}
		
		
	}
	
	return 0;
}


Measured memory_bytes: 28548
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <sstream>
using namespace std;
 
void solve() {
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	long long ans = a * c;
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	ans = max(ans, b * d);
	cout << ans << endl;
}
 
int main () {
	int t = 1;
	for(int tt = 0; tt < t; tt++) solve();
	return 0;
}

Measured memory_bytes: 3632
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
CD = [list(map(int, input().split())) for _ in range(M)]
for a, b in AB:
    dis = float('inf')
    for i, cd in enumerate(CD):
        now_dis = abs(a - cd[0]) + abs(b - cd[1])
        if now_dis < dis:
            dis = now_dis
            checkpoint = i+1
    print(checkpoint)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vmax 10000
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main(){
  int a,b;cin>>a>>b;
  cout<<max(a+b,max(a-b,a*b))<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}

int N, A, B;

int main() {
	cin >> N >> A >> B;
	cout << min(A * N, B) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<ll> A(N), B(N);
  for(int i=0;i<N;++i) cin>>A[i]>>B[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if(N%2==0) {
    cout<<(B[N/2]+B[N/2-1])-(A[N/2]+A[N/2-1])+1<<endl;
  }
  else {
    cout<<B[N/2]-A[N/2]+1<<endl;
  }
}



Measured memory_bytes: 6328
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        int[] read = inta();
        WriteLine(Min(read[0]*read[1],read[2]));
    
    }
    //各種読取
    static string rstr(){
        return ReadLine();
    }
    static int rint(){
        return int.Parse(ReadLine());
    }
    static long rlong(){
        return long.Parse(ReadLine());
    }
    static string[] stra(){
        return ReadLine().Split(' ');
    }
    static int[] inta(){
        string[] read_str_array = ReadLine().Split(' ');
        int[] return_int_array = new int[read_str_array.Length];
        for(int countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
        }
        return return_int_array;
    }
    static int[,] inta2(int num_array,int in_array){
        int[,] int_array2 = new int[num_array,in_array];
        for(int i=0;i<num_array;i++){
            int[] temp_array = inta();
            for(int j=0;j<in_array;j++){
                int_array2[i,j] = temp_array[j];
            }
        }
        return int_array2;
    }
    static long[] longa(){
        string[] read_str_array = ReadLine().Split(' ');
        long[] return_long_array = new long[read_str_array.Length];
        for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
        }
        return return_long_array;
    }
    static double[] doublea(){
        string[] read_str_array = ReadLine().Split(' ');
        double[] return_double_array = new double[read_str_array.Length];
        for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
        }
        return return_double_array;
    }
    // A/B小数点以下切上
    static long divideup(long divided,long divid){
        long temp_divide = divided/divid;
        if(divided % divid > 0){
            temp_divide++;
        }
        return temp_divide;
    }
    static long GCD(long a,long b){
        if(a < b){
            long temp = a;
            a = b;
            b = temp;
        }
        if(a % b == 0){ return b; }
        else{
            long temp = b;
            b = a%b;
            a = temp;
            return GCD(a,b);
        }
    }
    static long LCM(long a,long b){
        return a * b / GCD(a,b);
    }
}
//知見
// (string) hogestr -> (char[]) hoge
    // char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
    // string hoge = new string(hoge);
// Hashtable ×  Dictionary ○
// Dictionary hoge<string,int>
    // hoge.ContainsKey(string) -> return boolean
    // hoge[string] -> return int
    // hoge[int] -> CE
// Dictionary hoge<int1,int2>
    // hoge<int1,int2>: hoge[int1] -> return int2
    // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2
// SortedDictionary() > SortedList() ???
// キュー　-> 幅優先 ???
// スタック -> 深さ優先 ???


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

int main(){
  int r, c;
  cin >> r >> c;

  int a[r+1][c+1];

  for (int i = 0; i < r; i++) {
    int j, sum = 0;
    for (j = 0; j < c; j++) {
      cin >> a[i][j];
      sum += a[i][j];
    }
    a[i][j] = sum;
  }

  for (int i = 0; i < c + 1; i++) {
    int j, sum = 0;
    for (j = 0; j < r; j++) {
      sum += a[j][i];
    }
    a[j][i] = sum;
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      if(j != c) {
        cout << a[i][j] << " ";
      } else {
        cout << a[i][j];
      }
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3120
#include <stdio.h>
int main(void){
    int K,i,j;
    char S[100];
    scanf("%d %s",&K,S);
    for(i=0;S[i]!='\0';i++);
    if(i > K){
        for(j=0;j!=K;j++){
        printf("%c",S[j]);
        }
        printf("...\n");
    }
    else{
        printf("%s\n",S);
    }
    return 0;
}

Measured memory_bytes: 1644
s = int(input())
dv = []
mod = 10**9+7
for i in range(1,int((s+0.5)**0.5)+1):
  if s%i == 0:
    if s//i != i:
      dv.append(s//i)
    dv.append(i)
dv.sort()
ans = 0
cnt = 0
for i in dv:
  if s//i <= 8:
    break
  ans += pow(10,(s//i)-1,mod)*9-i
  ans %= mod
  cnt += 1
ans += (s-1)//8
t = s
for i in range(1,11):
  minus = i*9*10**(i-1)
  if minus > t:
    mx = (t+i-1)//i+10**(i-1)
    break
  else:
    t -= minus
bettable = [[[0,0] for i in range(9)] for j in range(9)]
for i in range(9):
  for j in range(i+1,9):
    for k in range(i+1,j):
      bettable[i][j][0] += k*10**(k-1)*9
      bettable[i][j][1] += 10**(k-1)*9
for i in range((s+7)//8,mx):
  avgl = s//i
  if avgl*i == s and 10**(avgl-1)*9 >= i:
    ans += 10**(avgl-1)*9-i+1
    continue
  avgh = avgl+1
  for l in range(1,avgl+1):
    for h in range(avgh,9):
      t = s-bettable[l][h][0]
      j = i-bettable[l][h][1]
      if t < 0 or j < 0:
        continue
      lnum = min(j,10**(l-1)*9)
      hnum = min(j,10**(h-1)*9)
      if (h*j-t)%(h-l) == 0:
        x = (h*j-t)//(h-l)
        if 0 < x <= lnum and 0 < j-x <= hnum:
          ans += 1
          break
print(ans%mod)

Measured memory_bytes: 49116
import java.util.Scanner;

class Main{
	public static void main(String[] ag) {
		Scanner sc=new Scanner(System.in);
		int Qs=sc.nextInt();
		int[] times=new int[Qs];
		int wa=0;
		for(int i=0; i<Qs; i++) {
			times[i]=sc.nextInt();
			wa+=times[i];
		}
		int M=sc.nextInt();
		for(int i=0; i<M; i++) {
			int a=sc.nextInt();
			System.out.println(wa-times[a-1]+sc.nextInt());
		}
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second

using namespace __gnu_pbds;
using namespace std;
const int mod = 1e9 + 7;
// const int mod=998244353;
//const int mod=1e9+9;
//const int INF=4e18+10;
const int INF = 4e18 + 10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) \
int n;      \
cin >> n;
#define readv(x, n)   \
vector<int> x(n); \
for (auto &i : x) \
    cin >> i;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template <typename T1, typename T2>
void set_min(T1 &a, T2 b)
{
    a = min(a, (T1)b);
}

int multiply(int a, int b, int in_mod) { return (a * b) % in_mod; }
int mult_identity(int a) { return 1; }


auto power(auto a, int b, int in_mod)
{
    auto prod = mult_identity(a);
    auto mult = a % in_mod;
    while (b != 0)
    {
        if (b % 2)
        {
            prod = multiply(prod, mult, in_mod);
        }
        mult = multiply(mult, mult, in_mod);
        b /= 2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod - 2, in_mod);
}

void  solve()
{

    string s;
    cin>>s;
    int mx = 0;
    for(int i= 0;i<3;i++)
    {
        for(int j= i;j<3;j++)
        {
            bool flag=false;
            for(int k=i;k<=j;k++)
            {
                if(s[k]!='R')
                    flag=true;
            }
            if(!flag)
                mx= max(mx, j-i+1);
        }
    }
    cout<<mx<<endl;

}



signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cerr.tie(NULL);
#ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen("INPUT.txt", "r", stdin);
        freopen("OUTPUT.txt", "w", stdout);
    }
#endif
    auto clk = clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t = 1;
    // cin >> t;

    for (int test = 1; test <= t; test++)
    {
        // cout<<"Case #"<<test<<":\n";
        //cout<<"Trip #"<<test<<": ";
        // cout<<endl;
        solve();
        // solveB();

        // cout<<endl;
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    clk = clock() - clk;
    // cerr << fixed << setprecision(6) << "Time: " << ((long double)clk) / CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 3676
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

#define Emax 2000
#define Vmax 1000
#define Dmax (10000)
#define INF (1000000)

using namespace std;

typedef unsigned int uint;
typedef long long int llint_t;

struct Edge {
  int from, to, cost;
};

Edge edges[Emax];
static llint_t d[Vmax];
static int Vnum, Enum, r;

void bellman_ford() {
  fill_n(d, Vnum, INF);
  d[r] = 0;
  for (int i = 0; i < Vnum; i++) {
    for (int j = 0; j < Enum; j++) {
      auto uv = edges[j];
      auto u = uv.from;
      auto v = uv.to;
      if (d[u] == INF) continue; // unreachable vertex
      if (d[u] + uv.cost < d[v]) {
        d[v] = d[u] + uv.cost;
        if (i == Vnum - 1) {
          puts("NEGATIVE CYCLE");
          exit(0);
        }
      }
    }
  }
}

int main(int ac, char **av) {
  scanf("%d %d %d", &Vnum, &Enum, &r);

  for (int i = 0; i < Enum; i++) {
    int s, t, d;
    scanf("%d %d %d", &s, &t, &d);
    Edge e;
    e.from = s;
    e.to = t;
    e.cost = d;
    edges[i] = e;
  }

  bellman_ford();

  for (int i = 0; i < Vnum; i++) {
    if (d[i] == INF) {
      printf("INF\n");
    } else {
      printf("%d\n", d[i]);
    }
  }
  return 0;
}


Measured memory_bytes: 2728
#include<bits/stdc++.h>
using namespace std;
int ar[300000],n,k,mn=1000000003,mx=0 ;
int fun(int l)
{
    int p=l ; int ct=0 ;
    for(int i = 0 ; i < n ; i++)
    {
        int d=ar[i] ;
        int k=d/p ; ct+=k ;
      //  cout<<k<<" "<<ct<<" " ;
        if(d%p!=0) ct++ ; //cout<<ct<<endl ;
        ct-- ;
    }
    //cout<<"final "<<ct<<endl ;
    return ct ;
}
int main()
{
    cin>>n>>k ;
    for(int i = 0 ; i < n ; i++) {cin>>ar[i] ; mn=min(mn,ar[i]) ; mx=max(mx,ar[i]) ; }
    if(!k){cout<<mx<<endl; return 0 ; }
    int lo=1 , hi=mx , ans ;
    while(lo<=hi)
    {
        int md=(lo+hi)/2 ;
        int x=fun(md) ;
        //cout<<lo<<" "<<hi<<" "<<md<<" "<<x<<endl ;
        if(x<=k){ ans=md ; hi=md-1; }
        else lo=md+1 ;
    }
    cout<<ans<<endl ;
}


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

using namespace std;

int main() {
	long long k;
	
	cin >> k;
	
	long long number = 0;
	int i = 1;
	
	while (i <= 1000001) {
		number = (number * 10 + 7) % k;
		
		if (number == 0) {
			cout << i;
			break;
		}
		
		i++;
	}
	
	if (i >= 1000001) {
		cout << -1;
	}
	
	return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;

const int N=9e5+10;

ll fac[N],inv[N],pw[N];

ll ksm(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod,b>>=1;
	}
	return res;
}

ll C(ll n,ll m){
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int main(){
	ll n,m,k,j=1,ans=0;
	scanf("%lld%lld%lld",&n,&m,&k);
	if(k>m) swap(k,m);
	fac[0]=inv[0]=pw[0]=1;
	for(int i=1;i<=n+k+m;i++) fac[i]=fac[i-1]*i%mod,pw[i]=pw[i-1]*3%mod;
	inv[n+k+m]=ksm(fac[n+k+m],mod-2);
	for(int i=n+k+m-1;i;i--) inv[i]=inv[i+1]*(i+1)%mod;
	for(int i=0;i<=m+k;i++){
		ans=(ans+C(n+i-1,n-1)*pw[m+k-i]%mod*j%mod)%mod;
		if(i<k) j=2*j%mod;
		else if(i>=m) j=(2*j-C(i,k)-C(i,i-m)+2*mod)%mod;
		else j=(2*j-C(i,k)+mod)%mod;
	}
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}

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

using namespace std;

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

    pair<int, int> T[N];
    for(int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        T[i] = make_pair(b, a);
    }

    sort(T, T+N);

    long now = 0;
    for(int i=0; i<N; i++){
        if(now + T[i].second > T[i].first){
            cout << "No";
            return 0;
        }
        now += T[i].second;
    }

    cout << "Yes";

    return 0;

}

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

static class NagataKanaIsAGenius {
    public static void Main() {
        long[]nm=Console.ReadLine().Split().Select(long.Parse).ToArray();
        long n=nm[0];
        long m=nm[1];
        Tuple<long,long>[]data=new Tuple<long,long>[m];
        for(long i=0;i<m;i++){
            long[]uv=Console.ReadLine().Split().Select(long.Parse).ToArray();
            long u=uv[0]-1;
            long v=uv[1]-1;
            data[i]=new Tuple<long,long>(u,v);
        }
        p=new long[n];
        for(long i=0;i<n;i++){
            p[i]=-1;
        }

        long now= (long)n*(n-1)/2;
        long[]ans=new long[m];
        for(long i=m-1;i>=0;i--){
            ans[i]=now;
            long u=data[i].Item1;
            long v=data[i].Item2;
            u=Find(u);
            v=Find(v);
            if(u==v)continue;
            now-=p[u]*p[v];
            p[v]+=p[u];
            p[u]=v;
        }
        for(int i=0;i<m;i++){
            Console.WriteLine(ans[i]);
        }
    }
    static long[]p;
    static long Find(long x)=>p[x]<0?x:p[x]=Find(p[x]);
}


Measured memory_bytes: 25908
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int S[n];
    for(int i=0; i<n; i++)  scanf("%d",&S[i]);
    int q;
    scanf("%d",&q);
    int t;
    int count=0;
    for(int i=0; i<q; i++){
        scanf("%d",&t);
        for(int j=0; j<n; j++){
            if(t==S[j]){
                count++;
                break;
            }
        }
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2760
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF=1e18;

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

    ll N, M;
    cin >> N >> M;
    vector<ll> products(N);
    ll all = 0;
    for (int i=0; i<N; i++) { 
        cin >> products[i];
        all += products[i];
    }

    int count = 0;
    for (int i=0; i<N; i++) {
        if (products[i] * 4 * M >= all) {
            count++;
        }

        if (count >= M) {
            cout << "Yes" << '\n';
            return 0; 
        }
    }
    cout << "No" << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

const char sp = ' ';
string s;
const int INF = 0xE869120;
int f[1111111][2];

int main() {
	cin >> s;
	reverse(s.begin(), s.end());
	s.push_back('0');
	f[0][1] = INF;
	for (int i = 0; i < s.size(); i++) {
		f[i + 1][0] = min(f[i][0] + s[i] - '0', f[i][1] + s[i] - '0' + 1);
		f[i + 1][1] = min(f[i][0] + 10 - (s[i] - '0'), f[i][1] + 10 - (s[i] - '0' + 1));
	}

	cout << f[s.size()][0] << endl;

	return 0;
}

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

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


Measured memory_bytes: 3640
#include <iostream>

using namespace std;


int main(){

	int n;
	long long int cnt=0;
	long long int *a;

	cin>>n;
	a = new long long int[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}

	for(int i=0;i<n;i++){
		while(a[i]>0){
			if(a[i]>=2){
				cnt+=a[i]/2;
				a[i]%=2;
			}
			else if(i==n-1){
				break;
			}
			else if(a[i]>=1 && a[i+1]>=1){
				cnt++;
				a[i]-=1;
				a[i+1]-=1;
			}
			else{
				break;
			}
		}
	}
	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	string s; cin >> s;
	vector<int>cnt(N, 0);
	rep(i, N) {
		if (s[i] == 'W') {
			cnt[0]++;
			cnt[i]--;
		}
		else {
			if (i == N - 1)continue;
			cnt[i + 1]++;
		}
	}
	REP(i, 1, N) {
		cnt[i] += cnt[i - 1];
	}
	int ans = 0;
	rep(i, N) {
		chmax(ans, cnt[i]);
	}
	ans = N - 1 - ans;
	cout << ans << "\n";

	return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  string s;
  cin>>s;
  string S;
  char memo='x';
  for(int i=0;i<s.size();i++){
    if(memo!=s[i])S.push_back(s[i]),memo=s[i];
  }
  int ans1=0;
  for(int i=0;i<S.size();i++){
    if(S[i]=='B'){
      if(i==0||i==S.size()-1)ans1++;
      else ans1+=2;
    }
  }
  int ans2=0;
  for(int i=0;i<S.size();i++){
    if(S[i]=='W'){
      if(i==0||i==S.size()-1)ans2++;
      else ans2+=2;
    }
  }
  cout<<min(ans1,ans2)<<endl;
  return 0;
}


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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define REP(i,n) for(ll i = 1; i < (n); i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")

using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1; 


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

  int n;
  cin >> n;
  map<int, int> mp;
  rep(i,n){
    int a;
    cin >> a;
    mp[a]++;
  }
  int ans = 0;
  for(auto it = mp.begin(); it != mp.end(); it++){
    if((*it).first <= (*it).second) ans += (*it).second - (*it).first;
    else ans += (*it).second;
  }
  cout << ans << "\n";

}

Measured memory_bytes: 4736
import math
n,k = map(int,input().split())

ret=0

for i in range(1,n+1):
    p=math.ceil(math.log2(k/i))
    p=p if p>0 else 0
    ret+=math.pow(0.5,p)/n

ret=math.floor(ret*1e12)*1e-12
print(ret)


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

int main(){
  int D,G,p[11],c[11];
  cin >> D >> G;
  for(int i=0;i<D;i++){
    cin >> p[i] >>c[i];
  } 
  int ans=1e9;
  for(int mask=0;mask<(1<<D);mask++){
    int s = 0, num = 0, rest_max=-1;
    for(int i = 0;i < D;i++){
      if(mask&(1<<i)){
        s+=100*(i+1)*p[i]+c[i];
        num+=p[i];
      }else{
        rest_max=i;
      }
    }
    if(s<G){
      int s1=100*(rest_max+1);
      int need=(G-s+s1-1)/s1;
      if(need >= p[rest_max]){
        continue;
      }
      num+=need;
    }
    ans=min(ans,num);
  }
  cout<< ans <<endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;
const int maxn = 3e5 + 5;

void go() {
    int n, k;
    cin >> n >> k;
    vector<int>v(n);
    for (auto &i : v) {
        cin >> i;
    }
    int ans = 1e9;
    f(n - k + 1) {
        int low = v[i];
        int up = v[i + k - 1];
        up = max(up, 0);
        low = min(low, 0);
        low = -low;
        ans = min(ans, up + low + min(up, low));
    }
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
}


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

using namespace std;

int main(){
    long long H, W;
    cin >> H >> W;

    vector<long long> s(3);
    long long ans = __INT_MAX__;
    for(long long i = 1; i < W; i++){
        s[0] = H * i;
        s[1] = (W-i) * (H/2);
        s[2] = (W-i) * ((H+1)/2);
        sort(s.begin(), s.end());
        ans = min(ans, s[2]-s[0]);
    }
    for(long long i = 1; i < H; i++){
        s[0] = W * i;
        s[1] = (H-i) * (W/2);
        s[2] = (H-i) * ((W+1)/2);
        sort(s.begin(), s.end());
        ans = min(ans, s[2]-s[0]);
    }
    
    ans = min(ans, H*(W/3 + min(W%3, 1LL)) - H*(W/3));
    ans = min(ans, W*(H/3 + min(H%3, 1LL)) - W*(H/3));

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
import sys
import collections

n = int(input())
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b, c = [int(x) for x in input().split()]
    adj[a].append((b, c))
    adj[b].append((a, c))
q, k = [int(x) for x in input().split()]
dist = [0] * (n + 1)
queue = collections.deque()
queue.append(k)
while len(queue) > 0:
    u = queue.popleft()
    for v, weight in adj[u]:
        if dist[v] == 0:
            queue.append(v)
            dist[v] = dist[u] + weight
for j in range(q):
    l, r = [int(x) for x in input().split()]
    print(dist[l] + dist[r])
# print(*data, sep='\n')


Measured memory_bytes: 83104
#32 ABC135C
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b.append(0)
res=0

if a[0]>=b[0]:
	res+=b[0]
	a[0]-=b[0]
	b[0]=0
else:
	res+=a[0]
	b[0]-=a[0]
	a[0]=0

for i in range(1,n+1):
	if b[i-1]>0:
		if a[i]<=b[i-1]:
			res+=a[i]
			b[i-1]-=a[i]
			a[i]=0
		else:
			res+=b[i-1]
			a[i]-=b[i-1]
			b[i-1]=0
	if a[i]>=b[i]:
		res+=b[i]
		a[i]-=b[i]
		b[i]=0
	else:
		res+=a[i]
		b[i]-=a[i]
		a[i]=0
#print(a)
#print(b)
print(res)

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int IT = 2e5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

char s[maxn], c[2];

void solve() {
    int q, t, f, n, flag = 0, l, r;
    scanf("%s", s + IT);
    n = strlen(s + IT);
    l = IT - 1, r = n + IT;
    scanf("%d", &q);
    while (q--) {
        scanf("%d", &t);
        if (t == 1) flag ^= 1;
        else {
            scanf("%d %s", &f, c);
            if (f == 1) {
                if (flag) s[r++] = c[0];
                else s[l--] = c[0];
            } else {
                if (flag) s[l--] = c[0];
                else s[r++] = c[0];
            }
        }
    }

    if (flag) {
        for (int i = r - 1; i > l; i--) printf("%c", s[i]);
    } else {
        for (int i = l + 1; i < r; i++) printf("%c", s[i]);
    }
    puts("");
}

int main() {
	// header();
	solve();
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    int d;
    cin >> d;
    vector<int> c(26); //満足度の下がりやすさ
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int> (26)); //満足度の増減(たてが日時、よこがコンテストの種類)
    rep(i, d) {
        rep(j, 26) cin >> s[i][j];
    }
    vector<int> t(d); //コンテスト開催種類
    rep(i, d) cin >> t[i];
    int satis = 0; //満足度
    vector<int> date(26); //コンテストの開催日時の記憶(last用)
    set<int> be; //コンテストが開催されたかどうかの判断
    rep(i, d) {  //日時 0-indexed
        date[t[i] - 1] = i; //コンテストの日時 0-indexed
        be.insert(t[i]); //コンテストが開催されたことを記憶。1-indexed
        satis += s[i][t[i] - 1];
        rep(j, 26) {  //1日の終わりの満足度の減少 0-indexed
            int last;
            if(be.count(j + 1)) last = date[j] + 1; //1-indexed
            else last = 0; 
            satis -= c[j] * (i + 1 - last);
        }
        cout << satis << endl;
    }
}

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> reds(a), blues(b), whites(c);
    rep(i, a) cin >> reds[i];
    rep(i, b) cin >> blues[i];
    rep(i, c) cin >> whites[i];

    sort(reds.rbegin(), reds.rend());
    sort(blues.rbegin(), blues.rend());
    sort(whites.rbegin(), whites.rend());
    vector<ll> eats;
    rep(i, x) eats.push_back(reds[i]);
    rep(i, y) eats.push_back(blues[i]);
    for (ll l : whites) eats.push_back(l);
    sort(eats.rbegin(), eats.rend());
    ll ans = accumulate(eats.begin(), eats.begin() + x + y, 0ll);
    cout << ans << endl;
}


Measured memory_bytes: 8688
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <deque>
using namespace std;
int N;
int a[100002];
typedef long long int ll;
const ll mod=1e9+7;
ll mm=1;
int index;
int v[100002];
ll fact[100001],inv[100001];

ll calc(ll a,ll b){
  if(b==0)return 1;
  if(b%2==0){
    ll d=calc(a,b/2);
    return (d*d)%mod;
  }
  else{
    return (a*calc(a,b-1))%mod;
  }
}

ll C(ll n,ll k){
  if(n<k)return 0;
  return (((fact[n]*calc(fact[k],mod-2))%mod)*calc(fact[n-k],mod-2))%mod;
}

int main(){
  int l,r;
  for(int i=0;i<=100001;i++)v[i]=-1;
  cin >> N;
  for(int i=0;i<=N;i++){
    cin >> a[i];
    if(v[a[i]]== -1)v[a[i]]=i;
    else{l=v[a[i]] ;r=i;}
  }
  fact[0]=1;
  for(int i=1;i<=N+1;i++)fact[i]=(fact[i-1]*i)%mod;
  //printf("%d %d\n",l,r);

  
  for(int k=1;k<=N+1;k++){
    cout << (C(N+1,k)- C(l+N-r,k-1)+mod)%mod << endl;
  }
  return 0;
}


Measured memory_bytes: 2816
n = int(input())
S = list(str(input()))
S = [{ord(c)-ord('a')} for c in S]

def segfunc(x, y):
    return x | y

def init(init_val):
    # set_val
    for i in range(n):
        seg[i+num-1] = init_val[i]
    # built
    for i in range(num-2, -1, -1):
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])

def update(k, x):
    k += num - 1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[2*k+1], seg[2*k+2])

def query(p, q):
    if q <= p:
        return ide_ele
    p += num - 1
    q += num - 2
    res = ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res, seg[p])
        if q&1 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(segfunc(res, seg[p]), seg[q])
    return res

# identity element
ide_ele = set()

# num: n以上の最小の2のべき乗
num = 2**(n-1).bit_length()
seg = [ide_ele]*2*num

init(S)

import sys
input = sys.stdin.readline
q = int(input())
for i in range(q):
    t, x, y = map(str, input().split())
    if t == '1':
        x = int(x)
        y = ord(y)-ord('a')
        update(x-1, {y})
    else:
        x = int(x)
        y = int(y)
        print(len(query(x-1, y)))


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

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

int main() {
    unsigned long long a, b;
    cin >> a;
    cin >> b;
    unsigned long long x, tmp;

    x = a * b;
    if (a < b) {
        tmp = a;
        a = b;
        b =tmp;
    }
    unsigned long long r;
    r = a % b;
    while (r!= 0) {
        a = b;
        b = r;
        r = a % b;
    }

    cout << x / b << endl;
}

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

int main(){
	int n, p;
	while(true){
		scanf("%d%d", &n, &p);
		if(n == 0 && p == 0){
			break;
		}
		int mayor[50];
		for(int i = 0; i < 50; i++){
			mayor[i] = 0;
		}	
		bool finish = false;
		int m = -1;
		int pp = p;
		int t = 0;
		while(true){
			// 終了判定
			for(int i = 0; i < n; i++){
				if(mayor[i] == p){
					finish = true;
					m = i;
					break;
				}
			}
			if(finish){
				break;
			}
			
			if(t == n){
				t = 0;
			}
			
			// シュミレート
			
			if( pp > 0){
				mayor[t]++;
				pp--;
				t++;
			}
			else{
				pp = mayor[t];
				mayor[t] = 0;
				t++;
			}
		}
		printf("%d\n", m);
	}
	return 0;
}

Measured memory_bytes: 876
import math

N = int(input())

res = 10**12+1

if N==1:
    print(0)
else:
    for a in range(1, int(math.sqrt(N))+1):
        if (N%a)==0:
            b = int(N/a)
            if res>a+b-2:
                res = a+b-2
    
    if res == 10**12+1:
        print(N-1)
    else:
        print(res)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(),std::greater<int>())


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll r, d,x;
    cin >> r >> d >> x;
    
    for (int i = 1; i <= 10; ++i) {
        ll ans = r * x - d;
        cout << ans << endl;
        x = ans;
    }
    
    return 0;
}


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

int main(){
  ll H, W, N; cin >> H >> W >> N;
  vector<ll> ans(10, 0LL);
  vector< pair<ll, ll> > sq;
  
  for(ll i = 0; i < N; i++){
    ll a, b; cin >> a >> b;
    a--; b--;
    for(ll h = a-2; h <= a; h++){
      for(ll w = b-2; w <= b; w++){
        if(h < 0 || h >= H-2 || w < 0 || w >= W-2)
          continue;
        
        sq.emplace_back(make_pair(h, w));
      }
    }
  }
  
  sort(sq.begin(), sq.end());
  
  pair<ll, ll> prv = sq[0];
  ll cnt = 0;
  ans[0] = (H-2) * (W-2);
  for(auto p: sq){
    if(p == prv) cnt++;
    else{
      ans[cnt]++;
      cnt = 1;
      ans[0]--;
    }
    prv = p;
  }
  ans[cnt]++;
  ans[0]--;
  
  for(ll i = 0; i < 10; i++){
    cout << ans[i] << endl;
  }
  
}

Measured memory_bytes: 18536
n, a, b = gets.split(' ').map{|x| x.to_i}
if (a >= b) then
  big = a
  small = b
else
  big = b
  small = a
end
max = small
min = big + small - n
min = 0 if (min < 0)
puts max.to_s + ' ' + min.to_s


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
int main() {
  int n;
  cin>>n;
  rep(i,10){
    n-=1000;
    if(n<=0){
      cout<<(n*-1);
      return 0;
    }
  }
}

Measured memory_bytes: 3616
from collections import deque

ss = input()
q = int(input())
s = deque()

for i in range(len(ss)) :
  s.append(ss[i])

r = 0
for i in range(q) :
  t = list(map(str,input().split()))
  if t[0] == '1' :
    r += 1
  if t[0] == '2' :
    f = t[1] ; c = t[2]
    if r%2 == 0 :
      if f == '1' :
        s.appendleft(c)
      else :
        s.append(c)
    else :
      if f == '2' :
        s.appendleft(c)
      else :
        s.append(c)
        
if r%2 == 1 :
  s.reverse()
  
print(*s,sep='')

Measured memory_bytes: 12520
Public Class Program
  Shared Sub Main()
    Dim n As Integer = Integer.Parse(Console.ReadLine())
    Dim ps As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
    Dim count As Integer = 0
    Dim output As String = "YES"
    For i As Integer = 0 To n - 1
      If ps(i) <> i + 1 Then
        If ps(ps(i) - 1) = i + 1 Then
          count += 1
        Else
          output = "NO"
          Exit For
        End If
      End If
    Next
    If count <> 0 AndAlso count <> 2 Then output = "NO"
    Console.WriteLine(output)
  End Sub
End Class

Measured memory_bytes: 13140
a=input()
b=input()
b=list(b)
n=len(a)
flag=0
for i in range(0,n):
    a=list(a)
    c=a[n-1]
    a=a[0:n-1]
    a.insert(0,c)
    #a=str(a)
    #print(a)
    if a==b:
        flag=1
        break
if flag==0:
    print('No')
else:
    print("Yes")

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

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

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    String a[] = new String[n];
    String b[] = new String[m];
    boolean ju = false;
    for(int i = 0 ; i < n ; ++i){
      a[i] = sc.next();
    }
    for(int i = 0 ; i < m ; ++i){
      b[i] = sc.next();
    }
    
    for(int i = 0; i <= n-m; i++){
      for(int j = 0; j <= n-m; j++){
        int count = 0;
        for(int k = 0; k < m; k++){
          if(b[k].equals(a[i+k].substring(j,j+m))){
            count++;
          }
        }
        if(count == m){
          ju = true;
          break;
        }
      }
      if(ju) break;
    }
    
    if(ju) System.out.println("Yes");
    else System.out.println("No");
    
  }
}


Measured memory_bytes: 36908
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=200010,Mo=924844033;
int n,tt;
int A[N*4],B[N*4],rev[N*4],head[N],to[N*2],nxt[N*2],sz[N],fac[N],inv[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline int Pow(int x,int y) {
    int ret=1;
    while(y) {
	if(y&1) ret=1LL*ret*x%Mo;
	x=1LL*x*x%Mo,y>>=1;
    }
    return ret;
}
inline void NTT(int *a,int n,int f) {
    for(int i=0;i<n;i++) if(i<rev[i]) swap(a[i],a[rev[i]]);
    for(int i=1;i<n;i<<=1) {
	int wn=Pow(5,(Mo-1)/(i<<1)),x,y;
	for(int j=0;j<n;j+=i<<1)
	    for(int k=0,w=1;k<i;k++,w=1LL*w*wn%Mo) {
		x=a[j+k],y=1LL*a[j+k+i]*w%Mo;
		a[j+k]=(x+y)%Mo,a[j+k+i]=(x-y)%Mo;
	    }
    }
    if(f==1) return;
    reverse(a+1,a+n);
    int Inv=Pow(n,Mo-2);
    for(int i=0;i<n;i++) a[i]=1LL*a[i]*Inv%Mo;
}
inline void dfs(int x) {
    sz[x]=1;
    for(int i=head[x];i;i=nxt[i]) {
	int y=to[i];
	if(!sz[y]) {
	    dfs(y),sz[x]+=sz[y];
	    --A[sz[y]],--A[n-sz[y]];
	}
    }
}
int main() {
    int s,L;
    cin>>n,A[n]=n;
    for(int i=1;i<n;i++) {
	int x=gi(),y=gi();
	to[++tt]=y,nxt[tt]=head[x],head[x]=tt;
	to[++tt]=x,nxt[tt]=head[y],head[y]=tt;
    }
    dfs(1),fac[0]=1;
    for(int i=1;i<=n;i++) fac[i]=1LL*fac[i-1]*i%Mo;
    inv[n]=Pow(fac[n],Mo-2);
    for(int i=n;i;i--) inv[i-1]=1LL*inv[i]*i%Mo;
    for(int i=1;i<=n;i++) A[i]=1LL*A[i]*fac[i]%Mo;
    for(int i=0;i<=n;i++) B[i]=inv[n-i];
    for(s=1,L=0;s<=n+n;s<<=1) L++;
    for(int i=0;i<s;i++) rev[i]=((rev[i>>1]>>1)|((i&1)<<L-1));
    NTT(A,s,1),NTT(B,s,1);
    for(int i=0;i<s;i++) A[i]=1LL*A[i]*B[i]%Mo;
    NTT(A,s,-1);
    for(int i=1;i<=n;i++) printf("%lld\n",1LL*(A[n+i]+Mo)*inv[i]%Mo);
    return 0;
}

Measured memory_bytes: 19968
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;
class MainClass
{
	static void Main(string[] args)
	{
		Answer(new ConsoleInput(Console.In, ' '));
	}
	public static void Answer(ConsoleInput cin)
	{
	  var N = cin.ReadInt;
      var val = N;
      if (val % 2 != 0) { val *= 2;}
      WriteLine(val);
	}
  
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 11220