akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<vector>
using namespace std;

const long mod = 1000000007;
const long indlim = 5368709119;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
long fact(long x) { if (x == 0) return 1; else return((fact(x - 1) * x) % mod); }
long mybase(long N, long B) { if (N == 0) return 0; string S = ""; while (N != 0) { string M = to_string(N % B); N -= N % B; N /= B; S = M + S; }return stol(S); }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = 0;
	long N; cin >> N;
	long A[100009]; for (int i = 0; i < N; i++) cin >> A[i];
	long B[100009]; for (int i = 0; i < N; i++) cin >> B[i];
	long C[100009]; for (int i = 0; i < N; i++) cin >> C[i];

	sort(A, A + N); sort(B, B + N); sort(C, C + N);

	size_t LBA[100009] = {}; for (int i = 0; i < N; i++) LBA[i] = N - (lower_bound(B, B + N, A[i] + 1) - B);
	size_t LBB[100009] = {}; for (int i = 0; i < N; i++) LBB[i] = N - (lower_bound(C, C + N, B[i] + 1) - C);

    long RSLBB[100009] = {}; for(int i = N - 1; i >= 0; i--) RSLBB[i] = RSLBB[i + 1] + LBB[i]; //累積でO_n
    
	for (int i = 0; i < N; i++) res += RSLBB[N - LBA[i]]; //累積でO_n^2からO_n

	cout << res << endl;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);

		int n = Integer.parseInt(scn.next());
		int m = Integer.parseInt(scn.next());

		long[][] ns = new long[2][n];
		long[][] ms = new long[2][m];

		for (int i = 0; i < n; i++) {
			ns[0][i] = Long.parseLong(scn.next());
			ns[1][i] = Long.parseLong(scn.next());
		}

		for (int i = 0; i < m; i++) {
			ms[0][i] = Long.parseLong(scn.next());
			ms[1][i] = Long.parseLong(scn.next());
		}

		scn.close();

		for (int i = 0; i < n; i++) {
			long min = 200000001;
			int jj = 0;
			for (int j = 0; j < m; j++) {
				long x_dis = Math.abs(ns[0][i] - ms[0][j]);
				long y_dis = Math.abs(ns[1][i] - ms[1][j]);
				if (min > x_dis + y_dis) {
					min = x_dis + y_dis;
					jj = j;
				}
			}
			System.out.println(jj + 1);
		}
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int i,n,j,m,k,l;
	cin>>n>>m;
	bool ch;
	char a[n][n],b[m][m];
	for(i=0;i<n;i++)for(j=0;j<n;j++)cin>>a[i][j];
	for(i=0;i<m;i++)for(j=0;j<m;j++)cin>>b[i][j];
	for(i=0;i<n-m+1;i++){
		for(j=0;j<n-m+1;j++){
			ch=true;
			for(k=0;k<m;k++){
				for(l=0;l<m;l++){
//					cout<<a[i+k][j+l]<<" "<<b[k][l]<<" "<<i<<" "<<j<<endl;
					if(a[i+k][j+l]!=b[k][l]){
						ch=false;
						break;
					}
					if(!ch)break;
				}
			}
			if(ch==true){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
lList = [int(i) for i in input().split()]
point = 0
count = 0
flag = 0
for l in lList:
    count = count + 1
    point = point + l
    if point == x:
        if count == 1:
            print(count)
        else:
            print(count+1)
        flag =1
        break
    elif point > x:
        print(count)
        flag =1
        break
if flag == 0:
    print(count+1)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

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

  ull j = s.size() -1;
  ull result = 0;
  for (ull i=0; i < j; i++) {
    if (s[i] == s[j]) {
    } else {
      result++;
    }

    j--;
  }

  cout << result << endl;

  return 0;
}


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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 1e5 + 20;
const int maxm = (int) 1e6 + 20;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL MOD)
{
    if(n < 0) a = fp(a, MOD - 2, MOD), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % MOD) if(n & 1) res = res * a % MOD; return res;
}

int n;
pair<int, int> a[111], b[111];
bool vis[111];
bool c[111][111];
int p[111];

bool match(int u)
{
    for(int i = 0; i < n; i++)
    {
        if(c[u][i] == 0 || vis[i]) continue;
        vis[i] = 1;
        if(p[i] == -1 || match(p[i]))
        {
            p[i] = u;
            return 1;
        }
    }
    return 0;
}

void work()
{
    cin >>n;
    for(int i = 0; i < n; i++) cin >>a[i].fi >>a[i].se;
    for(int i = 0; i < n; i++) cin >>b[i].fi >>b[i].se;

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            c[i][j] = (a[i].fi < b[j].fi) && (a[i].se < b[j].se);

    int ans = 0;
    memset(p, -1, sizeof(p));
    for(int i = 0; i < n; i++)
    {
        memset(vis, 0, sizeof(vis));
        if(match(i))
            ans++;
    }
    cout <<ans <<endl;
}

int main(int argc, char **argv)
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
//    pre();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <map>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i;
	ll ans = 0;
	cin >> num;
	vector<int> d(num);
	map<int, int> mp;
	rep(i, num) {
		cin >> d[i];
		mp[i - d[i]]++;
		d[i] += i;
	}
	rep(i, num) {
		ans += mp[d[i]];
	}
	cout << ans << "\n";
	return 0;
}

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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    int left = 0, right = (int)1e12, mid;
    while (right - left > 1) {
        mid = (left + right) / 2;

        int t = max(0ll, mid - n);
        if (m >= 2 * t + 2 * mid)
            left = mid;
        else
            right = mid;
    }
    cout << left << endl;
    return 0;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long X, N;
	cin >> X >> N;
	vector<long long>A(N);
	for (long long i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	sort(A.begin(), A.end());
	long long j = 0;
	for (long long i = 0; i <= 1000; i++) {
		bool check = false, check2 = false;
		for (long long j = 0; j < N; j++) {
			if (A.at(j) == X - i) check = true;
			if (A.at(j) == X + i) check2 = true;
		}
		if (!check) {
			cout << X - i << endl;
			return 0;
		}
		if (!check2) {
			cout << X + i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main () {
  long H, W;
  cin >> H >> W;
  if ((H * W) % 3 == 0) {
    cout << 0 << endl;
    return 0;
  }
  long a, ans = 10000000000;
  long one, two, three;
  for(int i = 1; i < H; i++) {
    one = W * i;
    if(W % 2 == 0) two = (H - i) * (W / 2), three = (H - i) * (W / 2);
    else two = (H - i) * ((W - 1) / 2), three = (H - i) * (W - (W - 1) / 2);
    a = max(one,max(two, three)) - min(one,min(two, three));
    ans = min(ans, a);
  }
  if(H < W) swap(H,W);
  for(int i = 1; i < H; i++) {
    one = W * i;
    if(W % 2 == 0) two = (H - i) * (W / 2), three = (H - i) * (W / 2);
    else two = (H - i) * ((W - 1) / 2), three = (H - i) * (W - (W - 1) / 2);
    a = max(one,max(two, three)) - min(one,min(two, three));
    ans = min(ans, a);
  }
  cout << min(ans,min(H,W)) << endl;
  return 0;
}


Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 155 A - Poor
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/23
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
using namespace std;

int a, b, c;

void solve() {
    if (!(a ^ b) & !(b ^ c)) {
        printf("No\n");
        return;
    }
    if (!(a ^ b) | !(b ^ c) | !(c ^ a)) {
        printf("Yes\n");
        return;
    }
    printf("No\n");
    return;

}

int main() {

    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);

    solve();

}

Measured memory_bytes: 3084
#include <iostream>

using namespace std;

const int maxn = 100 + 10;
const int maxnn = 1e5 + 10;

long long  n , W , now = 1 , pre;
long long dp[maxnn];
long long ans;
long long v[maxn] , w[maxnn];

int main() {
    cin >> n >> W;
    for (int i = 1; i <= n; i++)
        cin >> w[i] >> v[i];
    for (int i = 1; i < maxnn; i++) {
        dp[i] = 1e9 + 10;
    }
    for (int i = 1; i <= n; i++){
        for (long long j = maxnn-1; j >= 0; j--){
            if (j - v[i] < 0){
                continue;
            }
            dp[j] = min(dp[j] , dp[j-v[i]] + w[i]);
        }
    }
    //cout<<dp[10] << endl;
    
    for (long long i = 1; i < maxnn; i++) {
        if (dp[i] <= W) {
            ans = max (ans , i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        String t = scanner.next();
        int result = 0;
        for (int i = 0; i < 3; i++) {
            String s_char = s.substring(i,i +1);
            String t_char = t.substring(i,i +1);
            if (s_char.equals(t_char)) result++;
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 3005;
const int inf = 1e9;
int dp[maxn][maxn];
string s, t, ans="";
void resenje(int i, int j){
    if(i<=0 || j<=0)return;
    if(s[i-1] == t[j-1]){
        ans=s[i-1]+ans;
        resenje(i-1,j-1);
    }
    else{
        if(dp[i-1][j]>dp[i][j-1])resenje(i-1,j);
        else resenje(i,j-1);
    }
}
int main()
{
    cin >> s >> t;
    int n=s.length(), m=t.length();
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1] == t[j-1])dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    resenje(n,m);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 35968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5, mod = 1e9 + 7;
int a[maxn];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);

    int n, x = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) x ^= a[i];
    
    cout << (x == 0 ? "Yes" : "No") << endl;
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int s;
  cin >> s;
  int cnt = 1;
  set<int> st;
  st.insert(s);
  while(true) {
    if(s % 2 == 0) {
      s = s / 2;
    } else {
      s = s * 3 + 1;
    }
    cnt++;
    if(st.count(s)) {
      break;
    } else {
      st.insert(s);
    }
  }
  cout << cnt << endl;
  return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    int n;
    map<string,int> mp;
    cin >> n;
    for(int i = 0; i < n; i++) {
        string t; cin >> t;
        mp[t]++;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

}

Measured memory_bytes: 3632
#include <stdio.h>

int main(){
  int n,i,j, a[6];
  double x;

  for(i=0;i<6;i++){
    a[i]=0;
  }
  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%lf", &x);
    if(x<165.0) a[0]++;
    else if(x<170) a[1]++;
    else if(x<175) a[2]++;
    else if(x<180) a[3]++;
    else if(x<185) a[4]++;
    else a[5]++;
  }

  for(i=0;i<6;i++){
    printf("%d:", i+1);
    for(j=0;j<a[i];j++){
      printf("*");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio (false) ;cin.tie(NULL);
#define tc  int t;cin>>t;for(int i=0;i<t;i++)
#define ll long long int
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define um(a,b) unordered_map<a,b>
#define vv(a) vector<a>
#define pp(a,b) pair<a,b>
ll power(ll a,ll b,ll mod){  ll ans=1;  while(b>0){
  if(b&1){ ans=(ans*a)%mod;} a=(a*a)%mod;  b=b/2; } return ans;}

int main(){
FIO
ll n;
cin>>n;
string s;
cin>>s;
ll c=0;
for(ll i=0;i<s.length();i++){
    if(s[i]=='W')
        c++;
}
ll ans=0;
ll i=s.length()-1;
while(c--){
    if(s[i]=='R')
        ans++;
    i--;
}
cout<<ans<<endl;

}


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

using namespace std;

struct Restaurant {
    string city;
    int points;
    int num;
};

bool cmp(Restaurant s, Restaurant t) {
    if (s.city != t.city)
        return s.city < t.city;
    else
        return s.points > t.points;
}

int main() {
    unsigned int n;
    cin >> n;

    vector<Restaurant> vt;
    for (int i = 1; i <= n; ++i) {
        string s;
        int p;
        cin >> s >> p;
        vt.push_back(Restaurant({s, p, i}));
    }

    sort(vt.begin(), vt.end(), cmp);
    for (int i = 0; i < n; ++i) {
        cout << vt[i].num << endl;
    }
    return 0;
}


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

using namespace std;
#define taskname ""
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn = 2e5 + 5;
ll res = 0;
int a[maxn], n;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen(taskname".INP", "r",stdin);
	//freopen(taskname".OUT", "w",stdout);
    cin >> n;
    for(int i = 1 ; i <= n ; ++i)cin >> a[i];
    a[0] = -1;
    for(int i = 1 ; i <= n ; ++i)
        if(a[i] - a[i - 1] > 1)return cout << -1 , 0;
    for(int i = 2 ; i <= n ; ++i)
        if(a[i - 1] + 1 == a[i])res ++;
        else res += a[i];
    cout << res;
}


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

using namespace std;

#define REP(i,m) for(ll i=0; i<m; i++)
#define FOR(i,n,m) for(ll i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

ll POW(ll a, ll b){
	if(b==1) return a;
	if(b%2==0) return POW(a*a%INF, b/2);
	return a*POW(a, b-1)%INF;
}

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> d;
	FOR(i, 1, 100001){
		if(m%i==0){
			if(i*i == m) d.pb(i);
			if(i*i < m){
				d.pb(i);
				d.pb(m/i);
			}
		}
	}
	sort(ALL(d));
	for(int i = d.size()-1; i >= 0; i--){
		if(m / d[i] >= n){
			cout << d[i] << endl;
			return 0;
		}
	}
	return 0;
} 


Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        int N, T,A;
        cin >> N >> T>>A;
        if (abs(N-T)>abs(N-A))
        {
                cout << 'B' << endl;
        } else{
                cout << 'A' << endl;
        }

        
        return 0;
}


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

int main() {
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << setprecision(10) << hypot(x1 - x2, y1 - y2) << endl;
}


Measured memory_bytes: 3352
#include <stdio.h>
int main(){
	int i,tortalwpoint = 0,tortalkpoint = 0,kpoint1 = 0,kpoint2 = 0,kpoint3 = 0,wpoint1 = 0,wpoint2 = 0,wpoint3 = 0,wpoint,kpoint;
	for(i=0; i<10;i++){
		scanf("%d",&wpoint);
		if(wpoint >= wpoint1) {
			wpoint3 = wpoint2;
			wpoint2 = wpoint1;
			wpoint1 = wpoint;
		}
		else if(wpoint <= wpoint1 && wpoint >= wpoint2){
			wpoint3 = wpoint2;
			wpoint2 = wpoint;
		}
		else if(wpoint <= wpoint2 && wpoint >= wpoint3){
			wpoint3 = wpoint;
		}
		else ;
	}
	for(i=10;i<20;i++){
		scanf("%d",&kpoint);
		if(kpoint >= kpoint1) {
			kpoint3 = kpoint2;
			kpoint2 = kpoint1;
			kpoint1 = kpoint;
		}
		else if(kpoint <= kpoint1 && kpoint >= kpoint2){
			kpoint3 = kpoint2;
			kpoint2 = kpoint;
		}
		else if(kpoint <= kpoint2 && kpoint >= kpoint3){
			kpoint3 = kpoint;
		}
		else ;
	}
	tortalwpoint = wpoint1+wpoint2+wpoint3;
	tortalkpoint = kpoint1+kpoint2+kpoint3;
	printf("%d %d\n",tortalwpoint,tortalkpoint);
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#define dbg(x) cout << #x"="<< (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;

using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_buck(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second

int main()
{
    ll  N,x,ans=0;
    cin>>N>>x;
    ll over;
    vector<ll> a(N+1);
    a[0]=0;
    for(int i=1;i<=N;i++){
        cin>>a[i];
        if(a[i]+a[i-1]>x){
            over=(a[i]+a[i-1])-x;
            a[i]-=over;
            ans+=over;
        }
    }
    cout<<ans<<endl;
 
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

#define D_MAX 1000000000
#define N_MAX 100000
#define M_MAX 10000
#define min(x,y) (((x)<(y))?(x):(y))

int d;
int n;
int m;

int ad[N_MAX+1];
int ak[M_MAX+1];
int awork[N_MAX+1];

void MergeSort(int array[],int left,int right){
  int mid;
  int i;
  int j;
  int x;
  int y;
  
  if( left >= right ){
    return;
  }
  
  mid = (left + right) / 2;
  MergeSort( array, left, mid);
  MergeSort( array, mid+1, right);
  
  for( i=left; i<=mid; i++){
    awork[i] = array[i];
  }
  
  j = right;
  for( i=mid+1; i<=right; i++){
    awork[i] = array[j];
    j--;
  }
  
  x = left;
  y = right;
  
  for( i=left; i<=right; i++){
    if(awork[x] <= awork[y]){
      array[i] = awork[x];
      x++;
    }else{
      array[i] = awork[y];
      y--;
    }
  }
}


int calcDist(void){
  int i;
  int j = 1;
  int sum = 0;
  int diff;
  int preDiff = 0;
  int minDist = d;
  int tmpDist;
  int halfDist = d >> 1;
  
  for( i=1; i<=m; i++){
    
    while(ad[j] < ak[i]){
      j++;
    }
    minDist = min( abs(ad[j-1]-ak[i]),abs(ad[j]-ak[i]) );
    sum += minDist;
    
  }
  
  return sum;
}


void input(void){
  int i;
  scanf("%d",&d);
  if( d != 0){
    scanf("%d",&n);
    scanf("%d",&m);
    ad[0] = 0;
    for( i=1; i<=n-1; i++){
      scanf("%d",&ad[i]);
    }
    ad[n] = d;
    for( i=1; i<=m; i++){
      scanf("%d",&ak[i]);
    }
  }
}

int main(void){
  int i;
  int sumDist = 0;
  while( 1 ){
    input();
    if( d == 0 ){
      break;
    }
    MergeSort( ad, 0, n);
    MergeSort( ak, 1, m);
    sumDist = calcDist();
    printf("%d\n",sumDist);
    sumDist = 0;
  }
}




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

using namespace std;

int main (int argc, char **argv) {
  int a, b, c;
  cin >> a;
  cin >> b;
  cin >> c;

  if (a == b) cout << c << endl;
  else if (b == c) cout << a << endl;
  else if (a == c) cout << b << endl;
  return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
n = int(input())
a = [[int(i) for i in input().split()] for i in range(n)]
a = sorted(a, key=itemgetter(1))
sum = 0
ans = 'Yes'
for i in range(n):
  sum += a[i][0]
  if sum > a[i][1]:
    ans = 'No'
    break
print(ans)

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

ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int n;
    cin >> n;
    vector<int> a(n);
    ll all;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if(i == 0) all = a[i];
        else all = gcd(all, a[i]);
    }
    
    unordered_set<int> seen;
    bool pc = true;
    for (int i = 0; i < n; ++i) {
        int tmp = a[i];
        for (int j = 2; j * j <= tmp; ++j) {
            if(tmp > 1 && tmp % j == 0 && seen.count(j)) {
                pc = false;
                break;
            }
            while(tmp > 1 && tmp % j == 0) {
                seen.insert(j);
                tmp /= j;
            }
        }
        if(tmp > 1 && seen.count(tmp)) pc = false;
        else if(tmp > 1) seen.insert(tmp);
        if(!pc) break;
    }

    if(pc) puts("pairwise coprime");
    else if(all == 1ll) puts("setwise coprime");
    else puts("not coprime");
}


Measured memory_bytes: 7216
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element

signed main()
{
	char a;
	cin >> a;
	if ('a' <= a && a <= 'z')
	{
		cout << "a" << endl;
	}
	else
	{
		cout << "A" << endl;
	}
}



Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	public class Program
	{

		static void Main(string[] args)
		{
			int N = int.Parse(Console.ReadLine());
			int[] H = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();

			int ans = 0;
			int max = 0;
			for (int i = 0; i < N; i++) {
				if (max <= H[i]) {
					ans++;
					max = H[i];
				}
			}
			Console.WriteLine(ans);
		}
	}
}

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

int main(){
  int N,ans=0;
  int L[201];

  cin>>N;

  for(int i=0;i<2*N;i++) cin>>L[i];

  sort(L,L+N*2);
 
  for(int i=0;i<2*N;i+=2){
    ans+=min(L[i],L[i+1]);
  }

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


Measured memory_bytes: 256
#include <stdio.h>

double sequence(double a, int n);

int main()
{
	double a;
	double result[100];
	int i=0,count;
	int ret;
	while(1){
		ret=scanf("%lf", &a);
		if(ret==EOF){
			break;
		}
		result[i]=sequence(a, 10);
		i++;
	}
	count=i;
	for(i=0; i<count; i++){
		printf("%.8f\n", result[i]);
	}
	return 0;
}

double sequence(double a, int n)
{
	int i;
	double data[100];
	double sum=0;
	data[0]=a;
	for(i=1; i<n; i++){
		if(i%2!=0){
			data[i]=(data[i-1]*2);
		}
		else{
			data[i]=(data[i-1]/3);
		}
	}
	for(i=0; i<n; i++){
		sum+=data[i];
	}
	return sum;
}

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

const int INF = 1001001001;
const int mod = 1000000007;

ll pow(ll base, ll order) {
	ll ans = 1;
	rep(i,order - 1) ans *= base;
	return ans;
}

int gcd(int a, int b) {
	if (a < b) {
		int c = a;
		a = b;
		b = c;
	}
	if (b == 0) return a;
	return gcd (b, a % b);
}

ll sum(ll x) { // sum of subsequent numbers from 0 to x
	return x*(x + 1)/2;
}

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

	vector<pair<pair<string, int>, int>> sp(n);
	rep(i, n) {
		string city;
		int score;
		cin >> city >> score;
		sp[i] = make_pair(make_pair(city, -score), i + 1);
	}
	//rep(i, n) cout << sp[i].first.first << " " << sp[i].first.second << endl;
	sort(sp.begin(), sp.end());
	rep(i, n) cout << sp[i].second << endl;
}


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

using namespace std;

constexpr int INF = 0x3f3f3f3f;
constexpr int N = 100000;
constexpr int CLOSE = 0;
constexpr int OPEN = 1;

struct Contestants {
	int l, r;
};

Contestants c[N + 1];
multiset<int> sl, sr;
int n;

bool comp_r(const Contestants &a, const Contestants &b) {
	if (a.r == b.r) {
		return a.l < b.l;
	}

	return a.r < b.r;
}

bool comp_l(const Contestants &a, const Contestants &b) {
	if (a.l == b.l) {
		return a.r < b.r;
	}

	return a.l < b.l;
}

void init() {
	sl.clear();
	sr.clear();

	for (int i = 1; i <= n; i++) {
		sl.insert(c[i].l);
		sr.insert(c[i].r);
	}
}

int main() {
	int ans, l, r, i;

	scanf("%d", &n);

	for (i = 1; i <= n; i++) {
		scanf("%d%d", &c[i].l, &c[i].r);
	}

	// Biggest.
	init();
	ans = 0;

	for (i = 1; i <= n; i++) {
		sl.erase(sl.find(c[i].l));
		sr.erase(sr.find(c[i].r));
		ans = max(ans, max(0, c[i].r - c[i].l + 1) + max(0, *sr.begin() - *sl.rbegin() + 1));
		sl.insert(c[i].l);
		sr.insert(c[i].r);
	}

	// Left to right.
	init();
	sort(c + 1, c + 1 + n, comp_r);
	l = -INF;
	r = INF;

	for (i = 1; i <= n - 1; i++) {
		sl.erase(sl.find(c[i].l));
		sr.erase(sr.find(c[i].r));
		l = max(l, c[i].l);
		r = min(r, c[i].r);
		ans = max(ans, max(0, r - l + 1) + max(0, *sr.begin() - *sl.rbegin() + 1));
	}

	// Right to left.
	init();
	sort(c + 1, c + 1 + n, comp_l);
	l = -INF;
	r = INF;

	for (i = n; i >= 2; i--) {
		sl.erase(sl.find(c[i].l));
		sr.erase(sr.find(c[i].r));
		l = max(l, c[i].l);
		r = min(r, c[i].r);
		ans = max(ans, max(0, r - l + 1) + max(0, *sr.begin() - *sl.rbegin() + 1));
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 12416
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<VL> VVL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    ll x,y,n,m,h,k,ans=0,sum=0;
    string s,t;
    cin >> n;
    VL a(5);
    int P[10] = {0,0,0,0,0,0,1,1,1,2};
    int Q[10] = {1,1,1,2,2,3,2,2,3,3};
    int R[10] = {2,3,4,3,4,4,3,4,4,4};
    rep(i,n){
        cin >> s;
        if(s[0]=='M')a[0]++;
        if(s[0]=='A')a[1]++;
        if(s[0]=='R')a[2]++;
        if(s[0]=='C')a[3]++;
        if(s[0]=='H')a[4]++;
	}
    rep(i,10){
        ans += a[P[i]] * a[Q[i]] * a[R[i]];
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD 998244353
typedef long long int lli;

const int ALNUM = 26;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0; s[i] != '\0'; ++i){
        char char_out = (s[i] + n <= 'Z') ? s[i] + n : s[i] + n - ALNUM;
        cout << char_out;
    }
    cout << endl;
    return 0;
}

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

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  for(int i=0;;++i){
    int pay;
    cin >> pay;
    if(!pay) return 0;
    if(i) cout << endl;
    int c10,c50,c100,c500;
    cin >> c10 >> c50 >> c100 >> c500;
    int left=c10*10+c50*50+c100*100+c500*500-pay;
    if(c10>left%50/10) cout << 10 << ' ' << c10-left%50/10 << endl;
    if(c50>left%100/50) cout << 50 << ' ' << c50-left%100/50 << endl;
    if(c100>left%500/100) cout << 100 << ' ' << c100-left%500/100 << endl;
    if(c500>left/500) cout << 500 << ' ' << c500-left/500 << endl;
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
long long int N, M;
int main()
{
    while(scanf("%lld%lld",&N, &M)!=EOF)
    {
        long long int sum1, sum2, sum;
        sum1 = N;
        sum2 = (M-2*N)/4;
        sum = sum1+sum2;
        if(M/2<N)
            printf("%lld\n",M/2);
        else
            printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 256
/*
Author: Sanskar Agarwal
Nick: sanskarag
Birla Institute Of Technology, Mesra
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define INF 100009
#define mod 1000000007
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define test while(t--)solve();

void solve()
{
	int n;
	cin >> n;
	int arr[n][3];
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
			cin >> arr[i][j];
	}
	int dp[n][3];
	dp[0][0] = max(arr[0][1], arr[0][2]);
	dp[0][1] = max(arr[0][0], arr[0][2]);
	dp[0][2] = max(arr[0][0], arr[0][1]);
	for (int i = 1; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			int prev = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]);
			dp[i][j] = arr[i][j] + prev;
		}
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
}

int main()
{
	fast
	int t;
	// cin >> t;
	t = 1;
	test
	return 0;
}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;

    int x[n+1], y[n+1], t[n+1];

    for (int i = 1; i <= n; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }

    t[0] = 0, x[0] = 0, y[0] = 0;

    //int d[n] ,t[n];
    bool flag = false;

    REP(i, n){

        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);

        if ( dt >= dist && dt%2 == dist%2){
            flag = true;
        }
        else{
             flag = false;
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(n);
    for (int i = 0; i < n; i++)cin >> s[i];
    vector<int> t(m);
    for (int i = 0; i < m; i++)cin >> t[i];

    vector<vector<ll>> dp(n + 1, vector<ll>(m + 1));
    for (int i = 0; i <= n; i++)dp[i][0] = 1;
    for (int j = 0; j <= m; j++)dp[0][j] = 1;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j];
            if (s[i] != t[j])dp[i + 1][j + 1] -= dp[i][j];

            dp[i + 1][j + 1] += MOD * 10, dp[i + 1][j + 1] %= MOD;
        }
    }

    cout << dp[n][m] << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);

struct CumulativeSum2D {
  vector<vector<int>> data;

  CumulativeSum2D(int w, int h) : data(w+1, vector<int>(h+1, 0)) {}

  void add(int x, int y, int z){
    //++x; ++y; // 0-indexedの場合
    if(x >= data.size() || y >= data[0].size()) return;
    data[x][y] += z;
  }

  void build() {
    for(int i = 1; i < data.size(); i++){
      for(int j = 1; j < data[i].size(); j++){
        data[i][j] += data[i][j-1] + data[i-1][j] - data[i-1][j-1];
      }
    }
  }

  int query(int sx, int sy, int gx, int gy){
    return data[gx][gy] - data[sx-1][gy] - data[gx][sy-1]  + data[sx-1][sy-1];
  }
};

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

  CumulativeSum2D cs = CumulativeSum2D(N,N);

  REP(i,M){
    int l,r;
    cin >> l >> r;

    cs.add(l,r,1);
  }
  cs.build();

  REP(i,Q){
    int p,q;
    cin >> p >> q;
    cout << cs.query(p,p,q,q) << endl;
  }
}



Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;
bool check[100001];
int n, m;

bool bfs(vector<int> &ans, const vector<vector<int>> &v)
{
    queue<int> q;
    q.push(1);
    check[1] = true;
    
    while(!q.empty())
    {
        int room = q.front();
        q.pop();
        
        for(int i = 0; i < v[room].size(); i++)
        {
            int connectedRoom = v[room][i];
            if(ans[connectedRoom] == -1)
            {
                ans[connectedRoom] = room;
                q.push(connectedRoom);
                check[connectedRoom] = true;
            }
        }
    }
    
    for(int i = 2; i <= n; i++)
        if(ans[i] == -1) return false;
    return true;
}

int main()
{
    cin >> n >> m;
    
    int head, tail;
    vector<vector<int>> rooms(n + 1, vector<int>());
    vector<int> ans(n + 1);
    
    for(int i = 1; i <= n; i++)
    {
        ans[i] = -1;
    }
    
    for(int i = 0; i < m; i++)
    {
        cin >> head >> tail;
        rooms[head].push_back(tail);
        rooms[tail].push_back(head);
    }
    
    if ( !bfs(ans, rooms) )
    {
        cout << "No" << endl;
        return 0;
    }
    
    cout << "Yes" << endl;
    for(int i = 2; i <= n; i++)
    {
        cout << ans[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 10304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 1e5 + 5;

long long n,k,f[N];

ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>k;
	ll ans=0;
	for(int i=k;i>=1;i--){
		f[i]=power(k/i,n);
		for(int j=2*i;j<=k;j+=i) f[i]-=f[j];
		ans=(ans+i*f[i]%mod)%mod;//大小×个数才是该数所有的和
	}
	cout<<(ans+mod)%mod<<'\n';
	return 0;
}

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

int main() {
	long long N;
	string s,r;
	cin >> N >> s >> r;
	long long length=2*N;
	int cut=0;
	for(int i=0; i<N; i++){
		if(s[i]==r[0]){
			for(int j=0; i+j<N; j++){
				if(s[i+j]==r[j]){cut+=1;
				if(i+j==N-1){i=N;}}
				else{cut=0; break;}
			}
		}
	}
	length-=cut;
	
	cout << length <<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*

//PriorityQueue
fun main(args: Array<String>) {
    val (n, _c) = readLine()!!.split(' ').map(String::toInt)
    val stcList = mutableListOf<Triple<Int, Int, Int>>()
    (1..n).forEach {
        val (s, t, c) = readLine()!!.split(' ').map(String::toInt)
        stcList.add(Triple(s, t, c))
    }
    stcList.sortBy { it.first }
    val stQueue = ArrayDeque(stcList)
    val curQueue = PriorityQueue<Triple<Int, Int, Int>>(n, Comparator { o1: Triple<Int, Int, Int>?, o2: Triple<Int, Int, Int>? ->
        if (o1!!.second > o2!!.second) 1 else -1
    })
    var ans = 0
    while (stQueue.isNotEmpty()) {
        val pair = stQueue.pop()
        val limit = pair.first
        val tempList = mutableListOf<Triple<Int, Int, Int>>()
        while (curQueue.isNotEmpty() && curQueue.peek().second <= limit) {
            val poll = curQueue.poll()
            if (pair.third != poll.third && poll.second == limit) tempList.add(poll)
        }
        curQueue.add(pair)
        curQueue.addAll(tempList)
        ans = Math.max(ans, curQueue.size)
    }
    println(ans)
}


Measured memory_bytes: 81652
import java.util.Scanner;
public class Main{

    static void PRINT(int x,int y){
        for(int i=1;i<=x;i++){
            for(int j=1;j<=y;j++){
            	if((i+j)%2==0)System.out.print("#");
            	else System.out.print(".");
            }
            System.out.println("");
        }
        System.out.println("");
    }


    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0&&W==0)break;
            else PRINT(H,W);
        }
        sc.close();
    }


}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    string s;
    cin >> s;

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

    if(s[0] == s[1] and s[1] != s[2] and s[2] == s[3]){
        Yes();
    }
    else{
        No();
        
    }

    return 0;
}


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

using namespace std;

int main(){
  int n, q, x;
  vector<int> v;
  cin >> n;
  for ( int i = 0; i < n; i++ ){
    cin >> x;
    v.push_back(x);
  }
  int sum = 0;
  cin >> q;
  for ( int i = 0; i < q; i++ ){
    cin >> x;
    if ( find(v.begin(), v.end(), x) != v.end() ) sum++;
  }

  cout << sum << endl;

  return 0;
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    string s,t;
    cin>>s>>t;
    sort(ALL(s));
    sort(ALL(t));
    reverse(ALL(t));
    rep(i,min(s.size(),t.size())){
        int ss=s[i]-'a',tt=t[i]-'a';
        if(ss<tt){
            Yes;return 0;
        }
        if(ss>tt){
            No;return 0;
        }
    }
    if((s.size())<(t.size())){
        Yes;
    }
    else{
        No;
    }
    return 0;
}


Measured memory_bytes: 256
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0: break
    ans = 0
    for i in range(1, a+1):
        for j in range(i+1, a+1):
            for k in range(j+1, a+1):
                if i + j + k == b :
                    ans += 1
    print(ans)


Measured memory_bytes: 5592
#include<iostream>
using namespace std;
int main()
{
    int c=0,i,m=0;
    string s,t;
    cin>>s;
    cin>>t;
    for(int i=0;s[i]&&t[i];i++){

         if(s[i]==t[i]){
            c++;

         }
         else{
            c=0;
            m++;
            break;
         }
    }
    if(c)
        cout << "Yes";
    else
        cout << "No";
    //cout <<s[i];
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main(){
  int n, m;
  cin >> n >> m;
  vl vec(n, 0);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    vec[a]++; vec[b]--;
  }
  bool allEven = true;
  int sum = 0;
  rep(i, n-1){
    sum += vec[i];
    if(sum%2==1) allEven = false;
  }
  if(allEven) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

int main(){
  int a, b;
  char op;


  while(1){
    cin>>a>>op>>b;
    if(op=='?'){
      break;
    }
    if(op=='+'){
      cout<<a+b<<endl;
    }
    if(op=='-'){
      cout<<a-b<<endl;
    }
    if(op=='*'){
      cout<<a*b<<endl;
    }
    if(op=='/'){
      cout<<a/b<<endl;
    }
  }

  return 0;
  

}

Measured memory_bytes: 3096