akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int N;
	cin >> N;
	vvi cost(N, vi(N));
	REP(i, N) {
		REP(j, N) {
			cin >> cost[i][j];
		}
	}

	ll ans = 0;
	REP(i, N) {
		REP(j, i) {
			ans += min(cost[i][j], cost[j][i]);
		}
	}

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

Measured memory_bytes: 1248
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim_i = (b); i < lim_i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Tue Mar 17 20:36:37 JST 2020
 **/

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

const Int K = 1e5 + 1;
signed main() {
    Int n, W;
    cin >> n >> W;
    vector<Int> w(n), v(n);
    REP(i, n) cin >> w[i] >> v[i];
    vector<Int> dp(K, 1e18);
    dp[0] = 0;
    Int ans = 0;
    REP(i, n) {
        for (Int j = K - 1; j >= 0; j--) {
            if (j - v[i] >= 0) chmin(dp[j], dp[j - v[i]] + w[i]);
            if (dp[j] <= W) chmax(ans, j);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <utility>
#include <queue>
#include <climits>
using namespace std;

#define endl '\n'
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define FORE(i, a, b) for(int i=(a); i<=(b); i++)
typedef pair<int, int> ii;
typedef long long LL;
typedef long double LD;

int k, n, mx;
int a[105];

void solve(){
    cout << max(mx-(k-mx+1), 0) << endl;
}

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    std::cin.tie(0);
    while(cin >> k >> n) {
    	mx = 0;
    	FOR(i, 0, n) {
    		cin >> a[i];
    		mx = max(mx, a[i]);
    	}
		solve();
    }
    return 0;
}

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

int main()
{
	int k,a,b;
	cin >> k >> a >> b;
	for(int i = a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
	return 0;
}

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

int main(){
  ll n;
  cin >> n;
  ll ans=1000000000000000;
  for(ll i=1;i*i<=n;i++){
    if(n%i != 0)continue;
    ll j=n/i;
    ans=min(ans,i+j-2);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    string str;
    cin >> str;
    if (str == "A") {
        cout << "T" << endl;
    } else if (str == "T") {
        cout << "A" << endl;
    } else if (str == "C") {
        cout << "G" << endl;
    } else {
        cout << "C" << endl;
    }
    return 0;
}

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

int n, p[20005], a[20005], b[20005];

int main() {
	scanf("%d", &n);
	for ( int i = 1; i <= n; i++ ) {
		scanf("%d", &p[i]);
	}
	for ( int i = 1; i <= n; i++ ) {
		a[i] = a[i - 1] + 20000;
	}
	for ( int i = n; i > 0; i-- ) {
		b[i] = b[i + 1] + 20000;
	}
	for ( int i = 1; i <= n; i++ ) {
		a[p[i]] -= (n - i);
	}
	for ( int i = 1; i <= n; i++ ) {
		printf(i == n?"%d\n":"%d ", a[i]);
	}
	for ( int i = 1; i <= n; i++ ) {
		printf(i == n?"%d\n":"%d ", b[i]);
	}
	return 0;
}

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

const int MN = 1e5+5;
int st[3*MN], N, arr[MN], i, x, y, ans;

void build(int i,int s,int e){
    if(s!=e){
        build(2*i,s,(s+e)/2);
        build(2*i+1,(s+e)/2+1,e);
        st[i] = __gcd(st[2*i], st[2*i+1]);
    }
    else st[i] = arr[s];
}

int qu(int i,int s,int e,int ss,int se){
    if(s>=ss&&e<=se) return st[i];
    else if((s+e)/2<ss) return qu(2*i+1,(s+e)/2+1,e,ss,se);
    else if((s+e)/2>=se) return qu(2*i,s,(s+e)/2,ss,se);
    else return __gcd(qu(2*i,s,(s+e)/2,ss,se),qu(2*i+1,(s+e)/2+1,e,ss,se));
}

int main(){
    for(scanf("%d",&N),i=1;i<=N;i++)
        scanf("%d",&arr[i]);
    build(1,1,N);
    ans = max(qu(1,1,N,2,N),qu(1,1,N,1,N-1));
    for(i=2;i<N;i++){
        ans = max(ans, __gcd(qu(1,1,N,1,i-1),qu(1,1,N,i+1,N)));
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    long long A,B;
    cin >> A >> B;
    cout << max({A+B, A-B, A* B}) << endl;
    return 0;
}


Measured memory_bytes: 256
N = list(map(int,input()))
K = int(input())
L = len(N)

def comb(n,k):
    if n < 0 or k < 0 or k > n:
        return 0
    ans = 1
    for i in range(k):
        ans *= n-i
    for i in range(k):
        ans //= i+1
    return ans

i = 0
D = [0] * K
M = K
for k in range(K):
    while i < L and N[i] == 0:
        i += 1
    if i < L:
        D[k] = i
        i += 1
    else:
        M = k
        break

ans = 0
for k in range(M):
    i = D[k]
    ans += comb(L-1-i,K-k)*(9**(K-k))
    ans += (N[i]-1) * comb(L-1-i,K-1-k)*(9**(K-1-k))
if K == M:
    ans += 1

print(ans)


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const int INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n;
	cin >> n;
	int ans = n;
	for(int i = 0; i <= n ; i++){
		int nine = i;
		int six = n-nine;

		int num9 = 0;
		int x = 9;
		while(x < nine) x *= 9;
		while(x >= 9){
			num9 += nine / x;
			nine -= (nine / x)*x;
			x /= 9;
		}
		num9 += nine;


		int num6 = 0;
		int y = 6;
		while(y < six) y *= 6;
		while(y >= 6){
			num6 += six / y;
			six -= (six / y)*y;
			y /= 6;
		}
		num6 += six;
		ans = min(ans,num6+num9);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long ans;
int r[100001];
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for (int i = 1; i < N+1; i++) {
        int p;
        cin >> p;
        r[p] = i;
    }
    multiset<int> S{0, 0, N+1, N+1};
    int ip[2], in[2];
    for (int i = N; i > 0; i--) {
        S.insert(r[i]);
        auto it = S.find(r[i]);
        for (int j = 0; j < 2; j++) {
            ip[j] = *prev(it, j+1);
            in[j] = *next(it, j+1);
        }
        ans += (long long)i * (*it-ip[0]) * (in[1]-in[0]);
        ans += (long long)i * (ip[0]-ip[1]) * (in[0]-*it);
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <map>
using namespace std;
int n;

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
map <string,int> mp;
mp.clear();
cin>>n;
string s;
int kq=0;
for (int i=1;i<=n;i++){
    cin>>s;
    if (mp[s]==0){
        kq++;
        mp[s]=1;
    }
}
cout<<kq;
}


Measured memory_bytes: 19248
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		char[] c = nc();
		int ans = 0;
		for (int i = 0; i < 4; i++) {
			if (c[i] == '+') {
				ans++;
			} else {
				ans--;
			}
		}
		out(ans);
	}

	/*
	 * 以下メソッド集
	 */
	static int[] sort(int[] n) {
		Arrays.sort(n);
		return n;
	}

	static void debug() {
		out("---");
	}

	static void debug(long a) {
		out("-------");
		out(a);
		out("-------");
	}

	static void debug(String a) {
		out("-------");
		out(a);
		out("-------");
	}

	static long[] sort(long[] n) {
		Arrays.sort(n);
		return n;
	}

	static int ketasuu(int n) {
		String str = "" + n;
		return str.length();
	}

	static int account(String str) {
		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static long min(long d, long e) {
		return Math.min(d, e);
	}

	static int min(int a, int b) {
		return (int) Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


Measured memory_bytes: 35556
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);


ll soinsu(ll k,ll i){
    if(k%i!=0){
        return k;
    }else{
        return soinsu(k/i,i);
    }
}


std::vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    }
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
ll gcd(ll a,ll b){
if(a==0||b==0)return max(a,b);
if(b>a)swap(a,b);
 while(1){
        if(a%b!=0){
            ll tmp=b;b=a%b;
            a=tmp;
        }else{
            return b;
        }
    }
}

int main() {
    sieve(1000000);
    ll a,b;
    cin>>a>>b;

    if(b>a)swap(a,b);
    ll ab = gcd(a,b);

    ll ans=0;

    bool f = false;
   // cout<<ab<<endl;

   ll k = ab;

    for(ll i=2;i<=1000000;i++){
        if(IsPrime[i]&&k%i==0){
            ans++;
            while(k%i==0){
                k/=i;
            }
        }
    }

if(k!=1){
    ans++;
}


    cout<<ans+1<<endl;

    return 0;
}


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

int main() {
    //マジでわからんやつやんけ
    string w;
    cin >> w;
    bool flag = true;
    rep(i, w.size()) {
        //countを覚えた!!
        if (count(w.begin(), w.end(), w.at(i)) % 2 != 0) {
            flag = false;
        }
    }
    if(flag) {
        //小文字やた
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}
    

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int N;
	int count = 0;
	scanf("%d", &N);

	for (int i = 1; i <= N; i++){
		if (i % 2 == 1){
			int divisor = i;
			int eight = 2;
			for (int k = 2; k < divisor / 2; k++){
				if (i%k == 0) {
					eight = eight + 2;
					divisor = i / k;
				}
			}
			if (eight == 8) count++;
		}
	}

	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	
	if (a == b and b == c)
		cout << "No" << endl;
	else if (a != b and b != c and c != a)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}

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


int main() {
    int time[5];

    for (int i=0; i < 5; i++) {
        cin >> time[i];
    }
    
    int min_1stdig  = 10;
    int idx;
    for(int i=0; i < 5; i++) {
        if (time[i] % 10 > 0 && time[i] % 10 < min_1stdig) {
            idx = i;
            min_1stdig = time[i] % 10;
        }
    }
    int res = 0;
    for(int i=0; i < 5; i++) {
        if (i == idx) {
            res += time[i];
        } else { 
            if (time[i] % 10 == 0){
                res += time[i];
            } else {
                res += time[i] + (10 - time[i] % 10);
            }
                
        }
        
    }
    cout << res << "\n";
}

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

class Program
{
    public static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int H = int.Parse(Console.ReadLine());
        int W = int.Parse(Console.ReadLine());


        Console.WriteLine(((N+1 - H) * (N + 1 - W)).ToString());
        return;
    }
}


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

#define fs first
#define se second
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

string a, b;

void izryt() {
	rep(i, a.size()) {
		int n = a[i] - '0', m = b[i] - '0';
		if (n == m) continue;

		cout << (n > m ? "GREATER" : "LESS") << endl;
		return;
	}

	cout << "EQUAL" << endl;
}

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

	if (a.size() == b.size()) {
		izryt();
	} else {
		cout << (a.size() > b.size() ? "GREATER" : "LESS") << endl;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int xs[110];

void solve() {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        xs[x]++;
    }
    int m = INT_MAX;
    for (int p = 0; p <= 100; ++p) {
        int sum = 0;
        for (int j = 0; j <= 100; ++j) {
            sum += pow(j - p, 2) * xs[j];
        }
        m = min(m, sum);
    }
    cout << m << endl;
}

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


Measured memory_bytes: 256
#include<cstdio>

#define MAXN 100000
int N,L,A[MAXN+5];

int main(){
    scanf("%d%d",&N,&L);
    for(int i=1;i<=N;i++)
        scanf("%d",A+i);
    for(int i=1;i<N;i++){
        if(A[i+1]+A[i]>=L){
            puts("Possible");
            for(int j=1;j<i;j++)
                printf("%d\n",j);
            for(int j=N-1;j>=i;j--)
                printf("%d\n",j);
            return 0;
        }
    }
    puts("Impossible");
}


Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();
            long K = sc.nextInt();
            long[] A = new long[N];
            long[] B = new long[M];
            for (int i = 0; i < N; i++) {
                A[i] = sc.nextInt();
            }
            for (int i = 0; i < M; i++) {
                B[i] = sc.nextInt();
            }

            long[] sumA = new long[N + 1];
            for (int i = 0; i < N; i++) {
                sumA[i + 1] = sumA[i] + A[i];
            }
            long[] sumB = new long[M + 1];
            for (int i = 0; i < M; i++) {
                sumB[i + 1] = sumB[i] + B[i];
            }

            int max = 0;
            for (int i = 0; i < N + 1; i++) {
                if (K - sumA[i] >= 0) {
                    max = Math.max(max, i + index(K - sumA[i], sumB));
                }
            }

            System.out.println(max);
        }
    }

    static int index(long k, long[] v) {
        int l = 0;

        int r = v.length - 1;
        if (v[r] <= k) {
            return r;
        }

        for (; l + 1 < r;) {
            int m = (l + r) / 2;
            long vm = v[m];
            if (vm <= k) {
                l = m;
            } else {
                r = m;
            }
        }

        return l;
    }
}


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

int main()
{
  ll n,W;
  cin>>n>>W;
  ll w[n],v[n],i,j;
  int sum=0;
  for(i=0;i<n;i++)
  {
    cin>>w[i]>>v[i];
    sum+=v[i];
  }
  
  long long s[sum+1][n];
  memset(s,-1,sizeof(s));
  s[0][0]=0;
  if(w[0]>W);
  else
  s[v[0]][0]=w[0];
  for(i=0;i<n-1;i++)
  {
    for(j=0;j<=sum;j++)
    {
      if(s[j][i]!=-1)
      {
        if(s[j][i]+w[i+1]>W);
        else
        {
            if(s[j+v[i+1]][i+1]!=-1)
            s[j+v[i+1]][i+1]=min(s[j][i]+w[i+1],s[j+v[i+1]][i+1]);
            else
            s[j+v[i+1]][i+1]=s[j][i]+w[i+1];
        }
        if(s[j][i+1]!=-1)
        s[j][i+1]=min(s[j][i],s[j][i+1]);
        else
        s[j][i+1]=s[j][i];
      }
    }
  }
  for(i=sum;i>=0;i--)
  {
    if(s[i][n-1]!=-1)
    {
      cout<<i<<endl;
      break;
    }
  }
  
  
  return 0;
}



Measured memory_bytes: 78336
/*
 * 2409.cc: Power
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_M = 100;

const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii rs[MAX_N];
int dists[MAX_N + 1];

/* subroutines */

/* main */

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

  for (int i = 0; i < m; i++) {
    cin >> rs[i].first >> rs[i].second;
    rs[i].first--;
  }
  sort(rs, rs + m);

  for (int i = 0; i <= n; i++) dists[i] = INF;
  dists[0] = 0;

  for (int i = 0; i < m; i++) {
    int &xi = rs[i].first, &yi = rs[i].second;
    if (dists[xi] < INF) {
      int ud = dists[xi] + 1;
      for (int j = xi + 1; j <= yi; j++)
	if (dists[j] > ud) dists[j] = ud;
    }
  }

  if (dists[n] >= INF) cout << "Impossible" << endl;
  else printf("%d\n", dists[n]);
  return 0;
}

Measured memory_bytes: 1160
/*
123 321
ABCDEFG
GABCDEF
FGABCDE
EFGABCD
DEFGABC
CDEFGAB
BCDEFGA
*/
#include<bits/stdc++.h>
using namespace std;

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i=1;i<=m;i++) {
		int l = i, r = n+1-i;
		if(n%2==0 && r-l <= l+n-r) r--;
		printf("%d %d\n", l, r);
		//printf("%d %d %d %d\n", l, r, r-l, l+n-r);
	}
	
	return 0;
}

Measured memory_bytes: 3776
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll N;

ll dfs(ll n, ll f3, ll f5, ll f7) {
    if(n>N) return 0;
    
    ll res=0;
    if(f3&&f5&&f7) res++;
    
    for(ll i=3; i<=7; i+=2)
        res+=dfs(n*10+i, f3||(i==3), f5||(i==5), f7||(i==7));
    
    return res;
}

int main(void) {
    cin >> N;
    pt(dfs(0, 0, 0, 0));
}



Measured memory_bytes: 256
n, q = (int(_) for _ in input().split())

s = input()


lr = [[int(i) for i in input().split()] for i in range(q)]



csum = [0 for i in range(n+1)]



for i in range(1,n+1):
    if s[i-1:i+1] == 'AC':
        csum[i] = csum[i-1] + 1
    else:
        csum[i] = csum[i-1]




for i in range(q):
    print(csum[lr[i][1]-1] - csum[lr[i][0]-1])



Measured memory_bytes: 24432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
typedef pair<ll,pii> ipii;
#define MOD 1000000007
#define mod(a) ((a)%MOD)
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define dbg(x) cerr<<#x<<" = "<<x<<"\n"
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<"\n"
#define dbg3(x,y,z) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<" , "<<#z<<" = "<<z<<"\n"
#define INF (1LL<<60)
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(v) v.begin(),v.end()
#define endl '\n'
ll gcd(ll a,ll b){if(a==0) return b; return gcd(b%a,a);}
ll powm(ll base,ll exp,ll mod=MOD) {base%=mod;ll ans=1;while(exp){if(exp&1LL) ans=(ans*base)%mod;exp>>=1LL,base=(base*base)%mod;}return ans;}
 



vector<ipii> p;
ll dp[1003][20004];

bool comp(ipii a,ipii b){
     return (a.ft+a.sd.ft)<(b.ft+b.sd.ft);
}


int main(){
      sync;
      ll n;
      cin>>n;
      for(int i=0;i<n;i++){
            ll w,s,v;
            cin>>w>>s>>v;
            p.pb({s,{w,v}});
      }

        sort(all(p),comp);
        ll ans=0;
        for(int i=0;i<=20004;i++){
               dp[0][i]=(p[0].sd.ft<=i?p[0].sd.sd:0);
        }
        for(int i=1;i<n;i++){
             for(int j=0;j<=20000;j++){
                  if(j==0){
                       dp[i][j]=0;continue;
                  }
                  dp[i][j]=dp[i-1][j];
                  if(p[i].sd.ft<=j){
                        dp[i][j]=max(dp[i][j],dp[i-1][min(j-p[i].sd.ft,p[i].ft)]+p[i].sd.sd);
                  }
             }
        }

        for(int i=0;i<=20000;i++) ans=max(ans,dp[n-1][i]);
        cout<<ans<<endl; 
}

Measured memory_bytes: 156544
n, m = map(int, input().split())
nl = set(range(n))
ab = [list(map(int, input().split())) for _ in nl]
ab.sort()
num, ans = 0, 0
for a, b in ab:
    if num + b < m:
        num += b
        ans += a * b
    else:
        ans += a * (m - num)
        break
print(ans)

Measured memory_bytes: 34964
s = input()
n = len(s)
mod = 2019

t = [0]*n
dp = [0]*2020
t[0] = int(s[-1])
dp[t[0]] += 1
for i in range(n-1):
    t[i+1] = t[i] + int(s[-2-i])*pow(10, i+1, mod)
    t[i+1] %= mod
    dp[t[i+1]] += 1
ans = 0
for D in dp[1:]:
    ans += D*(D-1)//2
print(ans+(dp[0]+1)*(dp[0])//2)




Measured memory_bytes: 16304
from bisect import bisect_left
D = int(input())
C = list(map(int, input().split()))  # 低下
S = [list(map(int, input().split())) for _ in range(D)]
T = [int(input())-1 for _ in range(D)]
Last = [-1] * 26
def calc_pena(day):
    res = 0
    for l, c in zip(Last, C):
        res += (day-l)*c
    return res
T2 = [[-1] for _ in range(26)]
def change(day, contest):
    diff = 0
    contest_old = T[day]
    T[day] = contest
    idx = bisect_left(T2[contest_old], day)
    diff -= C[contest_old] * (T2[contest_old][idx+1] - day) * (day - T2[contest_old][idx-1])
    del T2[contest_old][idx]
    idx = bisect_left(T2[contest], day)
    diff += C[contest] * (T2[contest][idx] - day) * (day - T2[contest][idx-1])
    T2[contest].insert(idx, day)
    diff += S[day][contest] - S[day][contest_old]
    return diff

ans = 0
for i, (s, t) in enumerate(zip(S, T)):
    Last[t] = i
    ans += s[t]
    ans -= calc_pena(i)
    T2[t].append(i)
for i in range(26):
    T2[i].append(D)  # 番兵

M = int(input())
DQ = [list(map(int, input().split())) for _ in range(M)]
for d, q in DQ:
    ans += change(d-1, q-1)
    print(ans)


Measured memory_bytes: 22176
import math
import collections
import fractions
import itertools

def solve():
    a = int(input())
    b = int(input())
    if a > b:
        print("GREATER")
    elif a < b:
        print("LESS")
    else:
        print("EQUAL")
    return 0

if __name__ == '__main__':
    solve()

Measured memory_bytes: 10292
#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 - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll a(n), b;
    ll flg = 0, p = 0, res, sum = 0;
    REP(i, n){
        cin >> a[i];
        if(a[i] == 0) flg = 1;
        if(a[i] < 0) p++;
        res = abs(a[i]);
        b.push_back(res);
        sum += res;
    }
    if(flg || (p % 2 == 0)){
        cout << sum << endl;
        return 0;
    }
    VSORT(b);
    sum -= 2 * b[0];
    cout << sum << endl;
    return 0;
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    ll h, w, n; cin >> h >> w >> n;
    vector<ll> anslis(10, 0);
    map<Pii, int> mp;
    anslis[0] = (h-2) * (w-2);
    REP(i, 0, n){
        int a, b; cin >> a >> b;
        a--; b--;
        mp[Pii(a, b)]++;
        REP(l, 0, 9){
            int na = a + dx[l], nb = b + dy[l]; 
            int count = 0, f = 1;
            REP(k, 0, 9){
                int nx = na + dx[k], ny = nb + dy[k];
                if(nx < 0 || ny < 0 || nx >= h || ny >= w){
                    f = 0;
                    break;
                }
                if(nx == a && ny == b){
                    continue;
                }else{
                    if(mp[Pii(nx, ny)] == 1){
                        count++;
                    }
                }
            }
            if(f){
                anslis[count]--;
                anslis[count+1]++;
            }
        }
    }
    REP(i, 0, 10){
        cout << anslis[i] << endl;
    }
}

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

int main(){
  vector<int>a(5);
  int k;
  rep(i,5)cin>>a[i];
  cin>>k;
  
  sort(a.begin(),a.end());
  if(a[4]-a[0]<=k)cout<<"Yay!"<<endl;
  else cout<<":("<<endl;

  return 0;
}

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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
#define N 100010
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;
ll T,n;

int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    long double d =(n*1.0)/3;
    cout << setprecision(20) << d*d*d;

    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 REP(i, d, n) for(int i=(d); i<(n); ++i)
#define rrep(i, n)   for(int i=(n-1); i>=0; --i)
#define all(v)       v.begin(), v.end()
#define rall(v)      v.rbegin(), v.rend()
#define int          long long
template<typename T>
using vv  =  vector<vector<T>>;
using vi  = vector<int>;
using vvi = vector<vector<int>>;
using P   = pair<int, int>;
using ll  = long long;
constexpr ll INF = 1LL << 60;

signed main(){

    int n;
    cin >> n;

    int ans = 1;
    bool flag = false;
    bool zero = false;
    rep(i, n){
        int a;
        cin >> a;
        if(ans != 0 && a > (ll)(1e18) / ans){
            flag = true;
        } 
        if(a == 0){
            zero = true;
        }
        ans *= a;
    }

    if(flag && !zero){
        cout << -1 << endl;
    }
    else if(zero){
        cout << 0 << endl;
    }
    else{
        cout << ans << endl;
    }

    return 0;
}


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

int main () {
  int N; cin >> N;
  
  int max =0;
  int max_i =0;
  
  for (int i=1; i<=N; i++) { //i phải = 1
    int j=i;
    int count = 0;	//phải nằm nước while trong for
    while(j%2 ==0) {
      j /= 2;
      count ++;
    }
    if (count >= max) {
      max = count;	//phải có và phải đúng thứ tự
      max_i = i;
    }
  }
  cout << max_i << endl;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main()
{
    int n;
    cin >> n;
    vector<int> num(1e5 + 1, 0);
    int a;
    rep(i, n)
    {
        cin >> a;
        num[a]++;
        num[a + 1]++;
        if (a != 0)
        {
            num[a - 1]++;
        }
    }
    int res;
    int cnt = 0;
    rep(i, 1e5 + 1)
    {
        if (num[i] > cnt)
        {
            cnt = num[i];
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3744
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
V ans;

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

  cin >> n;
  bool f[100001];  // 1000000以下の素数を調べよう！
  rrep(i, 2, 100001) { f[i] = false; }
  rrep(i, 2, 100001) {
    if (!f[i]) {
      for (int j = i + i; j <= 100000; j += i) {
        f[j] = true;
      }
    }
  }
  f[2] = false;
  rrep(i, 2, 55556) {
    if (!f[i] && i % 5 == 1) ans.p_b(i);
    if (Size(ans) == n) break;
  }
  rep(i, n) {
    if (i == n - 1)
      Cout(ans[i]);
    else
      cout << ans[i] << " ";
  }
  return 0;
}

Measured memory_bytes: 384
/**
 * Title: B - I miss you...
 * Url: https://atcoder.jp/contests/abc154/tasks/abc154_b
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    string s; cin >> s;
    for(int i=0; i<s.length(); i++) cout << "x";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    for(int n; 0<(n=readln().chomp().to!int()); )
    {
        auto m = iota(n).map!(_=>readln().split().map!(to!int).array()).array().map!(a=>a~a.reduce!"a+b"()).array();
        m~=iota(m[0].length).map!(i=>iota(m.length).map!(j=>m[j][i]).reduce!"a+b"()).array();
        m.map!(a=>a.map!(v=>format("%5d",v)).join()).join("\n").writeln();
    }
}

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

using ll = long long;

const ll MOD = 1e9+7;
int N;
int a[111111]; // 入力配列
int v[111111]; // v[i]: 入力配列中にiがいくつあるか

// 2^x乗を計算
ll calc(ll x) {
   ll ret = 1;
   while (x > 0) {
      ret = ((ret%MOD) * (2%MOD)) % MOD;
      x--;
   }
   return ret;
}

int main() {
   cin >> N;
   for (int i = 0; i < N; i++) {
      cin >> a[i];
      v[a[i]]++;
   }

   bool ok = true;
   // Nが奇数か偶数かで場合分け
   if (N&1) {
      if (v[0] != 1) ok = false;
      for (int i = 2; i < N; i+=2) {
         if (v[i] != 2) ok = false;
      }
   } else {
      for (int i = 1; i <= N; i+=2) {
         if (v[i] != 2) ok = false;
      }
   }

   if (ok) {
      cout << calc(N/2) % MOD << endl;
   } else {
      cout << 0 << endl;
   }

   return 0;
}

Measured memory_bytes: 1024
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [1]*n

for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] < h[b - 1]:
        ans[a - 1] = 0
    elif h[a - 1] > h[b - 1]:
        ans[b - 1] = 0
    else:
        ans[a - 1] = 0
        ans[b - 1] = 0

print(ans.count(1))


Measured memory_bytes: 20116
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

int main()
{
  int N, M;
  std::cin >> N >> M;
  std::vector<int> H(N, 0);
  std::multimap<int, int> J;
  for (int i = 0; i < N; i++)
  {
    std::cin >> H[i];
  }
  for (int i = 0; i < M; i++)
  {
    int tmp, tmp2;
    std::cin >> tmp >> tmp2;
    J.emplace(tmp, tmp2);
    J.emplace(tmp2, tmp);
  }

  int count = 0;
  for (int i = 1; i <= N; i++)
  {
    if (J.count(i) == 0)
    {
      count++;
    }
    else
    {
      const auto &search = J.equal_range(i);
      if (std::all_of(search.first, search.second, [&](const std::pair<int, int> &x) {
            return H.at(i - 1) > H.at(x.second - 1);
          }))
      {
        count++;
      }
    }
  }
  std::cout << count << std::endl;

  return 0;
}

Measured memory_bytes: 12596
import java.util.*;
public class Main {
  	public static int muld(int n,int m){
      int cnt = 0;
      for(int i = 1;i <= n/i;i++){
        if(n % i == 0){
          if(i == n/i) cnt++;
          else cnt += 2;
        }
      }
      if(n == m) return cnt;
      else return muld(n-1,m)+cnt;
    }
  
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
      	int cnt;
   
      	if(n <= 630000) cnt = muld(n-1,1);
      	else cnt = 8509899 + muld(n-1,630000);
      
		System.out.println(cnt);
	}
}

Measured memory_bytes: 52812
#include<iostream>
using namespace std;
int main() {
	string S;
	cin >> S;
	if (S == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (S == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else {
		cout << "Sunny" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	static long MOD = 1000000007L;
	int N;
	long[] A, B, temp;
	long gcd, lcm;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		this.A = new long[N];
		String[] tokens = in.readLine().split(" ");
		for (int i = 0; i < N; ++i) {
			A[i] = Long.parseLong(tokens[i]);
		}
		this.B = new long[N];
		this.temp = Arrays.copyOf(A, A.length);
	}

	List<Long> getSoinsuuBunkai(long val) {
		long div = -1;
		for (long i = 2; i < Math.sqrt(val) + 1; ++i) {
			if (val % i == 0) {
				div = i;
				break;
			}
		}
		if (div < 0) {
			// val が素数
			List<Long> result = new ArrayList<>(1);
			result.add(val);
			return result;
		} else {
			List<Long> result = getSoinsuuBunkai(val / div);
			result.add(div);
			return result;
		}
	}

	Map<Long, Integer> count(List<Long> sosuu) {
		Map<Long, Integer> map = new HashMap<>();
		for (int i = 0; i < sosuu.size(); ++i) {
			if (map.containsKey(sosuu.get(i))) {
				map.put(sosuu.get(i), map.get(sosuu.get(i)) + 1);
			} else {
				map.put(sosuu.get(i), 1);
			}
		}
		return map;
	}

	void calc() {
		// 最小公倍数と最大公約数を求める
		// まずAの値を全部素因数分解する
		List<Long>[] a = new List[N];
		for (int i = 0; i < N; ++i) {
			a[i] = getSoinsuuBunkai(A[i]);
		}
		Map<Long, Integer> map = new HashMap<>();
		for (List<Long> sosuu : a) {
			Map<Long, Integer> subMap = count(sosuu);
			for (Long key : subMap.keySet()) {
				if (map.containsKey(key)) {
					map.put(key, Math.max(subMap.get(key), map.get(key)));
				} else {
					map.put(key, subMap.get(key));
				}
			}
		}
		lcm = lcm(map);
		// Bの一覧を求める
		for (int i = 0; i < N; ++i) {
			B[i] = (lcm * inv(A[i])) % MOD;
		}
	}

	long lcm(Map<Long, Integer> map) {
		long result = 1;
		for (Long key : map.keySet()) {
			for (int i = 0; i < map.get(key); ++i) {
				result *= key;
				result %= MOD;
			}
		}
		return result;
	}

	long gcd(long large, long small) {
		if (small > large) {
			return gcd(small, large);
		}
		if (large % small == 0) {
			return small;
		}
		return gcd(small, large % small);
	}

	void showResult() {
		long result = 0L;
		for (int i = 0; i < N; ++i) {
			result += B[i];
			result %= MOD;
		}
		System.out.println(result);
	}

	static long inv(long val) {
		long result = 1L;
		long k = MOD - 2L;
		long y = val;
		while (k != 0) {
			if ((k & 1L) > 0) {
				result = (result * y) % MOD;
			}
			y = (y * y) % MOD;
			k /= 2;
		}
		return result;

	}
}

Measured memory_bytes: 28684
N, X = map( int, input().split())
now = "P"
A = [1]*(N+1)
P = [1]*(N+1)
for i in range(N):
    A[i+1] = 2*A[i]+3
    P[i+1] = 2*P[i]+1
now = N
ans = 0
X -= 1
while now > 0:
    if A[now]//2 == X:
        ans += P[now-1]+1
        X = -1
        break
    elif A[now]//2 < X:
        ans += P[now-1]+1
        X -= A[now-1]+2
    else:
        X -= 1
    if X < 0:
        break
    now -= 1
if X >= 0:
    ans += 1
print(ans)


Measured memory_bytes: 3064
// Date: 2020-03-21

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define D(x) cout<<#x<<" = "<<x<<endl;
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

set<pii> st;
LL cnt[10], n, m, q;
pii a[N];

const int xx[] = {0, 1, 1, 1, 2, 2, 2, 3, 3, 3};
const int yy[] = {0, 1, 2, 3, 1, 2, 3, 1, 2, 3};

void cal(int x, int y) {
    rep(i, 1, 9) {
        int f = 1, t = 0;
        rep(j, 1, 9) if(j != i) {
            int nx = x + xx[j]-xx[i], ny = y + yy[j]-yy[i];
            if(nx < 1 || nx > n || ny < 1 || ny > m) {
                f = 0;
                break;
            }
            if(st.count(mk(nx, ny))) t++;
        }
        if(f) cnt[t]--, cnt[t+1]++;
    }
}

int main() {
    FIO;
    cin >> n >> m >> q;
    cnt[0] = (n-2) * (m-2);
    rep(i, 1, q) cin >> a[i].fi >> a[i].se;
    sort(a+1, a+1+q);
    rep(i, 1, q) {
        cal(a[i].fi, a[i].se);
        st.insert(a[i]);
    }
    rep(i, 0, 9) cout << cnt[i] << '\n';

    return 0;
}

Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,d=0,i,a1,b1;
    scanf("%lld %lld",&a,&b);
   a1=min(a,b);
   b1=max(a,b);
    for(i=a1;i<=b1;i++)
    {
        if(abs(a1-i)==abs(b1-i))
         {
            d=1;
             break;
         }

    }
    if(d==1)
     printf("%lld\n",i);
    else
      printf("IMPOSSIBLE\n");
}



Measured memory_bytes: 256
def solve(n, A):
    def cycles():
        V = [False] * n
        B = sorted(A)
        T = {B[i]: i for i in range(n)}
        C = []

        for i in range(n):
            if V[i]:
                continue
            cur = i
            cycle = []
            while not V[cur]:
                V[cur] = True
                cycle.append(cur)
                cur = T[A[cur]]
            C.append(cycle)

        return C

    ans = 0
    s = min(A)

    for cycle in cycles():
        S = sum([A[i] for i in cycle])
        m = min([A[i] for i in cycle])
        an = len(cycle)
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s)

    return ans


def main():
    n = int(input())
    A = [int(x) for x in input().split()]

    print(solve(n, A))


main()



Measured memory_bytes: 5856
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.BitSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			k = scanner.nextInt();
			m = scanner.nextInt();
			r = scanner.nextInt();
			if ((n | k | m | r) == 0)
				break;
			if (m == 0)
				System.out.println(BigDecimal.ONE.divide(BigDecimal.valueOf(n),
						r, RoundingMode.DOWN));
			else {
				BitSet bs = new BitSet();
				BigInteger den = BigInteger.ONE;
				for (int i = 2; i <= n; i++) {
					if (!bs.get(i)) {
						long p = i;
						while (p <= n)
							p *= i;
						den = den.multiply(BigInteger.valueOf(p / i));
						for (int j = i; j <= n; j += i)
							bs.set(j);
					}

				}
				BigInteger num = den;
				for (int i = 1; i <= n - 1; i++) {
					num = num.add(den.divide(BigInteger.valueOf(i)));
				}
				System.out.println(new BigDecimal(num).divide(new BigDecimal(
						den.multiply(BigInteger.valueOf(n))), r,
						RoundingMode.DOWN));
			}
		}
	}

	int n, k, m, r;
}

Measured memory_bytes: 62644
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Text.Printf

main :: IO ()
main = mapM_ (print . process . read) . lines =<< getContents
  where
    process n = length [(a,b,c,d)|a<-[0..9],b<-[0..9],c<-[0..9],d<-[0..9], a+b+c+d==n]



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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n,m;cin>>n>>m;
    vvl c(n);
    rep(i,m){
        int a,b;cin>>a>>b;
        a--;b--;
        c[a].push_back(b);
        c[b].push_back(a);
    }
    rep(i,n)out(c[i].size());
}


Measured memory_bytes: 256