akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

int N, K;
string S;

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

    cin >> N >> K >> S;
    string t = S;
    S += string(S.rbegin(), S.rend());
    FOR(i, 1, N + 1) chmin(t, S.substr(i, N));
    int l = 1;
    while(l < t.size() && t[0] == t[l])
        l++;
    int k = N;
    if(--K < 15) chmin(k, l << K);
    cout << string(k, t[0]) + t.substr(l, N - k) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int i = 0;
        for(i=1;;i++){
            int x = stdIn.nextInt();

            if(x == 0){
                break;
            }

            System.out.printf("Case %d: %d\n",i,x);

        }

        stdIn.close();

    }

}


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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long k;
	cin >> k;
	long long ans[50];
	long long times = (k+49)/50;
	for(int i = 0; i < 50; ++i) {
		ans[i] = (49) + times - 1;
	}
	ans[49]++;
	long long extra = 50*times - k;
	while(extra--) {
		int itmx = 0;
		int vlmx = 0;
		for(int i = 0; i < 50; ++i) {
			if(ans[i] > vlmx) {
				vlmx = ans[i];
				itmx = i;
			}
		}
		for(int i = 0; i < 50; ++i) {
			if(i == itmx) ans[i] -= 50;
			else ++ans[i];
		}
	}
	cout << 50 << endl;
	for(int i = 0; i < 50; ++i){
		cout << ans[i] << ' ';
	}
	cout << endl;

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

A_list.sort()

# Check Reports(Ai) that is correct or not.
if N%2 == 0:
    i=0
    for x in range(int(N/2)):
        if A_list[i] == A_list[i+1] == 2*x + 1:
            i += 2
            continue
        else:
            #NG
            print("0")
            sys.exit()

elif N%2 == 1:
    i=0
    for x in range( int((N-1)/2) ):
        if i == 0 and A_list[i] == 0:
            i += 1
            continue
        elif A_list[i] == A_list[i+1] == 2*x:
            i += 2
            continue
        else:
            #NG
            print("0")
            sys.exit()

# Calculate Order
order = 1
for i in range(N//2):
    order = order * 2 % (10**9 + 7)

print(order)


Measured memory_bytes: 14008
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


ll copy_and_cnt(const int &N, const int &top, const int &end,vector<vector<ll>> &memo) {
    if (memo[top][end] != -1) return memo[top][end];

    ll ans = 0;

    // 先頭と最後の桁が同じなら相手は一桁もあり得り、それは必ず成り立つ
    if (top == end) ans++;

    // 二桁の場合
    if ( N >= stoi(to_string(end)+to_string(top))) ans++;
    int mid = 0;
    int cnt = 0;
    string end_str;
    int zeros = 0;
    string zero;
    int sum_mid = 0;
    REP(i,5) {
        mid = 0;
        // end<hoge>topで表せる数で hogeを999...にしてって、どこまで入るのかを調査する。
        while ( N >= stoi(to_string(end)+zero+to_string(mid)+to_string(top))) {
            mid++;
        }
        sum_mid += mid;
        zero.push_back('0');
    }




    memo[top][end] = sum_mid+ans+zeros;
    return sum_mid+ans+zeros;
}


ll solve(int N) {
    vector<vector<ll>> memo(10,vector<ll>(10,-1));
    ll ans = 0;
    FOR(a,1,N+1) {
        if ( a%10 == 0 ) continue;
        string a_str = to_string(a);
        ans += copy_and_cnt(N,a_str[0]-'0',a_str[a_str.size()-1]-'0',memo);
    }
    return ans;
}

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

    cout << solve(N) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main( void )
{
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if( s[0] == s[2] ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
class Point
  attr_accessor :x, :y
  def initialize(s)
    @x,@y = s.split(" ").map{|z| z.to_i}
  end
end

n = gets.chomp.to_i
red = []
blue = []
for i in 0..n-1 do
  red << Point.new(gets.chomp)
end
for i in 0..n-1 do
  blue << Point.new(gets.chomp)
end
blue.sort!{|a,b| a.x <=> b.x }
red.sort!{|a,b| b.y <=> a.y }

count = 0
for b in blue do
  for r in red do
    if r.x < b.x && r.y < b.y
      count += 1
      red.delete(r)
      break
    end
  end
end

printf("%d\n",count)

Measured memory_bytes: 1788
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int>> result;
  int forbid;
  if (n % 2 == 0) forbid = n + 1;
  else forbid = n;
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      if (i + j != forbid)
        result.emplace_back(i, j);
  printf("%d\n", (int)result.size());
  for (pair<int, int> edge : result)
    printf("%d %d\n", edge.first, edge.second);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<array>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef int long long ll;
static const int N=100;
static const int white=0;
static const int gray=1;
static const int black=2;

int n,d[N],f[N],tt;
int color[N],nt[N];
int mp[N][N];

int next(int u){
    
    for(int v=nt[u];v<n;v++){
        nt[u]=v+1;
        if(mp[u][v]!=0)return v;
    }
    return -1;
}


void dfs_visit(int r){
    
    rep(i,n)nt[i]=0;
    stack<int> s;
    s.push(r);
    color[r]=gray;
    d[r]=++tt;
    while(!s.empty()){
        int u=s.top();
        int v=next(u);
        if(v!=-1){
            if(color[v]==white){
            d[v]=++tt;
            color[v]=gray;
            s.push(v);
            }
        }else{
            color[u]=black;
            f[u]=++tt;
            s.pop();
        }
    }
}



void dfs(){

    rep(i,n){color[i]=white;}
    tt=0;
    
    for(int i=0;i<n;i++){
        if(color[i]==white){
            dfs_visit(i);
        }
    }
    rep(i,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    
}

int main(){
    cin>>n;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            mp[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        rep(j,b){
            int c;
            cin>>c;
            mp[a-1][c-1]=1;
        }
    }
    
    dfs();
    
    return 0;
}



Measured memory_bytes: 3132
var
  i,j:longint;
  s,s1,s2:ansistring;
begin
  readln(s1);
  readln(s2);
  i:=1;
  j:=1;
  while (i<=length(s1))or(j<=length(s2)) do
  begin
    if i<=length(s1) then begin s:=s+s1[i];inc(i);end;
    if j<=length(s2) then begin s:=s+s2[j];inc(j);end;
  end;
  writeln(s);
end.

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

int main(){
    int N, K;
    cin >> N >> K;
    double ans = 0;
    for (int i = 1; i <= N; ++i){
        int num = i;
        int counter = 0;
        while (num < K){
            num*=2;
            counter++;
        }
        ans += 1/(double)(1<<counter);
    }

    cout << fixed << setprecision(15) << ans/(double)N << endl;
    return 0;
}

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

int main(){
  int count=0;
  string S;
  cin >> S;
  for(int i=0;i<(S.length())/2;i++){
    if(S[i]!=S[S.length()-(i+1)]){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
p = []
q = []
for i in range(n):
    a,b = map(int,input().split())
    p.append(a)
    q.append(b)

sop = sorted(p)
soq = sorted(q)
ans = 0
if n % 2 == 1:
    ans = soq[(n+1)//2-1] - sop[(n+1)//2-1] + 1
elif n % 2 == 0:
    s = soq[n//2-1]+soq[n//2]
    t = sop[n//2-1]+sop[n//2]
    ans = (s*0.5-t*0.5+1)*2 - 1
print(int(ans))

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

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

    int Ans;
    if((n-1)%(k-1) == 0){
        Ans = (n-1)/(k-1);
    }
    else{
        Ans = (n-1)/(k-1) +1;
    }

    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <string>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0;i < N;i ++){
        cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    cout << A.at(N-1) - A.at(0) << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    int n;
    cin>>n;
    char a[110];
    scanf("%s",a);
    int j = strlen(a);
    if(n < j){
        for(int i = 0; i < n; i++){
            printf("%c",a[i]);
        }
        printf("...");
    }
    else{
        printf("%s",a);
    }
    return 0;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	double n;
	cin >> n;
	double cnt = 0;
	rep(i, n) {
		if (((int)n - i) % 2)
			cnt++;
	}
	printf("%.10f\n", cnt / n);
}



Measured memory_bytes: 256
s = input()
t = input()

dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])

ret_rev = []

i, j = len(s) - 1, len(t) - 1
while i >= 0 and j >= 0:
    if s[i] == t[j]:
        ret_rev.append(s[i])
        i, j = i - 1, j - 1
    elif dp[i + 1][j + 1] == dp[i + 1][j]:
        i, j = i, j - 1
    else: # i.e. dp[i + 1][j + 1] == dp[i][j + 1]
        i, j = i - 1, j

ret = "".join(ret_rev[::-1])

print(ret)


Measured memory_bytes: 113244
import sys
from collections import deque

n = int(input())
matches = [[a - 1 for a in map(int, line.split())] for line in sys.stdin]
#print(matches)
q = deque(range(n))
#print(q)
depth = [0] * n
waiting = [-1] * n

while q:
    a = q.popleft()
    b = matches[a].pop()
    #print(a, b)
    if waiting[b] == a:
        depth[a] = depth[b] = max(depth[a], depth[b]) + 1
        if matches[a]:
            q.append(a)
        if matches[b]:
            q.append(b)
    else:
        waiting[a] = b

if any(matches):
    print(-1)
else:
    print(max(depth))

Measured memory_bytes: 66780
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <cmath>

const double PI=acos(-1);

struct vec{
    double r;
    double rand;
    vec(){
        r=100.0;
        rand=0.0;
    }
    vec(double r,double rand){
        this->r=r;
        this->rand=rand;
    }
};

using namespace std;

int main()
{
    //std::cout<<std::setprecision(9);
    //std::cout<<std::setiosflags(std::ios::scientific);
    queue<vec> que;
    vec v;
    int N;
    cin>>N;
    int num=1;
    que.push(v);
    for(int i=0;i<N;i++){
        for(int j=0;j<num;j++){
            v.r=que.front().r/3.0;
            v.rand=que.front().rand;
            que.push(v);
            v.rand+=PI/3;
            que.push(v);
            v.rand=que.front().rand-PI/3;
            que.push(v);
            v.rand=que.front().rand;
            que.push(v);
            que.pop();
        }
        num*=4;
    }
    double x=0.0,y=0.0;
    printf("%.8f %.8f\n",x,y);
    //cout<<x<<" "<<y<<endl;
    while(!que.empty()){
        v=que.front();
        que.pop();
        x+=v.r*cos(v.rand);
        //y=(y+v.r*sin(v.rand)<0.0)?0.0:y+v.r*sin(v.rand);
        y+=v.r*sin(v.rand);
        if(y<0.0){
            y=0.0;
        }
        printf("%.8f %.8f\n",x,y);
        //cout<<x<<" "<<y<<endl;
    }
}

Measured memory_bytes: 1300
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[500][500];

int main(){
  cin >> n >> m >> l;
  ll a,b;
  a = n / l;
  b = m / l;
  if(n % l == 0)b++;
  print(b-a);
  return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)

if S[-1] == '1' or S[0] == '0':
    print(-1)

else:
    for i in range(N - 1):
        if S[i] != S[N - 2 - i]:
            print(-1)
            break
    else:
        tmp = 1
        for i in range(N - 1):
            if S[i] == '1':
                print(tmp, i + 2)
                tmp = i + 2
            else:
                print(tmp, i + 2)

Measured memory_bytes: 9288
#include<cstdio>

class CMultiplication
{
	public:
		// Public member function
		CMultiplication(void);
		bool InputMatrixVector(void);
		bool CheckPrm(int row, int col);
        bool CheckPrm(int prm);
		void PrintMulVector(void);
	private:
		// Private member variable
		static const int LINE_MAX = 100;
		static const int ELEMENT_MAX = 1000;
		int matrix[LINE_MAX][LINE_MAX];
		int vector[LINE_MAX];
		int col;
		int row;
		int vectormul[LINE_MAX];
};

CMultiplication::CMultiplication(void)
{
	for(int i = 0; i < LINE_MAX; i++)
	{
		for(int j = 0; j < LINE_MAX; j++)
		{
			matrix[i][j] = 0;
		}
		vector[i] = 0;
		vectormul[i] = 0;
	}
	col = 0;
	row = 0;
}

bool CMultiplication::InputMatrixVector(void)
{
	scanf("%d %d", &row, &col);
    if(CheckPrm(row, col) == false)
    {
        return false;
    }
    
	for(int i = 0; i < row; i++)
	{
		for(int j = 0; j < col; j++)
		{
			scanf("%d", &matrix[i][j]);
            if(CheckPrm(matrix[i][j]) == false)
            {
                return false;
            }
		}
	}
    
	for(int k = 0; k < col; k++)
	{
		scanf("%d", &vector[k]);
        if(CheckPrm(vector[k]) == false)
        {
            return false;
        }
	}
	
	for(int i = 0; i < row; i++)
	{
		for(int j = 0; j < col; j++)
		{
			vectormul[i] += (matrix[i][j] * vector[j]);
		}
	}
	
	return true;
}

bool CMultiplication::CheckPrm(int row, int col)
{
	if( (row < 1) || (row > LINE_MAX) ||
		(col < 1) || (col > LINE_MAX) )
	{
		return false;
	}
	
	return true;
}
bool CMultiplication::CheckPrm(int prm)
{
	if( (prm < 0) || (prm > ELEMENT_MAX) )
    {
		return false;
	}
	
	return true;
}

void CMultiplication::PrintMulVector(void)
{
	for(int i = 0; i < row; i++)
	{
		printf("%d\n", vectormul[i]);
	}
}

int main(void)
{
	CMultiplication mul;
	
	if(mul.InputMatrixVector() == false)
    {
        return -1;
    }
	
	mul.PrintMulVector();
	
	return 0;
}



Measured memory_bytes: 2776
D, G = gets.split.map(&:to_i)
ary = D.times.map{gets.split.map(&:to_i)}
min_cnt = D*100
# 完全に解くか全く解かないかの組み合わせ
[0, 1].repeated_permutation(ary.size) do |a|
    # 完全に解いた結果の回数と得点
    sum, cnt = 0, 0
    a.size.times do |n|
        next if a[n] == 0
        cnt += ary[n][0]
        sum += 100*(n+1)*ary[n][0] + ary[n][1]
        if sum >= G
            min_cnt = [min_cnt, cnt].min
            break
        end            
    end
    next if sum >= G
    # 解いていないもののうち一番大きいiのケースだけ判定
    idx = a.rindex(0)
    next unless idx
    ary[idx][0].times do |n|
        cnt += 1
        sum += 100*(idx+1)
        min_cnt = [min_cnt, cnt].min if sum >= G
    end
end
puts min_cnt

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define ARRS int(3e5+600)
#define BARRS int(2e6+600)
#define MAX ((long long)(1e17+1))
#define MMAX ((long long)(1e9+10))
#define HS1 ((long long)(1000001329))
#define HS2 ((long long)(1000001531))
#define MOD ((long long)1000000007)
#define SQ 31622780
#define PI 3.14159265358979323846264338327950288419716939937510

vector<ll> v[ARRS];
vector<ll> pas;
ll fx[ARRS];
void go(ll x){
    fx[x]--;
    pas.pb(x);
    for(auto y:v[x]){
        fx[y]--;
        if(!fx[y])go(y);
    }
}


int main(){
   #ifdef KHOKHO
    freopen("in.in","r",stdin);
    freopen("out.out","w+",stdout);
   #endif //KHOKHO
    ll n,m,k,p;
    cin>>n>>m;
    for(int i=0; i<m; i++){
        cin>>k>>p;
        v[k].pb(p);
        fx[p]++;
    }

    for(int i=0; i<n; i++){
        if(!fx[i])
            go(i);
    }

    for(auto x:pas){
        cout<<x<<" ";
    }

   return 0;
}

Measured memory_bytes: 11008
import java.util.*;
public class Main {
	public static void main(String[] args){
      	
		Scanner sc = new Scanner(System.in);
		
		String a = sc.next();
		String[] strarray = a.split("");

		if (strarray[0].equals(strarray[1])&&strarray[1].equals(strarray[2])) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
		
		
      	sc.close();
    }
		
		
}


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

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxK 305
#define MOD 1000000007
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()
#define EPS 1e-9

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

const int n = 6;
double p[n], q[n], w[n];

void read(double &x) {
    int a; scanf("%d", &a);
    x = a/100.0;
}

double Calc(double x) {
    double res = 0;
    fto(i, 0, n-1) res += max(p[i]*x, q[i]*(1-x));
    return res;
}

int main () {
    fto(i, 0, n-1) read(p[i]);
    fto(i, 0, n-1) read(q[i]);

    double lo = 0, hi = 1, res = 1;
    fto(iter, 0, 100) {
        double m1 = (2*lo+hi)/3, f1 = Calc(m1);
        double m2 = (lo+hi*2)/3, f2 = Calc(m2);
        if (f1 <= f2) {
            hi = m2;
            res = min(res, f1);
        }
        if (f1 >= f2) {
            lo = m1;
            res = min(res, f2);
        }
    }

    printf("%.15g", res);

    return 0;
}


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

int main() {
    int N; cin >> N;
    int left = 0, right = N - 1;
    string ls, rs;
    cout << left << endl;
    cin >> ls;
    if(ls == "Vacant") return 0;
    cout << right << endl;
    cin >> rs;
    if(rs == "Vacant") return 0;
    while(true) {
        int mid = (left + right) / 2;
        string ms;
        cout << mid << endl;
        cin >> ms;
        if(ms == "Vacant") return 0;
        bool odd = (mid - left + 1) % 2;
        bool same = ms == ls;
        if(odd ^ same) {
            right = mid;
            rs = ms;
        }
        odd = (right - mid + 1) % 2;
        same = ms == rs;
        if(odd ^ same) {
            left = mid;
            ls = ms;
        }
    }
    return 0;
}


Measured memory_bytes: 852
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, K = map(int, input().split())
X = list(map(int, input().split()))

left = 0
right = K - 1

ans = INF
while right < len(X):
    val1 = abs(X[left]) + abs(X[right] - X[left])
    val2 = abs(X[right]) + abs(X[right] - X[left])
    ans = min(ans, val1, val2)
    left += 1
    right += 1
print(ans)

Measured memory_bytes: 20468
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>

using namespace std;

int n[4],l,r;
string st;

int main(){
    for(int i=0;i<4;i++){
        scanf("%d",&n[i]);
    }
    l=n[0]+n[1];
    r=n[2]+n[3];
    if(l>r)st="Left";
    if(l==r)st="Balanced";
    if(l<r)st="Right";
    cout<<st<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t K, A, B;
  cin >> K >> A >> B;
  int64_t bis = 1;
  int64_t ans = 0;
  if(A >= B-1){
    ans = K+1;
  }else{
    int64_t x = A - 1;
    if(x >= K){
      ans = K+1;
    }
    else{
      int64_t y = K - x;
      if(y %2 == 0){
        ans = A + (y/2)*(B-A);
      }
      else{
        ans = A + ((y-1)/2)*(B-A) + 1;
      }
    }
  }
  cout << ans << endl; 
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);
		String str;
		
		while(sc.hasNextLine()){
			str = sc.nextLine();
			
			char[] c_str = str.toCharArray();
			for(int j = 0;j < 26;j++){
				for(int pos = 0,max = c_str.length;pos < max;pos++){
					if(c_str[pos] >= 'a' && c_str[pos] <= 'z'){
						c_str[pos]++;
						if(c_str[pos] > 'z'){ c_str[pos] = 'a';}
					}
				}
				
				
				String newstr = new String(c_str);
				if(newstr.indexOf("the") != -1 || newstr.indexOf("this") != -1 || newstr.indexOf("that") != -1){
					break;
				}
			}
			String newstr = new String(c_str);
			System.out.println(newstr);
			
		}
		
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  while (a != 0 & a > 10) {
    a = a % 10;
  }

  if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9)
    cout << "hon" << endl;
  else if (a == 0 || a == 1 || a == 6 || a == 8)
    cout << "pon" << endl;
  else if (a == 3)
    cout << "bon" << endl;
}

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

using namespace std;

int MAX = 998244353;

long long int power(long long int value, long long int times) {
    if (times == 1)
        return value % MAX;
    long long int half = power(value, times/2);
    if (times&1)
        return (((half*half) % MAX) * value ) % MAX; 
    return (half*half) % MAX;
}

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

    vector<int> vertex(N);

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

    if (vertex[0] != 0) {
        cout << 0 << "\n";
        return 0;
    }
        


    sort(vertex.begin(), vertex.end());

    int previous_count = 0;

    bool fail = false;
    long long int ways = 1;

    int idx;

    for (idx = 0; idx < N; idx++)
        if (vertex[idx] != 0)
            break;
        else
            previous_count++;

    if (previous_count != 1)
        fail = true;
    else {
        int value = vertex[0];
        int count = 0;
        for (idx = 0; idx < N; idx++) {
            if (vertex[idx] != value) {
               
                if (vertex[idx] != value+1) {
                    fail = true;
                    break;
                }

                (ways *= power(previous_count, count)) %= MAX;

                previous_count = count;
                count = 1;
                value = vertex[idx];
            } else
                count++;
        }

        (ways *= power(previous_count, count)) %= MAX;  
    }

    if (fail)
        cout << 0;
    else
        cout << ways;
    cout << "\n";

    return 0;
}


Measured memory_bytes: 640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath>
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
  int L,R,d;
  cin >> L >> R >> d;
  int count = 0;
  for(int i = L;i <= R;i++){
    if(i%d == 0){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3628
<?php

fscanf(STDIN, "%d%d", $n, $k);
$p_list = explode(' ', trim(fgets(STDIN)));

$accumulated_p = [0];
for ($i = 1; $i <= $n; ++$i) {
    $accumulated_p[$i] = $accumulated_p[$i - 1] + ($p_list[$i - 1] + 1) / 2;
}

$sum_expected_value = [];
for ($i = $k; $i <= $n; ++$i) {
    $sum_expected_value[] = $accumulated_p[$i] - $accumulated_p[$i - $k];
}

echo max($sum_expected_value);


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

int main(){

  int N;
  long long Y;
  int k;

  cin >> N >> Y;

  for(int i = 0; i <= N; i++){
    for(int j = 0; j <= N - i; j++){
      int k = N - i - j;
      if(k >= 0){
        if(10000*i + 5000*j + 1000*k == Y){
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iterator>
#include <functional>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define sz(a)  int((a).size())
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define CLR(a) memset((a), 0, sizeof(a))
#define INF (1 << 31) - 1
const int dh[8] = {-1, 1, 0, 0,1,1,-1,-1};
const int dw[8] = {0, 0, 1, -1,1,-1,1,-1};
typedef long long ll;
typedef pair<int, int> p;
typedef vector <int> VI;
typedef vector <string> VS;

vector <int> his;

int main(){

	ll n,a,b;
	cin >> n;
	cin >> a;
	cin >> b;
	
	ll ans = 0;
	ll prev;
	cin >> prev;
	
	for(int i = 0; i < n - 1; i++){
		ll next;
		cin >> next;

		ans += min((next - prev) * a, b);
		prev = next;		
	}	

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


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

template <class T>
T abs(T a) { return (a > 0 ? a : -a); };

int main() {
    std::string s, c;
    std::cin >> s;

    std::copy_if(s.begin(), s.end(), std::inserter(c, c.begin()), [](auto ch) { return ch != 'x'; });
    auto n = (int)c.length();
    if (n == 0) {
        std::cout << 0 << std::endl;
        return 0;
    }
    for (auto i = 0; i < n; i++) {
        if (c[i] != c[n - 1 - i]) {
            std::cout << -1 << std::endl;
            return 0;
        }
    }

    auto index = 0;
    std::vector<int> v(n);
    for (auto i = 0; i < n; i++) {
        while (s[index] != c[i]) index++;
        v[i] = index++;
    }

    auto ret = abs(v[0] - ((int)s.length() - v[n - 1] - 1)) * 2;
    for (auto i = 1; i < n; i++) {
        ret += abs((v[i] - v[i - 1]) - (v[n - i] - v[n - i - 1]));
    }

    std::cout << ret / 2 << std::endl;

    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

char c[105];  //AKIHABARA
char s[105][105]={{" "},{" KIHBR"},
{" AKIHBR"},{" KIHABR"},{" KIHBAR"},{" KIHBRA"},
{" AKIHABR"},{" AKIHBAR"},{" AKIHBRA"},
{" KIHABAR"},{" KINABRA"},{" KIHBARA"},
{" AKIHABAR"},{" AKIHABRA"},{" AKIHBARA"},
{" KIHABARA"},{ " AKIHABARA"}};

int main(){
	scanf("%s",c+1);
	int n=strlen(c+1);
	//printf("%d\n",n);
	//printf("%s\n",c+1);
	c[0]=' ';
	//printf("%d\n",n);
	if(n<5){
		printf("NO");
		return 0;
	}
	if(n>9){
		printf("NO");
		return 0;
	}
	
	for(int i=1;i<=16;i++){
		bool sm=true;
		for(int j=1;j<=strlen(s[i]+1);j++){
			if(c[j]!=s[i][j]){
				sm=false;
				break;
			}
		}
		if(sm){
			printf("YES");
			return 0;
		}
	}
	printf("NO");
	return 0;
}

/*
  //KIHBR
int count=0;
char tpl[10]={" KIHBR"};
for(int i=1;i<=n;i++){
	if(c[i]=='A')continue;
	if(c[i]==tpl[++count]);
	else{
		printf("NO");
		return 0;
	}
}
printf("YES");
return 0;
*/

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long dp[55][55][2500];
int n;
int arr[55];
long long solve(int idx , int rem , int taken)
{
    if(rem < 0 || taken < 0) return 0;
    if(idx == n) return rem == 0 && taken == 0;
    long long & ret = dp[idx][taken][rem];
    if(~ret) return ret;
    return ret = solve(idx+1 , rem , taken) + solve(idx+1 , rem - arr[idx] , taken-1);
}
int main()
{
    int a;
    cin>>n>>a;
    for(int i = 0 ; i<n ; ++i) cin>>arr[i];
    memset(dp , -1 , sizeof dp);
    long long ans = 0;
    for(int i = 1 ; i<=n ; ++i) ans += solve(0 , a*i , i);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 59264
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll inf = ll(5e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

class debug
{
public:
    typedef long long ll;
    template<typename T> void vd(vector<T> vec);
    template<typename T> void vd2(vector<vector<T>> vec);
    template<typename T> void vpd(vector<pair<int, int>> vec);
    template<typename T> void ad(T *arr, ll n);
    template<typename T, size_t N> void ad2(T (&arr)[N], ll n);
    template<typename T> void md(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vd(vector<T> vec)
{
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T> void debug::vd2(vector<vector<T>> vec)
{
    for(auto vv : vec) for(auto vvv : vv) cout << vvv << " ";
    cout << endl;
}

template<typename T> void debug::vpd(vector<pair<int, int>> vec) {
    for(auto const& vv : vec) {
        cout << vv.first << " " << vv.second << endl;
    }
    cout << endl;
}

template<typename T> void debug::ad(T *arr, ll n)
{
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T, size_t N> void debug::ad2(T (&arr)[N], ll n)
{
    for(int i=0; i<=N; i++) for(int j=0; j<=n; j++) cout << arr[i][j] << " ";
    cout << endl;
}

template<typename T> void debug::md(T mp)
{
    cout << "key : value" << endl;
    for(auto const& m : mp) cout << m.first << " : " << m.second << endl;
    cout << endl;
}
debug debug;

ll dp[110][100010];

class DKnapsack1 {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n, W;
	    in >> n >> W;
	    vector<int> w(n), v(n);
	    for(int i=0; i<n; i++){
	        in >> w[i] >> v[i];
	    }

	    Fill(dp, 0LL);
	    for(int i=0; i<n; i++){
	        for(int j=0; j<=W; j++){
	            int ni=i+1, nj=j;
	            chmax(dp[ni][nj], dp[i][j]);
	            if(nj+w[i] <= W){
	                nj += w[i];
	                chmax(dp[ni][nj], dp[i][j] + v[i]);
	            }
	        }
	    }

	    ll res = 0;
	    for(int j=0; j<=W; j++){
            chmax(res, dp[n][j]);
	    }

	    out << res << endl;
	}
};


int main() {
	DKnapsack1 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 86144
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

# n, m = 3, 2
# a = [[1, 2], [2, 3]]

pot_starts = []
pot_ends = []

for i in a:
    if i[0] == 1:
        pot_starts.append(i[1])
    elif i[1] == n:
        pot_ends.append(i[0])

if set(pot_starts).intersection(set(pot_ends)):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 54632
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

//acacbcb
//aca bcb
//ac  bcb
int main() {
	string s;
	cin >> s;
	int n = (int) s.size();
	bool ok = false;
	for (int i = 1; i < n - 1; i++) {
		if (s[i] == s[0] || s[i] == s[n - 1]) {
			ok = true;
		}
	}
	if (s[0] == s[n - 1]) {
		if (ok)
			cout << ((n - 5) % 2 == 0 ? "Second" : "First");
		else
			cout << ((n - 3) % 2 == 0 ? "Second" : "First");
	}
	else {
		cout << ((n - 2) % 2 == 0 ? "Second" : "First");
	}
}


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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HI;
typedef priority_queue<int, vector<int>, greater<int> > HDI;

const int N = 100010, M = 1010;

int n, m;
int a[N], b[N];
int p[N], size[N];
vector<LL> res;

int find(int x)
{
	if (x != p[x]) p[x] = find(p[x]);
	return p[x];
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i <= n; i ++ ) p[i] = i, size[i] = 1;
	
	for (int i = 0; i < m; i ++ ) scanf("%d%d", &a[i], &b[i]);
	
	LL tot = (LL)(n - 1) * n / 2LL;
	res.push_back(tot);
	for (int i = m - 1; i; i -- )
	{
		int aa = find(a[i]), bb = find(b[i]);
		if (aa != bb)
		{
			tot -= (LL)size[aa] * size[bb];
			size[bb] += size[aa];
			p[aa] = bb;
		}
		res.push_back(tot);
	}
	reverse(res.begin(), res.end());
	
	for (auto u : res) printf("%lld\n", u);
    return 0;
}

Measured memory_bytes: 3828
N, K = map(int, input().split())
ub = K * 2
b = [[0 for j in range(ub + 1)] for i in range(ub + 1)]

def create_bound(p):
	if p - K + 1 >= 0:
		return [(p - K + 1, p + 1)]
	else:
		return [(0, p + 1), ((p - K + 1) % ub, ub)]

for i in range(N):
	x, y, c = input().split()
	nx = int(x) % ub
	ny = (int(y) + (K if c == "W" else 0)) % ub
	for add in [0, K]:
		for xlb, xub in create_bound((nx + add) % ub):
			for ylb, yub in create_bound((ny + add) % ub):
				b[xlb][ylb] += 1
				b[xlb][yub] -= 1
				b[xub][ylb] -= 1
				b[xub][yub] += 1

for i in range(ub):
	for j in range(ub):
		b[i][j + 1] += b[i][j]
for j in range(ub):
	for i in range(ub):
		b[i + 1][j] += b[i][j]
print(max(max(b[i]) for i in range(ub)))


Measured memory_bytes: 87132
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

t = 0

for i in range(n):
    if i > 0 and a[i] == a[i - 1] + 1:
        t += c[a[i - 1] - 1]

print(sum(b) + t)


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

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

    int a, b;
    cin >> a >> b;
    int x, y, z;
    x = a + b;
    y = a - b;
    z = a * b;
    cout << max(max(x, y), z) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ls ro<<1
#define fi first
#define se second
#define rs ro<<1|1
#define ll long long
#define int long long
#define pb push_back
#define vi vector<int>
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define lson ro<<1,l,mid
#define umap unordered_map
#define uset unordered_set
#define rson ro<<1|1,mid+1,r
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

using namespace std;

const int INF = 0x3f3f3f3f;
const int N=2e5+10;

int s[N],x[N],a[N];

signed main() {
	IOS;
#ifdef xiaofan
	freopen("in.txt","r",stdin);
#endif

	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++){
		s[i]=s[i-1]+a[i];
		x[i]=x[i-1]^a[i];
	}
	int l=1,r=1;
	int ans=0;
	while(r<=n){
		while((s[r]-s[l-1])!=(x[r]^x[l-1]))
			l++;
		//cout<<l<<" "<<r<<endl;
		ans+=r-l+1;
		r++;
	}
	cout<<ans<<endl;

#ifdef xiaofan
	cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
#endif
	return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;

int H, W;
string maze[1100];
int dp[1100][1100];

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        cin >> maze[i];
    }

    dp[0][0] = 1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (dp[i][j] == 0) continue;

            if (i < H && maze[i + 1][j] != '#') {
                dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % M;
            }
            if (j < W && maze[i][j + 1] != '#') {
                dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % M;
            }
        }
    }

    cout << dp[H - 1][W - 1] << endl;
}

Measured memory_bytes: 5632
A,B,N = string.match(io.read(), "(%d+) (%d+) (%d+)")
A,B,N = tonumber(A), tonumber(B), tonumber(N)

x = N
if B-1 < N then
	x = B-1
end

tmp = math.floor((A*x)/B) - A * math.floor(x/B)
print(tmp)


Measured memory_bytes: 2740
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, ans=0;

    cin >> N;

    for(i=1; i<=sqrt(N); i++){
        if((N-i)%i==0){
            if(i < (N-i)/i) ans += (N-i)/i;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int main(){
    fcin;
    ll n, a, b;
    cin >> n >> a >> b;

    ll d = n / (a + b);
    ll r = n % (a + b);

    cout << d * a + min(r, a) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
//union by size + path having
class UnionFind{
	public:
	vector<long long> par; // 各元の親を表す配列
	vector<long long> siz; // 素集合のサイズを表す配列(1 で初期化)


	// Constructor
	UnionFind(long long sz_) : par(sz_), siz(sz_,1LL){
		for (long long i = 0; i < sz_; ++i)
		par[i] = i; // 初期では親は自分自身
	}
	void init(long long sz_){
		par.resize(sz_);
		siz.assign(sz_,1LL); // resize だとなぜか初期化されなかった
		for (long long i = 0; i < sz_; ++i)
			par[i] = i; // 初期では親は自分自身
	}
	// Member Function


	// Find
	long long root(long long x){ // 根の検索
		while (par[x] != x){
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}
	// 結合(Unite, Merge)
	bool merge(long long x, long long y){
		x = root(x);
		y = root(y);
		if (x == y){
			return false;
		}
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]){
			swap(x, y);
		}
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}


	// 連結判定(つながっているときはture,つながっていなければfalse)
	bool issame(long long x, long long y){ 
		return root(x) == root(y);
	}


	// 素集合のサイズ
	long long size(long long x){ 
		return siz[root(x)];
	}
};
int main(){
	int n,m;
	int ans;
	cin >>n>>m;
	int x,y,z;
	ans=n;
	UnionFind det(n);
	rep(i,m){
		cin>>x>>y>>z;
		x--;
		y--;
		if(det.merge(x,y)==true){
			ans--;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int bubbleSort(int A[], int N) {
  int flag = 1;
  int n = 0, j, tmp;

  while(flag) {
    flag = 0;
    for(j = N - 1;j > 0;j--) {
      if(A[j] < A[j - 1]) {
        tmp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = tmp;

        flag = 1;
        n++;
      }
    }
  }

  return n;
}

int main() {
  int n, m, i, a[100];

  scanf("%d", &n);
  for(i = 0;i < n;i++)
    scanf("%d", &a[i]);

  m = bubbleSort(a, n);

  for(i = 0;i < n - 1;i++)
    printf("%d ", a[i]);
  printf("%d\n", a[i]);
  printf("%d\n", m);

  return 0;
}



Measured memory_bytes: 2048
#!/usr/bin/ruby                                                                                                                                   
# -*- coding: utf-8 -*-                                                                                                                           

sales = 0
total = 0
count = 0.0
while s = gets
  cost, num = s.chomp.split(',').map do |s|
    s.to_i
  end
  sales += cost * num
  total += num
  count += 1
end
puts sales
puts (total / count).round

Measured memory_bytes: 6128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    for (int i =0; i<n; i++) {
      a[i] = sc.nextLong();
    }
    for (int i =n-1; i >=0; i -=2) {
      System.out.print(a[i] + " ");
    }
    if (n % 2 == 0) {
      for (int i =0; i <n-1; i +=2) {
        System.out.print(a[i] + " ");
      }
    } else {
      for (int i =1; i <n-1; i +=2) {
        System.out.print(a[i] + " ");
      }
    }
  }
}

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

inline ll read() {
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
	return x * f;
}

ll mod;

struct M { ll a[3][3]; };
M operator * (const M &a, const M &b) {
	M c;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			c.a[i][j] = 0;
			for (int k = 0; k < 3; k++) {
				c.a[i][j] = (c.a[i][j] + a.a[i][k] * b.a[k][j] % mod) % mod;
			}
		}
	}
	return c;
}

M qp(M a, ll b) {
	M c;
	for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) c.a[i][j] = i == j;
	while (b) {
		if (b & 1) c = c * a;
		a = a * a;
		b >>= 1;
	}
	return c;
}

int main() {
	ll n = read(), a0 = read(), d = read(); mod = read();
	n--;
	ll bit = 10, ans = 0;
	ll st = 0;
	for (int i = 1; i <= 19; i++) {
		ll l = st, r = n, p = -1;
		while (l <= r) {
			ll mid = l + r >> 1;
			if (mid * d + a0 < bit) l = mid + 1, p = mid;
			else r = mid - 1;
		}
		if (p != -1) {
			M a;
			a.a[0][0] = bit % mod; a.a[0][1] = a.a[1][1] = a.a[2][2] = 1LL;
			a.a[0][2] = a.a[1][0] = a.a[2][0] = a.a[2][1] = 0LL;
			a.a[1][2] = d % mod;
			a = qp(a, p - st + 1);
			ll ast = a0 % mod + d % mod * st % mod; ast %= mod; 
			ans = (ans * a.a[0][0] % mod + ast * a.a[0][1] % mod + a.a[0][2] % mod) % mod;
			st = p + 1;
		}
		if (st > n) break;
		bit *= 10;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector> 
using namespace std;
int main (){
    int n;
    int x;
    scanf("%d",&n);
    int p[n];
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        p[x-1]=i;
    }
    int y;
    x=0;y=0;
    for(int i=0;i<n-1;i++){
        if(p[i]<p[i+1]){
            x++;
            if(y<x)y=x;
        }else{
            x=0;
        }
    }
    printf("%d\n",n-y-1);
}

Measured memory_bytes: 1024