akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

typedef long long ll;

ll c[30],s[370][30];
int a[370],last[30];

unsigned seed=chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(seed);

ll f(int d)
{
    ll x=0;
    memset(last,-1,sizeof(last));
    for(int i=0;i<d;i++){
        x+=s[i][a[i]];
        last[a[i]]=i;
        for(int j=0;j<26;j++){
            x+=c[a[i]]*(i-last[a[i]]);
        }
    }
    return x;
}

int main()
{
    auto start=chrono::high_resolution_clock::now();
    ll x=0;
    int d,ans[370];
    scanf("%d",&d);
    for(int i=0;i<26;i++){
        scanf("%lld",&c[i]);
    }
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            scanf("%lld",&s[i][j]);
        }
    }
    while(true){
        for(int i=0;i<d;i++) a[i]=rng()%26;
        ll y=f(d);
        if(y>x) copy(a,a+d,ans),x=y;
        auto stop=chrono::high_resolution_clock::now();
        int duration=chrono::duration_cast<chrono::microseconds>(stop-start).count();
        if(2000000-duration>100000) break;
    }
    for(int i=0;i<d;i++){
        if(i) printf(" ");
        printf("%d",a[i]+1);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 3924
import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit
def prime_table(N):
    is_prime = np.zeros(N, np.int64)
    is_prime[2:3] = 1
    is_prime[3::2] = 1
    for p in range(3, N, 2):
        if p * p >= N:
            break
        if is_prime[p]:
            is_prime[p * p::p + p] = 0
    return is_prime, np.where(is_prime)[0]

@njit((i8[:], ), cache=True)
def main(MX):
    _, primes = prime_table(300)
    primes_small = primes[primes < 18]
    primes_large = primes[primes > 18]
    M, X = MX[::2], MX[1::2]
    nums = np.array([1], np.int64)
    for p in primes_small:
        tmp = [1]
        while p * tmp[-1] < 300:
            tmp.append(p * tmp[-1])
        nums = np.ravel(
            nums.reshape(-1, 1) * np.array(tmp, np.int64).reshape(1, -1))

    U = nums[-1]

    ret = 0
    for n in nums:
        base = 0
        extra = np.zeros(300, np.int64)
        for i in range(len(M)):
            m, x = M[i], X[i]
            a = np.gcd(m, U)
            b = m // a
            if n % a != 0:
                continue
            if b == 1:
                base += x
            else:
                extra[b] += x
        score = base + np.sum(np.maximum(extra, 0))
        ret = max(ret, score)
    return ret

MX = np.array(read().split(), np.int64)[1:]

print(main(MX))

Measured memory_bytes: 107676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define DBG(v) cerr << #v << " = " << (v) << endl;

int ans[509][509];

void f(const int l, const int r, const int num) {
	if (l == r)
		return;
	const int mid = (l + r) / 2;
	for (int i = l; i <= mid; ++i)
		for (int j = mid + 1; j <= r; ++j)
			ans[i][j] = ans[j][i] = num;
	f(l, mid, num + 1);
	f(mid + 1, r, num + 1);
}

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

	int n;
	cin >> n;
	f(0, n - 1, 1);
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j)
			cout << ans[i][j] << ' ';
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

const int MAX_N = 200005;

//[1, n]
int bit[MAX_N + 1] = {0};

int sum(int i){
	int s = 0;
	while(i > 0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(int i, int x){
	while(i <= MAX_N){
		bit[i] += x;
		//bit[i] = max(bit[i], x);
		i += i & - i;
	}
}

bool impossible(vector<vector<int>> v){
	int odd = 0;
	rep(i,26){
		if(v[i].size() % 2) odd++;
	}
	return odd >= 2;
}

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

	vector<vector<int>> v(26);
	rep(i,s.size()){
		v[s[i] - 'a'].emplace_back(i);
	}
	if(impossible(v)){
		cout << -1 << endl;
		return 0;
	}

	pair<int, int> p[26];
	rep(i,26) p[i] = make_pair(0, v[i].size() - 1); //front, back

	int len = s.size() - 1;
	long long ans = 0;
	rep(i,s.size() / 2){
		int t;
		int minCost = INF;
		rep(j,26){
			if(v[j].size() <= 1) continue;

			int front, back;
			tie(front, back) = p[j];
			if(front >= back) continue;

			int front_p = v[j][front];
			int back_p = v[j][back];

			int left = front_p - sum(front_p + 1);
			int right = back_p - sum(back_p + 1);
			//show(j)
			//cout << v[j][u.first] << ' ' << v[j][u.second] << endl;
			//cout << left << ' ' << right << endl;

			int cost = left + (len - right);
			if(minCost > cost){
				minCost = cost;
				t = j;
			}
		}
		//cout << static_cast<char>(t+'a') << endl;
		//show(minCost)

		ans += minCost;
		add(v[t][p[t].first] + 1, 1);
		add(v[t][p[t].second] + 1, 1);
		p[t].first++;
		p[t].second--;
		len-=2;
	}

	cout << ans << endl;
}


Measured memory_bytes: 2808
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

// g を最大公約数に持つような数列 a が作れるか？
bool check(ll n, ll m, ll g) {
  m -= g * n;
  return m >= 0 && m % g == 0;
}

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

  ll n, m;
  cin >> n >> m;

  if (n == 1) {
    cout << m << endl;
    return 0;
  }

  ll ans = 0;

  for (ll i = 1; i * i <= m; i++) {
    if (m % i != 0) continue;
    if (check(n, m, i)) chmax(ans, i);
    if (check(n, m, m / i)) chmax(ans, m / i);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3648
n=int(input())
mass=[input()]
mass.append(input())
MOD=10**9+7
if mass[0][0]==mass[1][0]:
    ans=3
    x=0
    y=1
    yoko=False
else:
    ans=6
    x=0
    y=2
    yoko=True
while y<n:
    if x==0:
        if mass[x][y]==mass[x+1][y]:#縦
            if yoko:
                y+=1
            else:
                ans*=2
                y+=1
            yoko=False
        else:#横
            if yoko:
                ans*=3
            else:
                ans*=2
            yoko=True
            y+=2
print(ans%MOD)


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

int main() {
	int n;
	cin >> n;
	vector<ll>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	sort(a.begin(), a.end());
	if (a.at(0)==0) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	for (int i = 0; i < n; i++) {
		ll lim = 1000000000000000000 / ans;
		if (lim < a.at(i)) {
			cout << -1 << endl;
			return 0;
		}
		ans *= a.at(i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4048
import java.util.*;
import java.io.*;
public class Main {
	public static void main(String args[]) {
		FastScanner in = new FastScanner();
		int x=in.nextInt();
		System.out.println(1-x);
	}

	///////////////////////////
	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

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

		int[] nextArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

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


Measured memory_bytes: 32648
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using ll = long long;
#define AC ios::sync_with_stdio(0),cin.tie(0);

int main()
{
    AC
    int n;
    double r=0;
    cin>>n;
    vector<double> v(n+1);
    for(int i=1;i<=n;i++) cin>>v[i];
    vector<vector<double>> dp(n+1,vector<double>(n+1));
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=i;j++)
        {
            int x=j,y=i-j;
            if(x) dp[x][y]+=dp[x-1][y]*v[i];
            if(y) dp[x][y]+=dp[x][y-1]*(1-v[i]);
        }
    }
    for(int i=n;i>n-i;i--) r+=dp[i][n-i];
    cout<<fixed<<setprecision(10)<<r<<'\n';
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const ll mod=998244353;

int main()
{
    double n,x;
    int t;
    cin>>n>>x>>t;
    cout<<(int)ceil(n/x)*t;
    return 0;
}


Measured memory_bytes: 3736
n = list(input())
if n[-1] =="2":
    print("hon")
elif n[-1] =="4":
    print("hon") 
elif n[-1] =="5":
    print("hon") 
elif n[-1] =="7":
    print("hon") 
elif n[-1] =="9":
    print("hon") 
elif n[-1] == "0":
    print("pon")
elif n[-1] == "1":
    print("pon")
elif n[-1] == "6":
    print("pon")
elif n[-1] == "8":
    print("pon")
elif n[-1] == "3":
    print("bon")

Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(void) {
    ll A,B;
    cin>>A>>B;
    if(A==B) cout<<0<<endl;
    if((A+B)%2==0) cout<<(A+B)/2;
    else cout<<"IMPOSSIBLE"<<endl;
}

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

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int N, R;
    cin >> N >> R;

    int ans;
    if (N >= 10) {
        ans = R;
    } else {
        ans = R + 100 * (10 - N);
    }

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


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

int count_two(int n);
int check_min(int n);

int main(void){
    int n;
    cin >> n;
    cout << check_min(n) << endl;
    return 0;
}

int count_two(int n){
    if(n % 2 == 0)
        return count_two(n / 2) + 1;
    else
        return 0;
}

int check_min(int n){
    if(n == 0)
        return 10000;
    int a;
    cin >> a;
    return min(check_min(n - 1), count_two(a));
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007
//#define MOD 7

using namespace std;

int main(void){
    // Your code here!
    long long l, r, min_value = LLONG_MAX;
    
    cin >> l >> r;
    for(long long i = l; i < min(r, l + 2019); i++)
        for(long long j = l + 1; j < min(r+1, l + 2019); j++)
            min_value = min(min_value, (i * j) % 2019);
    
    cout << min_value << endl;    
    
    return 0;
}

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

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        PrintWriter printWriter = new PrintWriter(System.out);
        int k = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        for (int i = a; i < b + 1; i++){
            if (i % k == 0) {
                printWriter.println("OK");
                printWriter.flush();
                return;
            }
        }
        printWriter.println("NG");
        printWriter.flush();
    }
}


Measured memory_bytes: 35812
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
	int n, m;
	cin >> n >> m;
	vector<long long> inputs;
	REP(i, m) {
		long long a;
		cin >> a;
		inputs.push_back(a);
	}
	sort(inputs.begin(), inputs.end());
	reverse(inputs.begin(), inputs.end());
	if (m == 1) {
		if (n == 1) {
			cout << 1 << endl;
			cout << 1 << endl;
			cout << 1 << endl;
		}
		else {
			cout << inputs[0] << endl;
			cout << 2 << endl;
			cout << n - 1 << " " << 1 << endl;
		}
	}
	else{
		int ok = 0;
		REP(i, inputs.size()) {
			ok += inputs[i] % 2;
		}
		if (ok > 2) {
			cout << "Impossible" << endl;
		}
		else {
			int gogo[2] = { -1,-1 };
			for(int i = inputs.size()-1;i >= 0;--i){
				if (inputs[i] % 2 == 1) {
					if (gogo[0] == -1) {
						gogo[0] = i;
					}
					else {
						gogo[1] = i;
					}
				}
			}
			if (gogo[0] != -1) {
				swap(inputs[inputs.size()-1], inputs[gogo[0]]);
				if (gogo[1] != -1) {
					swap(inputs[0], inputs[gogo[1]]);
				}
			}
			REP(i, inputs.size()) {
				cout << inputs[i] << " ";
			}
			cout << endl;
			inputs[0]--;
			inputs[inputs.size() - 1]++;
			if (inputs[0] == 0) {
				inputs.erase(inputs.begin());
			}
			cout << inputs.size() << endl;
			REP(i, inputs.size()) {
				cout << inputs[i] << " ";
			}
			cout << endl;
		}
	}
}

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

ll knapsack2(int weight[], int value[], int n, int w){
    if(n == 0)
        return 0;
    // For each value, store the minimum total weight required
    // to get to that value
    // In the end, check for which value (starting from maximum)
    // the minimum total weight required is less than or equal to 'w'

    int maxValue = 0;
    for(int i=0; i<n; i++)
        maxValue += value[i];

    vector<ll> dp(maxValue+1, INT_MAX);
    dp[0] = 0;
    for(int i=1; i<=n; i++)
        for(int j=maxValue; j>=0; j--)
            if(j-value[i-1] >= 0 and dp[j-value[i-1]]!=INT_MAX)
                dp[j] = min(dp[j], dp[j-value[i-1]]+weight[i-1]);

    for(int j=maxValue; j>=0; j--)
        if(dp[j] <= w)
            return j;
    return 0;
}

int main()
{
 int n, w;
 cin>>n>>w;
 int weight[n], value[n];
 for(int i=0; i<n; i++)
    cin>>weight[i]>>value[i];
 ll ans = knapsack2(weight, value, n, w);
 cout<<ans;
 return 0;
}


Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace io{
	const int l=1<<20;
	char buf[l],*s,*t;
	inline char gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			return s==t?EOF:*s++;
		}
		return *s++;
	}
	char c;
	template<class IT>inline void gi(IT &x){
		x=0;c=gc();while(c<'0'||c>'9')c=gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^'0');c=gc();}
	}
};
using io::gi;
struct qwq{
	int a,b;
	inline bool operator<(const qwq &x)const{
		return a<x.a;
	}
};
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
const ll p=1000000007ll,inf=1000000000000000000ll;
const int N=1005;
int v[N][N],a[N][N],c[N],l[N],s1[N],s2[N];
int main(){
	int n,i,j,x,y,tim=0,t1=0,t2;
	scanf("%d",&n);
	for(i=1;i<=n;++i)c[i]=1;
	for(i=1;i<=n;++i)for(j=1;j<n;++j)scanf("%d",&a[i][j]);
	for(i=1;i<=n;++i)l[i]=a[i][1];
	for(i=2;i<=n;++i)if(l[i]<i&&l[l[i]]==i)s1[++t1]=i;
//	printf("Init ok\n");
//	for(i=1;i<=t1;++i)printf("s1 %d\n",s1[i]);
	while(t1){
		++tim;t2=0;
//		printf("tim=%d\n",tim);
		for(;t1;--t1){
			x=s1[t1];y=l[x];
			v[x][y]=v[y][x]=1;
			l[x]=a[x][++c[x]];
			l[y]=a[y][++c[y]];
//			printf("l[%d]=%d l[%d]=%d\n",x,l[x],y,l[y]);
			if(l[l[x]]==x)s2[++t2]=x;
			if(l[l[y]]==y)s2[++t2]=y;
		}
		t1=t2;
		for(i=1;i<=t2;++i)s1[i]=s2[i];
//		for(i=1;i<=t1;++i)printf("s1 %d\n",s1[i]);
	}
	for(i=2;i<=n;++i)for(j=1;j<i;++j)if(!v[i][j]){printf("-1");return 0;}
	printf("%d",tim);
	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
vector<long long>a;
vector<vector<long long>>dp;
long long sa(long long b,long long e)
{
  if(dp[b][e]!=-1)return dp[b][e];
  if(b==e)return a[b];
  if(e-b==1)
  {
    return abs(a[e]-a[b]);
  }
  long long tmp1,tmp2;
  tmp1=min(a[b]-a[b+1]+sa(b+2,e),a[b]-a[e]+sa(b+1,e-1));
  tmp2=min(a[e]-a[b]+sa(b+1,e-1),a[e]-a[e-1]+sa(b,e-2));
  dp[b][e]=max(tmp1,tmp2);
  return dp[b][e];
}
int main()
{
  ios::sync_with_stdio(false);
  long long n;
  cin>>n;
  a=vector<long long>(n);
  dp=vector<vector<long long>>(n,vector<long long>(n,-1));
  for(long long i=0;i<n;i++)
  {
    cin>>a[i];
  }
  cout<<sa(0,n-1)<<endl;
  return 0;

}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
typedef long long LL;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    //freopen("input.txt", "r", stdin);
  #endif // LOCAL
  string a, b;
  cin >> a >> b;
  int x, y;
  cin >> x >> y;
  string s;
  cin >> s;
  if (s == a) x--;
  else y--;
  cout << x << " " << y << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
 
using namespace std;
 
int main(){
    double R;
    cin >> R;

    cout << 2*R*3.1415 << endl;
    
    return 0;
}

Measured memory_bytes: 3788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long K = sc.nextLong();
		if (s.length()==1) {
			System.out.println(K/2);
			return ;
		}
		long count =0;
		boolean b = true;
		for (int i=1;i<s.length();i++) {
			if (s.charAt(i-1)!=s.charAt(i)) {
				b =false;
				break;
			}
		}
		if (b==true) {
			System.out.println(s.length()*K/2);
			return ;
		}
		 b = true;
		for (int i=1;i<s.length();i++) {
			if (s.charAt(i-1)==s.charAt(i)) {
				count ++;
				if (i==s.length()-1) {
					b = false;
				}
				i++;
			}
		}
		for (int i=1;i<s.length();i++) {
			if (s.charAt(i-1)!=s.charAt(i)) {
				if (i%2==0) {
					b =false;
				}
				break;
			}
		}
		if (b==true&&s.charAt(s.length()-1)==s.charAt(0)) {
			System.out.println(count *K+K-1);
		} else {
			System.out.println(count *K);
		}
	}
}


Measured memory_bytes: 35836
#include<iostream>
#include<algorithm>
#include<string>
#include <vector>

using namespace std;

int main(){

	int n,min,max;
	char in[8];

	cin>>n;

	for(int i=0;i<n;i++){
		cin>>in;
		sort(in,in+8);
		min=atoi(in);
		sort(in,in+8,greater<int>());
		max=atoi(in);
		cout<<max-min<<endl;
	}
}

Measured memory_bytes: 3116
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int nn = n;
    int fx = 0;
    while(n>0){
      fx += n - (n/10)*10;
      n = n / 10;
    }
    if(nn % fx == 0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23124
a=gets.chomp.to_s
d = a.chars.last.to_i

b = [2,4,5,7,9]
c = [0,1,6,8]
res = ''
if b.include?(d)
  res = 'hon'
elsif c.include?(d)
  res = 'pon'
else
  res = 'bon'
end

puts res

Measured memory_bytes: 14396
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_N = 1;

int main() {
  int n, m, ans = 0; cin >> n >> m;
  vi cnt(m+1, 0);
  for (int i = 0; i < n; i++) {
    int k; cin >> k;
    for (int j = 0; j < k; j++) {
      int a; cin >> a;
      cnt[a]++;
    }
  }
  for (int i = 0; i <= m; i++) {
    if (cnt[i] == n) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
lst=[]
for i in range(5):
  a=int(input())
  b=10-a%10
  if b==10:
    b=0
  lst.append((b,a))
lst.sort()

ans=0
for i in range(4):
  c=lst[i][1]
  d=lst[i][0]
  ans+=c+d
ans+=lst[4][1]
print(ans)

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

int main( ) {
	string s ; 
	cin >> s ; 
	if(s[0] == s[1] && s[1] == s[2] ) cout << s ; 
	else {
		char l[4] = { s[0] , s[0] , s[0] , 0 } ; 
		string k( l );
		if( s < k ) cout << k ;
		else cout << (char)(s[0]+1) << (char)(s[0]+1) << (char)(s[0]+1) ;    
	}
}

Measured memory_bytes: 256
h, w = map(int, input().split())

pic = [[0 for i in range(w)] for j in range(h)]
pic2 = [[0 for i in range(w)] for j in range(2 * h)]

for i in range(h):
    pic[i] = input()
   # print(pic[i])
   # c = [c for c in pic[i]]
   # print(c)

#print(pic[0][0])
#print(pic[0][1])

for i in range(2 * h):
    for j in range(w):
        pic2[i][j] = pic[i //2][j]
    #print(pic2[i])

for i in range(2 * h):
    print(''.join(pic2[i]))


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

int main() {
  string s;
  cin >> s;
  int count = 1;
  vector<int> continuance;
  for (int i = 1; i < s.size(); ++i) {
    if (s.at(i - 1) == s.at(i)) {
      count++;
    } else {
      continuance.push_back(count);
      count = 1;
    }
  }
  continuance.push_back(count);
  vector<int> ans(s.length());
  int i = 0, idx = -1;
  for (int& c : continuance) {
    if (i % 2 == 0) {
      idx += c;
      ans.at(idx + 1) += c / 2;
      ans.at(idx) += (c / 2) + (c % 2);
    } else {
      ans.at(idx) += c / 2;
      ans.at(idx + 1) += (c / 2) + (c % 2);
      idx += c;
    }
    ++i;
  }
  for (int& a : ans) cout << a << endl;
  return 0;
}




Measured memory_bytes: 1528
x,y=map(int,input().split())
A=[1,3,5,7,8,10,12]
B=[4,6,9,11]
C=[2]
if x in A:
    if y in A:
        print("Yes")
    else:
        print("No")
elif x in B:
    if y in B:
        print("Yes")
    else:
        print("No")
else:
    print("No")
          
          
        

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
using namespace std;
int arr[32] = {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};
int main() {
	int K;
	scanf("%d", &K);
	printf("%d", arr[K - 1]);
	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      for(int i=0; i!=n; i++)
        seq[i] = Integer.parseInt(br.readLine());

      System.out.println( shellSort(seq, n) );

      StringBuilder str = new StringBuilder(n*5);
      for (int i : seq)
        str.append(i).append("\n");

      str.setLength(str.length()-1);
      System.out.println(str);
    }
  }

  public static int shellSort(int a[], int n) {
    int cnt=0;
    int m = 0;
    int[] aG = new int[100];
    for (int g=1,max=n+1; g < max; g=(g*3+1)) {
      aG[m++] = g;
    }
    StringBuilder str = new StringBuilder(m*5);
    str.append(m).append("\n");

    for(int i=(m-1); i!=-1; i--){
      cnt += insertionSort(a, n,aG[i]);
      str.append(aG[i]).append(" ");
    }

    str.setLength(str.length()-1);
    System.out.println(str);

    return cnt;
  }
  
  public static int insertionSort(int a[], final int max, final int g) {
    int cnt=0;

    for (int i=g,j=0,v=0; i < max; i++) {
      for( j=(i-g), v=a[i]; j>=0 && a[j]>v; j-=g ) {
        a[j+g] = a[j];
        cnt++;
      }
      a[j+g] = v;
    }

    return cnt;
  }
}


Measured memory_bytes: 87392
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
a,b = [list(i) for i in zip(*l)]
l = [list(map(int,input().split())) for i in range(m)]
c,d = [list(i) for i in zip(*l)]

for i in range(n):
    p = 10 ** 9
    t = 50
    for j in range(m):
        e = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if p > e:
            p = e
            t = j + 1
    print(t)

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

int main(){
    int N, a[100101] = {};
    cin >> N;
    for(int i = 0; i < N; ++i){
        int in;
        cin >> in;
        a[in]++;
    }
    int ret = 0;
    for(int i = 0; i < 100000 - 2; ++i){
        ret = max(ret, a[i]+a[i+1]+a[i+2]);
    }
    cout << ret << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

struct DICE {
	int num[7];
};

void throwdice(char, struct DICE *);
int rot(int, int, struct DICE *);
int issame(struct DICE *, struct DICE *);

int main(void)
{
	struct DICE dice1, dice2;
	int i;
	
	for(i=1; i<=6; i++) {
		scanf("%d",&dice1.num[i]);
	}
	for(i=1; i<=6; i++) {
		scanf("%d",&dice2.num[i]);
	}
	if( issame(&dice1, &dice2) ) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

void throwdice(char ch, struct DICE *dice)
{
	int temp;
	switch (ch) {
	case 'N':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[5] ;
		dice->num[5] = dice->num[1] ;
		dice->num[1] = dice->num[2] ;
		dice->num[2] = temp;
		break;
	case 'S':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[2] ;
		dice->num[2] = dice->num[1] ;
		dice->num[1] = dice->num[5] ;
		dice->num[5] = temp;
		break;
	case 'E':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[3] ;
		dice->num[3] = dice->num[1] ;
		dice->num[1] = dice->num[4] ;
		dice->num[4] = temp;
		break;
	case 'W':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[4] ;
		dice->num[4] = dice->num[1] ;
		dice->num[1] = dice->num[3] ;
		dice->num[3] = temp;
		break;
	}
}

int rot(int top, int front, struct DICE *dice)
{
	int cnt;
	cnt = 0;
	while (dice->num[2] != front) {
		if (dice->num[3] == front || dice->num[4] == front) {
			throwdice('E', dice);
		}
		throwdice('N', dice);
		cnt++;
		if(cnt == 4) {
			return -1;
		}
	}
	cnt = 0;
	while (dice->num[1] != top) {
		throwdice('E', dice);
		cnt++;
		if(cnt == 4) {
			return -1;
		}
	}
	return 0;
}

int issame(struct DICE *dice1, struct DICE *dice2)
{
	int i, flag = 1;
	if( rot(dice2->num[1], dice2->num[2], dice1) == -1 ) {
		return 0;
	}
	for (i=3; i<=6; i++) {
		if(dice1->num[i] != dice2->num[i]) {
			flag = 0;
		}
	}
	return flag;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int main(void){
  
  int N, X;  cin >> N >> X;
  int min_cost = 1000000;
  vector<int> m(N);
  for(int i = 0 ; i < N ; i++){
    cin >> m[i];
    min_cost = min(min_cost, m[i]);
    X -= m[i];
  }
  
  int ans = N;
  ans += X / min_cost;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> da >> db;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------
  
  cout << ceil((da+db)/2) << endl;

}

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

using namespace std;

const long long INF = 1LL<<60;
const int MAX_N = 110;
const int MAX_V = 100100;
long long dp[MAX_N][MAX_V];

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

    vector<long long> w(N);
    vector<long long> v(N);

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

    // 初期化
    for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;
    // 初期条件
    dp[0][0] = 0;

    //j means sum_v
    for(int i=0; i<N; ++i){
        for(int j=0; j<MAX_V; ++j){
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            if(j - v[i] >=0){
                dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]]+w[i]);
            }else{
                dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            }
        }
    }

    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if (dp[N][sum_v] <= M) res = sum_v;
    }
    cout << res << endl;
}

Measured memory_bytes: 86400
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define maxm 
#define mod 
#define maxn 

int main()
{
	int a, b, c, d;
	
	scanf("%d%d%d%d", &a, &b, &c, &d);
	int x = max(a, c), y = min(b, d);
	if (x > y) {
		puts("0");
	} else {
		printf("%d\n", y - x);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
int main() 
{ 
   
   
   ll n,sum=0;
   cin>>n;
   ll arr[n];
   for(int i=0;i<n;i++) {
       cin>>arr[i];
       sum^=arr[i];
   }
   for(int i=0;i<n;i++) {
       ll z=sum^arr[i];
       cout<<z<<" ";
   }
	return 0; 
} 


Measured memory_bytes: 5156
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    rep(i,n){
        if(s[i]=='?')s[i] = 'D';
    }
    cout << s << endl;
    return 0;
}

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

template <class I> I chmin(I &x, I y) { return x > y ? x = y : x; }

const int MaxN(500003);
const int INF(0x3f3f3f3f);
int p[MaxN], q[MaxN], d[MaxN];
vector<int> G[MaxN];

#define lc rt << 1
#define rc rt << 1 | 1

int Seg[MaxN << 2];

void Build(int rt, int l, int r)
{
	Seg[rt] = INF;
	if(l == r) return;
	int mid = (l + r) >> 1;
	Build(lc, l, mid);
	Build(rc, mid + 1, r);
}

void Modify(int rt, int l, int r, int pos, int v)
{
	chmin(Seg[rt], v);
	if(l == r) return;
	int mid = (l + r) >> 1;
	if(pos <= mid) Modify(lc, l, mid, pos, v);
	else Modify(rc, mid + 1, r, pos, v);
}

int Query(int rt, int l, int r, int ql, int qr)
{
	if(ql <= l && r <= qr)
		return Seg[rt];
	int mid = (l + r) >> 1;
	int res = INF;
	if(ql <= mid) chmin(res, Query(lc, l, mid, ql, qr));
	if(qr > mid) chmin(res, Query(rc, mid + 1, r, ql, qr));
	return res;
}

#undef lc
#undef rc

int main()
{
	int n, K;
	scanf("%d%d", &n, &K);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &p[i]);
		q[p[i]] = i;
	}
	Build(1, 1, n);
	for(int i = n, x; i; i--)
	{
		x = Query(1, 1, n, max(q[i] - K + 1, 1), q[i]);
		if(x != INF) G[q[i]].push_back(q[x]), ++d[q[x]];
		x = Query(1, 1, n, q[i], min(q[i] + K - 1, n));
		if(x != INF) G[q[i]].push_back(q[x]), ++d[q[x]];
		Modify(1, 1, n, q[i], i);
	}
	set<int> Q;
	for(int i = 1; i <= n; i++)
		if(!d[i]) Q.insert(i);
	for(int i = 1; i <= n; i++)
	{
		int u = q[i] = *Q.begin();
		Q.erase(Q.begin());
		for(auto v : G[u])
			if(!--d[v]) Q.insert(v);
	}
	for(int i = 1; i <= n; i++)
		p[q[i]] = i;
	for(int i = 1; i <= n; i++)
		printf("%d\n", p[i]);
	return 0;
}


Measured memory_bytes: 52352
while true
  n, x = gets.split.map(&:to_i)
  break if n.zero? && x.zero?

  count = 0
  i = 1
  i.upto(n).each do |i|
    (i+1).upto(n).each do |j|
      (j+1).upto(n).each do |k|
        count += 1 if i + j + k == x
      end
    end
  end
  puts count
end



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

int main() {
  int A, B;
  cin >> A >> B;
  
  int cnt = 0;
  for ( ; A <= B; A++) {
    int a, b, c, d;
    a = A / 10000;
    b = (A - a * 10000) / 1000;
    c = A / 10 % 10;
    d = A % 10;
    
    if (a == d && b == c) cnt++;
  }
  
  cout << cnt << endl;
}

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

int dp[5010][2];

int n, k;
int a[5001];
bool isnec(int x) {
    for (int i = 0; i <= k; i++)
        dp[i][0] = dp[i][1] = 0;

    int z = 0;

    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        if (i == x) continue;
        for (int j = 0; j <= k; j++) {
            dp[j][1-z] = dp[j][z] || (j >= a[i] && dp[j-a[i]][z]);
        }

        z = 1-z;
    }

    for (int j = max(k - a[x], 0); j < k; j++) {
        if (dp[j][z]) return true;
    }

    return false;
}


int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];

    sort(a, a+n);

    int p = 0;
    int q = n;

    while (q-p > 0) {
        int s = (p+q)/2;
        if (!isnec(s)) {
            p = s+1;
        } else {
            q = s;
        }
    }

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

Measured memory_bytes: 256
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
string s;
int main()
{
	cin>>s;
	int i;
	for(i=0;i<s.size();i++)
	{
		if(i+1<s.size()&&s[i]==s[i+1])
		{
			cout<<i+1<<" "<<i+2<<endl;
			break;
		}
		else
		{
			if(i+2<s.size()&&s[i]==s[i+2])
			{
				cout<<i+1<<" "<<i+3<<endl;
				break;
			}
		}
	}
	if(i==s.size())cout<<"-1 -1"<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;
using ll = long long;

// int main(){
//     int L;
//     cin >> L;
//     double l = L/3.l;
//     printf("%.12f\n.",pow(l,3));
//     return 0;
// }

int main() {
    int L;
    cin >> L;
 
    double d = L / 3.l;
    // double ans = );
 
    printf("%.12f\n", pow(d,3));
 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int n, m, t[100] = {}, p[100] = {}, x[100] = {};

    scanf("%i", &n);

    for (int i = 0; i < n; ++i) {
        scanf("%i", &t[i]);
    }

    scanf("%i", &m);

    for (int i = 0; i < m; ++i) {
        scanf("%i %i", &p[i], &x[i]);
    }

    for (int i = 0; i < m; ++i) {
        int sum = 0;
        for (int j = 0; j < n; ++j) {
            if((p[i] - 1) == j){
                sum += x[i];
            }else{
                sum += t[j];
            }
        }
        printf("%i\n", sum);
    }

    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys
from itertools import accumulate


def main():
    # 入力処理
    N = int(input())
    As = sorted([int(x) for x in input().split()])
    print(As, file=sys.stderr)

    # アルゴリズム本体
    Bs = list(accumulate(As))
    print(Bs, file=sys.stderr)

    M = 0
    Rs = [A / B for A, B in zip(As[1:N], Bs[0:N-1])]
    for i, R in enumerate(Rs):
        if R > 2:
            M = i + 1

    # 出力
    print(N - M, file=sys.stderr)
    print(N - M)


if __name__ == '__main__':
    main()


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

string s;
ll K;
ll dp[101][2][5]; // i桁目まで確定していて、現時点でs以下であるかがjという状態で、0でない数字がk個ある数の個数

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>s>>K;
  ll n=s.size();
  
  dp[0][0][0]=1;
  rep(i,n) rep(j,2) rep(k,K+1){
    ll num=s[i]-'0';
    rep(nxt,10){
      if(num<nxt && j==0) continue; // s未満であることが未確定で、現在見ている桁より大きい値を採用することはできない
      
      ll nj=j;
      if(nxt<num) nj=1; // 今見ている桁より小さい値を採用するなら、以降はs未満であることが確定する
      ll nk=k;
      if(nxt!=0) nk++;
      dp[i+1][nj][nk]+=dp[i][j][k];
    }
  }
  ll ans=dp[n][0][K]+dp[n][1][K];
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<algorithm>//everybody dies in their nightmares
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<string>
#include<vector>
#include<sstream>
#include<cmath>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;

const int N = 6e5 + 5;
int t;
const double p = 3.1415926;

int main()
{
	int n, k;
	while (cin >> n >> k)
	{
		ll ans = 0;
		f(i, k, n + 1)
		{
			ll a = 0, b = i - 1, c = n - i + 1, d = n;
			ll x = (a + b)*i / 2, y = (c + d)*i / 2;
			ans = (ans + y - x + 1)%mod;
		}
		cout << ans << endl;
		
	}
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];

int prim()
{
    int u,minv;
    int d[MAX],p[MAX],color[MAX];

    rep(i,n)
    {
        d[i]=INFTY;
        p[i]=-1;
        color[i]=WHITE;
    }

    d[0]=0;

    while (true)
    {
        minv=INFTY;
        u=-1;
        rep(i,n)
        {
           if (minv>d[i] && color[i]!=BLACK)
           {
               minv=d[i];
               u=i;
           }
        }

        if(u==-1)break;
        color[u]=BLACK;
        rep(v,n)
        {
            if(color[v]!=BLACK && M[u][v]!=INFTY)
            {
                if (d[v]>M[u][v])
                {
                    d[v]=M[u][v];
                    p[v]=u;
                    color[v]=GRAY;
                }
            }
        }
    }
    int sum=0;
    rep(i,n)
    {
        if(p[i]!=-1)sum+=M[i][p[i]];
    }
    return sum;
}

int main()
{
    cin>>n;
    rep(i,n)
    {
        rep(j,n)
        {
            int e;
            cin>>e;
            M[i][j]=(e==-1) ? INFTY:e;
        }
    }

    cout<<prim()<<endl;

    return 0;
}



Measured memory_bytes: 3116
import itertools
import functools
L = "ATGC"
MOD = 10 ** 9 + 7
@functools.lru_cache(maxsize = None)
def rec(s, k):
    if s.count("AGC"):
        return 0
    for i in range(3):
        t = list(s)
        t[i], t[i + 1] = t[i + 1], t[i]
        if ''.join(t).count("AGC"):
            return 0
    if k == 0:
        return 1
    ret = 0
    for x in L:
        ret = (ret + rec(x + s[:3], k - 1)) % MOD
    return ret

N = int(input())
if N == 3:
    print(61)
else:
    ret = 0
    for s in itertools.product(L, repeat = 4):
        ret = (ret + rec(''.join(s), N - 4)) % MOD
    print(ret)


Measured memory_bytes: 54108
package main

import "fmt"

func main() {
	var x1, y1, x2, y2 int
	fmt.Scan(&x1, &y1, &x2, &y2)

	a := x2 - x1
	b := y2 - y1

	x3 := x2 - b
	y3 := y2 + a
	x4 := x1 - b
	y4 := y1 + a

	fmt.Println(x3, y3, x4, y4)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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


int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll H, W, K;
  cin >> H >> W >> K;

  vector<string> c(H);
  REP(i, H)
    cin >> c[i];

  ll ans(0);
  REP(I, 1<<H) {
    REP(J, 1<<W) {
      ll count(0);
      REP(i, H) {
	if (!(I & (1<<i)))
	  continue;
	REP(j, W) {
	  if ((J & (1<<j)) && c[i][j] == '#')
	    count ++;
	}
      }
      if (count == K)
	ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), k = sc.nextInt();
		sc.close();
		for(int i = 0; i < k && i <= b - a; ++i)
			System.out.println(i + a);
		int s = k - 1;
		if(a + k >= b - k + 2)s = b - a - k;
		if(k > b - a + 1)s = -1;
		for(int i = s; i >= 0; --i)
			System.out.println(b - i);
	}

}


Measured memory_bytes: 21076
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    a, b, c, k = nm()

    if k <= a + b:
        ans = min(a, k)
    else:
        ans = a - (k - (a + b))
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9732
#include<iostream>
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(x>a){
    if(x>b){
      if(x-a>x-b){
	cout<<"B"<<endl;
      }
      else{
	cout<<"A"<<endl;
      }
    }
    else{
      if(x-a>b-x){
	cout<<"B"<<endl;
      }
      else{
	cout<<"A"<<endl;
      }
    }
  }
  else{
    if(x>b){
      if(a-x>x-b){
	cout<<"B"<<endl;
      }
      else{
	cout<<"A"<<endl;
      }
    }
    else{
      if(a-x>b-x){
	cout<<"B"<<endl;
      }
      else{
	cout<<"A"<<endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
//NAME-DEEPESH BHATT
//Institute-IIT Dhanbad
//MOTTO-THINK FIRST,CODE LATER
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007  ;
#define pb push_back
#define mp make_pair
#define endl '\n'
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
ll power(ll a,ll n)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p);
    if (n % 2)
        return (p * a);
    else
        return p;
}
int main()
{
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(NULL);
    ll test=1;
    /*cin>>test;*/
    while(test--) {
        string s1,s2;
        cin>>s1>>s2;
        int m=s1.length();
        int n=s2.length();
        int **dp=new int*[m+1];
        for(int i=0;i<=m;i++){
            dp[i]=new int[n+1];
        }
        //DP table stores lcs from s1[m-i] to s1[m] and s2[n-j] to s2[n]...if s1[m-i]=s2[n-j] it means we have
        // to include the elements so just add 1 to dp[i-1][j-1]...else take the max of
        //dp[i-1][j] ans dp[i][j-1].
        for(int i=0;i<=m;i++){
            for(int j=0;j<=n;j++){
                dp[i][j]=0;
            }
        }
        string s="";
        //Now i need to print lcs string.
        for(int i=1;i<=m;i++){
            for(int j=1;j<=n;j++){
                if(s1[m-i]==s2[n-j]){
                    dp[i][j]=dp[i-1][j-1]+1;
                } else
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
        int i=m,j=n;
        while(i>0&&j>0){
            if(s1[m-i]==s2[n-j]){
                s.push_back(s1[m-i]);
                i--;
                j--;
            }
            else{
                if(dp[i-1][j]>dp[i][j-1]){
                    i--;
                }
                else{
                    j--;
                }
            }
        }
        cout<<s;
    }
    return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  string tenkey[10] = {".,!? ",
                     "abc",
                     "def",
                     "ghi",
                     "jkl",
                     "mno",
                     "pqrs",
                     "tuv",
                     "wxyz"};
  cin >> n;

  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;

    for (int j = 0; j < s.size(); j++) {
      int count = -1;
      int num = s[j] - '0';
      while (s[j] != '0') {
        count++;
        j++;
      }
      //cout << "num-1 = " << num-1 << endl;                                                                                                      
      //cout << "count = " << count << endl;                                                                                                      
      if (count >= 0) {
        //cout << "tenkey[num-1].size() = " << tenkey[num-1].size() << endl;                                                                      
        cout << tenkey[num-1][count % tenkey[num-1].size()];
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1208