akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.nextLine()); //nextInt???Int??¨????????????????????????????????????????????????????????§????????§nextLine??????????????¨?¬?????????§???????????????????????§?????????
		String x[] = scan.nextLine().split(" ");
		String y[] = scan.nextLine().split(" ");
		scan.close();
		System.out.println(CalcD(x, y, 1));
		System.out.println(CalcD(x, y, 2));
		System.out.println(CalcD(x, y, 3));
		System.out.println(CalcD(x, y, Double.NEGATIVE_INFINITY));
	}

	public static double CalcD(String X[], String Y[], double P){
		if(P == Double.POSITIVE_INFINITY || P == Double.NEGATIVE_INFINITY){
			double max = 0;
			for(int i = 0; i < X.length; i++){
				max = Math.max(Math.abs(Integer.valueOf(X[i]) - Integer.valueOf(Y[i])), max);
			}
			return max;
		}else{
			double sig = 0;
			for(int i = 0; i < X.length; i++){
				sig += Math.pow(Math.abs(Integer.valueOf(X[i]) - Integer.valueOf(Y[i])), P);
			}
			double d = Math.pow(sig, 1 / P);
			return d;
		}
	}
}

Measured memory_bytes: 26576
// A.cpp
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int m, d;
    scanf("%d%d", &m, &d);
    int ans = 0;
    for (int i = 1; i <= m; i++)
        for (int a = 2; a <= 9; a++)
            for (int b = 2; b <= 9; b++)
                if (a * 10 + b <= d && a * b == i)
                    ans++;
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,n) for(h=0;h<n;h++)in(v[h]);
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define cf(n) printf("%I64d\n",n)
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,n) for(h=0;h<n;h++)pr(v[h]); lin
#define ck printf("continue\n")
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define N 100005
typedef long long int ll;
int par[N],lev[N],tot[N];
void makeset(int n)
{
    fill(par,par+n,-1);
    fill(tot,tot+n,1);
    return;
}
int findset(int x)
{
    int y=x;
    while(par[y]>=0)
        y=par[y];
    if(x!=y)
        par[x]=y;
    return y;
}
void combine(int a,int b)
{
    a=findset(a);
    b=findset(b);
    if(a!=b)
    {
        if(lev[a]<lev[b])
            par[a]=b,tot[b]+=tot[a];
        else if(lev[a]>lev[b])
            par[b]=a,tot[a]+=tot[b];
        else
            lev[b]++,par[a]=b,tot[b]+=tot[a];
    }
    return ;
}
int main()
{
    int m,k,n,i,a,h;
    in2(m,k);
    n=pow(2,m);
    if(m==1)
    {
        if(k==0)
            pr(k),pr(k),pr(1-k),out(1);
        else
            out(-1);
    }
    else
    {
        if(k>=n)
            out(-1);
        else
        {
            vi v(2*n);
            v[0]=k,v[n]=k;
            a=0;
            for(i=1;i<n;i++)
            {
                if(a==k)
                    a++;
                v[n+i]=a,v[n-i]=a;
                a++;
            }
            dbg(v,2*n);
        }
    }
}


Measured memory_bytes: 2816
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
loop = []
start = 0
index = 0
check = [-1] * N
fin = False
count = 0
while True:
    if check[index] != -1:
        start = check[index]
        break
    else:
        loop.append(index)
        if len(loop) == K + 1:
            print(index + 1)
            sys.exit()
        check[index] = count
        count += 1
        index = a[index]


if (K + 1 - start) % len(loop[start:]) == 0:
    print(loop[-1] + 1)
else:
    print(loop[start + (K + 1 - start) % len(loop[start:]) - 1] + 1)


Measured memory_bytes: 31276
$N=int(<STDIN>);
push @T,0;push @X,0;push @Y,0;
for($i=0;$i<$N;$i++){
	($t,$x,$y)=split " ",<STDIN>;
	push @T,$t;push @X,$x;push @Y,$y;
}
for($i=1;$i<=$#T;$i++) {
	$dt=$T[$i]-$T[$i-1];
	$dx=$X[$i]-$X[$i-1];
	$dy=$Y[$i]-$Y[$i-1];
	$d=$dt-$dx-$dy;
	if($d<0 || $d%2>0) { $f=1; last;  }
}

print ($f?"No":"Yes");



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

int main(){
  int count[2];
  count[0] = 0;count[1] = 0;
  for(int i = 0;i < 3;i++){
    int a;
    cin >> a;
    if(a == 5){
      count[0]++;
    }else if(a == 7){
      count[1]++;
    }
  }

  if(count[0] == 2 && count[1] == 1){
    std::cout << "YES" << std::endl;
  }else{
    std::cout << "NO" << std::endl;
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a.at(i);
  }
  int now = 0;
  int count = 1;
  if ( n != 1) {
    rep(i, n-1) {
      if ((now == 0) && (a.at(i) < a.at(i+1))) {
        now = 1;
      }
      else if ((now == 0) && (a.at(i) > a.at(i+1))) {
        now = 2;
      }
      if ((now == 1) && (a.at(i) > a.at(i+1))) {
        now = 0;
        count++;
      }
      else if ((now == 2) && (a.at(i) < a.at(i+1))) {
        now = 0;
        count++;
      }
    }
    cout<<count<<endl;
    return 0;
  }
  
  cout << 1 << endl;
  return 0;

}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        int A = in.nextInt();
        String op = in.next();
        int B = in.nextInt();
        if ("+".equals(op)) {
            System.out.println(A + B);
        } else {
            System.out.println(A - B);
        }
    }
}

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

void rotate_side(vector<int> &si, int n) {
  if (n < 0) {
    n = 4 - (abs(n) % 4);
  }

  for (int i = 0; i < n; i++) {
    int tmp = si[0]; 
    si[0] = si[2];
    si[2] = si[5];
    si[5] = si[4];
    si[4] = tmp;
  }
}
void rotate_front(vector<int> &si, int n) {
  if (n < 0) {
    n = 4 - (abs(n) % 4);
  }

  for (int i = 0; i < n; i++) {
      int tmp = si[0];
      si[0] = si[1];
      si[1] = si[5];
      si[5] = si[3];
      si[3] = tmp;
  }
}

void rotate_top(vector<int> &si, int n) {
  if (n < 0) {
    n = 4 - (abs(n) % 4);
  }
  for (int i = 0; i < n; i++) {
    int tmp = si.at(1);
    si[1] = si[2];
    si[2] = si[3];
    si[3] = si[4];
    si[4] = tmp;
  }
}
 
void init_dice(vector<int> &si) {
  cin >> si[0];
  cin >> si[2];
  cin >> si[3];
  cin >> si[1];
  cin >> si[4];
  cin >> si[5];
}

int findLabel(vector<int> &si, int num) {
  return distance(si.begin(), find(si.begin(), si.end(), num));
}

bool compareDice(vector<int> &d1, vector<int> &d2) {
  int top = d1[0];
  int front = d1[2];
  
  set<int> s(d1.begin(), d1.end());
  set<int> s2(d2.begin(), d2.end());
  if (s.size() != s2.size() || s != s2) {
      return false;
  }

    // find top
    int d = findLabel(d2, top);
    // cout << "DEBUG: " << d << endl;
    switch (d) {
    case 0:
      // do nothing
      break;
    case 1:
      rotate_front(d2, 1);
      break;
    case 2:
      rotate_side(d2, 1);
      break;
    case 3:
      rotate_front(d2, 3);
      break;
    case 4:
      rotate_side(d2, -1);
      break;
    case 5:
      rotate_front(d2, 2);
      break;
    }

    // find front
    d = findLabel(d2, front);
    // cout << "DEBUG: " << d << endl;
    // cout << "DEBUG: ";
    // for (int k = 0; k < 6; k++) cout << si.at(k) << " ";
    // cout << endl;
    switch (d) {
    case 1:
      rotate_top(d2, 3);
      break;
    case 2:
      // do nothing
      break;
    case 3:
      rotate_top(d2, 1);
      break;
    case 4:
      rotate_top(d2, 2);
      break;
    default: // Different
      return false;
    }
    // cout << "DEBUG: ";
    // for (int k = 0; k < 6; k++) cout << si.at(k) << " ";
    // cout << endl;
    return ((d1 == d2) ? true : false);
}

int main() {
  int N;
  cin >> N;
  vector<vector <int>> dices(N, vector<int>(6));
  for (int i = 0; i < N; i++) init_dice(dices.at(i));

  for (int i = 0; i < N-1; i++) {
    for (int j = i + 1; j < N; j++) {
      if (compareDice(dices[i], dices[j])) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}



Measured memory_bytes: 3168
object Main{
	def main(args:Array[String]){
		val s = new java.util.Scanner(System.in)
		val n = s.nextInt
		val t = s.next
		val b,w = Array.fill(n+2)(0)

		for(i <- 0 to n - 1)
			b(i+1) = b(i) + (if(t.charAt(i) == '#') 1 else 0)
		for(i <- n-1 to 0 by -1)
			w(i+1) = w(i+2) + (if(t.charAt(i) == '.') 1 else 0)


//		println(b.mkString(" "))
//		println(w.mkString(" "))

		println((0 to n).map(i=>b(i)+w(i+1)).min)
	}
}

Measured memory_bytes: 40308
///   Journey to the End of earth   ///
/// Gunjan Kumar ///
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> // for less 
// using namespace __gnu_pbds; 
using namespace std;
#define ll  long long
#define s(n) scanf("%d",&n)
#define ls(n) scanf("%lld",&n)
#define p(n) printf("%d",n)
// #define ln() printf("\n")
#define pln(n) printf("%d\n",n)
#define lpln(n) printf("%lld\n",n)
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rev(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define tc           ll t1; cin>>t1; while(t1--)
#define inp         ll n; cin>>n; ll arr[n]; rep(i,0,n) cin>>arr[i];
#define vect vector<ll>
#define sortv(v)       sort(v.begin(),v.end())
#define lower(v,n)    lower_bound(v.begin(),v.end(),n)-v.begin()
#define upper(v,n)    upper_bound(v.begin(),v.end(),n)-v.begin()
#define bitcount(n) __builtin_popcount(n)
#define ln <<endl
#define inf          LONG_MAX
#define ninf         LONG_MIN
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const   ll mod=1e9+7;
const ll N=1e5+5;



int main()
{

         ios_base::sync_with_stdio(false);
         
         ll n,k;
         cin >> n >>k;
         ll arr[n];
         rep(i,0,n)
         cin >> arr[i];
         int pos=0;
         rep(i,k,n)
         {
           if(arr[i]>arr[pos++])
            cout<<"Yes"<<endl;
          else cout<<"No"<<endl;
         }
         
        
     return 0;
}



Measured memory_bytes: 5216
n,m=map(int,input().split())
h=list(map(int,input().split()))
ans=[1]*n
for i in range(m):
  a,b=map(int,input().split())
  if h[a-1]<=h[b-1]:
    ans[a-1]=0
  if h[a-1]>=h[b-1]:
    ans[b-1]=0
print(ans.count(1))

Measured memory_bytes: 20104
n, d = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        dist = 0
        for k in range(d):
            dist += (p[i][k] - p[j][k])**2
        if int(dist**0.5) == dist**0.5:
            cnt += 1
print(cnt)

Measured memory_bytes: 9376
#include <bits/stdc++.h>
using namespace std;
long long n;
string a,b;
char c;
int main()
{
	cin>>n;
	do{
		c=(n-1)%26+'a';
		a+=c;
		n=(n-1)/26;
	}while(n>0);
	for(int i=a.size()-1;i>=0;i--)b+=a[i];
	cout<<b;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> vector<T> make_vec(size_t n) { return vector<T>(n); }
template<typename T, typename... Args> auto make_vec(size_t n, Args... args) {
    return vector<decltype(make_vec<T>(args...))>(n, make_vec<T>(args...));
}
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value>::type fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<!is_same<T, U>::value>::type fill_v(U& u, const V... v) {
    for (auto& e : u) fill_v<T>(e, v...);
}

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

    string s;
    cin >> s;
    int n = s.size();
    int sum = 0;
    rep(i, n) {
        sum += s[i] - '0';
    }
    cout << (sum % 9 == 0 ? "Yes\n" : "No\n");
}


Measured memory_bytes: 3740
#include <iostream>
#include <cmath>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

const long double PI = 3.14159265358979;
const long double EPS = 1e-8;

struct Point {
	long double px, py;
};
struct Line {
	long double pa, pb;
};
bool operator< (const Line &a1, const Line &a2) {
	if (a2.pa - a1.pa > EPS) return true;
	else if (a1.pa - a2.pa > EPS) return false;
	else if (a2.pb - a1.pb > EPS) return true;
	return false;
}
bool operator== (const Line &a1, const Line &a2) {
	if (fabs(a1.pa - a2.pa) < EPS && fabs(a1.pb - a2.pb) < EPS) return true;
	return false;
}
bool operator== (const Point &a1, const Point &a2) {
	if (fabs(a1.px - a2.px) < EPS && fabs(a1.py - a2.py) < EPS) return true;
	return false;
}
bool operator< (const Point &a1, const Point &a2) {
	if (a2.px - a1.px > EPS) return true;
	else if (a1.px - a2.px > EPS) return false;
	else if (a2.py - a1.py > EPS) return true;
	return false;
}

Point rotate(Point a1) {
	Point A;
	A.px = a1.px * cos(30.0L * PI / 360.0L) - a1.py * sin(30.0L * PI / 360.0L);
	A.py = a1.px * sin(30.0L * PI / 360.0L) + a1.py * cos(30.0L * PI / 360.0L);
	return A;
}

Line makes(Point p1, Point p2) {
	Point p3 = Point{ (p1.px + p2.px) / 2.0L, (p1.py + p2.py) / 2.0L };

	long double a = -(p2.px - p1.px) / (p2.py - p1.py);
	long double b = p3.py - p3.px * a;
	return Line{ a, b };
}

int N; Point V[1009];
vector<tuple<Line, int, int>>vec;
bool used[1009];

bool check2(Line V1, Point V2) {
	long double E = V1.pb + V1.pa * V2.px;
	if (fabs(E - V2.py) < EPS) return true;
	return false;
}

bool check(Line BASE, vector<pair<int, int>>T) {
	for (int i = 0; i < N; i++) used[i] = false;
	for (int i = 0; i < T.size(); i++) { used[T[i].first] = true; used[T[i].second] = true; }

	vector<int>U; for (int i = 0; i < N; i++) { if (used[i] == false) U.push_back(i); }
	if (U.size() >= 3) return false;

	vector<Point> I;
	for (int i = 0; i < T.size(); i++) {
		I.push_back(Point{ (V[T[i].first].px + V[T[i].second].px) / 2.0L, (V[T[i].first].py + V[T[i].second].py) / 2.0L });
	}
	for (int i = 0; i < U.size(); i++) I.push_back(V[U[i]]);
	sort(I.begin(), I.end());
	I.erase(unique(I.begin(), I.end()), I.end());

	if (I.size() == 1) return false;

	for (int i = 0; i < U.size(); i++) {
		bool G = check2(BASE, V[U[i]]);
		if (G == false) return false;
	}
	return true;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> V[i].px >> V[i].py;
		V[i] = rotate(V[i]);
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			vec.push_back(make_tuple(makes(V[i], V[j]), i, j));
		}
	}
	sort(vec.begin(), vec.end());

	vector<pair<int, int>>V; Line BASE = get<0>(vec[0]); V.push_back(make_pair(get<1>(vec[0]), get<2>(vec[0])));
	bool flag = false;
	for (int i = 1; i <= vec.size(); i++) {
		if (i == vec.size() || !(BASE == get<0>(vec[i]))) {
			bool t = check(BASE, V);
			if (t == true) {
				flag = true;
			}
			if (i < vec.size()) BASE = get<0>(vec[i]);
			V.clear();
		}
		if (i < vec.size()) V.push_back(make_pair(get<1>(vec[i]), get<2>(vec[i])));
	}

	if (flag == true) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 27632
# Segment Treeを使う。一点更新，区間最大値

N, K = map(int, input().split())

seglen = 1 << 19

segtree = [0 for _ in range(seglen * 2)]
# segtree[seglen + i] = Bの最後の値に i を使う時のlongest len

def segset(ind, val):
    segtree[ind] = val
    ind //= 2
    while ind != 0:
        segtree[ind] = max(segtree[ind*2], segtree[ind*2 + 1])
        ind //= 2
    return


def segmax(l, r):
    ret = 0

    while l < r:

        if l % 2 == 1:
            ret = max(ret, segtree[l])
            l += 1
        l //= 2

        if r % 2 == 1:
            ret = max(ret, segtree[r - 1])
            r -= 1
        r //= 2

    return ret

A = []
for _ in range(N):
    a = int(input())
    A.append(a)

ans = 0

for a in A:
    a_ind = seglen + a

    l = max(seglen, a_ind - K)
    r = min(seglen + 400000, a_ind + K + 1)

    longest = segmax(l, r)

    segset(a_ind, longest + 1)

    ans = max(ans, longest + 1)

print(ans)

Measured memory_bytes: 142236
#include<stdio.h>
int main(){

    char s[4],r[4];
    int d=0,i;
    scanf("%s",s);
    scanf("%s",r);

        for(i=0;i<3;i++){
            if(s[i]==r[i]){
               d=d+1;
            }
        }
    printf("%d",d);



return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int min(int a,int b){

  int m=0;

  if(a>b)
    return b;
  else
    return a;
}

int main(void){

  const int coin[6]={1,5,10,50,100,500};

  while(1){
  int amount=0;
  int ans=0;
  int i;
  int t;

  scanf("%d",&amount);

  if(amount==0)
    {
      break;
    }

  int change=1000-amount;

  for(i=5;i>=0;i--){
    t=change/coin[i];
    change-=t*coin[i];
    ans+=t;
    if(change<1){
      break;
      }
    }

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

  }

  return 0;

}

  

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

int pow(int b, int n) {
    int r = 1;
    while(0 < n) {
        if(n%2 == 1) {
            r *= b;
            n--;
        }else{
            n /= 2;
            b *= b;
        }
    }
    return r;
}

int main() {
    int a;
    int b;
    int c;
    int k;
    scanf("%d%d%d", &a, &b, &c);
    scanf("%d", &k);
    int ichi;
    
    ichi = max(max(a, b), c);
    int po = ichi*pow(2, k) + a + b + c - ichi;
    printf("%d\n", po);

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
 
namespace AGC024_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var A = input[0];
            var B = input[1];
            var C = input[2];
            var K = input[3];
 
            if (Math.Abs(A-B) >= Math.Pow(10,18)) Console.WriteLine("Unfair");
            else Console.WriteLine(K % 2 == 0 ? A - B : B - A);
        }
    }
}

Measured memory_bytes: 11348
n, m = map(int, input().split())
k = [0] * m
s = []
for i in range(m):
    ks = list(map(int, input().split()))
    k[i] = ks[0]
    s.append(ks[1:])
p = list(map(int, input().split()))

ans = 0
for bit in range(1 << n):

    S = []
    for i in range(n):
        if bit & (1 << i):
            S.append(i)

    on = 0
    for j in range(m):
        c = 0
        for l in S:
            if ((l + 1) in s[j]):
                c += 1
        if c % 2 == p[j]:
            on += 1

    if on == m:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 1000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

int N;
int l[MAX_N], r[MAX_N];

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  REP(i,N) cin >> l[i] >> r[i];

  ll sum = 0;
  REP(i,N) sum += r[i] - l[i] +1;

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
ikeru = [[] for _ in range(n)]
for i in range(n-1):
	a, b = map(int, input().split())
	ikeru[a-1].append((b-1, i))

settansaku = set([])
setmada = {0}
listmada = [(0, None)]  #left: Vertex, right: Color
kouho = 1
num = [0 for _ in range(n-1)]

while kouho != 0:
	for i, cnt in listmada[:]:
		colors = {cnt}
		settansaku.add(i)
		setmada.remove(i)
		listmada.remove((i, cnt))
		kouho -= 1
		c = 0
		for k, j in ikeru[i]:
			if not k in setmada:
				if not k in settansaku:
					setmada.add(k)
					while True:
						if c not in colors:
							listmada.append((k, c))
							colors.add(c)
							num[j] = c
							break
						c += 1
					kouho += 1

print(max(num)+1)
print("\n".join([str(i+1) for i in num]))

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

int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int n;
    vector<vector<bool>> arr(3, vector<bool>(3));
    map<int,pair<int,int>> mp;
  
    auto row = [&] (int i) {
    	//return inside(i,j+1) && inside(i,j-1) && arr[i][j+1] && arr[i][j-1] && arr[i][j];
    	return arr[i][0] && arr[i][1] && arr[i][2];
    };

    auto col = [&] (int i) {
    	//return inside(i+1,j) && inside(i-1,j) && arr[i+1][j] && arr[i-1][j] && arr[i][j];
    	return arr[0][i] && arr[1][i] && arr[2][i];
    };

    auto diag = [&] () {
    	//return inside(i+1,j+1) && inside(i-1,j-1) && arr[i+1][j+1] && arr[i-1][j-1] && arr[i][j];
    	return (arr[0][0] && arr[1][1] && arr[2][2]) || (arr[0][2] && arr[1][1] && arr[2][0]);
    };

    for(int i = 0 ; i < 3; i++)
    	for(int j = 0; j < 3; j++) {
    		int x;
    		cin>>x;
    		mp[x] = {i,j};
    		//arr[i][j] = x;
    	}
    cin>>n;
    vector<int> b(n);
    for(int i = 0; i < n; i++) {
    	int x;
    	cin>>x;
    	b[i] = x;
    }

    for(int i : b) {
    	if(mp.find(i) != mp.end()) {
    		int r = mp[i].first;
    		int c = mp[i].second;
    		arr[r][c] = true;
    		if(row(r) || col(c) || diag()) {
    			cout<<"Yes";
    			return 0;
    		}
    	}
    }
    cout<<"No";


	return 0;		
}


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

int main()
{
    // s` < t` の辞書順になればよい
    // つまりsは昇順にソート、tは降順にソートして比較すればよい

    string s;
    cin >> s;
    sort(s.begin(), s.end());

    string t;
    cin >> t;
    sort(t.begin(), t.end(), greater<char>());

    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            bool ret = false;
            var read = RL();
            //dflist = spr(RL()).Select(x => c2i(x)).ToList();
            ret = (read[2] == read[3] && read[4] == read[5]);
            Console.WriteLine(bool2ret(ret));
            //Console.ReadLine();


        }
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static int c2i(string c) { return int.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C, long long D) {
    bool takahashi = true;
    while (true) {
        if (takahashi) {
            C -= B;
            if (C <= 0) {
                cout << "Yes" << endl;
                return;
            }
            takahashi = false;
        } else {
            A -= D;
            if (A <= 0) {
                cout << "No" << endl;
                return;
            }
            takahashi = true;
        }
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can
// remove this line by using your custom template)
int main() {
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    long long D;
    scanf("%lld", &D);
    solve(A, B, C, D);
    return 0;
}


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

typedef long long ll;

int N;
string S;
ll dp[5010][5010] = {0};// 操作回数 文字の長さ
ll mod = 1000000007;

int main()
{
   scanf("%d",&N);
   cin >> S;

   dp[0][0] = 1;

   for(int i = 1; i <= N; i++)
   {
       for(int j = 0; j <= N; j++)
       {
           dp[i][j] = dp[i - 1][max(0,j - 1)] + 2 * dp[i - 1][j + 1];
           dp[i][j] %= mod;
       }
   }

   printf("%lld\n",dp[N][S.size()]);
   return 0;
}


Measured memory_bytes: 195968
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }
    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }
    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
//-----------------------------------------
int main(void){
    ll N,Q;cin>>N>>Q;
    UnionFind uf(N);
    REP(i,Q){
        ll q;cin>>q;
        ll x,y;cin>>x>>y;
        if(q){//same
            cout<<uf.issame(x,y)<<"\n";
        }else{//unite
            uf.merge(x,y);

        }
    }
}


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

int main() {
  int a,b;
  cin>>a>>b;
  for(int i=1;i<1251;i++){
    if((8*i)/100==a&&i/10==b){
      cout<<i<<endl;
      break;
    }
    if(i==1250){
      cout<<"-1"<<endl;
    }
  }
}
 
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n;
long long m;
long long c;
long long a[100000];
long long mp[200][200];
long long j=0;
long long k=1;
void T(long long s){
	if(s % 2 == 0){
		for(long long i=0 ; i < m ;i++){
			if(a[j] == 0){
				j++;
				k++;
			}
			mp[s][i] = k;
			a[j]--;
		}
	}else{
		for(long long i=m - 1 ; i >= 0 ;i--){
			if(a[j] == 0){
				j++;
				k++;
			}
			mp[s][i] = k;
			a[j]--;
		}
	}
}
int main (){
	cin >> n;
	cin >> m;
	cin >> c;
	for(long long i=0 ; i < c ;i++){
		cin >> a[i];
	}
	for(long long i=0 ; i < n ;i++){
		T(i);	
	}
	for(long long i=0 ; i < n ;i++){
		for(long long j=0 ; j < m ;j++){
			cout << mp[i][j] << " ";
		}
		cout << endl;
	}
	
	
	
	
	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 512
// inputに入力データ全体が入る
function Main(input) {
 var a = Math.floor(input / 2);
 var b = input % 2;
 var ans = a + b;
  console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
//Small and Large Integers

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
const int inf = 2147483647;

int main (){
    ll a,b,c;cin>>a>>b>>c;
    if(b-a+1<=c*2){
        rep(i,a,b+1)cout<<i<<endl;
        return 0;
    }
    rep(i,a,a+c)cout << i<< endl;
    rep(i,b-c+1,b+1)cout << i<< endl;
    return 0;
}

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

typedef long long LL;

LL root(LL x) {
    LL ans = sqrtl(x)-1;
    while (ans*ans < x) ans++;
    return ans;
}

const int MX = 1e9;

void ans(LL a, LL b, LL c, LL d, LL e, LL f, LL s) {
    cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<endl;
    LL area = a*d+c*f+e*b-b*c-d*e-f*a;
    assert(area == s);
    assert(0<=a && a<=MX);
    assert(0<=b && b<=MX);
    assert(0<=c && c<=MX);
    assert(0<=d && d<=MX);
    assert(0<=e && e<=MX);
    assert(0<=f && f<=MX);
    exit(0);
}

int main() {
    LL s;
    cin>>s;
    LL rt = root(s);
    LL dif = rt*rt-s;

    if (dif <= MX)  ans(0,0,rt,dif,1,rt, s);

    dif = rt*(rt-1)-s;
    ans(0,0,rt,dif,1,rt-1, s);
}


Measured memory_bytes: 384
#include <iostream>                                                             
                                                                                
using namespace std;                                                            
                                                                                
int main (void) {                                                               
  int H, W;                                                                     
  while (true) {                                                                
    cin >> H >> W;                                                              
    if (H==0 && W==0) {                                                         
      break;                                                                    
    }                                                                           
    for (int i=0; i<H; i++) {                                                   
      for (int j=0; j<W; j++) {                                                 
        if ((i%2==0 && j%2==0) || (i%2!=0 && j%2!=0)) {                         
          cout << "#" << flush;                                                 
        } else {                                                                
          cout << "." << flush;                                                 
        }                                                                       
      }                                                                         
      cout << endl;                                                             
    }                                                                           
    cout << endl;                                                               
  }                                                                             
}                                                                               
                                                                                
                                           

Measured memory_bytes: 3072
/*************************************************************************
  > File Name: d.cpp
  > Author: Samuel
  > Mail: enminghuang21119@gmail.com
  > Created Time: Sun Mar 22 20:12:48 2020
*************************************************************************/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int in[200010];
ll ans[200010];
ll sum;
map<int, ll> m;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> in[i];
        m[in[i]]++;
    }
    for (auto i : m) {
        sum += (i.second - 1) * i.second / 2;
    }
    for (int i = 0; i < n; i++) {
        ll num = m[in[i]];
        cout << sum - num * (num - 1) / 2 + (num - 1) * (num - 2) / 2 << '\n';
    }
    return 0;
}


Measured memory_bytes: 10368
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
using namespace std;
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}
int gcd(int x, int y){
	if(x<y){
    return gcd(y,x);
  }
  if(y==0){
    return x;
  }
  return gcd(y,x%y);
}
int moji(char i){
  if(i=='a'){
    return 1;
  }
  if(i=='b'){
    return 2;
  }
  if(i=='c'){
    return 3;
  }
  if(i=='d'){
    return 4;
  }
  if(i=='e'){
    return 5;
  }
  if(i=='f'){
    return 6;
  }
  if(i=='g'){
    return 7;
  }
  if(i=='h'){
    return 8;
  }
  if(i=='i'){
    return 9;
  }
  if(i=='j'){
    return 10;
  }
  if(i=='k'){
    return 11;
  }
  if(i=='l'){
    return 12;
  }
  if(i=='m'){
    return 13;
  }
  if(i=='n'){
    return 14;
  }
  if(i=='o'){
    return 15;
  }
  if(i=='p'){
    return 16;
  }
  if(i=='q'){
    return 17;
  }
  if(i=='r'){
    return 18;
  }
  if(i=='s'){
    return 19;
  }
  if(i=='t'){
    return 20;
  }
  if(i=='u'){
    return 21;
  }
  if(i=='v'){
    return 22;
  }
  if(i=='w'){
    return 23;
  }
  if(i=='x'){
    return 24;
  }
  if(i=='y'){
    return 25;
  }
  if(i=='z'){
    return 26;
  }
  return 100;
  
}




int main() {
  string x,y;
  cin>>x>>y;
  if(x<y){
    cout<<"<"<<endl;
  }else if(x>y){
    cout<<">"<<endl;
  }else{
    cout<<"="<<endl;
  }

  
  


  


  

  




  
  
}

  

  




Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#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 print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

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

  int64 n, m; cin >> n >> m; 

  int64 a[n], b[n];
  rep(i, n) cin >> a[i] >> b[i];

  vector<pll> v;

  rep(i, n){
    v.emplace_back(a[i], b[i]);
  }

  sort(all(v));

  int64 ans = 0;

  for (int i = 0; i < n; ++i){
    if (v[i].second >= m){
      ans += m * v[i].first;
      print(ans); return 0;
    }
    else {
      ans += v[i].second * v[i].first;
      m -= v[i].second;
    }
  }


  return 0;
}


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


int main() {
  int k,x;
  
  cin >> k >> x;
  
  int total = 0;
  
  total = k*500;
  
  if(total>=x)
    cout << "Yes";
  
  else
    cout << "No";
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

using Graph = vector<vector<ll>>;

int main() {
    // 頂点数と辺数
    ll N, M; cin >> N >> M;
    ll ma = 0;

    // グラフ入力受取
    Graph G(N);
    for (ll i = 0; i < M; ++i) {
        ll a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    // 頂点 s をスタートとした探索
    vector<ll> dist(N, -1);
    queue<ll> que;
    vector<ll> lo;
    int count = 0;
    for (ll v = 0; v < N; ++v) {
        if (dist[v] != -1) continue; // v が探索済みならスルー
        dist[v] = 0, que.push(v);
        ll cnt = 0;
        ll lon = 0;
        while (!que.empty()) {
            int v = que.front(); que.pop();
            for (auto nv : G[v]) {
                if (dist[nv] == -1) {
                    dist[nv] = dist[v] + 1;
                    que.push(nv);
                }
            }
            cnt++;
        }
        lo.push_back(cnt);
        ma = max(cnt, ma);
        ++count;
    }
    cout << count-1 << endl;
}


Measured memory_bytes: 10188
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

int main(void) {
  int N, M;
  scanf("%d %d", &N, &M);

  int from1[200000];
  int dst1 = 0;
  bool toN[200001];
  memset(toN, 0, N);
  for (int i = 0; i < M; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a == 1) {
      from1[dst1++] = b;
    }
    if (b == N) {
      toN[a] = true;
    }
  }

  for (int i = 0; i < dst1; i++) {
    int v = from1[i];
    if (toN[v]) {
      printf("POSSIBLE\n");
      return 0;
    }
  }
  printf("IMPOSSIBLE\n");
  return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1000000007;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, q, x, K;
string s, t;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	ll a,b;
	cin>>a>>b;
	vll p(n);
	vll cnt(3,0);
	for(ll i=0;i<n;i++) {
		cin>>p[i];
		if(p[i] <= a) cnt[0]++;
		else if(p[i] > b) cnt[2]++;
		else cnt[1]++;
	}

	cout<<min({cnt[0],cnt[1],cnt[2]});
}


int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3652
class BIT: #0-indexed
    __slots__ = ["size", "tree","depth","n0"]
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length()
        self.n0 = 1<<self.depth

    def get_sum(self, i): #a_0 + ... + a_{i} #閉区間
        s = 0; i += 1
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def range_sum(self,l,r): #a_l + ... + a_r 閉区間
        return self.get_sum(r) - self.get_sum(l-1) 

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def bisect_left(self,w):
        #和が w 以上になる最小の index
        #w が存在しない場合 self.size を返す
        if w <= 0: return 0
        x,k = 0,self.n0
        for _ in range(self.depth):
            k >>= 1
            if x+k <= self.size and self.tree[x+k] < w:
                w -= self.tree[x+k]
                x += k
        return x


# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,k = map(int,readline().split())
*p, = map(int,readline().split())

b = BIT(n)
num = BIT(n)
MOD = 998244353
inv2 = (MOD+1)//2
for i in range(k):
    b.add(p[i]-1,inv2)
    num.add(p[i]-1,1)

ans = k*(k-1)//2%MOD*inv2%MOD

prob = (k-1)*pow(k,MOD-2,MOD)%MOD #(k-1/k)
pinv = pow(prob,MOD-2,MOD)
val = pinv*inv2%MOD #(k-1)/k/2: これを bit に足していく
rate = prob #倍率
for j in range(k,n):
    # p_i < p_j
    pj = p[j]-1
    v = b.get_sum(pj)
    ans += v*rate%MOD
    ans %= MOD

    # p_i > p_j
    w =  b.get_sum(n-1)-v
    ans += (j - num.get_sum(pj)) - w*rate%MOD
    ans %= MOD
    
    b.add(pj,val)
    num.add(pj,1)
    val = val*pinv%MOD
    rate = rate*prob%MOD

print(ans%MOD)


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

int main() {
std::string str,com;
int a,b,q;
std::cin>>str>>q;
while(q--){
	std::cin>>com>>a>>b;
	if(com=="print"){
		std::cout<<str.substr(a,b-a+1)<<"\n";
	}else if(com=="reverse"){
		for(int i=a,j=b;i<j;i++,j--){
			std::swap(str[i],str[j]);
		}
	}else{
		std::string str2;
		std::cin>>str2;
		for(int i=a;i<=b;i++)str[i]=str2[i-a];
	}
}
}

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

int main() {
   string s;
   std::cin >> s;
   int n = 0;
   for (size_t i = 0; i < 4; i++) {
      if (s.at(i) == '+') {
         n++;
      }else{
         n--;
      }
   }
   std::cout << n << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll val = ceil(n/1000.0)*1000;
	cout<<val-n;
	
	return 0;
}

Measured memory_bytes: 3644
/*
Contest: -
Problem:
Author: tzc_wk
Time:
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define y1			y1010101010101
#define y0			y0101010101010
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
const int MOD=1e9+7;
int n=read(),m=read(),dp[3001][3001][2];
inline void add(int &x,int y){
	x+=y;if(x>MOD)	x-=MOD;
}
signed main(){
	fz(i,0,n)	dp[0][i][0]=1;
	fz(i,0,m-1){
		fz(j,0,n){
			fz(k,0,1){
				if(j!=0)	add(dp[i+1][j-1][k|(j==1)],dp[i][j][k]);
				if(j!=0)	add(dp[i+1][j][k|(j==1)],dp[i][j][k]);
				if(j!=n)	add(dp[i+1][j][k|(j==0)],dp[i][j][k]);
				if(j!=n)	add(dp[i+1][j+1][k|(j==0)],dp[i][j][k]);
			}
		}
	}
	int ans=0;
	fz(i,0,n)	ans=(ans+dp[m][i][1])%MOD;
	printf("%d\n",ans);
	return 0;
}
/*
j-1 -0 +1 -0
j -1 +1 -0
j -0 +1 -1
j+1 -1 +1 -1
*/

Measured memory_bytes: 74024
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int lli;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define SZ(container) ((int)container.size())

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n, m;

struct UnionFind {
	vector<int> data;
	vector<vi> g;
	vector<int> W;
	UnionFind(int size) : data(size, -1), g(size), W(size, 0) {REP(i, n)g[i].push_back(i);}
	bool unionSet(int x, int y, int w) {
		int rx = root(x), ry = root(y);
		if (rx != ry) {
			if (data[ry] < data[rx]){
				swap(x, y);
				swap(rx, ry);
				w = -w;
			}
//			printf("%d %d %d %d\n", x, y ,rx, ry);
			int rW = W[x] - w - W[y];
			FOR(it, g[ry]) W[*it] += rW;
			g[rx].insert(g[rx].end(), ALL(g[ry]));
			g[ry].clear();
			data[rx] += data[ry]; data[ry] = rx;
		}
		return rx != ry;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
	int query(int x, int y){
//		printf("%d %d\n", W[x], W[y]);
		return W[x] - W[y];
	}
};

main(){
	int i,j;
	while(scanf("%d%d", &n, &m), n){
		UnionFind uf(n);
		REP(i, m){
			char c;
			int a, b, w;
			scanf(" %c %d %d", &c, &a, &b);
			a--;b--;
			if(c == '?'){
				if(uf.findSet(a, b)){
					printf("%d\n", uf.query(a, b));
				}else puts("UNKNOWN");
			}else{
				scanf("%d", &w);
				uf.unionSet(a, b, w);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 7984
import numpy as np

N ,M= map(int,input().split())
l=list(map(int,input().split()))
n0 = 2**int(np.ceil(np.log2(2*(max(l))-1)))

A = np.zeros(n0)

for i in range(N):
    A[l[i]-1]+=1

C = np.fft.ifft( np.fft.fft(A)*np.fft.fft(A) )
ans=0
j=2
q=[]
for ci in np.real(C[:2*(max(l))-1] + 0.5):
    q.append([int(ci),j])
    j+=1
#int(ci):足してjになる組み合わせの個数
q.reverse()
#print(q)
z=0
j=0
while z<M:
    ans+=q[j][0]*q[j][1]
    z+=q[j][0]
    j+=1
ans-=(z-M)*q[j-1][1]
print(ans)


Measured memory_bytes: 67172