akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll MODULO = 1e9 + 7;
const int MAXN = 3 * 100 * 1000;
ll fact[MAXN];
ll inv[MAXN];

ll Pow(ll x, ll n) {
  ll result = 1;
  while (n) {
    if (n % 2) result = result * x % MODULO;
    n /= 2;
    x = x * x % MODULO;
  }
  return result;
}

ll Inv(ll x) {
  return Pow(x, MODULO - 2);
}

ll C(ll n, ll k) {
  ll result = fact[n];
  result = result * inv[k] % MODULO;
  result = result * inv[n - k] % MODULO;
  return result;
}

int main()
{
  fact[0] = 1;
  for (ll i = 1; i < MAXN; ++i) fact[i] = fact[i - 1] * i % MODULO;
  for (int i = 0; i < MAXN; ++i) inv[i] = Inv(fact[i]);
  ll n, x, y;
  cin >> n >> x >> y;
  map<int, vll> m;
  for (int i = 0; i < n; ++i) {
    int c, w;
    cin >> c >> w;
    m[c].push_back(w);
  }
  vector<vll> v;
  for (auto x : m) {
    v.push_back(x.second);
    sort(v.back().begin(), v.back().end());
  }
  sort(v.begin(), v.end(), [](const vll& v1, const vll& v2) {
      return v1[0] < v2[0];
      });

  vi cnt;
  for (int t = 0; t < v.size(); ++t) {
    auto& cur = v[t];
    int i = -1;
    while (i + 1 < cur.size() && cur[i + 1] + cur[0] <= x) i++;
    while (i + 1 < cur.size() && cur[i + 1] + v[0][0] <= y && t != 0) i++;
    cnt.push_back(i + 1);
  }

  if (v.size() > 1) {
    int i = -1;
    while (i + 1 < v[0].size() && v[0][i + 1] + v[1][0] <= y) i++;
    cnt[0] = max(cnt[0], i + 1);
  }

  int i = 0;
  while (i + 1 < v.size() && v[i + 1][0] + v[0][0] <= y) i++;

  int sum = 0;
  ll result = 1;
  for (int j = 0; j <= i; ++j) {
    sum += cnt[j];
    result = result * C(sum, cnt[j]) % MODULO;
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 33644
#include <iostream>

int main()
{
	int n;
	std::cin >> n;

	int a[100] = { 0 };
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}

	for (int i = n - 1; i > 0; i--) {
		std::cout << a[i] << " ";
	}

	std::cout << a[0] << std::endl;
}

Measured memory_bytes: 1160
#include <iostream>

typedef long long ll;
using namespace std;

int main()
{
    ll x; cin >> x;
    ll ans;

    ans = x / 11 * 2;
    int rem = x % 11;
    if(rem > 0 && rem <= 6){
        ans++;
    }
    else if(rem > 6){
        ans += 2;
    }

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

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

using namespace std;
typedef long long LL;

const int MAXN = 2E5 + 5;

LL n, x, m;
LL sum[MAXN], a[MAXN], last[MAXN], st, ed;

int main() {
    //freopen("1.in", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> x >> m;
    a[1] = x, sum[1] = a[1];
    for (int i = 2; i <= n; i++) {
        a[i] = a[i - 1] * a[i - 1] % m;
        sum[i] = sum[i - 1] + a[i];
        if (a[i] == 0) {
            cout << sum[i - 1];
            return 0;
        }
        if (last[a[i]]) {
            st = last[a[i]];
            ed = i - 1;
            break;
        }
        last[a[i]] = i;
    }
    if (!ed)
        cout << sum[n];
    else {
        LL len = ed - st + 1;
        LL cyclesum = sum[ed] - sum[st - 1];
        LL ans = sum[st - 1];
        LL tot = n - st + 1;
        ans += tot / len * cyclesum;
        int rem = tot % len;
        ans += sum[st + rem - 1] - sum[st-1];
        cout << ans;
    }
    return 0;
}


Measured memory_bytes: 5140
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
	int a,b,c,n;
	cin >> a >> b >> c;
	cin >> n;
	while(n--){
		if(b<=a){
			b = b*2;
		}
		else{
			c = c*2;
		}
	}
	if(a<b&&b<c)
		printf("Yes");
	else
		printf("No");
}

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

int main(){
		int h;
		int w;
		
		while(1){
				cin>>h>>w;
						if(h==0 && w==0) break;
								for(int i=0 ; i<h ; i++){
										for(int j=0 ; j<w ; j++){
												cout<<'#';
										}		
										cout<<endl;
								}
								cout<<endl;
		}
		return 0;
}

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

int main()
{
    deque < char > d;
    string s,t;
    int flag;
    cin >> s >> t;
    for (int i=0;i<s.size();i++){
        d.push_back(s[i]);
    }
    for (int i=0;i<d.size();i++){
        d.push_front(d[s.size()-1]);
        d.pop_back();
        for (int j=0;j<t.size();j++){
            if (d[j]==t[j]){
                flag=1;
            }else{
                flag=0;
                break;
            }
        }
        if (flag==1){
            break;
        }
    }
    if (flag==1){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

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

int main(){
  vector<int> pp;
  int max = 55555;
  int prime[55556] = {};
  for(int i = 0; i <= max; i++) prime[i] = 1;
  prime[0] = prime[1] = 0;
  for(int i = 2; i * i <= max; i++){
    if(prime[i]){
      for(int j = i; i * j < max; j++){
        prime[i*j] = 0;
      }
    }
  }
  for(int i = 2; i <= 55555; i++){
    if(prime[i] && i % 5 == 1) pp.push_back(i);
  }
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cout << pp[i] << (i == n-1 ? "\n": " ");
  return 0;
}


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

int main(){
	int n,k,tmp,d[10]={0};
	cin>>n>>k;
	for(int i=0;i<k;i++){
		cin>>tmp;
		d[tmp]++;
	}
	while(1){
		string s=to_string(n);
		for(int i=0;i<s.size();i++){
			if(d[s[i]-'0'])break;
			if(i==s.size()-1){cout<<n<<endl;return 0;}
		}
		n++;
	}
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("io\\in.txt", "r", stdin);
    freopen("io\\out.txt", "w", stdout);
#endif

    string s;
    int k;
    cin >> s >> k;

    vi a{1};
    for (int i = 1; i < sz(s); i++) {
        if (s[i - 1] == s[i]) a.back()++;
        else a.pb(1);
    }

    if (sz(a) == 1) {
        cout << (ll)a[0] * k / 2;
        return 0;
    }

    ll cnt = 0;
    for (int i : a) cnt += i / 2ll * k;
    if (s[0] == s.back()) {
        for (int i : {a[0], a.back()}) cnt -= i / 2ll * (k - 1);
        cnt += (a[0] + a.back()) / 2ll * (k - 1);
    }
    cout << cnt;

    return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

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


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <istream>
using namespace std;

int main()
{
    int N, M, C;
    cin >> N >> M >> C;

    vector<int> B(M);
    vector<vector<int>> A(N, vector<int>(M));

    for (int i = 0; i < M; i++)
    {
        cin >> B[i];
    }

    int ans = 0;

    for (int i = 0; i < N; i++)
    {
        int sum = C;
        for (int j = 0; j < M; j++)
        {
            int Aij;
            cin >> Aij;
            sum += B[j] * Aij;
        }

        if (sum > 0)
        {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
// Aizu Vol-5 0582: Triangle Types
// 2017.8.30 bal4u@uu

#include <stdio.h>

int main()
{
	int a, b, c, t;
	int sa, sb, sc;

	sa = sb = sc = 0;
	while (1) {
		scanf("%d%d%d", &a, &b, &c);
		if (a + b <= c || b + c <= a || c + a <= b) break;
		if (c < a) t = c, c = a, a = t;
		if (c < b) t = c, c = b, b = t;
		t = a*a + b*b;
		if      (c*c == t) sa++;
		else if (c*c <  t) sb++;
		else               sc++;
	}
	printf("%d %d %d %d\n", sa+sb+sc, sa, sb, sc);
	return 0;
}

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

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

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

string s, t;
int sum[2][2][100005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s >> t;
    int n = s.length(), m = t.length();
    for(int i=0;i<n;i++){
        sum[0][0][i+1] = sum[0][0][i] + (s[i]=='A');
        sum[0][1][i+1] = sum[0][1][i] + (s[i]=='B');
    }
    for(int i=0;i<m;i++){
        sum[1][0][i+1] = sum[1][0][i] + (t[i]=='A');
        sum[1][1][i+1] = sum[1][1][i] + (t[i]=='B');   
    }
    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int A = (sum[0][0][b] - sum[0][0][a-1]) + 2*(sum[0][1][b] - sum[0][1][a-1]);
        int B = (sum[1][0][d] - sum[1][0][c-1]) + 2*(sum[1][1][d] - sum[1][1][c-1]);
        if(A%3 == B%3) printf("YES\n");
        else printf("NO\n");
    }
}

Measured memory_bytes: 5312
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

const int maxn = (int) 100 + 10;
int a[maxn];

int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  memset(a, 0, sizeof(a));
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    a[x] += 1;
  }
  return 1;
}

void solve() {
  //eprintf("n = %d\n", n);
  int k = n;
  while (!a[k]) {
    --k;
  }
  if (k == 1 && n > 2) {
    printf("Impossible\n");
    return;
  }
  int t = k;
  for (int i = 0; i <= k; ++i) {
    //eprintf("t = %d\n", t);
    if (!a[t]) {
      printf("Impossible\n");
      return;
    }
    --a[t];
    if (i & 1) {
      --t;
    }
  }
  if (k & 1) {
    ++t;
  }
  for (int i = 0; i <= t; ++i) {
    if (a[i] > 0) {
      //eprintf("last t = %d\n", t);
      printf("Impossible\n");
      return;
    }
  }
  printf("Possible\n");
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 384
A_list = []
for i in range(3):
    A = list(map(int, input().split()))
    A_list.append(A)
N = int(input())
for i in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A_list[i][j]==b:
                A_list[i][j]=0
ans = -1
for i in range(3):
    if A_list[i][0]==0 and A_list[i][1]==0 and A_list[i][2]==0:
        ans = 0
for i in range(3):
    if A_list[0][i]==0 and A_list[1][i]==0 and A_list[2][i]==0:
        ans = -2
if (A_list[0][0]==0 and A_list[1][1]==0 and A_list[2][2]==0) or (A_list[0][2]==0 and A_list[1][1]==0 and A_list[2][0]==0):
    ans = -3
print("No") if ans == -1 else print("Yes")

Measured memory_bytes: 3064
l = gets.to_i

ans = []

len = l.to_s(2).size
(len-1).times{|i|
  ans << [i+1, i+2, 0]
  ans << [i+1, i+2, 2**i]
}

s = l.to_s(2).reverse
cos = l
(len-1).times{|i|
  if s[i]==?1
    cos -= 2**i
    ans << [i+1, len, cos]
  end
}

puts [s.size, ans.size]*" "
ans.each{|x| puts x*" "}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int, int>;

int main() {
  long long W, a, b;
  cin >> W >> a >> b;
  if (((b+W)-a)*(b-(a+W))<=0) {
    cout << 0 << endl;
  }
  else {
    cout << min(abs(b-(a+W)), abs(b+W-a));
  }
}


Measured memory_bytes: 3576
N=int(input())
R=[int(input()) for i in range(N)]
S=[0 for i in range(N)]
S[0]=R[0]
for i in range(1,N):
    S[i]=min(S[i-1],R[i])
T=[R[i+1]-S[i] for i in range(N-1)]
print(max(T))



Measured memory_bytes: 23032
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
typedef long long ll;

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define MAX_INT 100000
#define MOD 1000000007
#define forf(i,a,b) for(int i=a;i<b;i++)


// vector<int> adj[1000002];
// int vis[1000002],dep[1000002],siz[1000002];


// void dfs(ll cur,ll par)
// {
//     vis[cur]=1;
//     siz[cur]=1;
//     for(auto x:adj[cur])
//     {
//         if(vis[x]!=1)
//         {
//             dep[x]=dep[cur]+1;
//             dfs(x,cur);
//             siz[cur]+=siz[x];
//         }    
//     }
// }


void solve()
{
    ll n;cin>>n;
    // ll m;cin>>m;
    // ll k;cin>>k;
    // string s="",s1="",s2="";
    // ll tmp=0,cnt=0,ans=0,tmp1=0,fg=0,fg1=0;
    // ll a[n];
    cout<<setprecision(12)<<float(n)*2*3.14159265358;
    
    
    
}
    
int main()
{
    IOS;
    
    // ll t;cin>>t;while(t--)
        solve();
 
    return 0;
}


Measured memory_bytes: 3768
import math
n = int(input())
coo = [list(map(int,input().split())) for i in range(n)]
sum = 0
for i in range(n):
    for j in range(i,n):
        sum += math.sqrt((coo[i][0]-coo[j][0])**2 + (coo[i][1]-coo[j][1])**2)

ans = 2 * sum / float(n)
print(ans)

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

int main(){
  int n;
  cin >> n;
  vector<int> x(n), l(n);
  rep(i,n) cin >> x[i] >> l[i];

  vector<P> s(n);
  rep(i,n) s[i] = P(x[i] + l[i], x[i] - l[i]);
  sort(s.begin(), s.end());
  int ans = 1;
  rep(i,n - 1){
    if(s[i].first > s[i+1].second){
      s[i+1] = s[i];
    }
    else ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 1e5+10, B = 16;

int val[N];
int dp[1 << B];

int solve(int bm) {
    if (!bm) return 0;
    if (dp[bm] != -1) return dp[bm];
    //dp[bm] = INF;
    int ans = INF;
    for (int i = 0; i < B; i++) {
        if (!(bm & (1 << i))) continue;
        for (int j = i+1; j < B; j++) {
            if (!(bm & (1 << j)) ) continue;
            int nbm = bm ^ (1 << i) ^ (1 << j) ^ (1 << (i ^ j));
            bool b = bm & (1 << (i ^ j));
            ans = min(ans, solve(nbm) + 1 + b);
        }
    }
    return dp[bm] = ans;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n-1; i++) {
        int x, y, a; cin >> x >> y >> a;
        val[x] ^= a;
        val[y] ^= a;
    }
    int ans = 0;
    int bm = 0;
    for (int i = 0; i < n; i++) {
        if (!val[i]) continue;
        if (bm & (1 << val[i])) ans++;
        bm ^= 1 << val[i];
    }
    memset(dp, -1, sizeof dp);
    cout << ans + solve(bm) << nl;
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

typedef struct
{
	int x, y;
} Point;

void rotate(int&x, int&y)
{
	swap(x, y);
	x = -x;
}

int main()
{
	int n;
	while (cin >> n) {
		if (n == 0)
			break;

		vector<vector<Point> > p;
		for (int i = 0; i < n+1; ++i) {
			int m;
			cin >> m;
			vector<Point> tmp(m);
			for (int j = 0; j < m; ++j)
				cin >> tmp[j].x >> tmp[j].y;
			p.push_back(tmp);
		}

		vector<Point> base1 = *p.begin();
		vector<Point> base2 = *p.begin();
		p.erase(p.begin());

		reverse(base2.begin(), base2.end());
		for (unsigned int i = 1; i < base1.size(); ++i) {
			base1[i].x -= base1[0].x;
			base1[i].y -= base1[0].y;
			base2[i].x -= base2[0].x;
			base2[i].y -= base2[0].y;
		}
		base1[0].x = base1[0].y = base2[0].x = base2[0].y = 0;

		vector<vector<Point> > p1(p);
		for (unsigned int i = 0; i < p1.size(); ++i) {
			for (unsigned int j = 1; j < p1[i].size(); ++j) {
				p1[i][j].x -= p1[i][0].x;
				p1[i][j].y -= p1[i][0].y;
			}
			p1[i][0].x = p1[i][0].y = 0;
		}

		vector<int> ans;
		for (unsigned int i = 0; i < p1.size(); ++i) {
			if (base1.size() != p1[i].size())
				continue;

			for (int r = 0; r < 4; ++r) {
				for (unsigned int j = 0; j < p1[i].size(); ++j)
					rotate(p1[i][j].x, p1[i][j].y);

				int match1 = 0, match2 = 0;
				for (unsigned int j = 0; j < base1.size(); ++j) {
					if (base1[j].x == p1[i][j].x && base1[j].y == p1[i][j].y)
						++match1;
					if (base2[j].x == p1[i][j].x && base2[j].y == p1[i][j].y)
						++match2;
				}
				if (match1 == base1.size() || match2 == base2.size()) {
						ans.push_back(i);
				}
			}
		}

		for (unsigned int i = 0; i < ans.size(); ++i)
			cout << ans[i]+1 << endl;
		cout << "+++++" << endl;

	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = Integer.parseInt(scanner.next());
        }

        for (int i = 1; i < size; i++) {
            System.out.println(concat(array));
            int value = array[i];
            int j = i - 1;
            while (j >= 0 && array[j] > value) {
                array[j + 1] = array[j];
                j--;
            }
            array[j + 1] = value;
        }
        System.out.println(concat(array));
    }

    private static String concat(int[] array) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int i = 0; i < array.length; i++) {
            joiner.add(String.valueOf(array[i]));
        }
        return joiner.toString();
    }
}

Measured memory_bytes: 29028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int main() {
  char C;
  cin >> C;
  char ans = (C - 'a') + 1 + 'a';
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

def main():
    #def cmb(n, r, mod):
    #    if ( r<0 or r>n ):
    #        return 0
    #    r = min(r, n-r)
    #    return g1[n] * g2[r] * g2[n-r] % mod
#
    #mod = 10**9+7 #出力の制限
    #N = 10**4
    #g1 = [1, 1] # 元テーブル
    #g2 = [1, 1] #逆元テーブル
    #inverse = [0, 1] #逆元テーブル計算用テーブル
#
    #for i in range( 2, N + 1 ):
    #    g1.append( ( g1[-1] * i ) % mod )
    #    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    #    g2.append( (g2[-1] * inverse[-1]) % mod )
    
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    ans = 0
    mod = 10 ** 9 + 7
    comb = Combination(1000000)
    # 最小になる数を求める
    for i, a in enumerate(A):
        if (N - 1 - i) >= K-1:
            #tmp = cmb(N-1-i,K-1,mod)
            tmp = comb(N-1-i, K-1)
            ans -= (a * tmp)
            ans %= mod
        else:
            break
    
    A.sort(reverse=True)
    for i, a in enumerate(A):
        if (N - 1 - i) >= K-1:
            #tmp = cmb(N-1-i,K-1,mod)
            tmp = comb(N-1-i, K-1)
            ans += (a * tmp)
            ans %= mod
        else:
            break

    print(ans)

    
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 141432
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

#define ll long long
#define PII pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size))           \
  scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name)
#define DEBUG(...) debug(__LINE__,__VA_ARGS__)
#define MOD 1000000007

using namespace std;

string to_string(string s) { return s; }

template <class T>
string to_string(vector<T> v) {
	string ret = "{";
	FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
	if (v.size() > 0) {
		ret += to_string(LAST(v));
	}
	ret += "}";
	return ret;
}

void debug_print() { cerr << endl; }

template <class Head, class... Tail>
void debug_print(Head head, Tail... tail) {
	cerr << to_string(head) << " ";
	debug_print(tail...);
}

template <class... T>
void debug(T... args) {
	debug_print(args...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
	cout << to_string(head) << " ";
	print(tail...);
}

int main() {
	GI2(N,M);
	vector<string> A(N),B(M);
	FOR(i,N)cin>>A[i];
	FOR(i,M)cin>>B[i];
	for(int y=0;y<=N-M;++y){
		for(int x=0;x<=N-M;++x){
			bool f=1;
			for(int q=0;q<M;++q){
				for(int p=0;p<M;++p){
					if(A[y+q][x+p]!=B[q][p]){
						f=0;
					}
				}
			}
			if(f){
				print("Yes");
				return 0;
			}
		}
	}
	print("No");
	return 0;
}


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

int lcs(string x, string y) {
	int m = x.size();
	int n = y.size();
	int c[1001][1001];
	int maxl = 0;

	x = ' ' + x;
	y = ' ' + y;

	for (int i = 0; i <= m; i++) c[i][0] = 0;
	for (int j = 1; j <= n; j++) c[0][j] = 0;

	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (x[i] == y[j]) {
				c[i][j] = c[i - 1][j - 1] + 1;
				if (c[i][j] > maxl) {
					maxl = c[i][j];
				}
			}
			else {
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			}
		}
	}
	return maxl;
}

int main()
{
	int n;
	string x, y;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		cout << lcs(x, y) << endl;
	}
	return 0;
}


Measured memory_bytes: 7024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  char s[101],t[101];
  scanf("%s%s",s,t);
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;i+j<n;j++){
      if(s[i+j]!=t[j]) break;
    }
    if(i+j>=n) break;
  }
  printf("%d\n",n+i);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

int main(void){
	ll x; cin >> x;
	for(ll a=-1000; a<1000; a++){
		for(ll b=-1000; b<1000; b++){
			if((a*a*a*a*a) - (b*b*b*b*b) == x){
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<ll>().max();

int main() {
	ll n;
	cin >> n;
	n--;
	ll ans = n*(n+1)/2;
	cout << ans << endl;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int64 res = 0, cnt = 0;
  REP(i, 3) {
    if (s[i] == 'R') cnt++;
    else {
      chmax(res, cnt);
      cnt = 0;
    }
  }
  cout << max(res, cnt) << endl;
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <math.h>

long modpow(long a, long n, long mod){
	if (n == 0) {
		return 1;
	}
	long answer;
	if (n%2 == 0) {
		answer = modpow(a, n/2, mod);
		answer *= answer;
	} else {
		answer = modpow(a, n-1, mod);
		answer *= a;
	}
	answer %= mod;
	return answer;
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  long mod = pow(10,9)+7;
  long bit[n][60];
  for (long i = 0; i < n; i++) {
    for (long j = 0; j < 60; j++) {
      bit[i][j] = 0;
    }
  }
  long count_bit[60];
  for (long i = 0; i < 60; i++) {
    count_bit[i] = 0;
  }
  for (long i = 0; i < n; i++) {
    bit[i][0] = a[i];
    for (long j = 1; j < 60; j++) {
      bit[i][j] += bit[i][j-1]/2;
      bit[i][j-1] %= 2;
    }
  }
  for (long i = 0; i < n; i++) {
    for (long j = 0; j < 60; j++) {
      if (bit[i][j] == 1) {
        count_bit[j]++;
      }
    }
  }
  long answer_bit[60];
  long plus;
  long sum = 0;
  for (long i = 0; i < 60; i++) {
    answer_bit[i] = count_bit[i]*(n-count_bit[i]);
    answer_bit[i] %= mod;
    plus = modpow(2,i,mod)*answer_bit[i];
    plus %= mod;
    sum += plus;
    sum %= mod;
  }
  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 143104
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
// #define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
void fileio()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
 

 
template <typename T> 
void swap(T& a, T& b){
    T temp = a;
    a = b;
    b = temp;
}

const int N = 1000001; 

vector<int> h;
vector<int> dp;

void solve(){
    int n;
    cin>>n;
    int k;
    cin>>k;

    h = vector<int>(n);
    dp  = vector<int>(n,INT_MAX);
    forn(i,0,n-1)
        cin>>h[i];

    dp[0] = 0;

    for(int i=1;i<n;i++){

        for(int j =i-1;j>=i-k && j>=0 ;j--){
            dp[i] = min(dp[i], dp[j]+abs(h[j]-h[i]));
        }   
    }
    cout<<dp[n-1]<<endl;
}
 
int32_t main()
{
    
    fast;
    // int t;
    // cin>>t;
    // for(int y=1;y<=t;y++)
    {
        // cout<<"Case #"<<y<<": ";
        solve();
    }
    return 0;
} 

Measured memory_bytes: 1792
#include <stdio.h>

int main(void){

  long n,k,x,y;
  scanf("%ld %ld %ld %ld", &n, &k, &x, &y);
  long answer;
  if (n <= k) {
    answer = x*n;
  } else {
    answer = x*k+y*(n-k);
  }
  printf("%ld\n", answer);

  return 0;
}

Measured memory_bytes: 128
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>

using namespace std;

#define fto(i,a,b) for (int i = (a); i <= b; i++)
#define fdw(i,a,b) for (int i = (a); i >= b; i--)
#define rep(i,a) for(int i = 0; i < a; i++) 
#define read(a) cin >> a
#define read2(a, b) cin >> a >> b
#define read3(a, b, c) cin >> a >> b >> c
#define read4(a, b, c, d) cin >> a >> b >> c >> d
#define write(a, b) cout << a << b
#define writeln(a) cout << a << "\n"

#define PI 3.14159265
#define oo 1000000000
#define ooLL 100000000000000000
#define log(a) cerr << #a << " = " << a << endl

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define next thongdeptrai
#define prev thongbachuthegioi
#define y1 thongsieucapvutru
#define y0 thongnotgay

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

#define maxn 100005

using namespace std;

int a[maxn], n;
int cnt[maxn];

int main() {

    // checking input file is not available with atCoder
  //  freopen("in.inp", "r", stdin);
    
    read(n);
    for(int i = 1; i <= n; i++) {
        read(a[i]);
        a[i]++;
    }

    for(int i = 1; i <= n; i++) 
        cnt[a[i] + 1]++, cnt[a[i] - 1]++, cnt[a[i]]++;

    int pos = 0;
    for(int i = 0; i <= 100002; i++) 
        if (cnt[pos] <= cnt[i]) pos = i;

    int res = 0;
    for(int i = n; i >= 1; i--) 
        if (a[i] + 1 == pos || a[i] - 1 == pos || a[i] == pos) res++;

    cout << res;
    

    #ifndef ONLINE_JUDGE
        cout << endl;
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


Measured memory_bytes: 1024
MOD = 10**9 + 7
n = int(input())
dp = [0]*(n+1)
dp[0] = 1
for i in range(3, n+1):
    for j in range(3, i+1):
        dp[i] += dp[i-j]
        dp[i] %= MOD
print(dp[n])

Measured memory_bytes: 64860
ans=[0]*4
while True:
    a,b,c=sorted(list(map(int,input().split(" "))))
    if a+b<=c:break
    d=a*a+b*b-c*c
    ans[0]+=1
    ans[1]+=d==0
    ans[2]+=d>0
    ans[3]+=d<0
print(*ans)


Measured memory_bytes: 5600
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<=b && a<=c){
        if(b<=c){
            printf("%d %d %d\n",a,b,c);
        }
        else if(c<=b){
            printf("%d %d %d\n",a,c,b);
        }
    }
    else if(b<=a && b<=c){
        if(a<=c){
            printf("%d %d %d\n",b,a,c);
        }
        else if(c<=a){
            printf("%d %d %d\n",b,c,a);
        }
    }
    else if(c<=a && c<=b){
        if(a<=b){
            printf("%d %d %d\n",c,a,b);
        }
        else if(b<=a){
            printf("%d %d %d\n",c,b,a);
        }
    }
    return 0;
}


Measured memory_bytes: 2052
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A = map(int, read().split())

    if N % 500 <= A:
        print('Yes')
    else:
        print('No')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 8992
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

struct edge{
	int to, from, c;
} es[5005];

int d[2505], vis1[2505], vis2[2505], ok[5005];
vector<pi> G1[2505], G2[2505];

void dfs1(int u) {
	vis1[u] = 1;
	for(pi v:G1[u]) {
		if(!vis1[v.F])
			dfs1(v.F);
		ok[v.S]++;
	}
}
void dfs2(int u) {
	vis2[u] = 1;
	for(pi v:G2[u]) {
		if(!vis2[v.F])
			dfs2(v.F);
		ok[v.S]++;
	}
}


int main()
{
	IO_OP;
	
	int n, m, p;
	cin >> n >> m >> p;
	for(int i=0;i<m;i++) {
		int u, v, c;
		cin >> u >> v >> c;
		G1[u].EB(v, i);
		G2[v].EB(u, i);
		es[i].from = u, es[i].to = v, es[i].c = -(c-p);
	}
	dfs1(1);
	dfs2(n);
	memset(d, 0x3f, sizeof d);
	d[1] = 0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if(ok[j] != 2) continue;
			edge e = es[j];
			if(d[e.to] > d[e.from] + e.c) {
				d[e.to] = d[e.from] + e.c;
				if(i == n-1) {
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}
	cout << max(-d[n], 0) << endl;
	
}



Measured memory_bytes: 768
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  printf("%d\n", min(n*a,b));
  return 0;
}


Measured memory_bytes: 256
S = input()
K = int(input())

if len(S) == 1:
    print(K//2)
    exit()
L = []
LS = []
ans = 0
streak = 1
s = ''

for i in range(len(S)-1):
    if i == 0:
        s = S[0]
        streak = 1
    
    if s == '':
        if S[i+1:i+2] == S[i:i+1]:
            s = S[i:i+1]
            streak += 1
    else:
        if S[i+1:i+2] == s:
            streak += 1
        else:
            L.append(streak)
            LS.append(s)
            s = ''
            streak = 1
    
    if i == len(S)-2:
        L.append(streak)
        LS.append(S[-1])
        # if streak == len(S):
        #     ans = K*(len(S)//2)
        #     print(ans)
        #     exit()

# print(LS)
# print(L)
if streak == len(S):
    ans = (len(S)*K)//2
    # print(len(S))
    print(ans)
    exit()

if LS[0] != LS[-1]:
    for l in L:
        # if l >=2:
        ans += l//2
    ans = K*ans
elif LS[0] == LS[-1]:
    for i in range(1,len(L)-1):
        ans += L[i]//2
    ans = K*ans + L[0]//2 + (K-1)*((L[0]+L[-1])//2) + L[-1]//2
print(ans)


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

#define N 100000

int main(void){
    vector<bool> prime(N+1,true);
    prime[0]=prime[1]=false;
    for (size_t i = 0; i <= sqrt(N); i++)
    {
        if (prime[i])
        {
            for (size_t j = 2; i*j <= N; j++)
            {
                prime[i*j]=false;
            }
        }
    }
    vector<int> likeCnt(N);
    for (size_t i = 1; i <= N; i++)
    {
        likeCnt[i]=likeCnt[i-1];
        if (i%2==1&&prime[i]&&prime[(i+1)/2])
        {
            likeCnt[i]++;
        }
    }
    /**************************************/
    int q;
    cin >> q;
    int l[q],r[q];
    for (size_t i = 0; i < q; i++)
    {
        cin >> l[i] >> r[i];
        cout << likeCnt[r[i]] - likeCnt[l[i]-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <queue>

int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> cmpx(1, 0);
  std::vector<int> cmpy(1, 0);
  std::vector<int> A(N), B(N), C(N);
  std::vector<int> D(M), E(M), F(M);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i] >> B[i] >> C[i];
    cmpx.push_back(A[i]);
    cmpx.push_back(B[i]);
    cmpy.push_back(C[i]);
  }
  for (int i = 0; i < M; ++i) {
    std::cin >> D[i] >> E[i] >> F[i];
    cmpx.push_back(D[i]);
    cmpy.push_back(E[i]);
    cmpy.push_back(F[i]);
  }
  auto cmprs = [&](std::vector<int> &vec) {
    std::sort(vec.begin(), vec.end());
    vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
  };
  auto fix = [&](const std::vector<int> &vec, int &v) {
    v = std::lower_bound(vec.cbegin(), vec.cend(), v) - vec.cbegin();
  };
  cmprs(cmpx);
  cmprs(cmpy);
  for (int i = 0; i < N; ++i) {
    fix(cmpx, A[i]);
    fix(cmpx, B[i]);
    fix(cmpy, C[i]);
  }
  for (int i = 0; i < M; ++i) {
    fix(cmpx, D[i]);
    fix(cmpy, E[i]);
    fix(cmpy, F[i]);
  }
  int sx = 0, sy = 0;
  fix(cmpx, sx);
  fix(cmpy, sy);
  if (sx + 1 == cmpx.size() || sx == 0) {
    std::cout << "INF\n";
    return 0;
  }
  if (sy + 1 == cmpy.size() || sy == 0) {
    std::cout << "INF\n";
    return 0;
  }
  int X = cmpx.size() - 1;
  int Y = cmpy.size() - 1;
  std::vector<std::vector<bool>> reach(X, std::vector<bool>(Y));
  std::vector<std::vector<bool>> side(Y + 1, std::vector<bool>(X));
  std::vector<std::vector<bool>> vert(X + 1, std::vector<bool>(Y));
  for (int i = 0; i < N; ++i) {
    for (int j = A[i]; j < B[i]; ++j) {
      side[C[i]][j] = true;
    }
  }
  for (int i = 0; i < M; ++i) {
    for (int j = E[i]; j < F[i]; ++j) {
      vert[D[i]][j] = true;
    }
  }
  std::queue<std::pair<int, int>> que;
  auto push = [&](int x, int y) {
    if (x < 0 || y < 0 || x >= X || y >= Y) {
      std::cout << "INF\n";
      std::exit(EXIT_SUCCESS);
    }
    if (!reach[x][y]) {
      reach[x][y] = true;
      que.emplace(x, y);
    }
  };
  push(sx, sy);
  push(sx - 1, sy);
  push(sx, sy - 1);
  push(sx - 1, sy - 1);
  while (!que.empty()) {
    auto [x, y] = que.front();
    que.pop();
    if (!side[y + 1][x]) push(x, y + 1);
    if (!side[y][x]) push(x, y - 1);
    if (!vert[x + 1][y]) push(x + 1, y);
    if (!vert[x][y]) push(x - 1, y);
  }
  int64_t ans = 0;
  for (int i = 0; i < X; ++i) {
    for (int j = 0; j < Y; ++j) {
      if (reach[i][j]) {
        ans += (int64_t) (cmpx[i + 1] - cmpx[i]) * (cmpy[j + 1] - cmpy[j]);
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 7420
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt(),b=s.nextInt();
        System.out.println(Math.max(Math.max(a+b,a-b),a*b));

    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

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

public class Main {
	private static void solve(){
		//Implement solution here.
		int n = ni();
		String s = next();
		String t = next();
		for(int i = 0; i < n; i++) {
			System.out.print(s.charAt(i));
			System.out.print(t.charAt(i));
		}
		
	}
	
	//Switch input source (stdin/file)
	private static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				scanner = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath)))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(scanner.nextLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, K;
  int M = 0;
  cin >> A >> B >> C >> K;

  if (K < A){
    M=K; 
  }else if (K <= (A+B) ) {
    M = A;
  } else {
    M = A - (K - A - B);
  }
  cout << M;
}

Measured memory_bytes: 3592
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if((a+b)/2 == (a+b+1)/2){
        cout << (a+b)/2;
    }    
    else{
        cout << "IMPOSSIBLE";
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline vector<pair<T,int> > factorize(T n)//NOTES:factorize( 
  {vector<pair<T,int> > R;for (T i=2;n>1;){if (n%i==0){int C=0;for (;n%i==0;C++,n/=i);R.push_back(make_pair(i,C));} 
   i++;if (i>n/i) i=n;}if (n>1) R.push_back(make_pair(n,1));return R;}

typedef long long ll;
constexpr ll inf = 1e12;

template<class T> inline bool isPrimeNumber(T n)//NOTES:isPrimeNumber( 
  {if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;} 

ll n;



int main(){
	cin>>n;
	auto x = factorize(n);
	int res = 0;
	for(auto xp : x){
		ll z = xp.first;
		for(int i = 1; i <= xp.second; ++i){
			ll t = pow(z, i);
			if(n % t == 0){
				n /= t;
				res++;
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3992
import java.util.*;
class Main {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  int b = sc.nextInt();
  System.out.println((a / b)  + " " + (a%b) + " " +  String.format("%.8f\n", (double)a/b ));
 }
}


Measured memory_bytes: 26564
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k, x, y = nin(4)

ans = min(n, k) * x + max(0, n - k) * y
print(ans)

Measured memory_bytes: 3064
#include <iostream>

#define N 100010

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

	int n, l, arr[N];
	std::cin >> n >> l;
	bool possible = false;
	int a, b;
	for (int i = 0; i < n; ++i) {
		std::cin >> arr[i];
		if (!possible && i > 0 && arr[i] + arr[i - 1] >= l) {
			possible = true;
			a = i - 1;
			b = i;
		}
	}
	if (!possible) {
		std::cout << "Impossible\n";
	} else {
		std::cout << "Possible\n";
		for (int i = 1; i <= a; ++i) {
			std::cout << i << '\n';
		}
		for (int i = n - 1; i > b; --i) {
			std::cout << i << '\n';
		}
		std::cout << b << '\n';
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<string>
using namespace std;
string str;
bool a;
int main(){
	cin>>str;
	for(int i=0;str[i];i++){
		if(a==0){
			if(str[i]=='C')	a=1;
		}else{
			if(str[i]=='F'){
				cout<<"Yes";
				return 0;
			}
		}
	}cout<<"No";
	return 0;
}

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

constexpr int D = 365;
constexpr int T = 26;
int c[D];
int s[D][T];

int last[T];
int score = 0;
vector<int> ans;

void Input() {
    int tmp; cin >> tmp;
    REP(i, T) cin >> c[i];
    REP(i, D) REP(j, T) cin >> s[i][j];
    return;
}

int FindMaxProfitContest(int day) {
    int max_profit = -1e9, argmax = -1;
    REP(type, T) {
        int profit = 0;
        profit += s[day - 1][type];
        profit += 2 * c[type] * (day - last[type]);
        if(profit > max_profit) {
            max_profit = profit;
            argmax = type;
        }
    }
    return argmax;
}

void Commit(int day, int contest) {
    ans.push_back(contest);
    last[contest] = day;
    score += s[day - 1][contest];
    REP(type, T) score -= c[type] * (day - last[type]);
    return;
}

void Output() {
    for(auto contest: ans) cout << contest + 1 << endl;
    return;
}

int main() {
    Input();
    for(int day = 1; day <= D; day++) {
        int contest = FindMaxProfitContest(day);
        Commit(day, contest);
    }
    Output();
    // cerr << score << endl;
    return 0;
}


Measured memory_bytes: 3676