akhauriyash/Code-Regression huggingface dataset:
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)

int count(int N)
{

        int cnt = 0;
        while (N)
        {
                cnt++;
                N /= 10;
        }
        return cnt;
}

int main()
{
        ll N;
        cin >> N;
        int ans = count(N);
        for (ll A = 1LL; A*A <=N; A++)
        {
                if (N % A != 0)
                        continue;
                ll B = N / A;

                int tmp = max(count(A), count(B));
                ans = min(ans, tmp);
        }

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n, k; cin >> n >> k;

	vector<bool> ms(n + 1);
	FOR_LT(i, 0, k) {
		int d; cin >> d;
		REP(d) {
			int a; cin >> a;
			ms[a] = true;
		}
	}

	int ans = 0;
	FOR_LE(i, 1, n) {
		if (!ms[i]) ans++;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 3656
using System;
class Program
{
    static void Main(string[] args)
    {
        // 整数の入力
        long initialMoney = long.Parse(Console.ReadLine());

        long money = 100;
        int year = 0;
        long rate = 0;

        while (money < initialMoney)
        {
            rate = money /100;
            money = money + (long)rate;
            year++;
        }

        Console.WriteLine(year);
    }
}

Measured memory_bytes: 27536
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < int(n);++i)
#define pb push_back
#define vi vector<int>
#define pll pair<ll,ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define ff first
#define ss second

void solve() {

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    /*ll t = 1;
    cin >> t;
    while (t--) {
        solve();
    }*/
    ll n;
    cin >> n;
    vi a(n);
    for(auto &i: a){
        cin >> i;
    }
    ll ch = a[0];
    ll cnt = 0;
    ll ans = 0;
    for(int i = 1; i<n;++i){
        ch = a[i - 1];
        if(i < n && ch >= a[i]){
            cnt++;
        }else{
            ans = max(cnt,ans);
            cnt = 0;
        }

    }
    ans = max(cnt,ans);
    cout << ans;
    return 0;
}


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

int main(int argc, char const *argv[]) {
    int N, L, sum=0, rem;
    cin >> N >> L;

    vector<int> taste(N);
    for (int i=0; i<N; i++) {
        taste.at(i) = L+i;
    }

    sum = (L+L+N-1)*N/2;

    if (L<0) {
        if (L+N-1>0) {
            rem = 0;
        } else {
            rem = L+N-1;
        }
    } else {
        rem = L;
    }

    cout << sum - rem << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int nish[4005][4005];
int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
  
  //  rest();
    int t=1;
    while(t--)
    {
      
      int count;
      cin>>count;
      string str;
      cin>>str;
      long long int ans=0;
      vector<int>res1(count+1,0);
      vector<int>res2(count+1,0);
      vector<int>res3(count+1,0);

      for(int i=1;i<=count;i++)
      {
        if(str[i-1]=='R'){
          res1[i]=max(res1[i],res1[i-1]+1);
          res2[i]=res2[i-1];
          res3[i]=res3[i-1];
        }
        else if(str[i-1]=='G'){
          res2[i]=max(res2[i],res2[i-1]+1);
          res1[i]=res1[i-1];
          res3[i]=res3[i-1];
        }
        else if(str[i-1]=='B'){
          res3[i]=max(res3[i],res3[i-1]+1);
          res2[i]=res2[i-1];
          res1[i]=res1[i-1];
        }

      }

      for(int i=0;i<count-2;i++)
      {
        for(int j=i+1;j<count-1;j++)
        {
          if((str[i]=='R' && str[j]=='G')|| (str[i]=='G' && str[j]=='R'))
          {
            int temp=j+(j-i);
            nish[i][j]+=temp<count?(str[temp]!='B'?res3[count]-res3[j+1]:res3[count]-res3[j+1]-1):res3[count]-res3[j+1];
          }
          else if((str[i]=='G' && str[j]=='B')|| (str[i]=='B' && str[j]=='G'))
          {
             int temp=j+(j-i);
            nish[i][j]+=temp<count?(str[temp]!='R'?res1[count]-res1[j+1]:res1[count]-res1[j+1]-1):res1[count]-res1[j+1];
          }
          else if((str[i]=='B' && str[j]=='R')|| (str[i]=='R' && str[j]=='B'))
          {
             int temp=j+(j-i);
            nish[i][j]+=temp<count?(str[temp]!='G'?res2[count]-res2[j+1]:res2[count]-res2[j+1]-1):res2[count]-res2[j+1];
          }
        }
      }
       //long long int ans=0;
       for(int i=0;i<count;i++)
       {
        for(int j=0;j<count;j++)
        {
          ans+=nish[i][j];
        }
       }

       //cout<<ans<<endl;



       cout<<ans<<endl;

    }

return 0;

}

Measured memory_bytes: 48872
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main() {
 scanf("%d %d %d %d",&a,&b, &c, &d);
  if ((a + b) > (c + d)) {
    puts("Left");
  }
  else if ((a + b) < (c + d)) {
    puts("Right");
  }
  else {
  	puts("Balanced");
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string a;
int i;
int main()
{
    cin>>a;
    for(i=1;i<a.size();i++)
    {
        if(a[i]==a[i-1])
        {
            cout<<"Bad\n";
            return 0;
        }
    }
    cout<<"Good\n";
    return 0;
}


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

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	static final long INF = (long) 1e+17;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		sc.close();
		System.exit(0);
	}

	void solve() {
		int N = nextInt(); // N個の町
		int M = nextInt(); // M本の道
		long L = nextLong(); // 燃料タンクの容量

		long[][] fuel = new long[305][305];
		long[][] dist = new long[305][305];
		int[] A = new int [100000];
		int[] B = new int [100000];
		int[] C = new int [100000];
		int[] s = new int[105000];
		int[] t = new int[105000];
		for(int i=1;i<=M;i++) {
			A[i]=nextInt();
			B[i]=nextInt();
			C[i]=nextInt();
		}
		int Q = nextInt();

		for(int i=1;i<=Q;i++) {
			s[i] = nextInt();
			t[i] = nextInt();
		}

	    for(int i = 1; i <= N; i++) {
	        for(int j = 1; j <= N; j++) {
	            fuel[i][j] = INF;
	            dist[i][j] = INF;
	        }
	        fuel[i][i] = 0;
	        dist[i][i] = 0;
	    }

	    for(int i = 1; i <= M; i++) {
	    	fuel[A[i]][B[i]] = Math.min(fuel[A[i]][B[i]], C[i]);
	    	fuel[B[i]][A[i]] = Math.min(fuel[B[i]][A[i]], C[i]);
	    }
	    for(int i = 1; i <= N; i++) {
	        for(int j = 1; j <= N; j++) {
	            for(int k = 1; k <= N; k++) {
	            	fuel[j][k] = Math.min(fuel[j][k], fuel[j][i] + fuel[i][k]);
	            }
	        }
	    }
	    for(int i = 1; i <= N; i++) {
	        for(int j = 1; j <= N; j++) {
	            if(i == j) continue;
	            if(fuel[i][j] <= L) dist[i][j] = Math.min(dist[i][j], 1L);
	        }
	    }
	    for(int i = 1; i <= N; i++) {
	        for(int j = 1; j <= N; j++) {
	            for(int k = 1; k <= N; k++) {
	            	dist[j][k] = Math.min(dist[j][k], dist[j][i] + dist[i][k]);
	            }
	        }
	    }
	    for(int i = 1; i <= Q; i++) {
	        if(dist[t[i]][s[i]] < INF) out.println(dist[t[i]][s[i]] - 1);
	        else out.println(-1);
	    }
	}
  
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

}

Measured memory_bytes: 66728
#include <cstdio>
using namespace std;

int main() {
  int N, K; scanf("%d %d", &N, &K);
  int A[100000]; for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  printf("%d\n", (N + K - 3) / (K - 1));
  return 0;
}


Measured memory_bytes: 512
N = int(input())
H = list(map(int, input().split()))
H = [0] + H
dp = [0] * (N + 1)
dp[1] = 0
dp[2] = abs(H[2] - H[1])

for i in range(3, N+1):
    dp[i] = min(dp[i-2] + abs(H[i-2] - H[i]), dp[i-1] + abs(H[i-1] - H[i]))

print(dp[N])

Measured memory_bytes: 20468
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	int sum=0;
	int ans=0;
	int sss=0;
	int ss=0;
	while(n--){
		string s;
		cin>>s;
		if(s=="AC"){
			sum++;
		}else if(s=="WA"){
			ans++;
		}else if(s=="RE"){
			sss++;
		}else{
			ss++;
		}
	}
	cout<<"AC x "<<sum<<endl;
	cout<<"WA x "<<ans<<endl;
	cout<<"TLE x "<<ss<<endl;
	cout<<"RE x "<<sss<<endl;
	return 0;
}
/*
AC x 3
WA x 1
TLE x 2
RE x 0

*/

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793



int main(){
  int N; cin >> N; int n = N*N;
  int id[N][N]; int d[N][N];
  rep(i, N){
    rep(j, N){
      d[i][j] = min({i, N-1-i, j, N-1-j});
    }
  }
  int P[n];
  rep(i, n){
    cin >> P[i]; P[i]--;
    id[P[i]/N][P[i]%N] = i;
  }
  queue<pair<int, int>>q;
  int ans = 0;
  //cout << d[1][1] << endl;
  rep(k, n){
      int i = P[k]/N, j = P[k]%N;
      ans+=d[i][j];
      int dd[5] = {-1, 0, 1, 0, -1};
      rep(ii, 4){
        int nx = i+dd[ii]; int ny = j+dd[ii+1];
        if(nx<0 || ny<0 || nx>=N || ny>=N) continue;
        q.push({nx, ny});
        d[nx][ny] = min(d[nx][ny], d[i][j]);
      }
    //cout << d[1][1] << " " << P[k] << endl;
      while(!q.empty()){
        auto p = q.front(); q.pop();
        int f = p.first, s = p.second;
        rep(ii, 4){
          int nx = f+dd[ii]; int ny = s+dd[ii+1];
          if(nx<0 || ny<0 || nx>=N || ny>=N) continue;
          int dis = d[f][s] + (id[f][s]>id[i][j]);
          if(dis<d[nx][ny]){
            d[nx][ny] = dis;
            q.push({nx, ny});
          }
        }
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6520
#include<iostream>
#include<sstream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stack>
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
char mp[2005][2005];
int l[2005][2005], r[2005][2005], h[2005][2005], b[2005][2005];
int n, m, ans;
int main()
{
	while (~scanf("%d%d", &n, &m))
	{
		ans = 1;
		memset(h, 0, sizeof(l));
		memset(b, 0, sizeof(l));
		memset(l, 0, sizeof(l));
		memset(r, 0, sizeof(l));
		for (int i = 1; i <= n; i++)
		{
			scanf("%s", mp[i] + 1);
			for (int j = 1; j <= m; j++)
			{
				if (mp[i][j] == '.')
				{
					h[i][j] = h[i - 1][j] + 1; 
					l[i][j] = l[i][j - 1] + 1;
				}
			}
		}
		for (int i = n; i >= 1; i--)
		{
			for (int j = m; j >= 1; j--)
			{
				if (mp[i][j] == '.')
				{
					b[i][j] = b[i + 1][j] + 1; 
					r[i][j] = r[i][j + 1] + 1;
					ans = max(ans, h[i][j] + b[i][j] + l[i][j] + r[i][j] - 3);
					//cout << i << " " << j << " " << l[i][j] << " " << r[i][j] << " " << h[i][j] << " " << b[i][j] << "*"; 
				}
			}
			//cout << endl;
		}
		
		printf("%d\n", ans);
	}
}

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

int main(void){
	int n,card[4][3][10]={},b,f,r,v;
  
  cin>>n;
  for (int i=0;i<n;i++){
  	cin>>b>>f>>r>>v;
    b--;
    f--;
    r--;
    card[b][f][r]+=v;
  }
  
  for (int i=0;i<4;i++){
    if (i!=0) cout<<"####################"<<endl;
   for (int j=0;j<3;j++){
     for (int k=0;k<10;k++){
       cout<<' '; 
       cout<<card[i][j][k];
     }
     cout<<endl;
   }
    
  }
	return 0;
}


Measured memory_bytes: 3080
import sys

n, m, *ab = map(int, sys.stdin.read().split())
ab = sorted(zip(*[iter(ab)] * 2))

def main():
    cost = 0
    r = m
    for a, b in ab:
        if b <= r:
            cost += a * b
            r -= b
        else:
            cost += a * r
            break
    return cost

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 25828
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll N, M, Q;
ll sum[501][501];

void CumulativeSum2() {
    for (ll i = 0; i < N+1; i++) {
        for (ll j = 1; j < N+1; j++) {
            sum[i][j] += sum[i][j - 1];
        }
    }
    for (ll j = 0; j < N+1; j++) {
        for (ll i = 1; i < N+1; i++) {
            sum[i][j] += sum[i - 1][j];
        }
    }
}

ll getSum2(ll x1, ll y1, ll x2, ll y2) {
    if (x1 == 0 && y1 == 0) return sum[y2][x2];
    else if (x1 == 0) return sum[y2][x2] - sum[y1 - 1][x2];
    else if (y1 == 0) return sum[y2][x2] - sum[y2][x1 - 1];
    else return sum[y2][x2] - sum[y1 - 1][x2] - sum[y2][x1 - 1] + sum[y1 - 1][x1 - 1];
}

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

    REP(i, 0, M){
        ll l, r;
        cin>>l>>r;
        sum[r][l]++;
    }
  
    CumulativeSum2();

    REP(i, 0, Q){
        ll p, q;
        cin>>p>>q;
        cout<<getSum2(p, p, q, q)<<endl;
    }

    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto v : m) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << ", " << p.second << "]";
  return os;
}
std::map<long long, long long> primeFactorization(long long n) {
  // 素因数分解
  std::map<long long, long long> pf;
  for (long long i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      n /= i;
      ++pf[i];
    }
  }
  if (n > 1) {
    ++pf[n];
  }
  return pf;
}


int main() {
  LL N, M;
  cin >> N >> M;
  auto pc = primeFactorization(M);
  DUMP(pc);
  VEC<LL> s;
  s.push_back(1);
  for (auto v : pc) {
    int siz = s.size();
    REP(k, 0, siz) {
      LL sum = s[k];
      REP(i, 0, v.second) {
        sum *= v.first;
        s.push_back(sum);
      }
    }
  }
  LL ma = 0;
  REP(i, 0, s.size()) {
    if (s[i] >= N) {
      ma = max(ma, M / s[i]);
    }
  }
  cout << ma << endl;

  return 0;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def same(self, x, y):
        return self.find(x) == self.find(y)
N,M = map(int,input().split())
p = list(map(int,input().split()))
q = UnionFind(N)

for _ in range(M):
    x,y = map(int,input().split())
    q.union(x-1,y-1)
cnt = 0
for i in range(N):
    if q.same(i,p[i]-1):
        cnt += 1
print(cnt)


Measured memory_bytes: 83320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        ++mp[s];
    }
    int m;
    cin >> m;
    rep(i, m) {
        string s;
        cin >> s;
        --mp[s];
    }
    int ans = 0;
    for ( auto tmp_mp : mp ) {
        ans = max(ans, tmp_mp.second);
    }
    cout << ans << endl;
    return 0;
}

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


int main()
{
    int N;
    cin >> N;
    vector<int> a(N), b(N);
    for( int i = 0; i < N; ++i ) cin >> a[i];
    for( int i = 0; i < N; ++i ) cin >> b[i];

    int ans = 0;
    // 各bit k ごとに値を決定していく
    for( int k = (1 << 28); k > 0; k = (k >> 1) ){
        for( int i = 0; i < N; ++i  ){  // k+1 bitより上は考える必要がない
            a[i] %= 2*k;
            b[i] %= 2*k;
        }
        sort( b.begin(), b.end() );
        long sum = 0;
        for( int i = 0; i < N; ++i ){  // a[i] を固定して k bit目が1のものの個数を求める
            sum += lower_bound(b.begin(), b.end(), 2*k-a[i]) - lower_bound(b.begin(), b.end(), k-a[i]);
            sum += lower_bound(b.begin(), b.end(), 4*k-a[i]) - lower_bound(b.begin(), b.end(), 3*k-a[i]);
        }
        //if(sum) cout << k << " " << sum << endl;
        ans += k * (sum % 2);
    }
    cout << ans << endl;

    return 0;
}

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



int main(){
    ll X ,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A,0);
    vector<ll> q(B,0);
    vector<ll> r(C,0);

    for(int i = 0; i < A; i++) cin >> p[i];
    for(int i = 0; i < B; i++) cin >> q[i];
    for(int i = 0; i < C; i++) cin >> r[i];

    sort(p.begin() ,p.end(),greater<ll>());
    sort(q.begin() ,q.end(),greater<ll>());
    sort(r.begin() ,r.end(),greater<ll>());
    for(int i = 0; i < A - X; i++) p.pop_back();
    for(int i = 0; i < B - Y; i++) q.pop_back();
    p.insert(p.end(),q.begin(),q.end());
    p.insert(p.end(),r.begin(),r.end());
    sort(p.begin() ,p.end(),greater<ll>());
    ll ans = 0;
    for(int i = 0; i < X + Y; i++) ans += p[i];

    cout << ans << endl;

}



Measured memory_bytes: 8480
#include<bits/stdc++.h>
#define L long long
using namespace std;
int m,x[210],p;
L n;
inline void dfs(L n)
{
    if(n==1)
      return;
    if(n&1)
      {
       int u=++p;
       dfs(n-1);
       x[++m]=u;
      }
    else
      {
       x[++m]=++p;
       dfs(n/2);
      }
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i;
	cin>>n;
	n++;
	dfs(n);
	printf("%d\n",2*m);
	for(i=1;i<=m;i++)
	  printf("%d ",i);
	for(i=1;i<=m;i++)
	  printf("%d ",x[i]);
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter
readline = sys.stdin.buffer.readline

s = readline().rstrip().decode('utf-8')
n = len(s)
m = 2019
lst1 = [0]*len(s)
res = ""
for i in range(n):
    res = int(str(res)+s[i])
    res %= m
    lst1[i] = res
 
ans = 0
 
if m == 2 or m == 5:
    for i in range(n):
        if lst1[i] == 0:
            ans += i+1
 
 
else:
    s = s[::-1]
    dig = 1
    lst1 = [0]*n
    for i in range(n):
        if i == 0:
          lst1[i] = int(s[i])%m
          continue
          
        dig *= 10
        dig %= m
        lst1[i] = lst1[i-1] + dig*int(s[i])
        lst1[i] %= m
    c = Counter(lst1)
    #zero sum range
    for i in c.values():
        #余りがその値だった時の個数iについて、割った値が0になる状態数はi*(i-1)//2
        ans += i*(i-1)//2
    ans += c[0]#割った余りが0の時はもちろん条件を満たす
print(ans)

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

int main(void) {
    int n;
    string s;
    while (cin >> n, n) {
        int l=0, r=0, state=0;
        int score=0;
        for(int i=0; i<n; i++) {
            cin >> s;
            //cout << "[" << s << "]";
            if (s[0] == 'l') { l = (s[1] == 'u' ? 1 : 0); }
            if (s[0] == 'r') { r = (s[1] == 'u' ? 1 : 0); }
            //cout << "{" << l << r << "}";
            if (l==1 && r==1) { if(state==0){ score++; } state = 1; }
            if (l==0 && r==0) { if(state==1){ score++; } state = 0; }
        }
        cout << score;
        cout << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

vll a;
lli k;

int main(){
  a = vll(3);
  cin >> a[0] >> a[1] >> a[2];
  cin >> k;
  for(lli i = 0;i < k;i++){
    a[max_element(a.begin(),a.end())-a.begin()] *= 2;
  }
  cout << accumulate(a.begin(),a.end(),0ll) << endl;
}


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

int main() {
	string S;
	long long K;
	cin >> S >> K;
	vector<vector<vector<long long> > > DP(K + 1, vector<vector<long long> >(S.size() + 1, vector<long long>(S.size() + 1, 0)));
	for (int k = 0; k <= K; k++) {
		for (int L = 0; L < S.size(); L++) {
			for (int R = S.size(); R > L; R--) {
				if (S[L] == S[R - 1]) DP[k][L + 1][R - 1] = max(DP[k][L + 1][R - 1], DP[k][L][R] + 2);
				else if (k != K) DP[k + 1][L + 1][R - 1] = max(DP[k + 1][L + 1][R - 1], DP[k][L][R] + 2);
				DP[k][L][R - 1] = max(DP[k][L][R - 1], DP[k][L][R]);
				DP[k][L + 1][R] = max(DP[k][L + 1][R], DP[k][L][R]);
				if (k != K) DP[k + 1][L][R] = max(DP[k + 1][L][R], DP[k][L][R]);
			}
		}
	}
	long long ANS = 0;
	for (int L = 0; L < S.size(); L++) {
		for (int R = S.size(); R >= L; R--) {
			ANS = max(ANS, DP[K][L][R]);
			if (R == L + 1) ANS = max(ANS, DP[K][L][R] + 1);
		}
	}
	cout << ANS << endl;
}

Measured memory_bytes: 216832
#include<bits/stdc++.h>
#define maxn 100010
#define pii pair<int,int>
using namespace std;
string s;
int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    int n;
    cin>>s;
    n=s.length();
    int f=0;
    for(int i=0;i<n/2;i++)
        if(s[i]!=s[n-2-i])f=1;
    if(s[n-1]!='0')f=1;
    if(s[0]!='1')f=1;
    if(f)
    {
        cout<<-1<<endl;
        exit(0);
    }
    s="0"+s;
    for(int i=n/2+1;i<n;i++)cout<<n<<" "<<i<<'\n';
    int x=n;
    int c=n/2;
    while(c>0)
    {
        while(c>0&&s[c]=='0')
        {
             cout<<x<<" "<<c<<'\n';
             c--;
        }
        if(c==0)break;
        cout<<x<<" "<<c<<'\n';
        x=c;
        c--;
    }
return 0;
}


Measured memory_bytes: 1664
<?php

fscanf(STDIN, '%d %d %d', $n, $m, $l);

for ($i = 0; $i < ($n + $m); $i++) {
    if ($i < $n) {
        $A[] = explode(' ', trim(fgets(STDIN)));
    } else {
        $B[] = explode(' ', trim(fgets(STDIN)));
    }
}

$C = array_fill(0, $n, array_fill(0, $l, 0));

for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $l; $j++) {
        for ($k = 0; $k < $m; $k++) {
            $C[$i][$j] += $A[$i][$k] * $B[$k][$j];
        }
    }
    $result[] = implode(' ', $C[$i]);
}

echo implode(PHP_EOL, $result), PHP_EOL;

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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int r,d,x;
int main() {
    cin >> r >> d >> x;
    for (int i=0;i<10;i++) {
    x *= r;
    x -= d;
    cout << x << endl;
    }
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
void solve(){
	int n,p,q,x;
	cin>>n;
	string ans="No";
	x=0;
	while(n--){
		cin>>p>>q;
		if(p==q){
			x++;
			if(x==3) ans="Yes";
		}
		else x=0;
	}
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	solve();

}

Measured memory_bytes: 3644
#include <stdio.h>
int main(void){
    int n,x;
    int a,b,i,j,k;
    
    while(1){
        scanf("%d %d",&n,&x);
        b=0;
        if(n==0&&x==0){
            break;
        }
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                for(k=1;k<=n;k++){
                    if(i==j||j==k||k==i){
                        }else{
                            a=i+j+k;
                            if(a==x){
                                b+=1;
                            }
                        }
                }
            }
        }
        printf("%d\n",b/6);
    }
    return(0);
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){

    int N,A,B;
    cin>>N>>A>>B;

    if((B-1-A)%2==1){
        cout<<"Alice"<<endl;
    }else{
        cout<<"Borys"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
x1,y1,x2,y2=map(int,input().split())
x3=x2-(y2-y1)
y3=y2-(x1-x2)
x4=x3-(y3-y2)
y4=y3-(x2-x3)
print('{} {} {} {}'.format(x3,y3,x4,y4))

Measured memory_bytes: 2940
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string.h>
#include<string>
#define ll long long 
#define r(i,n) for(ll i=0;i<n;i++)
#define rp(i,a,b) for(ll i=a;i<b;i++)
#define ret return 
#define elif else if
#define p(x) cout<<x<<endl;
ll inf=100001;
using namespace std;
int main(){
	while(1){// string t;cin>>t;p(t)
string s;cin>>s;
	cout<<s.substr(0,4)<<" "<<s.substr(4,8)<<endl;
	ret 0;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	int i, j;
	int n;
	vector<int>list;

	cin >> n;

	for (i = 0; i < n; i++) {
		int num;
		cin >> num;
		list.push_back(num);
	}

	sort(list.begin(), list.end(), greater<int>());

	int sum = list[0] / 2;

	for (i = 1; i < n; i++) {
		sum += list[i];
	}
	cout << sum << endl;


	









	getchar();
	getchar();
	return 0;
}

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

#define MAXN 200010

int n;
long long ans;
pair<int,int> a[MAXN];
multiset<int> x,y;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		int p,q;
		scanf("%d%d",&p,&q);
		x.insert(a[i].first=min(p,q));
		y.insert(a[i].second=max(p,q));
	}
	sort(a+1,a+n+1);
	ans=((long long)*x.rbegin()-*x.begin())*(*y.rbegin()-*y.begin());
	for (int i=1; i<=n; ++i)
	{
		x.erase(x.find(a[i].first)); y.insert(a[i].first);
		y.erase(y.find(a[i].second)); x.insert(a[i].second);
		ans=min(ans,((long long)*x.rbegin()-*x.begin())*(*y.rbegin()-*y.begin()));
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 20608
//#pragma GCC optimize("O2")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
const int maxn = 2e5 + 555;
using ld = long double;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int x;
	cin >> x;
	int y = 1;
	while(2*y <= x) y*=2;
	cout << y;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;

int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

  
  

    int n,d;
    cin >> n >> d;

    vector<double> v;

    for(int i = 0;  i < n; i++)
    {
      int x,y;
      cin >> x >> y;
      v.push_back(sqrt(x*x + y*y));
    }

    sort(all(v));

    int ans = 0;

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

      if(v[i] > d)
      {
        break;
      }
      ans = i + 1;
    }

    cout << ans;


    return 0;
}


Measured memory_bytes: 7432
#include<stdio.h>
int main(void)
{
	int n,a[20],v[20];
	int i,j,temp_v,temp_a,max,max_index=0;
	
	scanf("%d",&n);
	for (i = 0; i < n; i++) {
		scanf("%d %d",&a[i],&v[i]);
	}
	for (i = 0; i < n-1; i++) {
		for (j = i+1; j < n; j++) {
			if (a[i] > a[j]) {
				temp_a = a[i];
				a[i] = a[j];
				a[j] = temp_a;
				temp_v = v[i];
				v[i] = v[j];
				v[j] = temp_v;
			}
		}
	}
	max = v[0];
	for (i = 1; i < n; i++) {
		if (max < v[i]) {
			max = v[i];
			max_index = i;
		}
	}
	printf("%d %d\n", a[max_index], v[max_index]);
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int r = Integer.parseInt(sc.next());
    int d = Integer.parseInt(sc.next());
    long tmp = (long)Integer.parseInt(sc.next());  
    for(int i = 0; i < 10; i++) {
      tmp = r * tmp - d;
      System.out.println(tmp);
    }     
  }
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef pair<Real, Real> P; // Point
typedef pair<P, P> L; // segment or line
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

/* inner dot */
Real dot(P&a, P&b) {
  return car(a) * car(b) + cdr(a) * cdr(b);
}
Real operator*(P&a, P&b) {
  return car(a) * car(b) + cdr(a) * cdr(b);
}

/* scalar multiple */
P operator*(P a, Real c) {
  return cons(c * car(a), c * cdr(a));
}
P operator*(Real c, P a) {
  return cons(c * car(a), c * cdr(a));
}

P operator/(P a, Real d) {
  return cons(car(a) / d, cdr(a) / d);
}

Real det(P&a, P&b) {
  return car(a) * cdr(b) - cdr(a) * car(b);
}

/* vector operator */
P operator+(P a, P b) {
  return cons(car(a) + car(b), cdr(a) + cdr(b));
}

P operator-(P a) {
  return cons(-car(a), -cdr(a));
}

P operator-(P a, P b) {
  return cons(car(a) - car(b), cdr(a) - cdr(b));
}


Real Euclidean(P a, P b) {
  P p = a - b;
  return sqrt(pow(car(p), 2) + pow(cdr(p), 2));
}

/* 外接円 */
struct Circumcenter {
  P x; // 外心
  Real r; // 半径
  Circumcenter(P p0, P p1, P p2) {
    Real a = Euclidean(p1, p2);
    Real b = Euclidean(p2, p0);
    Real c = Euclidean(p0, p1);
    Real A = a * a;
    Real B = b * b;
    Real C = c * c;
    
    Real den = 2 * (A * B + B * C + C * A) - (A * A + B * B + C * C);
    Real dec_a = A * (B + C - A);
    Real dec_b = B * (C + A - B);
    Real dec_c = C * (A + B - C);

    x = (dec_a * p0 + dec_b * p1 + dec_c * p2) / den;

    r = Euclidean(x, p0);
  }
};

int main() {

  int n; cin >> n;

  while (n--) {
    Real x0, y0, x1, y1, x2, y2;
    cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2;
    Circumcenter c(P(x0,y0), P(x1,y1), P(x2,y2)); 
    printf("%0.3f %0.3f %0.3f\n", car(c.x), cdr(c.x),  c.r);
  }

  return 0;
}

Measured memory_bytes: 1232
import itertools

N, M, X = map(int, input().split())
list1 = list(range(N))
list2 = []
book = [list(map(int, input().split())) for _ in range(N)]

com = 0
for i in range(1,N+1):
  listi = list(itertools.combinations(list1, i))
  list2.extend(listi)

anslist = []
for i in range(len(list2)):
  anslistnew = [0] * (M+1)
  for j in range(len(list2[i])):
    for k in range(M+1):
      anslistnew[k] += book[list2[i][j]][k]
  for l in range(1, M+1):
    if anslistnew[l] < X:
      anslistnew[0] = 0
      break
  if anslistnew[0] > 0:
    anslist.append(anslistnew[0])
    
if anslist == []:
  print(-1)
else:
  print(min(anslist))

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

t = 0
ans = ''
while N != 0:
    a = N%2
    if t % 2 == 0:
        ans = str(int(a)) + ans
        N -= a
        N /= 2
    else:
        ans = str(int(a)) + ans
        N += a
        N /= 2
    t +=1
if ans == '':
    ans = '0'
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 333

int n, k, i, j;
char s[maxN];
int dp[maxN][maxN][maxN];

int compute(int l, int r, int k) {
    if (dp[l][r][k] != 0) return dp[l][r][k];

    int &ans = dp[l][r][k];
    if (r - l + 1 <= 2) {
        if (r == l) ans = 1;
        if (l + 1 == r) {
            if (s[l] == s[r])
                ans = 2;
            else
                ans = (k > 0 ? 2 : 1);
        }
    } else {
        ans = max(ans, compute(l + 1, r, k));
        ans = max(ans, compute(l, r - 1, k));
        if (s[l] == s[r]) ans = max(ans, 2 + compute(l + 1, r - 1, k));
        if (k > 0 && s[l] != s[r]) ans = max(ans, 2 + compute(l + 1, r - 1, k - 1));
    }

    return dp[l][r][k];
}

int main()
{
 //   freopen("test.in","r",stdin);

    scanf("%s%d", s + 1, &k);
    n = strlen(s + 1);
    printf("%d", compute(1, n, k));


    return 0;
}


Measured memory_bytes: 130816
N = int(input())
p = list(map(int,input().split()))
p2 = sorted(p)
if p == p2:
    print('YES')
else:
    c= 0
    for i in range(N):
        if p[i] != p2[i]:
            c += 1
    if c == 2:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 3060
import java.util.*;
public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		
		long c = n/(a+b)*a;
		long d = n%(a+b);
		
		c+= Math.min(d, a);
		System.out.println(c);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int main(){
	
	ll n, a[100000], cnt=0;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		if(a[i]%2!=0){
			cnt++;
		}
	}
	if(cnt%2==0){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 1024
n = int(input())
ss = [input() for _ in range(n)]
ans = bsa = bs = sa = 0
for s in ss:
    ans += s.count("AB")
    if s[0] == "B":
        if s[-1] == "A":
            bsa += 1
        else:
            bs += 1
    elif s[-1] == "A":
        sa += 1
if bsa>0:
    ans+=bsa-1
    if bs>0:
        ans+=1
        bs-=1
    if sa>0:
        ans+=1
        sa-=1
ans+=min(bs,sa)
print(ans)


Measured memory_bytes: 3700
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    if a[i] > b[i]:
        ans += b[i]
    elif b[i]-a[i] > a[i+1]:
        ans += a[i]+a[i+1]
        a[i+1] = 0
    else:
        ans += b[i]
        a[i+1] -= b[i]-a[i]

print(ans) 

Measured memory_bytes: 81892
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int value[100010];
int n, k;

inline int quickmul(int x, int y) {
    int ret = 1, mul = x;
    while (y) {
        if (y & 1) {
            ret = (LL)ret * mul % mod;
        }
        mul = (LL)mul * mul % mod;
        y >>= 1;
    }
    return ret;
}

inline void work() {
    cin >> n >> k;
    int ans = 0;
    for (int i = 1; i <= k; ++i) {
        ans = (ans + (LL)quickmul(k / i, n) * (i - value[i]) % mod + mod) % mod;
        for (int j = i + i; j <= k; j += i) {
            value[j] += i - value[i];
        }
    }
    cout << ans << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 4024
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(Bint i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
#define fst first
#define snd second
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
using namespace std;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    Bint x, k, d; cin >> x >> k >> d;
    if(abs(x) > k*d){
        prtl(abs(x) - k*d);
    }else{
        Bint m = abs(x)/d;
        if(x >= 0){
            Bint mn = INF;
            Bint g = m + (k-m)/2;
            rep(i, g-3, g+3){
                Bint h = x + (-d)*i + d*(k-i);
                if(abs(h) < mn){
                    mn = abs(h);
                }
            }
            prtl(mn);
        }else{
            Bint mn = INF;
            Bint g = m + (k-m)/2;
            rep(i, g-3, g+3){
                Bint h = x + d*i + (-d)*(k-i);
                if(abs(h) < mn){
                    mn = abs(h);
                }
            }
            prtl(mn);
        }
    }
}


Measured memory_bytes: 3708
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
  int n,k;
  double ans;
  cin>>n>>k;
  vector<double> dice(n);
  rep(i,n){
    double p;
    cin>>p;
    dice.at(i)=(p+1)/2;
  }
  rep(i,n-k+1){
    double p;
    if(i==0){
    for(int j=i;j<i+k;j++){
      p+=dice.at(j);
    }
    }
    else{
      p-=dice.at(i-1);
      p+=dice.at(i+k-1);
    }
    ans=max(ans,p);
  }
  printf("%.10f",ans);
}


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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  

const int MOD = M;

int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            cin >> v[i][j];
    }
    vector<int> dp(1<<n);
    dp[0] = 1;
    for(int mask=0;mask<(1<<n)-1;mask++)
    {
        int i= __builtin_popcount(mask);
        for(int j=0;j<n;j++)
        {
            if(v[i][j] and !(mask&(1<<j)))
            {
                int z = mask|(1<<j);
                dp[z] += dp[mask];
                if(dp[z] > MOD) dp[z] %= MOD;
            }
        }
    }
    cout << dp[(1<<n) - 1] << "\n";
    return 0;
}



Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 long long int gcd(long long int m,long long int n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
long long int lcm(long long int number1,long long int number2){
	return number1 * number2 / gcd(number1,number2);	
}

ll N;

vector<vector<ll>>A(2,vector<ll>(100));

ll dfs(ll a,ll b,ll sum){
  if(a==1&&b==N-1){
    return sum;
  }
  
  if(a<=1&&b<=N-1){

  
  ll m=0;
    ll n=0;
  if(a<1){
   m=dfs(a+1,b,sum+A[a+1][b]);
  }
  if(b<N-1){
  n=dfs(a,b+1,sum+A[a][b+1]);
  }
    
    return max(m,n);
  }
}

int main(){
cin>>N;
  
  rep(i,2){
    rep(j,N){
      cin>>A[i][j];
    }
  }
  

  cout<<dfs(0,0,0)+A[0][0]<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

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

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n;
	string s;
	cin >> n >> s;
	int tot = 0;
	for(char c:s) tot += c == 'W';
	int ans = INF;
	for(int i = 0, cnt = 0; i <= s.size(); i++) {
		int ccnt = (int)s.size() - i - (tot - cnt);
		ans = min(ans, max(ccnt, cnt));
		if(i != s.size()) cnt += s[i] == 'W';
	}
	cout << ans << endl;

}





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

int main()
{
    string s;
    cin>>s;
    int a = 0, b = 0; 

    for(int i=0;i<3;i++)
    {
        if(s[i] == 'A')
        a++;
        else 
        b++;

    }

    if(a>0 && b>0)
    cout<<"Yes"<<endl;

    else 
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
  char t[300000];
  int i;
  memset(t, 0x00, sizeof(t));
  scanf("%s\n", t);
  
  for (i = 0; t[i] != 0x00; i++) {
    if (t[i] == '?') t[i] = 'D';
  }
  
  printf("%s\n", t);
  return(0);
}


Measured memory_bytes: 1912
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
#define MOD 1000000007
using namespace std;

int main() {
	int a, b, T, time;
	int ans = 0;
	cin >> a >> b >> T;
	time = a;
	while (time <= T) {
		time += a;
		ans += b;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256