akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

ll inv_mod(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p*inv_mod(p % a, a)) / a + p);
}

ll expr(string const& s, int& p, ll const M);
ll term(string const& s, int& p, ll const M);
ll factor(string const& s, int& p, ll const M);
ll number(string const& s, int& p);

ll expr(string const& s, int& p, ll const M) {
    ll v1 = term(s, p, M);
    while(p < s.size() && (s[p] == '+' || s[p] == '-')) {
        char op = s[p++];
        ll v2 = term(s, p, M);
        if(op == '+') {
            v1 += v2;
        } else {
            v1 -= v2;
        }
        v1 = (v1 + M) % M;
    }
    return v1;
}

ll term(string const& s, int& p, ll const M) {
    ll v1 = factor(s, p, M);
    while(p < s.size() && (s[p] == '*' || s[p] == '/')) {
        char op = s[p++];
        ll v2 = factor(s, p, M);
        if(op == '*') {
            v1 *= v2;
        } else {
            if(v2 == 0) {
                throw std::runtime_error("");
            }
            ll x = inv_mod(v2, M);
            v1 *= x;
        }
        v1 %= M;
    }
    return v1;
}

ll factor(string const& s, int& p, ll const M) {
    if(isdigit(s[p])) {
        return number(s, p);
    }
    ll res = expr(s, ++p, M);
    ++p;
    return res;
}

ll number(string const& s, int& p) {
    ll n = 0;
    while(isdigit(s[p])) {
        n *= 10;
        n += s[p++] - '0';
    }
    return n;
}

int main() {
    string s;
    while(getline(cin, s), s != "0:") {
        int p = 0;
        ll M = number(s, p);
        string S;
        p++;
        for(int i=p; i<s.size(); ++i) {
            if(s[i] != ' ') {
                S += s[i];
            }
        }
        p = 0;
        try {
            cout << S << " = " << expr(S, p, M) << " (mod " << M << ')' << endl;
        } catch(...) {
            cout << "NG" << endl;
        }
    }
}


Measured memory_bytes: 3328
#include<stdio.h>

int main(){
	int a,b,c,i,x,p;
	p=0;
	scanf("%d %d %d %d %d",&a,&b,&c,&i,&x);
	for(i=a;i<=b;i++){
		x=c%i;
		if(x==0){
			p++;
		}
	}
	printf("%d\n",p);
	
return 0;
}


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

int main(void){
    vector< pair<int, int> > res;
    while(1) {
        int h, w;
        cin >> h >> w;
        if(w == 0) break;
        vector< pair<int, int> > d[100100];
        int min_ = h*h+w*w;
        int ans = 1 << 30;
        for(int i = 2; i < 150; i++) {
            for(int j = 1; j < i; j++) {
                if(min_ <= i*i+j*j && ans >= i*i+j*j) {
                    if(min_ != i*i+j*j) {
                        ans = i*i+j*j;
                        d[ans].push_back(make_pair(j, i));
                    }
                    else if(j > h) {
                        ans = i*i+j*j;
                        d[ans].push_back(make_pair(j, i));
                    }
                }
            }
        }
        sort(d[ans].begin(), d[ans].end());
        for(int i = 0; i < d[ans].size(); i++) {
            pair<int, int> p;
            p.first = d[ans][i].first;
            p.second = d[ans][i].second;
            res.push_back(make_pair(p.first, p.second));
            //cout << p.first << " " << p.second << endl;
            break;
        }
    }
    for(int i = 0; i < res.size(); i++) {
        cout << res[i].first << " " << res[i].second << endl;
    }
    return 0;
}


Measured memory_bytes: 5412
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    int n, nxt;
    cin >> n;
    vector<pair<int, int>> a(n+1);
    for (int i = 1; i <= n; i++){
        cin >> nxt;
        a[i] = {nxt, i};
    }
    sort(a.begin(), a.end());
    for (int i = 1; i <= n; i++){
        cout << a[i].second << " ";
    }

    return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>

#define MAX 1e8

int min(int a, int b){
  return (a < b ? a : b);
}

int dfs(int *dist, int N, int *r, int R, int now, int depth){
  if(depth == R) return 0;
  
  int min_dist = MAX;
  int min_ri = 0;
  for(int i = 0; i < R; i++){
    if(r[i] != -1){
      int ri = r[i];
      r[i] = -1;
      int d = dfs(dist, N, r, R, ri, depth + 1);
      if(now != -1) d += dist[now * N + ri];
      if(min_dist > d){
        min_dist = d;
        min_ri = ri;
      }
      r[i] = ri;
    }
  }
  
  return min_dist;
}

int main(){
  int N, M, R;
  scanf("%d %d %d", &N, &M, &R);
  
  int r[R];
  for(int i = 0; i < R; i++){
    scanf("%d", &r[i]);
    r[i]--;
  }
  
  int dist[N][N];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(i == j) dist[i][j] = 0;
      else dist[i][j] = MAX;
    }
  }
  
  for(int i = 0; i < M; i++){
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    
    dist[A - 1][B - 1] = dist[B - 1][A - 1] = C;
  }
  
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  
  printf("%d", dfs(dist, N, r, R, -1, 0));
  
  return 0;
}

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

using namespace std;
bool q[10000010];
vector<int> prime;
int maxn,Q;
inline void getP(int maxn){
	memset(q+1,true,maxn+1);
	q[1]=false;
	for(int i=2;i<=maxn;i++)if(q[i]==true){
		prime.push_back(i);
		for(int j=2;i*j<=maxn;j++){
			q[i*j]=false;
		}
	}
	return;
}
int n;
typedef long long ll;
map< pair<ll,ll> , int > mp;

int main()
{
	getP(3000);
	cin >> n;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		ll g1=1,g2=1;
		for(size_t j=0;j<prime.size();j++){
			int p=prime[j];
			if(1ll*p*p*p>x)break;
			int e=0;
			while(x%p==0){
				x/=p;
				++e;
			}
			e%=3;
			if(e==1)g1*=p;
			else if(e==2)g2*=p;
		}
		ll r=sqrt(x);
		if(r*r==x)g2*=r;
		else g1*=x;
		mp[make_pair(g1,g2)]++;
	}
	int ans=0;
	map< pair<ll,ll> , int >::iterator iter;
	for(iter=mp.begin();iter!=mp.end();iter++){
		ll x=iter->first.first,y=iter->first.second;
		if(x>y&&mp[make_pair(y,x)])continue;
		if(x==y)ans++;
		else ans+=max(mp[make_pair(x,y)],mp[make_pair(y,x)]);
	}
	cout<<ans<<endl;
	return 0;
}



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int c[11][1010];

int main(){
    int h, w, K;
    cin >> h >> w >> K;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '1') c[i][j] = 1;
        }
    }

    int res = INF;
    for (int i = 0; i < 1<<(h-1); ++i) {
        int sum[11][1010] = {};
        for (int j = 0; j < w; ++j) {
            sum[0][j] = c[0][j];
        }

        int num = 1;
        for (int j = 0; j < h-1; ++j) {
            if (i & (1<<j)){
                ++num;
            }
            for (int k = 0; k < w; ++k) {
                sum[num-1][k] += c[j+1][k];
            }
        }

        int cnt = num - 1;
        int v[11] = {};
        bool loop = false;
        for (int j = 0; j < w; ++j) {
            for (int k = 0; k < num; ++k) {
                v[k] += sum[k][j];
            }
            for (int k = 0; k < num; ++k) {
                if (v[k] > K){
                    for (int l = 0; l < num; ++l) {
                        v[l] = sum[l][j];
                        if (v[l] > K){
                            loop = true;
                            break;
                        }
                    }
                    ++cnt;
                    break;
                }
            }
        }
        if (!loop) chmin(res, cnt);
    }
    cout << res << endl;
}

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

int main() {
  int n,m;
  ll ans=0;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i,n){
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i,m){
    int a = q.top(); q.pop();
    q.push(a/2);
  }
  rep(i,n){
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
  return 0;
}

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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};
using namespace std;
void solve(){
    int a,b;
    cin>>a>>b;
   cout<<max({2*a-1,2*b-1,a+b});
}

int main(){
    std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

//-------------------------------------------------------//

int main() {
	int n, temp;
	cin >> n;
	unordered_map<int, int> m;
	
	FOR(i, n-1) {
		cin >> temp;
		m[temp]++;
	}
	
	for(int i = 1; i <= n; i++) {
		cout << m[i] << endl;
	}
	
	return 0;
}

















Measured memory_bytes: 11460
#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;
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if (A+B<C)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}

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

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

	int f = 0, ff;
	int NN = 0;

	for (int i = 0; i < N.length(); i++)
	{
		ff = N[i] - '0';
		f += ff;
		NN = NN * 10 + ff;
	}

	if (NN % f == 0) cout << "Yes" << endl;
	else cout << "No" << endl;



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int calc(int i){
    return i*(i+1)/2;
}

int main(){
    int a,b;
    cin >> a >> b;
    for(int i=0;i<998;i++){
        int sa = calc(i+1);
        int sb = calc(i+2);
        if(sa-a == sb-b){
            cout << sa-a << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include <iomanip>
using namespace std;
int main(){
    int N, M;
    int k[20], s[20][20],p[20];
    cin >> N >> M;
    for (int i = 0; i < M; i++){
        cin >> k[i];
        for (int j = 0; j < k[i]; j++){
            cin >> s[i][j];
        }
    }
    for (int i = 0; i < M; i++){
        cin >> p[i];
    }
    int totalCount = 0;
    for(int bit = 0; bit < (1<<N); bit++){
        bool flag = true;
        for(int i = 0; i < M; i++){
            int count = 0;
            for (int j = 0; j < k[i]; j++){
                if(bit & (1 << s[i][j] - 1)){
                    count++;
                }
            }
            if(count % 2 != p[i]){
                flag = false;
            }
        }
        if(flag == true){
            totalCount++;
        }
    }
    cout << totalCount << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int ans = 0;
    int count = 0;
    for (int i = 0; i < S.length(); ++i) {
        if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G') {
            count++;
            if (count > ans) {
                ans = count;
            }
        } else {
            count = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int dp[2][2][5001];

int main(){
  int n;
  int t[10000];
  cin >> n;
  for(int i=0;i<n-1;i++)cin >> t[i];
  
  for(int i=0;i<=n/2;i++)dp[0][0][i] = dp[0][1][i] = 100000000;
  dp[0][0][1] = 0;

  for(int i=0;i<n-1;i++){
    int ii = i&1;
    for(int j=0;j<=n/2;j++)dp[1-ii][0][j] = dp[1-ii][1][j] = 100000000;

    for(int j=0;j<2;j++){
      for(int k=0;k<=n/2;k++){
	if(k<n/2)dp[1-ii][j][k+1] = min(dp[1-ii][j][k+1], dp[ii][j][k]);
	if(i+1-k<n/2 && 0<=i+1-k+1)dp[1-ii][1-j][i+1-k+1] = min(dp[1-ii][1-j][i+1-k+1],dp[ii][j][k] + t[i]);
      }
    }
  }

  cout << min(dp[1][0][n/2],dp[1][1][n/2]) << endl;
}

Measured memory_bytes: 940
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print(int u){
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if(T[u].p == NIL) cout << "root, ";
    else if(T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";

    for(i=0, c=T[u].l; c != NIL; i++, c = T[c].r){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

//再帰的に深さを求める
int rec(int u, int p){
    D[u] = p;
    if(T[u].r != NIL) rec(T[u].r, p); //右の兄弟に同じ深さを設定
    if(T[u].l != NIL) rec(T[u].l, p+1); //最も左の子に自分の深さ+1を設定
}

int main(){
    int i, j, d, v, c, l, r;
    cin >> n;
    for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL; //木を初期化

    for(i=0; i<n; i++){
        cin >> v >> d;
        for(j=0; j<d; j++){
            cin >> c;
            if(j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for(i=0; i<n; i++){
        if(T[i].p == NIL) r=i;
    }

    rec(r, 0);

    for(i=0; i<n; i++) print(i);

    return 0;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

bool cnt[26];

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

  SCIN(S);
  // map< char, int > mp;
  REP(i, S.size()) {
    cnt[S[i] - 97] = true;
  }

  string ans = "";
  if (S.size() < 26) {
    ans += S;
    REP(i, 26) {
      if (!cnt[i]) {
	ans += i + 97;
	cout << ans << endl;
	return 0;
      }
    }
  } else {
    int tmp = S.size() - 1;
    RREP(i, S.size() - 1) {
      if (S[i] < S[i + 1]) break;
      tmp = min(tmp, i);
    }

    if (tmp == 0) {
      cout << -1 << endl;
      return 0;
    }

    REP(i, S.size()) {
      if (i < tmp - 1) {
	ans += S[i];
	cnt[S[i] - 97] = false;
      } else {
	cnt[S[i] - 97] = true;
      }
    }

    FOR(i, S[tmp - 1] - 96, 26) {
      if (cnt[i]) {
	ans += i + 97;
	cout << ans << endl;
	return 0;
      }
    }
    
  }
  cout << -1 << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

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

static const ll MOD = 1000000007;
//static const ll INF = 100000000;
//#define PI 3.14159265359

ll sum1(ll a, ll b) {
    ll ans = 0;
    for (ll i = 0; i < a; ++i) {
        ans += b - i;
    }
    return ans;
}

ll sum2(ll a) {
    ll ans = 0;
    for (ll i = 0; i < a; ++i) {
        ans += i;
    }
    return ans - 1;
}

int main() {
    // input
    ll N, K;
    cin >> N >> K;
    ll ans = 0;

    // process
    ll a = sum1(K, N);
    ll b = sum2(K);
    for (ll i = K; i <= N; ++i) {
        ans += a - b;
        ans %= MOD;
        a += N - i;
        b += i;
    }

    ans++;

    cout << ans % MOD;
    return 0;
}

Measured memory_bytes: 3188
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,t,v,w,x,y,a[200040];
string s;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	cout<<(1000-n%1000)%1000;
}

Measured memory_bytes: 3652
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] abcd = scanner.nextLine().split(" ", 4);
        int a = Integer.parseInt(abcd[0]);
        int b = Integer.parseInt(abcd[1]);
        int c = Integer.parseInt(abcd[2]);
        int d = Integer.parseInt(abcd[3]);

        if ((Math.abs(a - b) <= d && Math.abs(b - c) <= d) || Math.abs(a - c) <= d) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define N 100059
#define show(x) cerr << #x << " = " << x << '\n'
using namespace std;
int n, m, k, x, y;
int f[N], ans[N], s[N];
int get_f(int i){
    return f[i] == i ? i : f[i] = get_f(f[i]);
}
void _merge(int u,int v){
    int f1 = get_f(u),f2 = get_f(v);
    if(f1 != f2)f[f2] = f1,s[f1] += s[f2];
}
void init(){
    for(int i = 0;i <= n;i ++){
        f[i] = i;s[i] = 1;
    }
}
int main(int argc,char * argv[]){
    scanf("%d%d%d", &n, &m, &k);
    init();
    while(m --){
        scanf("%d%d", &x, &y);
        ans[x] ++,ans[y] ++;
        _merge(x,y);
    }
    while(k --){
        scanf("%d%d", &x, &y);
        if(get_f(x) == get_f(y))ans[x] ++,ans[y] ++;
    }
    for(int i = 1;i <= n;i ++){
        printf("%d ",s[get_f(i)] - ans[i] - 1);
    }
    return 0;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;

namespace _0527
{
	class Program
	{
		static void Main(string[] args)
		{
			while (true)
			{
				int n = int.Parse(Console.ReadLine());
				if (n == 0) break;
				List<int> colorchange = new List<int> { 0 };
				bool lastisblack = Console.ReadLine() == "1";
				bool firstisblack = lastisblack;
				for (int i = 1; i < n; i++)
				{
					bool black = Console.ReadLine() == "1";
					if (i % 2 == 0)
					{
						if (black != lastisblack)
						{
							colorchange.Add(i);
						}
					}
					else
					{
						if (black != lastisblack)
						{
							if (colorchange.Count == 1)
								firstisblack = black;
							else
								colorchange.RemoveAt(colorchange.Count - 1);
						}
					}
					lastisblack = black;
				}
				colorchange.Add(n);
				int ret = 0;
				for (int i = 1; i < colorchange.Count(); i++)
				{
					if (!firstisblack) ret += colorchange[i] - colorchange[i - 1];
					firstisblack = !firstisblack;
				}
				Console.WriteLine(ret);
			}
		}
	}
}


Measured memory_bytes: 18224
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 998244353
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}

ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}

int main(){
    string s;
    cin >> s;
    if (s[0]==s[1]){
        cout << 1 << " " << 2 << endl;
        return 0;
    }else{
        for (ll i=2;i<s.size();i++){
            if (s[i]==s[i-1]){
                cout << i << " " << i+1 << endl;
                return 0;
            }else if (s[i]==s[i-2]){
                cout << i-1 << " " << i+1 << endl;
                return 0;
            }
        }
        
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}



Measured memory_bytes: 512
K, A, B = map(int, input().split())

if B <= A + 2:
    print(1 + K)
else:
    ans = (K - (A - 1)) // 2 * (B - A) + A
    if (K - (A - 1)) % 2 == 1:
        ans += 1
    print(ans)



Measured memory_bytes: 2940
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n, k;
	cin >> n >> k;

	ll con = 0;
	
	while (n > 0) {
		n /= k;
		con++;
	}
	cout << con << en;

	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
g=m//2
k=m-g
for i in range(m):
    if i%2==1:
        a=n-g-((i+1)//2)
        b=a+i+1
        print(a,b)
    else:
        a=k-(i//2)
        b=a+i+1
        print(a,b)


Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    lli n,w;
    cin>>n>>w;
    lli i,j,dp[n+1][w+1]={0},weight[n+1],value[n+1];
    memset(dp,0LL,sizeof(dp));
    
    for(i=1;i<=n;i++) cin>>weight[i]>>value[i];
    
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=w;j++)
        {
            if(j-weight[i]>=0)
            {
                dp[i][j]=max(dp[i][j],dp[i-1][j-weight[i]]+value[i]);
            }
            dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));
        }
    }
    
    cout<<dp[n][w];
    return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int main(){
 LL n,x;
 cin>>n>>x;
 LL r=x;
 while(n){
  r+=x/(n-x)*(n-x)*2;
  if(x%(n-x)==0)break;
  r+=n-x+x%(n-x);
  LL nn=n-x,nx=n-x-x%(n-x);
  n=nn,x=nx;
 } cout<<r<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){

        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt(); scanner.nextLine();
        String S = scanner.nextLine();

        if(S.length() <= K){
            System.out.println( S );

        }else{
            System.out.println( S.substring(0,K) + "..." );
        }

        scanner.close();
    }
}

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

int main() {
    string s;
    cin >> s;
    int count_b = 0;
    int64_t ans = 0;
    rep(i,s.size()) {
        if (s[i] == 'B') {
            count_b++;
        }
        if (s[i] == 'W') {
            ans += count_b;
        }
    }
    cout << ans << endl;
}

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

int main(){
    long long int n, c, k;
    cin >> n >> c >> k;

    vector<long long int> t(n);
    for(int i=0; i<n; i++){
        cin >> t[i];
    }
    sort(t.begin(),t.end());

    long long int ans = 0, time = t[0], num = 1;
    for(int i=1; i<n; i++){
        if(num == c || t[i] - time > k){
            ans += 1;
            num = 1;
            time = t[i];
        }
        else num += 1;
    }
    ans += 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    bool flag = false;
    double half = w * h / 2;

    if ((x == 0 || x == w) && (y == 0 || y == h)) {
        cout << half << " 0" << endl;
        return 0;
    }

    if ((2 * x == w && (y == 0 || y == h)) || (2 * y == h && (x == 0 || x == w))) {
        cout << half << " 0" << endl;
        return 0;
    }


    if (x == 0 || x == w || y == 0 || y == h) {
        cout << half << " 1" << endl;
        return 0;
    }

    double a = h / w;


    if (abs(y - a * x) <= 0.000000001) {
        flag = true;
    } else if (abs(y + a - h) <= 0.000000001) {
        flag = true;
    }

    cout << half << " " << flag << endl;
}


Measured memory_bytes: 256
N = int(input())
S_list = [input() for x in range(N)]
#print(S_list)

# Aで終わる、かつ、Bで始まらない
a_count = 0
# Aで終わらない、かつ、Bで始まる
b_count = 0
# Aで終わる、かつ、Bで始まる
ab_count = 0

for s in S_list:
    if s[0] != "B" and s[-1] == "A":
        a_count += 1
    elif s[0] == "B" and s[-1] != "A":
        b_count += 1
    elif s[0] == "B" and s[-1] == "A":
        ab_count += 1

# 単体で含まれる"AB"の数
temp = sum([x.count("AB") for x in S_list])

if ab_count == 0:
    print(temp + min(a_count, b_count))
else:
    # a_count、b_countともに0の場合
    if a_count == 0 and b_count == 0:
        print(temp + ab_count - 1)

    # a_count または b_count が0でない場合
    else:
        print(temp + min(a_count, b_count) + ab_count)


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

int main(){
        int N,L;
        vector<string> vS;
        string tmpS;
        cin >> N >> L;
        rep(i,N){
                cin >> tmpS;
                vS.push_back(tmpS);
        }
        sort(vS.begin(),vS.end());
        rep(i,N){
                cout << vS[i];
        }
        cout << endl;
        return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long n = Long.parseLong(sc.next());
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());

    System.out.println(n / (a + b) * a + Math.min((n % (a + b)), a));

    sc.close();
  }
}

Measured memory_bytes: 23124
#pragma GCC optimize ("O3")
#pragma GCC target("avx,avx2,avx512f")
#pragma region header
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

using vi = vector<int>;

#pragma endregion header

void solve(int N, vi a, vi b) {
  int ans = 0;
  rep(i, N)rep(j, N)ans ^= a[i] + b[j];
  cout << ans << endl;
}


#pragma region main
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int N;
  cin >> N;
  vi a(N);
  for(int i = 0 ; i < N ; i++){
    cin >> a[i];
  }
  vi b(N);
  for(int i = 0 ; i < N ; i++){
    cin >> b[i];
  }
  solve(N, move(a), move(b));
}
#pragma endregion main


Measured memory_bytes: 4764
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int N, M;
    cin >> N >> M;
    bool from1[N];
    bool toN[N];
    REP(i, N) { from1[i] = false; toN[i] = false; }
    REP(i, M)
    {
        int a, b;
        cin >> a >> b;
        --a; --b;
        if (a == 0) from1[b] = true;
        if (b == N - 1) toN[a] = true;
    }
    REP(i, N)
    {
        if (from1[i] && toN[i])
        {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

string s[334];
int cnt[334],ans[334][334];

int main(void){
	int h,w,k,i,j,p,n=0;
	bool flag;
	cin >> h >> w >> k;
	for(i=0; i<h; ++i){
		cin >> s[i];
		for(j=0; j<w; ++j){
			if(s[i][j]=='#'){
				++cnt[i];
			}
		}
	}
	for(i=0; i<h; ++i){
		if(cnt[i]){
			p = i;
			break;
		}
	}
	for(i=p; i<h; ++i){
		if(!cnt[i]){
			for(j=0; j<w; ++j){
				ans[i][j] = ans[i-1][j];
			}
			continue;
		}
		flag = false;
		++n;
		for(j=0; j<w; ++j){
			if(s[i][j]=='#'){
				if(flag){
					++n;
				}else{
					flag = true;
				}
			}
			ans[i][j] = n;
		}
	}
	for(i=0; i<p; ++i){
		for(j=0; j<w; ++j){
			ans[i][j] = ans[p][j];
		}
	}
	for(i=0; i<h; ++i){
		for(j=0; j<w; ++j){
			cout << ((j)?" ":"") << ans[i][j];
		}
		cout << endl;
	}
	return 0;
}


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

int x[20], y[20];

int check(int nx, int ny, int N) {
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if(nx == x[i] && ny == y[i]) {
            cnt++;
            x[i] = y[i] = -1;
        }
    }
    return cnt;
} 

int main() {
    int N, M, l;
    char d;

    while(1) {
        cin >> N;
        if(N == 0) break;
        for(int i = 0; i < N; i++) {
            cin >> x[i] >> y[i];
        }
        cin >> M;
        int nx = 10, ny = 10, cnt = 0;
        for(int i = 0; i < M; i++) {
            cin >> d >> l;
            if(d == 'N') {
                for(int j = 0; j < l; j++) {
                    ny++;
                    cnt += check(nx, ny, N);
                }
            }
            else if(d == 'S') {
                for(int j = 0; j < l; j++) {
                    ny--;
                    cnt += check(nx, ny, N);
                }
            }
            else if(d == 'E') {
                for(int j = 0; j < l; j++) {
                    nx++;
                    cnt += check(nx, ny, N);
                }
            }
            else {
                for(int j = 0; j < l; j++) {
                    nx--;
                    cnt += check(nx, ny, N);
                }
            }
        }
        if(cnt == N) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    return 0;
}


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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	int INF = (int)1 << 60;
	int u = INF;
	int d = -INF;
	while (u - d > 1) {
		int m = (u + d) / 2;
		int c = 0;
		for (int i = 0; i < N; i++) {
			if (A[i] * A[i] <= m) c--;
			if (A[i] < 0) {
				int mn = (m / A[i]) - 5;
				while (mn * A[i] > m) mn++;
				int pos = lower_bound(A.begin(), A.end(), mn) - A.begin();
				//cerr << m << " " << A[i] << " " << mn <<  " " << pos << endl;
				c += N - pos;
			} else if (A[i] > 0) {
				int mx = (m / A[i]) + 5;
				while (mx * A[i] > m) mx--;
				int pos = upper_bound(A.begin(), A.end(), mx) - A.begin();
				//cerr << m << " " << A[i] << " " << mx <<  " " << pos << endl;
				c += pos;
			} else {
				if (m >= 0) {
					c += N;
				}
			}
		}
		//cerr << m << " " << c << endl;
		c /= 2;
		if (c >= K) {
			u = m;
		} else {
			d = m;
		}
	}
	cout << u << endl;
}


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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<int> v;
	int count = 1;
	for (int i = 1; i < n; i++) {
		if (a[i] == a[i - 1]) count++;
		else {
			v.push_back(count);
			count = 1;
		}
	}
	v.push_back(count);
	int ans = 0;
	for (const auto& item : v) ans += item / 2;
	cout << ans << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	int n;
	cin>>n;
	int free=0;
	vector<int>a(n),rate(8);
	rep(i,n){
		int temp=0;
		cin>>temp;
		if(temp>=3200)free++;
		else if(temp>=2800)rate.at(7)++;
		else if(temp>=2400)rate.at(6)++;
		else if(temp>=2000)rate.at(5)++;
		else if(temp>=1600)rate.at(4)++;
		else if(temp>=1200)rate.at(3)++;
		else if(temp>=800)rate.at(2)++;
		else if(temp>=400)rate.at(1)++;
		else rate.at(0)++;
		
	}	
	int ans=0;
	for(auto i:rate){
		if(i!=0)ans++;
	}
	
	cout<<max(ans,1)<<" "<<ans+free<<endl;
	
	return 0;
}


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

typedef long long ll;

typedef pair<int, pair<int, int> > p;

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

    int N;
    cin >> N;

    int a = 1;

    while(a * 2 <= N) {
        a *= 2;
    }

    cout << a << endl;
}

Measured memory_bytes: 256
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <set>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, c[200020], d[200020] = {}, cnt = 1, now = 0, ans = 0;
	cin >> a >> b;
	for (int i = 0; i < a; i++) {
		cin >> c[i];
	}
	sort(c, c + a);
	for (int i = 1; i < a; i++) {
		if (c[i] == c[i - 1])cnt++;
		else {
			d[now] = cnt;
			cnt = 1;
			now++;
		}
	}
	if (cnt) {
		d[now] = cnt;
		now++;
	}
	sort(d, d + now);
	now -= b;
	for (int i = 0; i < now; i++)ans += d[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3456
#include<stdio.h>
int main()
{
    int i,x;
    scanf("%d",&i);

    if(i>99&&i<1000){

    

    x=(i/10)%10;
    if((i%10)==7||(i/100)==7||x==7)
        printf("Yes\n");
    else printf("No\n");

    }


}


Measured memory_bytes: 1664
import copy
n=int(input())
a=list(map(int,input().split()))
a.insert(0,0)
a.append(0)
s=0
for i in range(n+1):
    s+=abs(a[i]-a[i+1])

for i in range(1,n+1):
    print(s+abs(a[i-1]-a[i+1])-abs(a[i-1]-a[i])-abs(a[i]-a[i+1]))

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

int main(){
  int N, K; cin >> N >> K;
  map<char,int> score;
  cin >> score['s'] >> score['p'] >> score['r'];
  string T; cin >> T;

  int point = 0;
  rep(i,K){
    int j=0;
    while (i + K*j<N){
      int index = i + K*j;
      if (j>0 && T.at(index-K) == T.at(index)) {
        T.at(index) = '0';
        j++;
        continue;
      }
      point += score.at(T.at(index));
      j++;
    }
  }

  cout << point << endl;
  return 0;
}

 

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    lr = []
    for _ in range(N):
        l,r = inputMap()
        lr.append((l,r))
        
    ans = 0
    for i in lr:
        l,r = i
        ans += r-l+1
    
    print(ans)
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38896
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        System.out.println(N == M ? "Yes" :"No");
    }

}



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

int main() {
  vector<int> standings(2);int ans=0;
  cin>>standings[0]>>standings[1];
  for(auto it=standings.begin();it!=standings.end();it++){
    int num = *it;
  	if(num<=3){
      ans += (4-num) * 100000;
    }
  }
  if(ans==600000)ans += 400000;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
// #define int long long
struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
}IoSetup;

using Int = __int128_t;
using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int SMOD = 1000000007;
constexpr int NMOD = 998244353;
constexpr int dx[]={1,0,-1,0,1,1,-1,-1};
constexpr int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T&b){if(a<b)return(a=b,1);return 0;}
template<class T>bool chmin(T &a, const T&b){if(b<a)return(a=b,1);return 0;}


signed main() {

    int64_t n;
    cin >> n;

    if(n == 1) {
        cout << 0 << endl;
        return 0;
    }
    if(n == 2) {
        cout << 2 << endl;
        return 0;
    }

    int64_t a = 1, b = 1, c = 1;
    for(int i = 0; i < n; i++) {
        a *= 10;
        b *= 9;
        c *= 8;
        a %= SMOD;
        b %= SMOD;
        c %= SMOD;
    }
    cout << (SMOD + SMOD + a - b - b + c) % SMOD << endl;
    
    return 0;
}


Measured memory_bytes: 3652
n=int(input())
m = [[-1 for i in range(n)] for j in range(n)]
for i in range(n): #隣接の辺のコストを入力
  nums = list(map(int, input().split()))
  for j in range(n):
    m[i][j] = nums[j]

d=[0]+[10**9]*n
visited=[0]*n
a=0
while 1:
  u=-1
  for i in range(n):
    if not visited[i] and (u<0 or d[i]<d[u]):
      u=i
  if u<0:
    break
  visited[u]=1
  a+=d[u]
  for v in range(n):
    t=m[u][v]
    if t+1 and d[v]>t:
      d[v]=t
print(a)


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

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y ;
  
  int res = 0;
  long long ans = a * x + b * y;
  for (int i = 0; i < 100001 ;i++){
    res = i * c * 2 + a * max(0, x - i) + b * max(0, y - i);
    if( res < ans ) ans = res;
  }
  cout << ans << endl;
    
}
  


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int A, B, C;

int dfs(vector<int>& v, int current, int ba, int bb, int bc) {
    if (current >= v.size()) {
        if (ba == 0 || bb == 0 || bc == 0)
            return 1e9;
        else {
            int ret = abs(ba - A) + abs(bb - B) + abs(bc - C);
            return ret;
        }
    }

    int ret = dfs(v, current + 1, ba, bb, bc);
    ret = min(
        ret, dfs(v, current + 1, ba + v[current], bb, bc) + (ba == 0 ? 0 : 10));
    ret = min(
        ret, dfs(v, current + 1, ba, bb + v[current], bc) + (bb == 0 ? 0 : 10));
    ret = min(
        ret, dfs(v, current + 1, ba, bb, bc + v[current]) + (bc == 0 ? 0 : 10));
    return ret;
}

int main() {
    int n;
    cin >> n >> A >> B >> C;

    vector<int> v(n);
    for (int i = 0; i < n; ++i)
        cin >> v[i];

    int ret = dfs(v, 0, 0, 0, 0);
    cout << ret << '\n';
}


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

int cnt;

void inserationSort(int A[], int n, int g)
{
    for(int i = g; i < n; i++){
        int v = A[i];
        int j = i - g;
        
        while(j >= 0 && A[j] > v){
            A[j+g] = A[j];
            j = j-g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void shellSort(int A[], int n)
{
    cnt = 0;
    int m = 0;
    int temp = n;
    int G[n];
    for(int i = 0; i < n; i++){
        temp = temp/2;
        if(i){
            if(temp != 0){
                G[i] = temp;
                m++;
            }
            else{
                break;
            }
        }
        else{
            G[i] = temp;
            m++;
        }
    }
    
    for(int i = 0; i < m; i++){
        inserationSort(A, n, G[i]);
    }
    
    cout << m << endl;
    for(int i = 0; i < m; i++){
        if(i) cout << " ";
        cout << G[i];
    }
    cout << endl;
    cout << cnt << endl;
}

int main()
{
    int n;
    cin >> n;
    int A[n];
    for(int i = 0; i < n; i++) cin >> A[i];
    
    shellSort(A, n);
    for(int i = 0; i < n; i++) cout << A[i] << endl;
    
    return 0;
}


Measured memory_bytes: 7008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n,m;
  cin >> n >> m;
  set<ll> cnt0,cntn;
  for(ll i=0;i<m;i++) {
    ll a,b;
    cin >> a >> b;
    if(a==1) {
      cnt0.insert(b);
    }
    if(b==n) {
      cntn.insert(a);
    }
  }
  for(ll p:cnt0) {
    if(cntn.count(p)) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 9600
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

ll A[200010], B[200010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    ll sol = 0;
    bool ok = 1;
    for (int i = 0;i < N;i++) cin >> A[i] >> B[i];
    ll mi = 1E9;
    for (int i = 0;i < N;i++) {
    	if (A[i] != B[i]) ok = 0;
    	sol += A[i] + B[i];
    	if (A[i] > B[i]) mi = min(mi, B[i]);
    }
    sol -= mi * 2;
    ll ans;
    if (ok) ans = 0;
    else ans = sol / 2;
    ll ck = 0;
    for (int i = 0;i < N;i++) ck += A[i] - B[i];
    if (ck == 0) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640