akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include <fstream>
#include<unordered_set>
#include<stack>
#include <map>
#include<unordered_map>
#include<time.h>
#include <chrono>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define all(x) x.begin(),x.end()
using namespace std;
#define MAX 1000001 
#define M 998244353
ll inverse(ll n)
{
	ll modu = M;
	ll m = modu;
	ll a = 0, b = 1;
	if (modu == 1)
		return 0;
	while (n > 1)
	{
		ll quo = n / modu;
		ll temp = modu;
		modu = n % modu, n = temp;
		temp = a;
		a = b - (quo * a);
		b = temp;
	}
	if (b < 0)
		b += m;
	return b;
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22)
		cout << "bust";
	else
		cout << "win";
	return 0;
}

Measured memory_bytes: 256
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
 #include <queue>
 #include <vector>
 #include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;

////////////////いろいろあるよ//////////////////////////////////
int main(){
	int N;
  	string S;
  
  cin >> N >> S;
  int a = S.size();
  int ii = min(a,N);
  REP(i,ii)cout << S[i];
  if(S.size()>N)cout << "...";
  cout << endl;
  
  

    
    
  
}

Measured memory_bytes: 3628
#include <iostream>

int main(){
  int a[5];
  for(int i=0;i<5;i++) std::cin >> a[i];
  int max=0;
  int imax=0;
  for(int i=0;i<5;i++){
    if((10-a[i]%10)>max && (a[i]%10!=0)){
      max=10-a[i]%10;
      imax=i;
    }
  }
  int time=0;
  //  std::cout << a[imax] << std::endl;
  for(int i=0;i<5;i++){
    if(i!=imax) time+=a[i]+9-((a[i]-1)%10);
  }
  time+=a[imax];
  std::cout << time << std::endl;
  return 0;
}


Measured memory_bytes: 256
blue_list = []
red_list = []
diff_list = []

N = int(input())
for _ in range(N):
  blue_list.append(input())
M = int(input())
for _ in range(M):
  red_list.append(input())
  
for word in set(blue_list):
    diff_list.append(blue_list.count(word)-red_list.count(word))
    
print(max(0,max(diff_list)))

Measured memory_bytes: 3188
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val p = (0 until n).map {
        Problem086Point(sc.next().toInt(), sc.next().toInt(), sc.next().toInt())
    }
    println(problem086c(p))
}

fun problem086c(p: List<Problem086Point>): String {
    var current = Problem086Point(0, 0, 0)
    for (pi in p) {
        val xyDiff = Math.abs(current.x - pi.x) + Math.abs(current.y - pi.y)
        val tDiff = Math.abs(current.t - pi.t)
        if (tDiff >= xyDiff && ((xyDiff % 2 == 0 && tDiff % 2 == 0) || (xyDiff % 2 == 1 && tDiff % 2 == 1))) {
            current = pi
            continue
        }
        return "No"
    }
    return "Yes"
}

data class Problem086Point(var t: Int, var x: Int, var y: Int)

Measured memory_bytes: 55504
N,M = map(int,input().split())
T = [[0]*N for i in range(N)]
G = []
for i in range(M):
    a,b = map(lambda x:int(x)-1,input().split())
    T[a][b] = 1
    T[b][a] = 1
    G.append((a,b))

def check(N,T):
    A = [0]*N
    Q = [0]
    while Q:
        q = Q.pop()
        if A[q]:continue
        A[q] = 1
        for c in range(N):
            if T[q][c]:
                Q.append(c)
    return sum(A)!=N

ans = 0
for g in G:
    a,b = g[0],g[1]
    T[a][b] = 0
    T[b][a] = 0
    if check(N,T):
        ans += 1
    T[a][b] = 1
    T[b][a] = 1
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <math.h>

// char 1 = 49
int main(void) {
	char s[11];
	int min = 1000, sum;

	scanf("%s", s);
	for (int i = 2; i < strlen(s); ++i) {

		sum =(int)(s[i - 2] - 48) * 100 + (s[i - 1] - 48) * 10 + s[i] - 48;
		min = (int)fmin(min, abs(sum - 753));
	}

	printf("%d", min);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=4009;
const int md=924844033;
int n,k;
bool vis[N][N];
int ed[N],tot;
int f[N][N][2];
int g[N],fac[N];
int main() {
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) 
		for(int j=0;j<=1;j++) 
			if(!vis[i][j]) {
				int len=0;
				for(int x=i,y=j;x<=n;x+=k,y^=1) 
					vis[x][y]=1,++len;
				ed[tot+=len]=1;
			}
	f[1][0][0]=1;
	for(int i=1;i<=tot;i++) 
		for(int j=0;j<=n;j++) {
			f[i+1][j][0]=(f[i][j][0]+f[i][j][1])%md;
			if(!ed[i]) f[i+1][j+1][1]=f[i][j][0];
		}
	for(int i=0;i<=n;i++) 
		g[i]=(f[tot][i][0]+f[tot][i][1])%md;
	fac[0]=1;
	for(int i=1;i<=n;i++) fac[i]=(ll)fac[i-1]*i%md;
	int ans=fac[n];
	for(int i=1,j=-1;i<=n;i++,j=-j) 
		ans=((ll)ans+md+(ll)j*fac[n-i]*g[i]%md)%md;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 136704
N = int(input())
L, R = 0, N
D = (L + R) // 2
pin = ["" for _ in range(N)]
print(0)
dp = input()
pin[0] = dp[:]
if dp != "Vacant":
    print(D)
    F = 0
    for i in range(18):
        s = input()
        pin[D] = s[:]
        if s == "Vacant":
            break
        else:
            if (L - D) % 2 == 0 and pin[D%N] != pin[L%N]:
                R = D
                D = (L + R) // 2
            elif (L - D) % 2 == 0 and pin[D%N] == pin[L%N]:
                L = D
                D = (L + R) // 2
            elif (R - D) % 2 == 0 and pin[D%N] != pin[R%N]:
                L = D
                D = (L + R) // 2
            elif (R - D) % 2 == 0 and pin[D%N] == pin[R%N]:
                R = D
                D = (L + R) // 2
            elif (L - D) % 2 == 1 and pin[D%N] == pin[L%N]:
                R = D
                D = (L + R) // 2
            elif (L - D) % 2 == 1 and pin[D%N] != pin[L%N]:
                L = D
                D = (L + R) // 2
            elif (R - D) % 2 == 1 and pin[D%N] == pin[R%N]:
                L = D
                D = (L + R) // 2
            elif (R - D) % 2 == 1 and pin[D%N] != pin[R%N]:
                R = D
                D = (L + R) // 2
            print(D)

Measured memory_bytes: 4680
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <limits>
using ll = long long;
using ld = long double;
int MOD = 1e9 + 7;
using namespace std;
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(){
    int n;
    cin>>n;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>vec[i];
    }
    vector<ll> dp(n+3,1e10);
    dp[0]=0;
    for(int i=n-1;i>=0;i--){
        //cout<<lower_bound(dp.begin(),dp.end(),vec[i])-dp.begin()<<endl;
        
        dp[upper_bound(dp.begin(),dp.end(),vec[i])-dp.begin()]=vec[i];
    }
   // cout<<endl;
    for(int i=1;i<=n+1;i++){
      //  cout<<dp[i]<<endl;
        if(dp[i]==1e10){
            cout<<i-1<<endl;
            return 0;
        }
    }
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second

Int INF = 1e18;
//Int mod = 1e9+7;
Int mod = 998244353;

vector<pair<Int, Int>> G[100001];

int main() {
    Int n, m;
    cin >> n >> m;    
    for (Int i = 0; i < m; i++) {
        Int a, b, c;
        cin >> a >> b >> c;
        G[a].emplace_back(b, c);
    }
    for (Int i = 1; i < n; i++) {
        G[i + 1].emplace_back(i, 0);
    }
    vector<Int> d(n + 1, INF);
    d[1] = 0;
    priority_queue<pair<Int, Int>, vector<pair<Int,Int>>, greater<pair<Int, Int>>> q;
    q.push({0, 1});
    while (!q.empty()) {
        pair<Int, Int> p = q.top();
        q.pop();
        Int v = p.se;
        if (d[v] < p.fi) {
            continue;
        }
        for (Int i = 0; i < G[v].size(); i++) {
            pair<Int, Int> to = G[v][i];
            if (d[to.fi] > d[v] + to.se) {
                d[to.fi] = d[v] + to.se;
                q.push({d[to.fi], to.fi});
            }
        }
    }
    dump(d[n] == INF ? -1 : d[n]);
    return 0;
}

Measured memory_bytes: 9340
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  int temp = 0;
  for(int i = 1; i <= n; ++i){
    temp += i;
    if(temp >= n){
      for(int j = i; j > 0; --j){
        if(n - j < 0) continue;
        n -= j;
        cout << j << endl;
      }
      break;
    }
  }
}

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


template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
    for(int i=0;i<vec.size();i++){
        if(i) s << ',';
        else s << '{';
        s <<setw(2)<< vec[i];
    }
    s << '}' << endl;
    return s;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    long long n;
    cin>>n;
    n*=2;
    long long ans = n;
    if(n==2){
        cout<<1<<endl;
        return 0;
    }
    for(long long i=1;i<=sqrt(n);i++){
        if(n%i==0){
            long long a = i,b = n/i;
            if(gcd(a,b)!=1) continue;
            long long x = modinv(b,a);
            if(b*x>1) ans = min(ans,b*x-1);
            long long y = modinv(a,b);
            if(a*y>1) ans = min(ans,a*y-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

const long long mod = 1000ll * 1000 * 1000 + 7;

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

    string s, t;
    cin >> s >> t;

    vector<int> b_s(s.size());
    int cur_b = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') {
            cur_b = (cur_b + 1) % 3;
        } else {
            cur_b = (cur_b + 2) % 3;
        }
        b_s[i] = cur_b;
    }

    vector<int> b_t(t.size());
    cur_b = 0;
    for (int i = 0; i < t.size(); i++) {
        if (t[i] == 'A') {
            cur_b = (cur_b + 1) % 3;
        } else {
            cur_b = (cur_b + 2) % 3;
        }
        b_t[i] = cur_b;
    }


    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--, c--, d--;

        int balance_s = ((b_s[b] - (a ? b_s[a - 1] : 0)) % 3 + 3) % 3;
        int balance_t = ((b_t[d] - (c ? b_t[c - 1] : 0)) % 3 + 3) % 3;
        if (balance_s != balance_t) {
            cout << "NO\n";
        } else {
            cout << "YES\n";
        }
    }

}


Measured memory_bytes: 1744
from itertools import groupby

M = 998244353
n = int(input())
a = map(int, input().split())
r = 0
if next(a) == 0:
    r = p = 1
    for i, (k, g) in enumerate(groupby(sorted(a)), 1):
        if k != i:
            r = 0
            break
        l = sum(1 for _ in g)
        r = r * pow(p, l, M) % M
        p = l
print(r)


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

//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>PII;
typedef vector<PII>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>MP;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
const int mod=1e9+7;
const int sze=1e5+2;
signed main(){
 int a,b,c;
 sl(a);sl(b);sl(c);
 if(a+b+c==17)cout<<"YES"<<endl;
 else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (a[i] > a[i + 1]) {
            if (a[i + 1] >= 1) {
                ans += (a[i + 1] + a[i]) / 2;
                a[i + 1] = (a[i + 1] + a[i]) % 2;
                a[i] = 0;
            } else {
                ans += a[i] / 2;
                a[i] %= 2;
            }
        } else if (a[i] < a[i + 1]) {
            ans += (a[i + 1] + a[i]) / 2;
            a[i + 1] = (a[i + 1] + a[i]) % 2;
            a[i] = 0;
        } else {
            ans += a[i];
            a[i] = a[i + 1] = 0;
        }
    }
    ans += a.back() / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import array

def main():
    n1 = int(input())
    li1 = array.array('l', [int(x) for x in input().split()])
    n2 = int(input())
    li2 = array.array('l', [int(x) for x in input().split()])
    count = 0

    for l in li2:
        if binary_search(li1, l):
            count += 1

    print(count)


def binary_search(li, x):
    if len(li) == 0:
        return False
    
    mid = len(li)//2
    
    k = li[mid]
    if k == x:
        return True
    elif k > x:
        li = li[:mid]
    else:
        li = li[mid+1:]
        
    return binary_search(li, x)

if __name__=='__main__':
    main()


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

map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}
int main() {
	int n; cin >> n;
	auto res = prime_factor(n);
	cout << n << ":";
	for (auto p : res) {
		rep(i, p.second)cout << " " << p.first;
	}
	cout << endl;
}

Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  int A,B;
  cin >> A >> B;
  int ans = max(A+B, A-B);
  ans = max(ans, A*B);
  cout << ans << endl;
}


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

typedef unsigned long long int ll;
typedef long long L;
#define pb push_back

ll binexp(ll a, ll b)
{
    if (b == 0)
        return 1;
    if ((b & 1) == 1)
        return a * binexp(a, b - 1);
    else
    {
        ll u = binexp(a, b >> 1);
        return u * u;
    }
}

int main()
{
//#ifndef ONLINE_JUDGE
  //  freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
//#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //your code starts here
    L n;
    cin >> n;
    if (!(n & 1))
    {
        cout << -1;
        return 0;
    }
    L ans = 1, flag = 0;
	L val=7%n;
    for (L i = 1; i <1e7; i++)
    {
        if(val==0) {
          cout<<i;
          return 0;
        } 
      val=(val*10+7)%n;
    }
    cout<<-1;
//#ifndef ONLINE_JUDGE
  //  cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
//#endif
    return 0;
}


Measured memory_bytes: 3620
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
point = 0
lst = list(set(s))

for i in range(len(lst)):
  tmp = s.count(lst[i]) - t.count(lst[i])
  if tmp > point:
    point = tmp

print(point)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int N = 3003;
int dp[N][N];
string s, p;
int n, m;

int f(int i, int j) {
    if (i == n || j == m) return 0;
    int &r = dp[i][j];
    if (r != -1) return r;
    if (s[i] == p[j]) r = 1+f(i+1, j+1);
    else r = max(f(i+1, j), f(i, j+1));
    return r;
}

string ans;

void build(int i, int j) {
    if (i == n || j == m) return;
    if (s[i] == p[j]) {
        ans.pb(s[i]);
        build(i+1, j+1);
    } else if (f(i, j) == f(i+1, j)) {
        build(i+1, j);
    } else {
        build(i, j+1);
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> s >> p;
    n = s.size();
    m = p.size();
    
    memset(dp, -1, sizeof dp);
    f(0, 0);
    build(0, 0);
    
    cout << ans << endl;
}


Measured memory_bytes: 39160
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
const int maxn=1e5+7;
const ll modn=1e9+7;
const int inf=2e9+7;
const double PI = acos(-1.0);
const double eps=1e-8;
inline int lowbit(int x){return x&-x;}
inline ll lowbit(ll x) {return x&-x;}
inline int CountOneBinary(ll num){int ans=0;while(num){if(num&1) ans+=1;num>>=1;}return ans;}
inline void read(int &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}
inline void read(ll &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}
inline ll qpow(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x%modn;x=x*x%modn;y>>=1;}return ans;}
inline double qpow(double x,ll y){double ans=1;while(y){if(y&1) ans=ans*x;x=x*x;y>>=1;}return ans;}
ll n;
int main()
{
    while(scanf("%lld",&n)==1)
    {
        if(n%2) printf("%lld\n",n*2);
        else printf("%lld\n",n);
    }
}


Measured memory_bytes: 256
from copy import deepcopy

N, M, X = [int(i) for i in input().split()]

CAS = [[int(i) for i in input().split()] for _ in range(N)]


ok = False
mi = [float('inf'), *[0]*(M)]

for i in range(2**N):
  t = [0]*(M+1)
  for j in range(N):
    if (i >> j) & 1:
      t = [a+b for a, b in zip(CAS[j], t)]

  if all(a >= X for a in t[1:]) and mi[0] > t[0]:
    mi = t
    ok = True


if ok:
  print(mi[0])
else:
  print(-1)


Measured memory_bytes: 9248
from sys import stdin
N = int(stdin.readline().rstrip())
# print(N)
L = [int(x) for x in stdin.readline().rstrip().split()]
# print(L)
count = 0
for i in range(N):
  for j in range(i,N):
    if L[j]!=L[i]:
      for k in range(j,N):
        if L[k]!=L[i] and L[k]!=L[j]:
          if L[i] == max(L[i],L[j],L[k]):
            # print('i')
            if L[i]<L[j]+L[k]:
              # print(i+1,j+1,k+1)
              count += 1
          elif L[j] == max(L[i],L[j],L[k]):
            # print('j')
            if L[j]<L[i]+L[k]:
              # print(i+1,j+1,k+1)
              count += 1
          elif L[k] == max(L[i],L[j],L[k]):
            # print('k')
            if L[k]<L[j]+L[i]:
              # print(i+1,j+1,k+1)
              count += 1
print(count)

Measured memory_bytes: 69020
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

  int a,b,c,d;
  cin >> a >> b >> c >> d;
  c-=a;
  d-=b;
  string U = string(d,'U');
  string D = string(d,'D');
  string L = string(c,'L');
  string R = string(c,'R');
  cout << U+R+D+L+"L"+U+"UR"+R+"DR"+D+"DL"+L+"U"<<endl;        
    

return 0;
}
///....


Measured memory_bytes: 256
n = int(input())
a = []
b = []

for i in range(n):
    aa,bb = map(int, input().split())
    a.append(aa)
    b.append(bb)

a.sort()
b.sort()

if n%2 == 1:
    p = a[n//2]
    q = b[n//2]
    ans = q - p + 1

else:
    p1 = a[n//2 -1]
    p2 = a[n//2]
    q1 = b[n//2]
    q2 = b[n//2 - 1]
    p = (p1+p2)*5
    q = (q1+q2)*5 
    ans = (q-p)//5 + 1

print(ans)

Measured memory_bytes: 98992
n=int(input())
a=1
S=[1]*n
for x in range(n):
  print(chr(S[x]+96),end="")
print()
j=1
i=1
while i<n:
  if S[-i]>max(S[:n-i]):
    i=i+1
  else:
    S[-i]+=1
    if i<=j:
      for x in range(n):
        print(chr(S[x]+96),end="")
      print()
      if S==[i for i in range(1,n+1)]:
        exit()
    else:
      j=i
      for k in range(1,i):
        S[-k]=1
      i=1
      j=1
      for x in range(n):
        print(chr(S[x]+96),end="")
      print()

Measured memory_bytes: 5676
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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 (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    string s; cin >> s;
    int len = s.size();
    int ans = 0, gnum = 0;
    // pnum <= gnum
    // 常にgnum>=0
    // gnum>0の時のみpを出せる
    rep(i,len) {
        if (s[i]=='g') {
            if (gnum) {
                // p
                gnum--;
                ans++;
            } else {
                // g
                gnum++;
            }
        } else {
            if (gnum) {
                // p
                gnum--;
            } else {
                gnum++;
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

  int N;
  cin >> N;
  vector<int> cnt(1e5 + 5);
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    sum += a;
    cnt[a]++;
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int B, C;
    cin >> B >> C;
    sum -= 1ll * cnt[B] * B;
    sum += 1ll * cnt[B] * C;
    cnt[C] += cnt[B];
    cnt[B] = 0;
    cout << sum << "\n";
  }
  return 0;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,c=0;
    float x;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        if(i%2!=0)
        {
            c++;
        }
    }

    cout<<double(c*1.0/n*1.0)<<endl;

}


Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++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 all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A,B;
  cin>>A>>B;
  if((A+B)%2==0)
    cout<<(A+B)/2<<endl;
  else
    cout<<"IMPOSSIBLE"<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

ll dp[110][20000];

int main() {
    int N, W; cin >> N >> W;
    rep(i, 110) rep(j, 20000) dp[i][j] = 0;
    rep(i, N) {
        int v, w; cin >> v >> w;
        rep(j, W+1) {
            chmax(dp[i+1][j], dp[i][j]);
            chmax(dp[i+1][j+w], dp[i][j] + v);
        }
    }
    cout << dp[N][W] << endl;
}



Measured memory_bytes: 20296
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main(){
    string S;
    int K;
    cin >> S >> K;
    // n to the power of 5e15 has log_10(n) * 5e15 digits
    double pos = 0.0;
    for (int i = 0; i < S.length(); i++){
        if (S[i] == '1') {
            pos += 1.0;
        }
        else{
            pos += 5000000000000000.0 * log10((double)(S[i] - '0'));
        }
        if (pos >= (double)K){
            cout << S[i] << endl;
            return 0;
        }
    }
    return 0;
}


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

int main()
{
    ll n, k;
    scanf("%lld%lld", &n, &k);

    if(n>k){
        n=n%k;
    }
    printf("%lld",min(n,abs(k-n)));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main (){
    int N,M,p[100000];
    string S[100000];
    bool ac_check[100000];
    bool is_ac[100000];
    for(int i = 0;i<M;i++){
        ac_check[i] = 0;
        is_ac[i] = 0;
    }

    cin >> N;
    cin >> M;
    for(int i = 0;i<M;i++){
        cin >> p[i] >> S[i];
        if(S[i] == "AC"){
            is_ac[p[i]] = 1;
        }   
    }
    int ac = 0;
    int wa = 0;

    for(int i = 0;i<M;i++){
        if(S[i]== "AC"&&!ac_check[p[i]]){
            ac_check[p[i]] = 1;
            ac++;
        }
        if(S[i]== "WA"&&!ac_check[p[i]]&&is_ac[p
        [i]]){
            wa++;
        }
    }
    
    cout << ac << " " << wa << endl;
    
    

    
    return 0;
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N, T, A; cin >> N >> T >> A;
    vector<int> H(N);
    for(int i = 0; i < N; i++)
    {
        cin >> H.at(i);
    }
    int temp = abs(1000*A - 1000*T + H.at(0)*6);
    int ans = 1;
    for(int i = 0 ; i < N; i++)
    {
        if(temp > abs(1000*A - 1000*T + H.at(i)*6) )
        {
            temp = abs(1000*A - 1000*T + H.at(i)*6);
            ans = i + 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// Bubble sort
#include <stdio.h>
#include <stdlib.h>

int main() {
  int i, j;
  int n, tmp;
  int cnt = 0;
  int *a;

  // input the size of an array
  scanf("%d", &n);

  a = (int *)malloc(n * sizeof(int));

  // input the number of an array
  for(i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  // sorting
  for(i = 0; i < n - 1; i++) {
    for(j = n - 1; j > i; j--) {
      if(a[j] < a[j - 1]) {
	tmp = a[j];
	a[j] = a[j - 1];
	a[j - 1] = tmp;
	cnt++;
      }
    }
  }

  // output
  for(i = 0; i < n; i++) {
    printf("%d", a[i]);
    if(i != n - 1) printf(" ");
    else printf("\n");
  }
  printf("%d\n", cnt);
  
  return 0;
}



Measured memory_bytes: 2124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJ1_8_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string STR = Console.ReadLine();
                double str = 0;
                if (STR == "0") break;
                else
                { 
                    for (long i = 0; i < STR.Length; i++)
                    {
                        str += double.Parse(STR.Substring(int.Parse(i.ToString()), 1));
                    }
                }
                Console.WriteLine(str);
            }
        }
    }
}



Measured memory_bytes: 18016
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long 
#define FF first
#define SS second
#define MOD 1000000007

using namespace std;

int gcd(int a, int b) {
  while (a > 0 && b > 0)
    if (a > b) a %= b;
    else b %= a;
  return a + b;
}

ll modpower(ll x, ll y, ll p) //x^y mod p
{
    ll res = 1;      // Initialize result
 
    x = x % p;  // Update x if it is more than or 
                // equal to p
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y %2!= 0)
            res = (res*x) % p;
 
        // y must be even now
        y = y/2;
        x = (x*x) % p;  
    }
    return res;
}

int visited[100001]={0};
set<int> ms;
void dfs(int src, vector< vector< int> > &graph)
{
	for(int i=0;i<graph[src].size();i++)
	{
		int u = graph[src][i];
		if(visited[u]==0)
		{
			visited[u]=1;
			ms.insert(u);
			dfs(u,graph);
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	vector<vector<int>> graph(n+1);
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		graph[x].pb(y);
		graph[y].pb(x);
	}
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		if(visited[i]==0)
		{
			ms.clear();
			ms.insert(i);
			visited[i]=1;
			dfs(i,graph);
			for(auto it = ms.begin();it!=ms.end();it++)
			{
				if(ms.find(arr[*it]-1)!=ms.end())
				{
					ans++;
				}
			}
		}
	}
	cout<<ans;

}










Measured memory_bytes: 14208
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>
// #include "utiltime.hpp"

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define printmx(matrix) Loop(i, matrix.size()) { Loop(j, matrix[i].size()) { cout << matrix[i][j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(double x) { ll m = (ll)sqrt(x); return m + (m * m <= (ll)(x) ? 0 : -1); }
ll ceilsqrt(double x) { ll m = (ll)sqrt(x); return m + ((ll)x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }

/*******************************************************/

int main() {
	string s; cin >> s;
	if (s.substr(0, 4) == "YAKI") cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;
  
int main()
{
    cin.tie(0);
    ios::ios_base::sync_with_stdio(false);
    int N, W, H;
    cin >> N >> W >> H;
    vector<bool> w((W << 1) + 1, false), h((H << 1) + 1, false);
    int x, y, r;
    for (int i = 0; i < N; ++i) {
        cin >> x >> y >> r;
        fill(w.begin() + max(0, (x - r) << 1), w.begin() + min(W << 1, (x + r) << 1) + 1, true);
        fill(h.begin() + max(0, (y - r) << 1), h.begin() + min(H << 1, (y + r) << 1) + 1, true);
    }
    for (int j = 1; j <= (W << 1) - 1; j += 2) {
        if (w[j])continue;
        for (int k = 1; k <= (H << 1) - 1; k += 2) {
            if (!h[k]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1252
import numpy as np
N = int(input())
A = []
B = []
for i in range(N):
    in1, in2 = list(map(int,input().split()))
    A.append(in1)
    B.append(in2)
temp1 = np.median(A)
temp2 = np.median(B)
if N % 2 == 0:
    ans = (temp2 - temp1) * 2 + 1
else:
    ans = (temp2 - temp1) + 1
print(int(ans))

Measured memory_bytes: 45920
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

int main() {
	int n, u, k, v;
	cin >> n;
	vector<int> ans(n,1000000000);
	vector<vector<int>> adj(n);
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		while (k--)cin >> v, adj[u-1].push_back(v-1);
	}
	queue<pair<int, int>> q;//<idx,path>
	q.push(pair<int, int>(0, 1));
	while (!q.empty()) {
		auto tmp = q.front(); q.pop();
		ans[tmp.first] = min(ans[tmp.first], tmp.second);
		if (ans[tmp.first] != tmp.second)continue;
		for (int i = 0; i < adj[tmp.first].size(); i++) q.push(pair<int, int>(adj[tmp.first][i], tmp.second+1));
	}
	for (int i = 0; i < n; i++)	cout << i + 1 << " " << (ans[i] == 1000000000 ? -1 : ans[i]-1) << endl;
	
}

Measured memory_bytes: 3988
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int C[] = new int[N];
		int A[][] = new int[N][M];
		for(int i = 0; i < N; i++) {
			C[i] = sc.nextInt();
			for(int j = 0; j < M; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		
		int ans = Integer.MAX_VALUE;
		out : for (int i = 0; i < (Math.pow(2, N)); i++) {
			int temp = 0;
			int a[] = new int[M];
			for (int j = 0; j < N; j++) {
				if ((1&i>>j) == 1) {
					temp += C[j];
					for(int k = 0; k < M; k++) {
						a[k] += A[j][k];
					}
				}
			}
			for(int k = 0; k < M; k++) {
				if(a[k] < X) {
					continue out;
				}
			}
			ans = Math.min(ans, temp);
		}
		if(ans == Integer.MAX_VALUE) {
			System.out.println(-1);
		} else {
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 37324
#include<iostream>
using namespace std;
int main(){
        int n,q,r=0;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++) cin>>a[i];
        cin>>q;
        int b[q];
        for(int i=0;i<q;i++) cin>>b[i];
        for(int i=0;i<q;i++) {
                int low=0,hi=n-1,mid;
                while(low<hi){
                        mid = (low+hi)/2;
                        if(a[mid]<b[i]) low = mid+1;
                        else hi =mid;
                }
                if(a[low]==b[i]) r++;
        }
        cout<<r<<endl;
        return 0;
}


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

int main(){
	int n;
	scanf("%d",&n);
	int arr[100];
	long long ans=0;
	for(int i=0;i<n;i++){
		scanf("%d",&arr[i]);
	}
	
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			ans+=(long long)((long long)arr[i]*(long long)arr[j]);
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 256
from fractions import gcd

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

a, b = nm()

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



ps = prime_factorize(gcd(a,b))

print(len(ps))

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

	int main(){
      int N;
      cin >> N;
      int T[N];
      int S=0;
      for (int i;i<N;i++){
        cin >> T[i];
        S+=T[i];
      }
      int M;
      cin >> M;
      int P,X;
      for (int i;i<M;i++){
        cin >> P >> X;
        cout << S+X-T[P-1] <<endl;
      }
    }


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

int main()
{
	int n;
	string s;
	cin >> n >> s;
	int ans = 0, cnt = 0;
	for(auto c : s){
		if(c == 'I') ans = max(ans, ++cnt);
		else --cnt;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

int a[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    ll ans  = 0;
    for(int i = 0; i < n - k; i++) ans += a[i];
    cout << ans;

    return 0;
}


Measured memory_bytes: 4360
// ARC089
// D - Practical Skill Test

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int INF = 1e9;
const int MAX_W = 300, MAX_H = 300;
const int MAX_D = MAX_W * MAX_H;

template <typename T>
class BIT {
public:
    vector<T> b;
    int n;
    void init(int num);
    T sum(int i);
    void add(int i, T x);
};

template <typename T>
void BIT<T>::init(int num) {
    n = num;
    b.clear();
    b.resize(n + 1);
    return;
}

template <typename T>
T BIT<T>::sum(int i) {
    T s = 0;

    for (; i > 0; i -= i & -i) {
        s += b[i];
    }
    return s;
}

template <typename T>
void BIT<T>::add(int i, T x) {
    for (; i <= n; i += i & -i) {
        b[i] += x;
    }
    return;
}

int operator-(pii p0, pii p1) {
    return abs(p0.first - p1.first) + abs(p0.second - p1.second);
}

int H, W, D;
int Q;
map<int, pii> n2l;
BIT<int> bit[MAX_D];

int main() {
    cin >> H >> W >> D;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int a;
            cin >> a;
            n2l[a - 1] = pii(i, j);
        }
    }
    for (int d = 0; d < D; d++) {
        bit[d].init(H * W / D + 1);
    }

    for (int d = 0; d < D; d++) {
        pii pre_hw, hw;
        hw = n2l.at(d);
        for (int n = d; n + D < H * W; n += D) {
            pre_hw = hw;
            hw = n2l.at(n + D);
            bit[d].add(n / D + 1, hw - pre_hw);
        }
    }

    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;

        int ans = bit[l % D].sum(r / D + 1 - 1) - bit[l % D].sum(l / D + 1 - 1);
        cout << ans << endl;
    }

    return 0;
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {

    string s;
    cin>>s;
    cout << s[0]<<s.size()-2<<s[s.size()-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ff;
typedef long long unsigned ul;
#define pf printf
#define sf scanf
#define mp make_pair
#define pb push_back
#define pfds(a) pf("%lld ",(a))
#define pfdn(a) pf("%lld\n",(a))
#define pffs(a) pf("%Lf ",(a))
#define pffn(a) pf("%Lf\n",(a))
#define pfss(a) pf("%s ",(a))
#define pfsn(a) pf("%s\n",(a))
#define scd(a) sf("%lld",&(a))
#define scf(a) sf("%Lf",&(a))
#define scs(a) sf("%s",(a))
#define scc(a) sf("%c",&(a))
#define FORF(i,a) for(ll (i)=0;(i)<(a);(i)+=1)
#define FORD(i,a) for(ll (i)=(a);(i)>=0;(i)-=1)
#define FORF2(i,a,b) for(ll (i)=(a);i<(b);(i)+=1)
#define FORD2(i,a,b) for(ll (i)=(a);i>=(b);(i)-=1)
#define max3(a,b,c) a>b?a>c?a:c:b>c?b:c
#define min3(a,b,c) a<b?a<c?a:c:b<c?b:c
void to_binary(int n){ if(!n) return; to_binary(n>>1); printf("%d",n&1 ? 1 : 0); }
const ul mod = 1e9+7;
const int size = 1e5 + 3;
int main()
{
	ll n;scd(n);
	ll arr[size],count[size]={0};
	FORF2(i,1,n+1) scd(arr[i]);
	FORF2(i,1,n+1)
	{
		count[arr[i]-1]+=1;
		count[arr[i]+1]+=1;
		count[arr[i]]+=1;
	}
	ll maxi=INT_MIN;
	FORF(i,size) maxi=max(maxi,count[i]);
	pfdn(maxi);
	return 0;
}

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

struct Edge {
    int from, to, cost;
    Edge (int from_, int to_, int cost_) {
        from = from_;
        to = to_;
        cost = cost_;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<P>> to(n);
    vector<Edge> e;
    int to_, from, cost;
    rep(i,m) {
        cin >> from >> to_ >> cost;
        from--; to_--;
        to[from].emplace_back(cost, to_);
        to[to_].emplace_back(cost, from);
        e.emplace_back(from, to_, cost);
    }

    int ans = 0;
    for (auto edge: e) {
        // スタート
        int sn = edge.from;
        // スタートからiまでの最小コスト
        vector<int> dp(n, INF);
        dp[sn] = 0;
        // 次に見るノードとこれまでの累計コストを入れる（昇順）
        priority_queue<P, vector<P>, greater<P>> pq;
        pq.emplace(0, sn);
        P c;
        while (!pq.empty()) {
            // 累計コストが最も小さいノードに移動
            c = pq.top();
            pq.pop();
            // もし現在のノードのコストが古いもので
            // すでにほかの経路で更新済みだったら次のノードへ移動
            if (dp[c.second] < c.first) continue;
            // 隣接ノードを見る
            for (auto n: to[c.second]) {
                // 最小コストが更新できるか確認
                if (dp[n.second] > dp[c.second] + n.first) {
                    dp[n.second] = dp[c.second] + n.first;
                    // 更新出来たら次に見るノードの候補に入れる
                    pq.emplace(dp[n.second], n.second);
                }
            }
        }

        if (dp[edge.to] < edge.cost) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
N = int(input())
L = list(map(int, input().split()))
count =0
for v in itertools.combinations(L, 3):
    a=v[0]
    b=v[1]
    c=v[2]
    if a+b> c and b+c >a and c+a>b:
        if a!=b and b!=c and c!=a:
            count+=1

print(count)

Measured memory_bytes: 9168
#include <iostream>
#include <vector>
#include <algorithm> 
#include <queue>
#include <functional>
#include <map>
#include <string>
using namespace std;




int main(void){

    int n;

    long mina = 0;
    int minb = 1000000005;

    cin >> n;

    for (int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        if (b < minb){
            minb = b;
            mina = a;
        }
    }


    while (minb >= 1){
        mina++;
        minb--;
    }

    cout << mina << endl;



}

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

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");
        int[] A = new int[n];
        for(int i = 0; i < n; i++){
            A[i] = Integer.parseInt(input[i]);
        }
        int changeBox = 0;

        for(int i = 0; i < n; i++){
            if(i == n - 1){
                System.out.println(A[i]);
            }else{
                System.out.print(A[i] + " ");
            }
        }
        for(int i = 1; i < n; i++){
            changeBox = (A[i]);
            int j = i - 1;
            while(j >= 0 && changeBox < (A[j])){
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = changeBox;
            for(int k = 0; k < n; k++){
                if(k == n - 1){
                    System.out.println(A[k]);
                }else{
                    System.out.print(A[k] + " ");
                }
            }
        }
    }
}

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

using namespace std;

int main(){
        int X,b,p,max=0;
        cin >> X;
        if (X < 4) max=1;
        else{
        for (b = 2; b <= (int)sqrt(X)+1; b++){
                //cout << "b : " << b << endl;
                for (p = 2; pow(b,p) <= X; p++){
                        //cout << "pow" << pow(b,p) << endl;
                }
                p--;
                if (max < pow(b,p)) max = pow(b,p);
        }
        }
        cout << max << endl;

        return 0;
}


Measured memory_bytes: 384