akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static CompetitiveProgramming.Utilities;


class Program
{
    static int N;
    static int[][] F;
    static int[][] P;

    public static void Main(string[] args)
    {
        N = Input.NextInt();
        F = new int[N][];
        foreach (var i in Range(0, N))
            F[i] = Input.LineInt();
        P = new int[N][];
        foreach (var i in Range(0, N))
            P[i] = Input.LineInt();

        var mask = Range(0, 10).Select(n => 1 << n).ToArray();

        int max = int.MinValue;
        foreach (var k in Range(0, (int)Math.Pow(2, 10)).Where(n => n != 0))
        {
            int val = 0;
            foreach (var shopindex in Range(0, N))
            {
                int count = 0;
                foreach (var j in Range(0, 10))
                {
                    if ((k & mask[j]) != 0)
                    {
                        if (F[shopindex][j] == 1)
                        {
                            count++;
                        }

                    }
                }
                val += P[shopindex][count];
            }
            max = Math.Max(max, val);
        }
        Console.WriteLine(max);
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

namespace CompetitiveProgramming
{
    public static class Utilities
    {
        public static IEnumerable<int> Range(int start, int count) => Enumerable.Range(start, count);
        public static IEnumerable<int> RangeTo(int start, int end) => Enumerable.Range(start, end - start);
    }
}


Measured memory_bytes: 17744
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

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;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int 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;

ll f(ll l) {
    int ans = 0;
    while (l > 0) {
        ans++;
        l %= __builtin_popcountll(l);
    }
    return ans;
}

int main() {

    int n;
    string s;
    cin >> n >> s;
    reverse(s.begin(), s.end());

    int pc = count(s.begin(), s.end(), '1');

    auto fac = [&](int i) -> vector<int> {
        if (i == 0) return vector<int>(0);
        vector<int> v(n, 0);
        int prev = 1 % i;
        rep(j, n) {
            v[j] = prev;
            prev *= 2;
            prev %= i;
        }
        return v;
    };

    vector<int> fac_up = fac(pc + 1);
    vector<int> fac_down = fac(pc - 1);

    auto ini = [&](int i, vector<int> &fac) -> int {
        if (i == 0) return -1;
        int prev = 0;
        rep(j, n) {
            if (s[j] == '1') prev += fac[j];
            prev %= i;
        }
        return prev;
    };

    int ini_up = ini(pc + 1, fac_up);
    int ini_down = ini(pc - 1, fac_down);

    vector<int> ans;
    rep(i, n) {
        if (s[i] == '0') {
            int pu = pc + 1;
            int now = (pu + ini_up + fac_up[i]) % pu;
            ans.push_back(f(now) + 1);
        } else {
            int pd = pc - 1;
            if (pd == 0) {
                ans.push_back(0);
                continue;
            }

            int now = (pd + ini_down - fac_down[i]) % pd;
            ans.push_back(f(now) + 1);
        }
    }

    reverse(ans.begin(), ans.end());


    for (int i : ans) cout << i << endl;

}


Measured memory_bytes: 6028
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
using ll = long long;

#define INF 1000000007
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int)(x).size())
#define MSG(a) cout << #a << " " << a << endl;

int main()
{
    string s;
    cin >> s;
    string ans = s[2] == s[3] && s[4] == s[5] ? "Yes" : "No";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int k;
  cin >> k;
  int x;
  cin >> x;
  if (k * 500 >= x) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


Measured memory_bytes: 256
local read = io.read
local insert = table.insert

local N = read("*n")
local key_A = {}
for i = 1, N do
	local A = read("*n")
	if key_A[A] then
		key_A[A] = key_A[A] + 1
	else
		key_A[A] = 1
	end
end

local total = 0
for key, value in pairs(key_A) do
	total = total + key * value
end


local out = {}
local Q = read("*n")
for i = 1, Q do
	local B, C = read("*n", "*n")
	if key_A[B] and key_A[C] then
		total = total - B*key_A[B] + C*key_A[B]
		key_A[C] = key_A[C] + key_A[B]
		key_A[B] = nil
	elseif key_A[B] then
		total = total - B*key_A[B] + C*key_A[B]
		key_A[C] = key_A[B]
		key_A[B] = nil
	end
	out[i] = total
end

print(table.concat(out, "\n"))


Measured memory_bytes: 12460
H, W, A, B = map(int, input().split())

g = [[0 for j in range(W)] for i in range(H)]
for i in range(B):
    for j in range(A,W):
        g[i][j] = 1
for i in range(B,H):
    for j in range(A):
        g[i][j] = 1

for i in range(H):
    print(''.join(map(str, g[i])))

Measured memory_bytes: 12788
def resolve():
    N = int(input())

    def prime_factorize(n):
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a

    a = prime_factorize(N)

    count_dict = {}
    total_key = 0
    for i in range(1024):
        total_key += i
        for j in range(total_key-i, total_key):
            count_dict[j] = i-1

    a_element_counter = {}
    for i in a:
        if i not in a_element_counter:
            a_element_counter[i] = 0
        a_element_counter[i] += 1

    ans = 0
    for e in a_element_counter.values():
        ans += count_dict[e]
    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 61596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main()
{
    int n;
    int d;
    cin >> n >> d;
    int c;
    int ans = 0;
    c = 2 * d + 1;
    if(n%c==0)
        ans = n / c;
    else
        ans = n / c + 1;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

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

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

map<ll, ll> prime_decomposition(ll n){
  map<ll, ll> mp;
  for(ll p = 2; p*p <=n; p++){
    if(n%p!=0) continue;
    ll cnt = 0;
    while(n%p == 0){cnt++; n /= p;}
    mp[p] = cnt;
  }
  if(n!=1) mp[n] = 1;
  return mp;
}

int main(){
  ll a,b; cin >> a >> b;
  ll g = gcd(a,b);
  ll ans = 1;
  map<ll,ll> mp = prime_decomposition(g);
  ans += SZ(mp);
  cout << ans << endl;
} 

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

int main(){
    int N;
    std::cin >> N;
    std::vector<int> a(N);
    for(int i = 0; i < N; i++){
        std::cin >> a[i];
        a[i]--; // to 0 origin
    }
    
    std::vector<bool> isUsed(N, false);
    int now = 0;
    int cnt = 0;
    while(!isUsed[now]){
        isUsed[now] = true;
        now = a[now];
        cnt++;
        if(now == 1){
            std::cout << cnt << std::endl;
            return 0;
        }
    }

    std::cout << -1 << std::endl;
    return 0;
}


Measured memory_bytes: 640
//
//  main.cpp
//  AOJ1129
//
//  Created by aki33524 on 2014/07/15.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

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

int main(int argc, const char * argv[])
{
    int n, r;
    while(cin>>n>>r, n|r){
        vector<int> deck(n);
        for(int i=0; i<n; i++)
            deck[n-i-1] = i+1;
        
        int p, c;
        for(int i=0; i<r; i++){
            cin >> p >> c;
            vector<int> tmp = deck;
            for(int j=0; j<c; j++){
                deck[j] = tmp[j+p-1];
            }
            for(int j=0; j<p-1; j++){
                deck[j+c] = tmp[j];
            }
        }
        cout << deck[0] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1216
INF = 10**18

H,N = map(int,input().split())
magic = [list(map(int,input().split())) for _ in range(N)]

dp = [INF]*(2*(10**4)+1)
dp[0] = 0

for i in range(N):
    d = magic[i][0]
    mp = magic[i][1]
    for j in range(d,2*(10**4)+1):
        dp[j] = min(dp[j-d]+mp,dp[j])
ans = INF
for i in range(H,2*(10**4)+1):
    ans = min(ans,dp[i])

print(ans)

Measured memory_bytes: 42588
h, w = map(int, input().split())
s = [input() for _ in range(h)]
ans = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            ans[i][j] = '#'
        else:
            left = max(0, j-1)
            right = min(w-1, j+1)
            top = max(0, i-1)
            bottom = min(h-1, i+1)
            for k in range(top, bottom+1):
                ans[i][j] += s[k][left:right+1].count('#')
for i in range(h):
    for j in range(w):
        print(ans[i][j], end='')
    print()


Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
 
using namespace std;
 
struct card {
    int num;
    char ch;
};
 
void show(card cd[], int n) {
    for (int i = 0; i < n - 1; i++)
        cout << cd[i].ch<<cd[i].num << " ";
    cout << cd[n - 1].ch<< cd[n - 1].num << endl;
}
 
void isStable(card cd_1[], card cd_2[], int n) {
    int j = 0;
    for (int i = 0; i < n - 1; i++) {
        while (cd_1[i].num != cd_2[j].num) j++;
        if (cd_1[i].ch != cd_2[j].ch) {
            cout << "Not stable" << endl;
            return;
        }
        j++;
        if (cd_1[i].num != cd_1[i + 1].num) j = 0;
    }
    cout << "Stable" << endl;
 
}
 
void bubbleSort(card cd[], int n) {
    bool f = true;
    while (f) {
        f = false;
        for (int i = n - 1; i >= 1; i--)
            if (cd[i].num < cd[i - 1].num) {
                swap(cd[i],cd[i-1]);
                f = true;
            }
    }
}
 
void selsctionSort(card cd[], int n) {
    int minj;
    for (int i = 0; i < n - 1; i++) {
        minj = i;
        for (int j = i + 1; j < n; j++) {
            if (cd[j].num < cd[minj].num)
                minj = j;
        }
        if (i != minj) {
            swap(cd[i], cd[minj]);
        }
    }
}
 
int main() {
    card cd[100];
    card cd_m[100];
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> cd[i].ch >> cd[i].num;
        cd_m[i] = cd[i];
    }
 
    bubbleSort(cd, n);
    show(cd, n);
    isStable(cd, cd_m, n);
 
    for (int i = 0; i < n; i++)
        cd[i] = cd_m[i];
 
    selsctionSort(cd, n);
    show(cd, n);
    isStable(cd, cd_m, n);
    return 0;
}

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

int main() {
    int h, w;  cin >> h >> w;
    vector<int> row(h, 1);
    vector<int> cols(w, 1);
    char a[h][w];

    for (int i=0; i<h; ++i) {
        for (int j=0; j<w; ++j) {
            cin >> a[i][j];
            if (a[i][j] == '#') {
                row[i] = 0;
                cols[j] = 0;
            }
        }
    }

    for (int i=0; i<h; ++i) {
        if (row[i]) continue;
        for (int j=0; j<w; ++j) {
            if (cols[j]) continue;
            
            cout << a[i][j];
        }

        cout << endl;
    }
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 3000 + 10;
const int Mod = 1e9 + 7;
int N, M;
int f[MAXN][MAXN][2];
int ans;

int main() {
	register int i, j, k;
	scanf("%d%d", &N, &M);
	f[0][0][1] = 1;
	for(i = 1; i <= N; ++i) f[0][i][0] = 1;
	for(i = 0; i < M; ++i)
		for(j = 0; j <= N; ++j)
			for(k = 0; k <= 1; ++k) {
				if(j > 0) (f[i + 1][j - 1][k | (j - 1 == 0)] += f[i][j][k]) %= Mod;
				if(j > 0) (f[i + 1][j][k | (j - 1 == 0)] += f[i][j][k]) %= Mod;
				if(j < N) (f[i + 1][j][k] += f[i][j][k]) %= Mod;
				if(j < N) (f[i + 1][j + 1][k] += f[i][j][k]) %= Mod;
			}
	for(i = 0; i <= N; ++i)
		(ans += f[M][i][1]) %= Mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 70784
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int mod=2019;
int L,R,len;
int main(){
	scanf("%d%d",&L,&R);
	len=R-L+1;
	if(len>=mod){
		int ans=mod;
		for(int i=0;i<mod;i++)
			for(int j=0;j<mod;j++)
				ans=min(ans,i*j%mod);
		printf("%d\n",ans);
		return 0;
	}
	int l=L%mod,r=R%mod;
	if(r<l) r+=mod;
	int ans=mod;
	for(int i=l;i<=r;i++)
		for(int j=i+1;j<=r;j++)
			ans=min(ans,i*j%mod);
	printf("%d\n",ans);
	return 0;
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    string s;cin >> s;
    if(count(ALL(s),s[0]) == 3)cout << "No" << endl;
    else cout << "Yes" << endl;
    
    return 0;
}

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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

// policy-based
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;	


using namespace std;


typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
 
const ll MAX = 3e5+100;
const ll inf = 1e12;
const ll mod = 1e9+7;




int main(){
	fastio;
	ll tc,n,k;
	cin >> n;
	if(n < 30) cout <<"No\n";
	else cout << "Yes\n";	
	

}

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


int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n)
    cin >> a[i];
  vector<bool> dp(k + 1, false);
  rep(i, k)
    if (!dp[i])
      for (int j : a)
        if (i + j <= k)
          dp[i+j] = true;
  if (dp[k])
    puts("First");
  else
    puts("Second");
  return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
p = [[int(j),i] for i,j in enumerate(read().split()) ]
p.sort()

longest = 1
now = 1
for i in range(1,n):
    if(p[i][1] > p[i-1][1]):
        now += 1
    else:
        now = 1
    longest = max(longest,now)

print(n-longest)

Measured memory_bytes: 106132
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int k;
  cin>>k;
  vector<int> vector{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<<vector[k-1]<<endl;


  return 0;
}




Measured memory_bytes: 256
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp::{max, min, Reverse};
use std::collections::*;
use maplit::*;
use num::Integer;
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

const INF : i64 = 1000000007;

fn main() {
  input! {
    n : usize, cw : usize,
  };

  let mut w = vec![0];
  let mut v = vec![0];
  for _ in 0..n {
    input! {
      weight : usize, value : usize,
    };
    
    w.push(weight);
    v.push(value);
  }

  let mut dp = vec![vec![0usize; cw + 1]; n + 1];
  
  for i in 1..=n {
    for j in 0..=cw {
      if j >= w[i] {
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }
  
  println!("{}", dp[n][cw]);
}


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

#ifndef __HEADERS__
#define __HEADERS__

#define up(i,j,k) for (int i = j; i <= k; i++)
#define down(i,j,k) for (int i = j; i >= k; i--)

#define lb long double
#define ll long long
#define ull unsigned long long

#define mp std::make_pair
#define pb push_back

#define all(x) x.begin(), x.end()
#define lowbit(x) ((x) & (-x))
#define mem(a) memset(a, 0, sizeof(a))
#define File(x)                       \
    freopen("" #x ".in", "r", stdin); \
    freopen("" #x ".out", "w", stdout);

#endif

inline int read() {
    int data = 0, w = 1; char ch = 0;
    while (ch != '-' && (ch > '9' || ch < '0')) ch = getchar();
    if (ch == '-') w = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') { data = data * 10 + ch - '0'; ch = getchar(); }
    return data * w;
}

inline void print (ll v) {
    if (v < 0) { putchar('-'); v = -v; }
    if (v > 9) print(v / 10);
    putchar(v % 10 + '0');
}

int main () {
    int a, b;
    a = read(); b = read();
    if (a >= 10 || b >= 10) return puts("-1"), 0;
    print(a * b);
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>//"geometry.cpp"
#include<iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
#include<queue>
#include<string>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<algorithm>//"lower_bound(it,it,v)", "next_permutation(a,a+n)"
#include<functional>//"greater<T>" Ex. sort(a,a+n,greater<int>());
#include<cmath>//"abs", "sqrt"
using namespace std;
#define pb push_back
#define fi first
#define sc second
#define mp make_pair
#define is insert
typedef pair<int,int> pii;//Add other types in the same way.

int main(){
	long long n,a,b;
	cin>>n>>a>>b;
	if(a>b) cout<<0<<endl;
	else if(n==1&&a==b) cout<<1<<endl;
	else if(n==1&&a<b) cout<<0<<endl;
	else cout<<((n-2)*(b-a))+1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

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

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

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 1001002003004005006ll;
const ll INF = 1001001001;
const double pi = acos(-1);

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int num = 1;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == num)
        {
            num++;
        }
    }
    num--;
    if (num == 0)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << n - num << endl;

    return 0;
}

Measured memory_bytes: 4028
#include <stdio.h>
int solve(int ,int);
int A[1000],B[1000], i, j,k,d,n;
int main() {
	scanf("%d", &n);
	for ( i = 0; i < n; i++)
	{
		scanf("%d", &A[i]);
	}
	scanf("%d", &d);
	for ( i = 0; i < d; i++)
	{
		scanf("%d", &B[i]);
	}
	for ( i = 0; i < d; i++)
	{
		if (solve(0,B[i]))
		{
			printf("yes\n");
		}
		else
		{
			printf("no\n");
		}
	}
	return 0;
}
int solve(int i, int m ) {
	int res;
	if (m == 0) {
		return 1;
	}
	if (i >= n) {
		return 0;
	}
	res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */



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

    int n; cin >> n;
    string s; cin >> s;
    string ans(n, '.');

    bool flg=false;
    rep(bit, 1<<2){
        // initialization
        rep(i, 2){
            if(bit&1<<i) ans[i]='S';
            else ans[i]='W';
        }
        // struct
        repr(i, 1, n-1){
            if(ans[i]=='S'){
                if(s[i]=='o') ans[i+1] = ans[i-1]=='S'? 'S':'W';
                else ans[i+1] = ans[i-1]=='S'? 'W':'S';
            }
            else{
                if(s[i]=='o') ans[i+1] = ans[i-1]=='S'? 'W':'S';
                else ans[i+1] = ans[i-1]=='S'? 'S':'W';
            }
        }
        // check
        bool ok=true;
        rep(i, n){
            if(ans[i]=='S'){
                if(s[i]=='o' && ans[getl(i, n)]!=ans[getr(i, n)]) ok=false;
                if(s[i]=='x' && ans[getl(i, n)]==ans[getr(i, n)]) ok=false;
            }
            else{
                if(s[i]=='o' && ans[getl(i, n)]==ans[getr(i, n)]) ok=false;
                if(s[i]=='x' && ans[getl(i, n)]!=ans[getr(i, n)]) ok=false;
            }
        }
        if(ok){
            flg=true; break;
        }
    }
    if(flg) cout << ans << endl;
    else cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			string line;
			while ((line = Console.ReadLine()) != null)
			{
				double[] l = line.Split(',').Select(i => double.Parse(i)).ToArray<double>();
				Point a = new Point(l[0], l[1]);
				Point b = new Point(l[2], l[3]);
				Point c = new Point(l[4], l[5]);
				Point d = new Point(l[6], l[7]);
				Console.WriteLine((f(b, d, a, c) > 0d || f(a, c, b, d) > 0d) ? "NO" : "YES");
			}
		}

		static double f(Point p1, Point p2, Point p3, Point p4)
		{
			return ((p1.X - p2.X) * (p3.Y - p1.Y) +
				(p1.Y - p2.Y) * (p1.X - p3.X)) * ((p1.X - p2.X) * (p4.Y - p1.Y)
				+ (p1.Y - p2.Y) * (p1.X - p4.X));
		}

		public class Point
		{
			public Point(double x, double y) { X = x; Y = y; }
			public double X { get; private set; }
			public double Y { get; private set; }
		}
	}
}

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

int main(){
    ll X;
    cin >> X;
    ll cnt  = 100;
    ll i = 0;
    while(cnt < X){
        cnt += cnt*0.01;
        i++;
    }
    cout << i << endl;
}

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

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

fn main() {
    let r: i32 = read();
    println!("{}", r*r)
}

Measured memory_bytes: 4352
n, k = gets.chomp.split.map(&:to_i)
a = []
n.times do
  a << gets.to_i
end
a.sort!
r = []
(0..(a.count - k)).each_with_index do |i|
  r << a[i + k - 1] - a[i]
end
puts r.min

Measured memory_bytes: 4328
#include <bits/stdc++.h> 
using namespace std;
#define     mod             1e9+7
#define     ll              long long
#define     mp              make_pair
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     ii              pair<int,int>
#define     vi              vector<int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int>>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            '\n'

/*
	For Debugging we have define TRACE.
*/

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif  

const int N = 1e7 + 5;
int a[N];
int reach [10000001];

void solve(){

	ll n;
	cin>>n;
	vector<int> arr(10001,0);

	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++){
			for(int k=1;k<=100;k++){
				ll ans = i*i + j*j + k*k + i*j + i*k + j*k;
				if(ans <= 10000){
					arr[ans - 1]++;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<arr[i]<<endl;
	}

}
 
int32_t main()
 
{  
    #ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    #endif

    IOS;

    solve();


}

Measured memory_bytes: 3652
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const l = -1000000
const r = 1000000

func main() {
	k, x := readInt(), readInt()

	ll := max(l, x-k+1)
	rr := min(r, x+k-1)
	for i := ll; i <= rr; i++ {
		fmt.Printf("%v ", i)
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

m = 0
mnt = 0
num = 0
for i, a in enumerate(A):
    num = i+1
    if mnt + a > K:
        num = i
        break
    mnt += a
A = A[:num]
ans = num

j = 0
for i in range(num+1):
    while j < M and mnt+B[j] <= K:
        mnt += B[j]
        j += 1
        ans = max(ans, j+num-i)
    if i == num:
        break
    mnt -= A[num-i-1]

print(ans)

Measured memory_bytes: 40620
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args)throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try{
      String[] S = br.readLine().split(" ");
      int K = Integer.parseInt(S[0]);
      int X = Integer.parseInt(S[1]);
      int Y = Integer.parseInt(S[2]);
      int[] ans = new int[K];
      for(int i = 1; i <= K; i++){
        for(int j = i+1; j <= K; j++){
            int a = j-i;
            int b = Math.abs(X-i)+Math.abs(Y-j)+1;
          int r = Math.min(a,b);
          ans[r]++;
        }
      }
      for(int i = 1; i <= K; i++){
        System.out.println(ans[i]);
      }
    }catch(Exception e){
    }
  }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int k, x;
  cin >> k >> x;
  int d = k - 1;
  rep(i, x - d, x + d + 1) cout << i << endl;
}


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

using namespace std;


int main()
{
    long long n,k;
    cin >> n>>k;
    vector<long long> h(n);

    for(int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    vector<long long> dp(n, INT_MAX);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; i++)
    {
        for(int j=1; j<=k;j++)
        {
            if(i<j)
                break;
            dp[i]=min(dp[i],dp[i - j] + abs(h[i] - h[i - j]));
        }
    }
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ab = a + b, cd = c + d;
  if (ab == cd){
    cout << "Balanced" << endl;
  }
  if (ab > cd){
    cout << "Left" << endl;
  }
  if (ab < cd){
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main(){
  int q,t,x;
  string k;
  map<string,int,less<>> a;

  cin >> q;
  for (int i = 0; i < q; i++){
    cin >> t;
    cin >> k;
    auto itr = a.find(k);
    if (t == 0){
      cin >> x;
      if (itr == a.end()){
        a.insert(make_pair(k, x));
      }else{
        a[itr->first]=x;
      }
    }else{
      cout << itr->second << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 27844
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

typedef long long ll;

ll n;
int L, ans = 0;
const int tfs[3] = {3,5,7};

void dfs(ll x){
	string s = to_string(x);
	if (s.size()>L) ;
	else {
		bool f3, f5, f7;
		f3 = s.find('3') != string::npos;
		f5 = s.find('5') != string::npos;
		f7 = s.find('7') != string::npos;
		if (x <= n && f3&&f5&&f7) ans++;
		for (int i = 0; i < 3; ++i) {
			dfs(x*10+tfs[i]);
		}
	}
}

int main(int argc, char const *argv[])
{
	cin >> n;
	string s;
	s = to_string(n);
	L = s.size();

	dfs(0);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n, l = map(int, input().split())

apples = [l + i for i in range(n)]
total = int(n * (l - 1) + n * (n + 1) / 2)

absmin = float('inf')
for val in apples:
    if abs(val) < abs(absmin):
        absmin = val

print(total - absmin)

Measured memory_bytes: 38384
n_vertex, n_edge = gets.split.map(&:to_i)
#puts "#{n_vertex} #{n_edge}"
edges = n_vertex.times.map { Array.new(n_vertex, -1) }
for i in 0...n_edge do
  u, v, d = gets.split.map(&:to_i)
#  puts "#{u} #{v} #{d}"
  edges[u - 1][v - 1] = d
  edges[v - 1][u - 1] = d
end
#for i in 0...n_vertex do
#  puts edges[i].join(" ")
#end
f = gets.split.map(&:to_i)
#puts f.join(" ")

for i in 1...n_vertex do
  if edges[0][i] > 0
    targ_v = i
    targ_d = edges[0][i]
    break
  end
end
#puts "#{targ_v} #{targ_d}"

t_max = gets.to_i
#puts "#{t_max}"
count = 0
for t in 0...t_max do
  n_new = gets.to_i
#  puts "#{n_new}"
  for i in 0...n_new do
    new_id, dst = gets.split.map(&:to_i)
#    puts "#{new_id} #{dst}"
  end
  n_put = gets.to_i
#  puts "#{n_put}"
  for i in 0...n_put do
    put_id = gets.to_i
#    puts "#{put_id}"
  end
  
  if t < (t_max - targ_d)
    command = -1
  else
    if count < targ_d
      command = targ_v + 1
      count += 1
    else
      command = -1
    end
  end
  puts command
  $stdout.flush
  
  verdict = gets.chomp
  break if verdict == "NG"
  n_achieve = gets.to_i
#  puts "#{n_achieve}"
  for i in 0...n_achieve do
    achieve_id = gets.to_i
#    puts "#{achieve_id}"
  end
end


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

#define all(x) begin(x), end(x)
#define log(x) cout << (x) << endl
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
using vi = vector<int>;


vi a, b;
int n, m1, m2;
map<int,int> idx;

int med(int r) {
	if (idx[r] < (n>>1))
		return b[n>>1];
	else
		return b[(n>>1)-1];
}


int main() {
	cin>>n;
	a.assign(n,0),b.assign(n,0);
	rep (i,n) cin>>a[i], b[i]=a[i];

	sort(all(b));
	rep (i,n) idx[b[i]]=i;

	rep (i, n) log(med(a[i]));

	return 0;
}


Measured memory_bytes: 12928
//解説AC(写経)
//https://youtu.be/TdR816rqc3s?t=6817
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n, -1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int main(){
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    int a, b;
    rep(i, m){
        cin >> a >> b;
        a--; b--;
        uf.unite(a, b);
    }
    int ans = 0;
    rep(i, n) {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4044
module Main where
import Control.Monad
import Data.STRef
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

primeList :: Int -> [Int]
primeList n = [i | i <- [0..n], sieve n VU.! i]

primeFactors :: Int -> [(Int, Int)]
primeFactors n = filter (\x -> snd x /= 0) $ VU.toList $ factors n

sieve :: Int -> VU.Vector Bool
sieve n = VU.create $ do
  vec <- VUM.replicate (n+1) True
  VUM.write vec 0 False
  VUM.write vec 1 False
  forM_ [2..n] $ \i -> do
    b <- VUM.read vec i
    when b $ forM_ [2*i,3*i..n] $ \j ->
      VUM.write vec j False
  return vec

factors :: Int -> VU.Vector (Int,Int)
factors n = VU.create $ do
  let sn = sqrtn n
  vp <- VUM.replicate (sn+1) True
  vf <- VUM.replicate (sn+1) (0,0)
  ir <- newSTRef 0
  kr <- newSTRef n
  VUM.write vp 0 False
  VUM.write vp 1 False
  forM_ [2..sn] $ \p -> do
    b <- VUM.read vp p
    i <- readSTRef ir
    k <- readSTRef kr
    when b $ do
      forM_ [2*p,3*p..sn] $ \j -> VUM.write vp j False
      let (a, m) = ff k p
      VUM.write vf i (p, a)
      writeSTRef ir (i+1)
      writeSTRef kr m
  i <- readSTRef ir
  k <- readSTRef kr
  when (k /= 1) $ VUM.write vf i (k, 1)
  return vf

-- Double を経由しているので、ちょっと微妙な実装・・・
sqrtn :: Integral a => a -> a
sqrtn n = let m = floor $ sqrt $ fromIntegral n
          in if n >= m^2 then m else m - 1

-- k = p^a * m
ff :: Int -> Int -> (Int, Int)
ff k p = go k 0
  where go :: Int -> Int -> (Int, Int)
        go m a = if m `mod` p == 0
                 then go (m `div` p) (a + 1)
                 else (a, m)

main :: IO ()
main = do
  [m] <- map read . words <$> getLine :: IO [Int]
  let aa = sum . map (solve . snd) . primeFactors $ m
  print aa

solve :: Int -> Int
solve k = go 1
  where go m = case compare (m * (m + 1)) (2 * k) of
                 LT -> go (m + 1)
                 EQ -> m
                 GT -> m - 1


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<setprecision(i)<<var<<endl;

//---------------------------------------------------------------

int main(){
  ll N,K;
  cin>>N>>K;
  double ans=0;
  REP(i,1,N+1){
    int cnt = 1;
    while(1){
      if(i*cnt>=K){
        ans+=1.0/cnt;
        break;
      }
      cnt*=2;
    }
  }
  ans/=N;
  cout<<fixed<<setprecision(10)<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int, pair<int, int>>
#define ss second
#define ff first
#define all(x) ((x).begin(), (x).end())

using namespace std;
using ll = long long;

const int mod = 1e9 + 7;
const ll oo = 1 << 30;

int main(){
    ios_base::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (a < 10 and b < 10? a*b : -1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  int n, m, l, a[100][100], b[100][100];
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> a[i][j];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < l; j++)
      cin >> b[i][j];
 
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      long ans = 0;
      for (int k = 0; k < m; k++)
        ans += a[i][k] * b[k][j];
      if (j) cout << ' ';
      cout << ans;
    }
    cout << endl;
  }
  return 0;
}
 

Measured memory_bytes: 3140
#include<cstdio>
#define maxn 4005
#define mod 924844033
int n,k,tot,dp[maxn][maxn][2],f[maxn],fact[maxn],ans;
bool vis[maxn][2],ed[maxn];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		for(int j=0;j<=1;j++)
			if(!vis[i][j])
			{
				int len=0;
				for(int x=i,y=j;x<=n;x+=k,y^=1) vis[x][y]=1,len++;
				tot+=len; ed[tot]=1;
			}
	ed[0]=true; dp[0][0][0]=1;
	for(int i=0;i<2*n;i++)
		for(int j=0;j<=n;j++)
		{
			dp[i+1][j][0]=(dp[i][j][0]+dp[i][j][1])%mod;
			if(!ed[i]) dp[i+1][j+1][1]=dp[i][j][0];
		}
	for(int i=0;i<=n;i++) f[i]=(dp[n*2][i][0]+dp[n*2][i][1])%mod;
	fact[0]=1;
	for(int i=1;i<=n;i++) fact[i]=1ll*fact[i-1]*i%mod;
	for(int i=0,j=1;i<=n;i++,j=-j) ans=(ans+1ll*j*f[i]*fact[n-i]%mod)%mod;
	printf("%d\n",(ans+mod)%mod);
}


Measured memory_bytes: 124544
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int total = 0;
		for (int i = 1; i <= N ; i++) {
			int count = 0;
			for (String c :Integer.toString(i).split("")) {
				count += Integer.parseInt(c);
			}
			if (A <= count && count <= B) {
				total += i;
			}
		}
		System.out.println(total);
	}	
}

Measured memory_bytes: 34132
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)


//セグ木ここから
//*
//↓ここを変える
typedef struct atai{ll a;}atai;
atai xx(atai x,atai y){
	atai r;
	r.a=x.a+y.a;//sum
	return r;
}
//↑ここを変える

int segNUM;
atai segN[1<<18],*seg;
void seguse(int n){segNUM=n;seg=segN+segNUM;}

//seg[]に値を与えてから初期化
void seginit(){for(int node=segNUM-1;node;node--)segN[node]=xx(segN[node*2],segN[node*2+1]);}
void segupdate(int node,atai x){
	//seg[node]をxに更新
	node+=segNUM;
	segN[node]=x;
	while(node/=2)segN[node]=xx(segN[node*2],segN[node*2+1]);
}

atai segcalcsub(int l,int r,int k,int cl,int cr){
	//完全に含むとき
	if(l<=cl&&cr<=r)return segN[k];

	int cm=(cl+cr)/2;
	//左側だけ
	if(r<=cm)return segcalcsub(l,r,2*k  ,cl,cm);
	//右側だけ
	if(cm<=l)return segcalcsub(l,r,2*k+1,cm,cr);
	//両方
	return xx(segcalcsub(l,r,2*k,cl,cm),segcalcsub(l,r,2*k+1,cm,cr));
}
atai segcalc(int l,int r){return segcalcsub(l,r,1,0,segNUM);}
//セグ木ここまで

char s[200010];
int c[30];
int a[200010];
int p[200010];

ll ans;
int main(){
	scanf("%s",s);
	ll n=strlen(s);
	rep(i,0,n)c[s[i]-'a']++;
	
	int idx=-1;
	rep(i,0,26)if(c[i]%2){
		if(idx==-1)idx=i;
		else{
			puts("-1");
			return 0;
		}
	}
	
	rep(i,0,26)c[i]/=2;
	c[idx]++;

	rep(i,0,n){
		int t=s[i]-'a';
		if(c[t]){
			if(c[t]==1&&t==idx)a[i]=-2;
			else a[i]=-1;
			c[t]--;
		}else a[i]=-3;
	}
	
	//前半パート
	{
		int cnt=0;
		rep(i,0,n){
			if(a[i]==-1||a[i]==-2)ans+=cnt;
			if(a[i]==-2||a[i]==-3)cnt++;
		}
	}
	
	int cnt=0;
	rep(i,0,n)if(a[i]==-1)a[i]=cnt++;
	cnt=0;
	for(int i=n-1;i>=0;i--)if(a[i]==-3)a[i]=cnt++;
	
	//数列の構成
	rep(i,0,26){
		for(int l=0,r=n-1;l<r;l++,r--){
			while(l<r&&s[l]-'a'!=i)l++;
			if(l==r)break;
			while(s[r]-'a'!=i)r--;
			p[a[l]]=a[r];
		}
	}
	
	//転倒数の計算
	seguse(1<<17);
	rep(i,0,n/2){
		ans+=segcalc(p[i],n/2).a;
		atai r={1};
		segupdate(p[i],r);
	}
	
	printf("%lld",ans);
}

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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int64_t> a(n),b(n),c(m),d(m);
  for(int i = 0; i < n; i++)cin>>a.at(i)>>b.at(i);
  for(int i = 0; i < m; i++)cin>>c.at(i)>>d.at(i);

 
  vector<int> ans(n);
  for(int i = 0; i < n; i++){
    int tmp = 0;
    int64_t mm = 10000000000;
    for(int j = 0; j < m; j++){
      int dis = abs(a.at(i)-c.at(j))+abs(b.at(i)-d.at(j));
      if(mm>dis){
        mm = dis;
        tmp = j;
      }
    }
    ans.at(i) = tmp;
  }
  for(int i = 0; i < n; i++)cout<<ans.at(i)+1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<vector>
    #include<algorithm>
    using namespace std;
    const int maxn = 1000000 + 10;
    #define INF 0x7fffffff
    #define clr(x,y) memset(x,y,sizeof(x))
    typedef long long ll;
    #define eps 10e-10
    const ll Mod = 1000000007;
    int main()
    {
        int n;
        while(cin >> n)
        {
            cout << n * (n + 1)/2 << endl;
        }
        return 0;
    }


Measured memory_bytes: 256
# スペース区切りの整数の入力
N, A, B = map(int, input().split())

totalSum = 0
tmpNum = 0

for n in range(N + 1):
    digit = 0
    digitSum = 0
    tmpNum = n
    while True:
        digit = tmpNum % 10
        digitSum = digitSum + digit
        if tmpNum >= 10:
            tmpNum = tmpNum / 10
            tmpNum = int(tmpNum)
        else:
            if A <= digitSum <= B:
                totalSum = totalSum + n
            break

print(totalSum)

Measured memory_bytes: 3060