akhauriyash/Code-Regression huggingface dataset:
A,B = input().split()
g = 0
for i in range(int(A[0:3]),int(B[0:3])+1):
    p = i//100
    q = (i%100)//10
    new_k = i*100+q*10+p
    if int(A) <= new_k <= int(B):
        g += 1
print(g)

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

void solve()
{
  int N; cin >> N;
  string S; cin >> S;
  S.erase(unique(S.begin(),S.end()),S.end());
  cout << S.size() << endl;
}
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(11);
  solve();
  return 0; 
}


Measured memory_bytes: 512
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
		int b = sc.nextInt();
		if (a>=b){
        	System.out.print(a-b);	
        }else{
        	System.out.print("0");
        }
    }
}

Measured memory_bytes: 21588
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	as := make([][][]int, n)
	for i := range as {
		var a int
		fmt.Scan(&a)
		as[i] = make([][]int, 0)
		for j := 0; j < a; j++ {
			var x, y int
			fmt.Scan(&x, &y)
			x--
			as[i] = append(as[i], []int{x, y})
		}
	}

	var ans int
	for i := 0; i < 1<<uint(n); i++ {
		var ng bool
		var cnt int
		for j := 0; j < n; j++ {
			if i&(1<<uint(j)) > 0 {
				for k := range as[j] {
					if i&(1<<uint(as[j][k][0])) > 0 {
						if as[j][k][1] == 0 {
							ng = true
						}
					} else {
						if as[j][k][1] == 1 {
							ng = true
						}
					}
				}
				cnt++
			}
		}
		if !ng && cnt > ans {
			ans = cnt
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 2e9
#define ll long long
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(v) v.begin(), v.end()

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n10=0, n01=0;
    if (s.size() == 1) cout << 0 << endl;
    else {
        //1010101010...
        REP(i, s.size()/2) {
            if (s.at(2*i) == s.at(2*i+1)) {
                n10++;
                n01++;
            } else if (s.at(2*i) == '1') {
                n01 += 2;
            } else n10 += 2;
            //cout << n10 << " " << n01 << endl;
        }
        if (s.size() % 2 != 0) {
            if (s.at(s.size()-1) == '1') n01++;
            else n10++;
        }
        cout << min(n10, n01) << endl;
    }
}



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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;

using namespace std;

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

    int n;
    cin >> n;
    vector<int> a(n);

    REP(i, n) cin >> a[i];

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

    int before = INT_MIN;
    int ans = 0;

    for (int item : a)
    {
        if (before < item)
        {
            ++ans;
            before = item;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll a[Max],b[Max],c[Max];
ll n;
void solve(){
	ll A,B,M;
	cin>>A>>B>>M;
	ll la=oo,lb=oo;
	rep(i,0,A){
		cin>>a[i];
		la = min(la,a[i]);
	}
	rep(i,0,B){
		cin>>b[i];
		lb = min(lb,b[i]);
	}
	ll res=la+lb;
	rep(i,0,M){
		ll x,y,d;
		cin>>x>>y>>d;
		res = min(res,a[x-1]+b[y-1]-d);
	} 
	cout<<res;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN = 510;
long long g[mxN][mxN];

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

	long long H,W,h,w;
	cin>>H>>W>>h>>w;
	long long cntInd = (H/h) * (W/w);
	long long cnttanya = cntInd * (h * w - 1);
	long long cntall = H * W - cntInd;
	if(cnttanya >= cntall) {
		cout<<"No\n";
		return 0;
	}
	long long lo = 1,hi = 1000000000ll,_7agatanya = -1,_7aga = -1;
	while(lo <= hi) {
		long long md = (lo + hi)>>1;
		
		if(cnttanya * md + cntInd < cntall * md) {
			hi = md - 1;
			_7agatanya = md;
			_7aga = (h * w - 1) * md + 1;
		} else {
			lo = md + 1;
		}
	}
	assert(_7aga > 0 && _7agatanya > 0);
	cout<<"Yes\n";
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			if((i+1)%h == 0 && (j+1)%w == 0) {
				g[i][j] = -_7aga;
			} else {
				g[i][j] = _7agatanya;
			}
			cout<<g[i][j]<<" \n"[j+1 == W];
		}
	}
	return 0;
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int c[14];

string solve(int ss, int gs, int h, int m, int t) {
  if(ss == 6) return "yes";
  else if(gs == 6) return "no";
  int f = 0;
  int rf = 0;
  if(!t) {
    if(h >= 1 && c[h]) {
      if(solve(ss + 1, gs, h - 1, m, !t) == "yes") rf = 1;
      f = 1;
    }
    if(m <= 13 && c[m]) {
      if(solve(ss + 1, gs, h, m + 1, !t) == "yes") rf = 1;
      f = 1;
    }
    if(!f) if(solve(ss, gs, h, m, !t) == "yes") rf = 1;
    return (rf ? "yes" : "no");
  }
  else if(t)  {
    if(h >= 1 && !c[h]) {
      if(solve(ss, gs + 1, h - 1, m, !t) == "no") rf = 1;
      f = 1;
    }
    if(m <= 13 && !c[m]) {
      if(solve(ss, gs + 1, h, m + 1, !t) == "no") rf = 1;
      f = 1;
    }
    if(!f) if(solve(ss, gs, h, m, !t) == "no") rf = 1;
    return (rf ? "no" : "yes");
  }
}

int main() {
  int n;
  cin >> n;
  rep(i, 0, n) {
    int a;
    rep(i, 0, 14) c[i] = 0;
    rep(i, 0, 6) cin >> a, c[a] = 1;
    int si = 0, gi = 0;
    cout << solve(0, 0, 6, 8, 0) << endl;
  }
}

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

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

inline void writ(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) writ(x/10);
	putchar(x%10+'0');
}
inline void write(int x){writ(x);putchar('\n');}

int main()
{
	int n=read();
	ll ans=0;
	for (int i=1;i<=n;++i) ans+=read();
	write(ans-n);
	return 0;
}

Measured memory_bytes: 256
import numpy as np
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

Z = np.linspace(X + 1, Y - 1, Y - X - 1)

for i in Z:
    if max(sorted(x)) < i and i <= min(sorted(y)):
        print("No War")
        exit()
print("War")

"""
3 2 10 20
8 15 13
16 22
"""


Measured memory_bytes: 13332
# C
N = int(input())
F = []
for _ in range(N):
    f = "".join(list(input().split()))
    F.append(int(f, 2))

P = []
for _ in range(N):
    P.append(list(map(int, input().split())))
    
ans = - float('inf')
for n in range(1, 1<<10):
    cur = 0
    for mise in range(N):
        mise_open = F[mise]
        both_open_cnt = bin(mise_open&n).count("1")
        cur += P[mise][both_open_cnt]
    ans = max(cur, ans)
print(ans)

Measured memory_bytes: 41580
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

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

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

const size_t N = 1e7 + 5;
const int MOD = 998244353;

int qpow(int base, int e) {
    int ret = 1;
    for (; e; e >>= 1) {
        if (e & 1) {
            ret = (LL) ret * base % MOD;
        }
        base = (LL) base * base % MOD;
    }
    return ret;
}

void iadd(int &dp, int val) {
    dp += val;
    if (dp >= MOD) {
        dp -= MOD;
    }
}

void ladd(int &dp, LL val) {
    dp = (dp + val) % MOD;
}

int n;
int fac[N], inv[N];

void prep() {
    fac[0] = 1;
    for (int i = 1; i <= n; ++i) {
        fac[i] = (LL) fac[i - 1] * i % MOD;
    }
    inv[n] = qpow(fac[n], MOD - 2);
    for (unsigned i = n; i; --i) {
        inv[i - 1] = (LL) inv[i] * i % MOD;
    }
}

int main() {
    n = read();
    prep();
    int ans = qpow(3, n);
    int pw2 = 2;
    for (int i = n; i > n / 2; --i) {
        ladd(ans, -1LL * pw2 * fac[n] % MOD * inv[i] % MOD * inv[n - i]);
        iadd(pw2, pw2);
    }
    if (ans < 0) ans += MOD;
    cout << ans;
    return 0;
}

Measured memory_bytes: 78336
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second


signed main(){
	
	ll n,temp = 0,r = 0,l = 0,ans = 0;
	cin >> n;
	bool flag = true,flag2 = true;
	
	ll a[n];
	
	rep(i,0,n){
		cin >> a[i];
	}
	
	
	while(flag2){
		flag2 = false;
		flag = false;
		temp = INF;
		
		rep(i,0,n){
			if(!flag && a[i] == 0) continue; //先頭0対策
			
			else if(!flag && a[i] != 0){ //先頭を見つける
				flag = true; 
				flag2 = true;
				l = i;
			}
			
			if(a[i] != 0) temp = min(a[i],temp); //最小値を見つける
			if(a[i] == 0 || temp > a[i] || i == n-1){ 
				rep(j,l,i+1){
					a[j] = max((ll)0,a[j]-temp);
				}
				ans += temp;
				
				//cout << temp << endl;
				//rep(k,0,n) cout << a[k] << " \n"[k == n-1];
				
				temp = INF;
				flag = false;
			}
		}
		
	}
	
	
	cout << ans << endl;
	
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(), (a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(), (a).end())

int main(){
    int n;
    cin>>n;
    vector<int64_t> dp(n);
    vector<int64_t> x(n);
    int64_t a,b;
    cin>>a>>b;
    rep(i,n){
        cin>>x[i];
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
        dp[i]= dp[i-1]+min((x[i]-x[i-1])*a,b);
    }
    cout<<dp[n-1]<<endl;

}

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

using namespace std;

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

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

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

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

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

  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> s[i][j];

  ll min_cost[h + 10][w + 10];
  rep(i, h) rep(j, w) min_cost[i][j] = LINF;
  queue<P> qu;
  qu.push({0, 0});
  min_cost[0][0] = 0;

  while (!qu.empty()) {
    auto p = qu.front();
    qu.pop();
    rep(i, 2) {
      int nx = p.se + dx[i], ny = p.fi + dy[i], cost = 0;
      if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
      if (s[p.fi][p.se] == '.' && s[ny][nx] == '#') cost = 1;
      if (min_cost[p.fi][p.se] + cost >= min_cost[ny][nx]) continue;
      min_cost[ny][nx] = min_cost[p.fi][p.se] + cost;
      qu.push({ny, nx});
    }
  }
  Cout(min_cost[h - 1][w - 1] + (s[0][0] == '#' ? 1 : 0));
  return 0;
}


Measured memory_bytes: 384
n = int(input())
ans = 0
bn, an, ban = 0, 0, 0
for _ in range(n):
    s = input()
    if s[0] == "B" and s[-1] == "A": ban += 1
    elif s[0] == "B": bn += 1
    elif s[-1] == "A": an += 1
    for i in range(1, len(s)):
        if s[i] == "B" and s[i-1] == "A": ans += 1
if ban:
    ans += ban - 1
    if bn:
        ans += 1
        bn -= 1
    if an:
        ans += 1
        an -= 1
ans += min(bn, an)
print(ans)


Measured memory_bytes: 3064
from collections import deque

def bfs(sx, sy, gx, gy):
    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    queue = deque([(sx, sy)])
    dist = [[0] * W for _ in range(H)]
    dist[sy][sx] = 1
    while queue:
        x, y = queue.popleft()
        for dirs in directions:
            nx = x + dirs[0]
            ny = y + dirs[1]

            if nx < 0 or nx >= W or ny < 0 or ny >= H:
                continue

            if maze[ny][nx] == '#':
                continue

            if dist[ny][nx] == 0:
                dist[ny][nx] = dist[y][x] + 1
                queue.append((nx, ny))
            if nx == gx and ny == gy:
                return dist[gy][gx]
    return -1

H, W = map(int, input().split())
maze = [input() for _ in range(H)]
cnt = 0
for i in range(H):
    cnt += maze[i].count('#')
ans = bfs(0, 0, W-1, H-1)
if ans == -1:
    print(ans)
else:
    score = H * W - cnt - ans
    print(score)



Measured memory_bytes: 3316
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

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

   vector<ll> a(n);
   for(int i=0;i<n;i++){
       ll x;
       cin>>x;
       a[i] = x;
   }

   vector<ll> b(n);
   for(int i=0;i<n;i++){
       b[i] = 0;
   }

   for(int i=0;i<n;i++){
       for(int j=i+1;j<n;j++){
           if(a[i]>a[j]) b[i]++;
       }
    //   cout<<b[i]<<" ";
   }
//    cout<<endl;

   vector<ll> c(n);
   for(int i=0;i<n;i++){
       c[i] = 0;
   }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i!=j && a[i] > a[j]) c[i]++;
        }
    //    cout<<c[i]<<" "; 
    }
//    cout<<endl;

    ll sum = 0;
    for(int i=0;i<n;i++){
        sum+= (b[i] * k)%1000000007;
        sum+= (c[i] * (((k-1)*k/2)%1000000007) )%1000000007;
        sum = sum%1000000007;
       //cout<<sum<<" ";
    }

    cout<<sum%(1000000007)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n+2),b(n);
  a[0]=0;
  a[n+1]=0;
  for(int i=1;i<=n;i++){
    cin >> a[i];
  }
  int sum=0;
  for(int i=1;i<=n+1;i++){
    sum+=abs(a[i]-a[i-1]);
  }
  for(int i=1;i<=n;i++){
    cout << sum-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]) << endl;
  }
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int X,t;
  cin >> X >> t;
  if(X>=t)  cout << X-t << endl;
  else  cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;
int mod = 1000000007;

int mypow(int e, int p){
   long long cur = 1;
   long long coef = e;
   while(p!=0){
      if(p%2==1){
         cur *= coef;
         cur %= mod;
      }
      coef *= coef;
      coef %= mod;
      p/=2;
   }
   return cur;
}

int main(){
   int N,K;
   cin >> N >> K;
   long long cnt[K+1];
   long long ans = 0;
   for(int i = K; i >= 1; i--){
      //cout << "now" << i << endl;
      long long n = K/i;
      //cout << n<< ", " << N << endl;
      cnt[i] = mypow(n,N);
      //cout << "..." << cnt[i] << endl;
      for(int j = i+i; j <= K; j += i){
         cnt[i] += mod;
         cnt[i] -= cnt[j];
         cnt[i] %= mod;
      }
      ans += i*cnt[i];
      ans %= mod;
   }
   cout << ans << endl;

   return 0;
}


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

using namespace std;

int main(void){
    int count = 0;
    int N, tmp;

    cin >> N;
    vector<int> d;
    for(int i=0;i<N;i++){
        cin >> tmp;
        d.push_back(tmp);
    }
    std::sort(d.begin(), d.end());

    cout << d[N/2] - d[N/2-1] << endl;
}

Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;
 
    vl L(n), R(n);
    ll p = 0, q = 0;  // L[p]はLの最大値で、R[q]はRの最小値
    ll MAXL = 0, MINR = INF;
    rep(i, n) {
        cin >> L[i] >> R[i];
        R[i]++;
        if(MAXL < L[i]) {
            MAXL = L[i];
            p = i;
        }
        if(MINR > R[i]) {
            MINR = R[i];
            q = i;
        }
    }
 
    ll ans = 0;
    // 区間pと区間qを同じ集合に入れる場合
    rep(i, n) {
        if(i == p || i == q) {
            continue;
        }
        chmax(ans, max(0LL, R[q] - L[p]) + R[i] - L[i]);
    }
 
    // 区間pと区間qを違う集合に入れる場合
    vector<pair<ll, ll>> c(n);
    rep(i, n) {
        ll a = max(0LL, R[i] - L[p]);
        ll b = max(0LL, R[q] - L[i]);
        c[i] = make_pair(a, -b);
    }
    sort(all(c));
    ll u = abs(c[0].second);
    exrep(i, 1, n-1) {
        chmax(ans, c[i].first + u);
        chmin(u, abs(c[i].second));
    }
 
    out(ans);
    re0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
typedef pair <int, pii> piii;
#define fr first
#define sc second
#define pb push_back
#define ppb pop_back()
#define ins insert
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define mpr make_pair
ll a[4], n;
pair <double, ll> b[4];
int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	for(int i = 0;i < 4; ++ i){
		cin >> a[i];
		b[i].fr = (1.0 * a[i]) / (1.0 * (1 << i));
		b[i].sc = i;
	}
	cin >> n;
	n *= 4;
	sort(b, b + 4);
	if(b[0].sc < 3 || (n / 4) % 2 == 0){
		cout << n / (1 << (b[0].sc)) * a[b[0].sc];
		return 0;
	}
	cout << (n - 4) / (1 << (b[0].sc)) * a[b[0].sc] + 4 / (1 << (b[1].sc)) * a[b[1].sc];
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int n2 = 0, n4 = 0;
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            if (a % 4 == 0) {
                n4++;
            } else if (a % 2 == 0) {
                n2++;
            }
        }
        int max = n4 * 2 + n2;
        if (n2 == 0) {
            max++;
        }
        if (max < N) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 50320
#include<stdio.h>

void swap(int *a,int *b){
	int temp=*a;
	*a=*b;
	*b=temp;
}

int main(){
	int i,n,c,a[3],j;
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	for(i=0;i<2;i++){
		for(j=2;j>i;j--){
			if(a[j]<a[j-1]){
				swap(&a[j],&a[j-1]);
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
} 


Measured memory_bytes: 2736
def main():
  from collections import deque
  k=int(input())
  l=deque([1,2,3,4,5,6,7,8,9])
  x=1
  for _ in range(k-1):
    x=l[0]
    l.popleft()
    if x%10>0:
      l.append(10*x+x%10-1)
    l.append(10*x+x%10)
    if x%10<9:
      l.append(10*x+x%10+1)
  print(l[0])
if __name__=='__main__':
  main()

Measured memory_bytes: 11924
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <vector>
using namespace std;


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

  vector<char> c(N);
  for (int i = 0; i < N; i++) cin >> c[i];

  int ans = 0;
  int l = 0, r = N - 1;

  while (l < r) {
    while (c[l] == 'R') l++;
    while (c[r] == 'W') r--;
    if (l < r) { ans++; l++; r--; }
  }

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


Measured memory_bytes: 3628
n = int(input())
hh = list(map(int, input().split()))
cnt = 0

while hh.count(0) != n:
  a = [i for i, x in enumerate(hh) if x == 0]
  
  if a != []:
    for i in range(len(a)-1):
      if a[i]+1 != a[i+1]:
        for j in range(a[i]+1 , a[i+1]):               
          hh[j] -= 1
        cnt += 1
        
    if a[0] != 0:       
      for j in range(a[0]):
        hh[j] -= 1
      cnt +=1
    
    if a[-1] != n-1:
      for j in range(a[-1]+1, n):      
        hh[j] -= 1
      cnt += 1
        
  else:
    for i in range(n):
      hh[i] -= 1
    cnt += 1
             
print(cnt)

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define msg(x) debug() << x
#define int long long

signed main(){
  int n , m ;
  cin >> n >> m;
  string s;
  cin >> s;
  vector<int>pos;
  reverse(s.begin() , s.end());
  for(int i=0;i<=n;i++){
    if(s[i]=='0'){
      pos.push_back(i);
    }
  }
  int now = 0;
  vector<int>ans;

  while(now < n){
    int nxt = *(--upper_bound(pos.begin() , pos.end() , now + m));
    if(nxt == now){
      cout << -1 << '\n';
      return 0;
    }
    ans.push_back(nxt - now);
    now = nxt;
  }
  reverse(ans.begin() , ans.end());

  for(int i : ans) cout << i <<" ";cout << '\n';
  
}

Measured memory_bytes: 2676
n = int(input())
arr = []

for _ in range(n):
    arr.append(int(input()))

max_1 = -9999999999
max_1_i = -1
max_2 = -9999999999
max_2_i = -1
for i in range(len(arr)):
    if max_1 <= arr[i]:
        max_2 = max_1
        max_2_i = max_1_i
        max_1 = arr[i]
        max_1_i = i
        
    else:
        if max_2 <= arr[i]:
            max_2 = arr[i]
            max_2_i = i

for i in range(len(arr)):
    if i == max_1_i:
        print(max_2)
    else:
        print(max_1)


Measured memory_bytes: 12532
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 3002
mt19937 myrand(time(0));

int r,c,k;
ll a[mx][mx];
ll dp[mx][mx][5];

ll call(ll x, ll y, ll taken){
    if(x>r || y>c) return 0;
    ll &ret=dp[x][y][taken];
    if(ret!=-1) return ret;
    ret=0;
    ret=max(ret,((taken<3)?a[x][y]:0)+call(x+1,y,0));
    if(taken<3) ret=max(ret,a[x][y]+call(x,y+1,taken+1));
    ret=max(ret,call(x,y+1,taken));
    return ret;
}

int main()
{
    scanf("%d %d %d",&r,&c,&k);
    for(int i=0;i<k;i++){
        int x,y,z;
        scanf("%d %d %d",&x,&y,&z);
        a[x][y]=z;
    }
    memset(dp,-1,sizeof dp);
    ll ans=call(1,1,0);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 426580
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

char S[575][575];
map<char, int> mp;
//解説AC
//https://atcoder.jp/contests/agc023/submissions/4531157
int
main(void){  
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n,t;
  cin >> n;
  REP(i,n) cin >> S[i];

  REP(i,n){
    bool ok = true;
    REP(j, n-1) FOR(k, j+1, n) if(S[(i+j)%n][k] != S[(i+k)%n][j]) ok = false;
    t += ok;
  }
  cout << t*n << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

//typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define Se second
#define Fi first
#define rep(i, n) for(int i=0;i<n;i++)
#define pb(x) push_back(x)

const int MX = 100005;

int N;
int D[MX];

int main()
{
	ll ans = 0;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", D+i);
	for(int i = 1; i <= N+1; i++) ans += abs(D[i] - D[i-1]);
	for(int i = 1; i <= N; i++){
		ll t = ans - abs(D[i-1] - D[i]) - abs(D[i] - D[i+1]) + abs(D[i-1] - D[i+1]);
		printf("%lld\n", t);
	}
}


Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<cstdio>
#define mx 500
using namespace std;
long long n,m,h,w;
int main()
{
	long long i,j,u,v;
	cin>>n>>m>>h>>w;
	if(n%h==0 && m%w==0)
	{
		cout<<"No"<<endl;
	}
	else
	{
		cout<<"Yes"<<endl;
		u=(h*w-1)*mx+1;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=m;j++)
			{
				if(i%h==0 && j%w==0)
				{
					cout<<-u<<" ";
				}
				else
				{
					cout<<mx<<" ";
				}
			}
			cout<<endl;
		}
	}
	return(0);
}

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

int main(){
  int n, q; cin >> n >> q;
  string s; cin >> s;
  vector<int> a(n);
  for(int i = 0; i < n-1; i++){
  	if(s[i]=='A'&&s[i+1]=='C') a[i]=1;
  }
  for(int i = 1; i < n; i++) a[i] += a[i-1];
  int l, r;
  for(int i = 0; i < q; i++){
  	cin >> l >> r;
  	if(l==1) cout << a[r-2] << endl;
  	else cout << a[r-2]-a[l-2] << endl;
  }
}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if( ( a - c )*( a - c ) <= (d * d))printf("Yes\n");
	else if((b - a)*(b - a) <= d*d && (b - c)*(b - c ) <= d*d)printf("Yes\n");
	else printf("No\n");
	return 0;
	}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Abra_Ka_Dabra ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

int main() {

	Abra_Ka_Dabra

	ll x, k, d;
	cin>>x>>k>>d;
	x = abs(x);
	ll m = x/d;
	if(m>k) cout<<x-(k*d)<<"\n";
	else{
        ll res = x-(m*d);
        k = k-m;
        if(k&1) res = abs(res-d);
        cout<<res<<"\n";
	}

	return 0;
}



Measured memory_bytes: 3688
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 2e8;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

int n, m;
Vi va, open;

void init()
{
	cin >> n >> m;
	va.resize(m);
	open.resize(m);

	REP(i, m)
	{
		int a, b; cin >> a >> b;
		va[i] = a;
		int open_mask = 0;

		REP(_i, b)
		{
			int chest; cin >> chest;
			open_mask |= 1 << chest - 1;
		}

		open[i] = open_mask;
	}
}



int main()
{
	init();

	Vi dp(1 << n, inf);
	dp[0] = 0;

	REP(i, m)
		chmin(dp[open[i]], va[i]);

	int target = (1 << n) - 1;

	REP(i, target)
	{
		for (int j = i + 1; j <= target; ++j)
			chmin(dp[i | j], dp[i] + dp[j]);
	}


	if (dp[(1 << n) - 1] == inf)
		cout << -1 << endl;
	else
		cout << dp[(1 << n) - 1] << endl;

}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().solver();
	}

	@SuppressWarnings("unchecked")
	void solver() {
		Scanner sc = new Scanner(System.in);
		int V = sc.nextInt();
		int E = sc.nextInt();
		ArrayList<Integer>[] g = new ArrayList[V];
		for (int i = 0; i < g.length; i++)
			g[i] = new ArrayList<>();
		for (int i = 0; i < E; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			g[a].add(b);
			g[b].add(a);
		}
		Integer[] color = new Integer[V];
		Arrays.fill(color, -1);
		int base = 0;
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < V; i++) {
			if (color[i] == -1) {
				color[i] = 0;
				counter[0] = 1;
				counter[1] = 0;
				if (!dfs(g, color, i)) {
					System.out.println(-1);
					return;
				} else {
					base += Math.min(counter[0], counter[1]);
					if (counter[0] != counter[1]) {
						int value = Math.abs(counter[0] - counter[1]);
						map.put(Math.abs(value), map.containsKey(value) ? map.get(value) + 1 : 1);
					}
				}
			}
		}
		boolean[] dp = new boolean[V / 2 - base + 1];
		dp[0] = true;
		Iterator<Entry<Integer, Integer>> it = map.entrySet().iterator();
		int x = 0;
		while (it.hasNext()) {
			Entry<Integer, Integer> entry = it.next();
			int value = entry.getKey();
			int c = entry.getValue();
			for (int i = dp.length - 1; i >= 0; i--) {
				if (dp[i]) {
					for (int j = 1; j <= c; j++) {
						if (i + j * value < dp.length) {
							dp[i + j * value] = true;
							if (dp[i])
								x = Math.max(x, i + j * value);
						} else {
							break;
						}
					}
				}
			}
		}
		System.out.println((long)(base + x) * (long)(V - x - base) - E);
	}

	int[] counter = new int[2];

	boolean dfs(ArrayList<Integer>[] g, Integer[] color, int cur) {
		for (int v : g[cur]) {
			if (color[v] == -1) {
				color[v] = 1 ^ color[cur];
				counter[color[v]]++;
				if (!dfs(g, color, v)) {
					return false;
				}
			} else {
				if (color[cur] != (1 ^ color[v]))
					return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 114280
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include"time.h"
using namespace std;

#define LL long long
#define FOR(k,m,n) for(LL (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl
const int INF = (1 << 30);

//毎回変える場所
#define N_MAX 200

int main() {
	int N;
	cin >> N;
	int a = max(1, (N / 4));
	FOR(i,a , 3501)FOR(j, i, 3501)FOR(k, j, 3501) {
		if (N*(i*j + j*k + k*i) == 4 * i*j*k) {
			cout << i << " " << j << " " << k << endl;
			cin >> N;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
import bisect
from collections import deque

N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for _ in range(N)]

colors = deque([10 ** 10])
for i in range(N):
    bi = bisect.bisect_left(colors, A[i])
    bir = bisect.bisect_right(colors, A[i])
    if bir == len(A):
        colors[len(A) - 1] = A[i]
    elif bi == 0:
        colors.appendleft(A[i])
    else:
        colors[bi - 1] = A[i]

print(len(colors) - 1)


Measured memory_bytes: 49116
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define pb push_back
#define e1 first
#define e2 second
#define x first
#define y second
#define tysiac 1010
#define milion 1000100
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define OUT(x) { cout << x; return 0; }
#define PRINT(x, y) {printf("%d %d\n", x, y); return;} 
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <ld, ld> PDD;
typedef pair <PII, PII> PP;
typedef pair <ll, int> PLI;
typedef pair <double, int> PDI;

const int mod = 1e9+7;
const int inf = 1e9+9;
const int MOD = 1e9+696969;
const ll INF = 1e18+3;
int T, n, m, K, a, b, c, k, d, g, Q, DL;

#define maxn 1000100
const int R = (1 << 13);
int dr[2 * R + 5];

ll t[maxn], x;

inline void insert(int x, int v) {
	x += R-1;
	dr[x] = v;
	x >>= 1;
	while (x) {
		dr[x] = min(dr[2 * x], dr[2 * x + 1]);
		 x /= 2;
	}
}

inline int query(int x, int y) {
	x += R-1;
	y += R-1;
	int ret = min(dr[x], dr[y]);
	if (x == y) return ret;
	while (x + 1 < y) {
		if (!(x & 1)) ret = min(ret, dr[x + 1]);
		if (y & 1) ret = min(ret, dr[y - 1]);
		x /= 2; y /= 2;
	}
	return ret;
}

inline int getquery(int x, int y) {
	if (x > 0) return query(x, y);
	return min(query(1, y), query(x + n, n));
}
int main() {
	boost;
	cin >> n >> x;
	FOR(i, 1, 2 * R) dr[i] = inf;
	FOR(i, 1, n) {
		cin >> t[i];
		insert(i, t[i]);
	}
	
	ll WYNALL = INF;
	for (ll fixed = 0; fixed <= n; ++fixed) {
		ll wyn = 0;
		wyn = fixed * x;
		FOR(i, 1, n) {
			wyn += getquery(i - fixed, i);
		}
		WYNALL = min(WYNALL, wyn);
		//cout << WYNALL << endl;
	}
	cout << WYNALL;
}


Measured memory_bytes: 384
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),m=s.nextInt();
		long[]dp=new long[100001];
		Arrays.fill(dp,1,100001,Long.MAX_VALUE);
		for(int q=0;q<n;++q) {
			int w=s.nextInt(),v=s.nextInt();
			for(int i=100000;i>=v;--i)
				if(dp[i-v]!=Long.MAX_VALUE)
					dp[i]=Math.min(dp[i],dp[i-v]+w);
		}
		for(int i=100000;i>=0;--i) {
			if(dp[i]<=m) {
				System.out.println(i);
				return;
			}
		}
	}
}


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

using namespace std;

int main()
{
    double r;
    cin>>r;
    const double PI=3.14159265358979323846;
    cout<<setprecision(20)<<PI*r*r<<" "<<setprecision(20)<<2*r*PI<<endl;
    return 0;
}


Measured memory_bytes: 3276
#include <cstdio>
#include <algorithm>
#include <stack>
#include <cmath>
#include <cstring>
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define llong long long

int main() {
  int n;
  scanf("%d ",&n);
  char a[102],b[102];
  REP(i,n) {
    fgets(a,101,stdin);
    fgets(b,101,stdin);
    int al = strlen(a);
    int bl = strlen(b);
    if(a[al-1] == '\n') a[--al] = '\0';
    if(b[bl-1] == '\n') b[--bl] = '\0';
    char answer[103];
    REP(j,102) {
      answer[j] = '0';
    }
    answer[102] = '\0';
    REPR(j,101) {
      int anow,bnow;
      if(--al >= 0) anow = a[al]-'0';
      else anow = 0;
      if(--bl >= 0) bnow = b[bl]-'0';
      else bnow = 0;
      int t = (answer[j]-'0') + anow + bnow;
      answer[j] = t%10 + '0';
      if(j != 0) answer[j-1] += t/10;
    }
    int k = 0;
    while(k < 101 && answer[k] == '0'){
      k++;
    }
    if(k > 21)printf("%s\n",answer+k);
    else printf("overflow\n");
  }
  return 0;
}

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

struct edge
{
	int to, cost;
};

int main() {
	int n;
	cin >> n;
	vector<vector<edge>> g(n);
	for (int i = 0; i < n-1; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		g[u].push_back({v, w});
		g[v].push_back({u, w});
	}
	struct state
	{
		int v, parent;
	};
	int color[n]; fill(color, color+n, 0);
	stack<state> st;
	st.push({0, -1});
	while (!st.empty()) {
		state p = st.top(); st.pop();
		for (auto ne : g[p.v]) {
			if (ne.to == p.parent) continue;
			if (ne.cost%2 == 0) color[ne.to] = color[p.v];
			else color[ne.to] = 1 - color[p.v];
			st.push({ne.to, p.v});
		}
	}
	for (int i = 0; i < n; i++) {
		cout << color[i] << endl;
	}
	return 0;
}

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

#define ll          long long
#define pb          push_back
#define mp          make_pair
#define PII         pair<ll int, ll int>
#define pi          pair<ll, int>
#define fast_io     ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define loop_in     for(int i=0; i<n; i++)
#define INF         100000000000000


vector <ll> vec;

int main()
{
    fast_io

    ll t, n, i, j;
    cin>>n;
    if(n%1000 == 0)
    {
        cout<<0<<endl;
        return 0;
    }
    n = n%1000;
    cout<<1000-n<<endl;
}


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

const ll Mod = 1000000007;
typedef long long LL;
LL n,k;
const LL mof=1e9+7;
LL p=mof;
const LL maxn=100007;
inline LL pow_mod(LL a,LL k,LL mo)
{
    LL ans=1;
    while(k)
    {
        if(k%2) ans=ans*a%mo;
        a=a*a%mo;
        k>>=1;
    }
    return ans%mo;
}
LL jc[maxn+7];
inline LL inv(LL x)
{
    return pow_mod(x,mof-2,mof);
}
LL Inv[maxn+7];
LL C(LL N,LL k)
{
    if(k>N||k<0)return 0;
    if(k==0||k==N)return 1;
    LL ans=1;
    ans=ans*jc[N]*Inv[k]%mof*Inv[N-k]%mof;
    return ans;
}
void init()
{
    jc[1]=jc[0]=1;
    for(LL i=2; i<=maxn; ++i) jc[i]=jc[i-1]*i%mof;
    for(int i=0; i<=maxn; ++i) Inv[i]=inv(jc[i]);
}

ll N;
vector<int> divs;
void get_divisors(ll N)
{
    for(int i=2;i*i<=N;++i)
    {
        if(N%i==0){
            divs.push_back(i);
            if(i*i!=N)
                divs.push_back(N/i);
        }
    }
    divs.push_back(N);
    sort(divs.begin(),divs.end());
}
ll ans = 0;
void dfs(int pos,int dnum,int n,ll invnum)
{
    if(n==1)
    {
        if(pos-1 <= N)
        {
            ans += C(N,pos-1)*jc[pos-1]%Mod*invnum%Mod,
            ans %= Mod;
        }
        return;
    }
    for(int i=dnum;i<divs.size();++i)
    {
        if(divs[i] > n)break;
        if(n%divs[i] == 0)
        {
            int tmp = n;
            for(int j=1;tmp%divs[i]==0;j++)
            {
                tmp /= divs[i];
                dfs(pos+j,i+1,tmp,invnum*Inv[j]%Mod);
            }
        }
    }
}
void solve(ll N, ll M)
{
    get_divisors(M);
    dfs(1,0,M,1);
    cout<<ans<<endl;
}


int main()
{
    init();
    
    cin >> N;
    ll M;
    cin >> M;
    solve(N, M);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int N, K; cin >> N >> K;
	vector<int> V1(N), V2;
	for (int i = 0; i < N; i++) cin >> V1[i];
	V2 = V1;
	reverse(V2.begin(), V2.end());
	
	ll ans = -INF;
	// K回のうち、何回とって何回捨てるか
	for (int i = 0; i <= K; i++) { // i : 合計で取る回数
		

		// i >= Nのときは注意
		if (i < N) {
			int rem = K - i; // 捨てる回数

			for (int j = 0; j <= i; j++) { // j : 右から取る回数
				int fromright = j;
				int fromleft = i - j;

				vector<int> tmp;
				for (int k = 0; k < fromright; k++) tmp.push_back(V1[k]);
				for (int k = 0; k < fromleft; k++) tmp.push_back(V2[k]);

				sort(tmp.begin(), tmp.end());
				ll tmpans = 0;
				for (int k = 0; k < tmp.size(); k++) {
					if (tmp[k] >= 0 || k >= rem) tmpans += tmp[k];
				}

				ans = max(ans, tmpans);
			}
		}
		else { // i >= N
			int res = K - N;
			ll tmpans = 0;
			vector<int> tmp;
			for (int j = 0; j < V1.size(); j++) {
				tmp.push_back(V1[j]);
				tmpans += V1[j];
			}
			sort(tmp.begin(), tmp.end());
			for (int j = 0; j < tmp.size() && res > 0; j++) {
				if (tmp[j] < 0) {
					tmpans -= tmp[j];
					res--;
				}
			}

			ans = max(ans, tmpans);
		}
		
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N=int(input())

def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)

    return divisors

l=make_divisors(N)
ans=0
for i in range(len(l)):
    num=l[i]-1
    if num==0:
        continue
    if num==1:
        continue
    p=N//num
    q=N%num
    if p==q:
        ans+=num 
print(ans)

Measured memory_bytes: 39024
def main():
  n = int(input())
  s = [input() for i in range(n)]
  nums = [1000 for i in range(26)]
  for i in range(26):
      for j in range(n):
          nums[i] = min(nums[i],s[j].count((chr)(97 + i)))

  for i in range(26):
    while nums[i] > 0:
        print((chr)(97 + i),end = "")
        nums[i] -= 1
  print("")

main()

Measured memory_bytes: 9172