akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
public class Main {
	static final long C =  1000000007;
	static final int CY = 1000000000;
	StringBuilder sb;
	public void calc() {
		sb = new StringBuilder();


		FastScanner sc = new FastScanner();

		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i=0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		long ans = 0;

		for (int i=0; i< n; i++) {
			if (a[a[i]-1] == i+1) {
				 ans++;
			}
		}

		System.out.println(ans/2);
	}



	public static void main(String[] args) {
		Main main = new Main();
		main.calc();

	}
	static class FastScanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			}else{
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
		private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
		private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
		private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true){
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				}else if(b == -1 || !isPrintableChar(b)){
					return minus ? -n : n;
				}else{
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
		public int nextInt() {
			if (!hasNext()) throw new NoSuchElementException();
			int n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true){
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				}else if(b == -1 || !isPrintableChar(b)){
					return minus ? -n : n;
				}else{
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


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

int main() {
  string S;
  cin >> S;
  
  int ans = 0;
  int ss = S.size();
  
  for (int i = 0; i < ss; i++) {
    for (int j = 0; j < ss; j++) {
      bool X = true;
      for (int k = i; k <= j; k++) {
        if (S.at(k) != 'A' && S.at(k) != 'C' && S.at(k) != 'G' && S.at(k) != 'T') {
          X = false;
        }
      }
      if (X) {
        ans = max(ans, j - i + 1);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int i,j,x=0,b=0;
char s[101];
scanf("%d",&j);
scanf("%s",&s);
for(i=0;i<j;i++)
{if(s[i]=='I')
x++;
else
x--;
if(x>b)
    b=x;
}
printf("%d",b);

return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define segN (1<<18)
const double PI = acos(-1);

struct segtree{
  int dat[segN*2];
  void init(){
    for(int i=0;i<segN*2;i++)
      dat[i]=0;
  }
  void update(int i,int x){
    i+=(segN-1);
    dat[i]=x;
    while(i){
      i=(i-1)/2;
      dat[i]=max(dat[i*2+1],dat[i*2+2]);
    }
  }

  int getMax(int a,int b,int k=0,int l=0,int r=segN){
    if(b<=l || r<=a)return -(1<<28);
    if(a<=l && r<=b)return dat[k];
    int m=(l+r)/2;
    int res= getMax(a,b,k*2+1,l,m);
    res=max(res, getMax(a,b,k*2+2,m,r) );
    return res;
  }
};

segtree T;
int N;
int sx,sy,tx,ty;
vector<int> X,Y;
typedef pair<int,int> P;

int main(){
  double len = 20.0*PI*0.25;
  
  cin>>sx>>sy>>tx>>ty;
  cin>>N;
  
  for(int i=0;i<N;i++){
    int x,y;
    cin>>x>>y;
    if( min(sx,tx)<=x && x<=max(sx,tx) ){
      if( min(sy,ty)<=y && y<=max(sy,ty) ){
        X.push_back(x);
        Y.push_back(y);
      }
    }
  }
  N=X.size();

  if(sx==tx||sy==ty){
    double ANS = abs(sx-tx) + abs(sy-ty);
    ANS *= 100.0;
    if( N == 1 )ANS += (len-10.0)*2.0;
    
    printf("%.15f\n",ANS);
    return 0;
  }
  
  if(sy>ty){
    for(int i=0;i<N;i++){
      Y[i]=ty+abs(Y[i]-sy);
    }
    swap(sy,ty);
  }

  if(sx>tx){
    for(int i=0;i<N;i++){
      X[i]=tx+abs(X[i]-sx);
    }
    swap(sx,tx);
  }

  vector<P> tmp;
  for(int i=0;i<N;i++)
    tmp.push_back( P(X[i],Y[i]) );
  sort(tmp.begin(),tmp.end());
  
  for(int i=0;i<N;i++){
    X[i]=tmp[i].first;
    Y[i]=tmp[i].second;
  }

  vector<int> cmpY;
  for(int i=0;i<N;i++)
    cmpY.push_back( Y[i] );
  sort(cmpY.begin(),cmpY.end());
  
  cmpY.erase( unique( cmpY.begin(), cmpY.end() ) , cmpY.end() );
  cmpY.push_back(ty);
  
  for(int i=0;i<N;i++)
    Y[i]=lower_bound(cmpY.begin(),cmpY.end(),Y[i])-cmpY.begin();

  
  T.init();
  for(int i=0;i<segN;i++){
    T.update(i, -1e9 );
  }
  T.update(0,0);

  int ans=0;
  
  for(int i=0;i<N;i++){
    int maxm=T.getMax(0,Y[i]+1);
    T.update( Y[i]+1, maxm+1 );
    ans=max(ans, maxm+1);
  }

  
  double ANS = abs(sx-tx) + abs(sy-ty);
  
  
  ANS *= 100.0;

    if(ans== abs(sx-tx)+1 || ans==abs(sy-ty)+1)ans--, ANS += (len*2.0-20.0);
  ANS -= (20.0 - len) * (double) ans;


  printf("%.15f\n",ANS);
  
  return 0;
}


Measured memory_bytes: 7272
#include <iostream>

using namespace std;

int main()
{
    int n,m,i,j,total,x;
    total=0;
    cin >> n;
    int t[n];
    
    for(i=0;i<n;i++){
        cin >> t[i];
    }
    
    cin >> m;
    int a[m][2];
    
    for(i=0;i<m;i++){
        cin >> a[i][0];
        cin >> a[i][1];
    }
    
    for (i=0;i<m;i++){
        x = t[a[i][0]-1];
        t[a[i][0]-1] = a[i][1];
        
        for (j=0;j<n;j++){
            total += t[j];
        }
        
        cout << total << endl;
        total = 0;
        t[a[i][0]-1] = x;
    }
    return 0;
}


Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------


//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int h,w;cin>>h>>w;
    char hw[50][50];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)
            cin>>hw[i][j];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(hw[i][j]=='#'){
                cout<<'#';
                continue;
            }
            int cnt=0;
            for(int x=0;x<8;x++){
                int nx=i+dx[x];
                int ny=j+dy[x];
                if(nx<h&&ny<w&&nx>=0&&ny>=0){
                    if(hw[nx][ny]=='#')
                        cnt++;
                    
                }
                
            }
            cout<<cnt;
        }
        cout<<endl;
    }
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    int k = -1;
    for (int i = 1; i * (i - 1) / 2 <= n; i++)
    {
        if (i * (i - 1) / 2 == n)
            k = i;
    }
    if (k == -1)
    {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    cout << k << endl;
    vector<vector<int>> s(k);
    int num = 1;
    for (int i = 0; i < k; i++)
    {
        for (int j = i + 1; j < k; j++)
        {
            s[i].push_back(num);
            s[j].push_back(num);
            num++;
        }
    }
    rep(i, k)
    {
        cout << s[i].size() << " ";
        rep(j, s[i].size()) cout << s[i][j] << " ";
        cout << endl;
    }
}

Measured memory_bytes: 3200
n, k = map(int, input().split())

if k%2!=0:
    factor = n//k
    print(factor**3)
else:
    factor1 = n//k
    res1 = factor1**3
    
    factor2 = 0
    for i in range(1, n+1):
        if (i %(k//2)==0) and (i%k!=0):
            factor2 += 1
    res2 = factor2**3
    print(res1 + res2)

Measured memory_bytes: 38640
from heapq import heappush, heappop

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

day = [[] for _ in range(10 ** 5)]
for a, b in ab:
    day[a - 1].append(b)

work, ans = [], 0
for i in range(m):
    for j in day[i]:
        heappush(work, -j)
    if len(work) > 0:
        ans -= heappop(work)
print(ans)


Measured memory_bytes: 101776
#include "bits/stdc++.h"
using namespace std;
 
// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
 
/*
--------------------------------------------
 
	type
 
--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;
 
/*
--------------------------------------------
 
	container
 
--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
 
/*
--------------------------------------------
 
	repetition
 
--------------------------------------------
*/
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a>b)?b:a
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPS(i,n) for(int i=0; i<(n); i++)
#define REPinit(a,n) for(int i=a; i<(n); i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)
 
//algorithm
//#define SORT(c) sort((c).begin(),(c).end())
 
/*
--------------------------------------------
 
	constant
 
--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
/*
 
	Optimizer
 
*/
//#pragma GCC optimize("Ofast")


/*
 
	Utility Algorithm
 
*/
template <typename T>
void swapAlgorithm(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}

LL euclideanAlgorithm(LL a, LL b) {
    LL a_tmp = a;
    LL b_tmp = b;

    if (a_tmp > b_tmp) {
        swapAlgorithm<LL>(a_tmp, b_tmp);
    }

    LL r = a_tmp % b_tmp;
    while (r != 0) {
        a_tmp = b_tmp;
        b_tmp = r;
        r = a_tmp % b_tmp;
    }
    return b_tmp;    
}

LL getLCM(LL a, LL b) {
    return (a * b)/(euclideanAlgorithm(a, b));
}

/*
  Code
*/

double eauclidDistance(pair<double, double>& x1, pair<double, double>& x2) {
  return sqrt((x1.first - x2.first) * (x1.first - x2.first) + (x1.second - x2.second) * (x1.second - x2.second));
}

void swap(int& a, int& b) {
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

int main(int argc, char const *argv[])
{
  string s;
  cin >> s;
  if(s.find('a') != -1 && s.find('b') != -1 && s.find('c') != -1) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include <iomanip>
using namespace std;
double Pi = acos(-1.0);
 
int main()
{
	double A,B,H,M;
	cin>>A>>B>>H>>M;
    double Hour=H*30+M*0.5;
    double Min=M*6;
    double ans = fabs(Hour-Min);
    if (ans>180) 
	{
        ans = 360-ans;
    }
    double result = sqrt(A*A+B*B-2*A*B*cos(ans*Pi/180));
    cout<<setiosflags(ios::fixed)<<setprecision(20);
    cout<<result<<endl;
	return 0;
}

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

int main(void) {
  int N;
  cin >> N;
  vector<long long> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }

  vector<long long> dp(N, 1e18);
  dp[0] = 0LL;
  for (int i = 0; i < N; i++) {
    if (i + 1 < N)
      dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
    if (i + 2 < N)
      dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
  }
  cout << dp[N - 1] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
int main(void){
    int i, j, n, a, b, sum;
    while ( scanf("%d %d %d", &a, &b, &n) != EOF ) {
        sum = 0;
        a %= b;
        while ( n-- ) {
            a *= 10;
            sum += a / b;
            a %= b;
        }
        printf("%d\n", sum);
    }
   return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int a[100][100] = {};
  int k;
  for(int i=0; i<n; i++){
    cin >> k;
    for(int j=0; j<k; j++){
      cin >> a[i][j];
    }
  }
  int ans = 0;
  bool s = 0;
  for(int i=1; i<=m; i++){
    s = 0;
    for(int j=0; j<n; j++){
      s=0;
      for(int k=0; k<100; k++){
        if(a[j][k] == i){
          s = 1;
        }
      }
      if(s==0){
        j=999;
        break;
      }
      if(j==n-1){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {

  int n;
  int k;
  long long int tmp;
  long long int arr[100] = {0};

  long long int max, min;

  scanf("%d", &n);

  for (k = 0; k < n; k++) {
    scanf("%lld", &tmp);
    arr[k] = tmp;
  }

  max = min = arr[0];

  for (k = 0; k < n; k++) {
    if (max < arr[k]) {
      max = arr[k];
    }
  }

  for (k = 0; k < n; k++) {
    if (min > arr[k]) {
      min = arr[k];
    }
  }

  printf("%lld\n", max-min);
  
  return 0;
}


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

int main()
{
	int table[201]{};
	for (int i{1}; i <= 200; i++)
	{
		for (int j{i}; j <= 200; j += i)
			table[j]++;
	}
	int n, count{};
	scanf("%d", &n);
	for (int i{1}; i <= n; i++)
		if (table[i] == 8 && i % 2)
			count++;
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define req(i, j, n) for(int i = j; i <= (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
int n;
  cin>>n;
for(int i=1;i<=50000;i++){
  int k=i;
  int p=k*0.08;
  int l=k+p;
if(l==n){
  cout<<k<<endl;
  return 0;}
}
  
  cout<<":("<<endl;
  return 0;
  

}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"errors"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

func NextStringsLine() []string {
	strs := []string{}
	stringsStr := NextLine()
	tmp := strings.Split(stringsStr, " ")
	for _, s := range tmp {
		strs = append(strs, s)
	}
	return strs
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// PowInt is integer version of math.Pow
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}
	fa := float64(a)
	fe := float64(e)
	fanswer := math.Pow(fa, fe)
	return int(fanswer)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	fa := float64(a)
	fanswer := math.Abs(fa)
	return int(fanswer)
}

// DeleteElement returns a *NEW* slice, that have the same and minimum length and capacity.
// DeleteElement makes a new slice by using easy slice literal.
func DeleteElement(s []int, i int) []int {
	if i < 0 || len(s) <= i {
		panic(errors.New("[index error]"))
	}
	// appendのみの実装
	n := make([]int, 0, len(s)-1)
	n = append(n, s[:i]...)
	n = append(n, s[i+1:]...)
	return n
}

// Concat returns a *NEW* slice, that have the same and minimum length and capacity.
func Concat(s, t []rune) []rune {
	n := make([]rune, 0, len(s)+len(t))
	n = append(n, s...)
	n = append(n, t...)
	return n
}

// sort package (snippets)
//sort.Sort(sort.IntSlice(s))
//sort.Sort(sort.Reverse(sort.IntSlice(s)))
//sort.Sort(sort.Float64Slice(s))
//sort.Sort(sort.StringSlice(s))

// copy function
//a = []int{0, 1, 2}
//b = make([]int, len(a))
//copy(b, a)

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

var x int

func main() {
	tmp := NextIntsLine()
	x = tmp[0]
	i := 1
	sum := 0
	for {
		sum += i
		if sum >= x {
			break
		}
		i++
	}
	fmt.Println(i)
}


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

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    m1 += k;
    h1 += m1 / 60;
    m1 %= 60;
    int diff = h2 - h1;
    diff *= 60;
    diff += m2 - m1;
    cout << max(0, diff) << endl;
}

Measured memory_bytes: 3636
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

public class Main {

	static final int C = 200_000;
	
	void submit() {
		int n = nextInt();
		int[] a = new int[n];
		
		int sz = 0;
		for (int i = 0; i < n; i++) {
			int x = nextInt() - 1;
			if (sz > 0 && x == a[sz - 1]) {
				continue;
			}
			a[sz++] = x;
		}
		
		n = sz;
		a = Arrays.copyOf(a, n);
		
		int[] aux = new int[C];
		int prev = 1;
		for (int i = n - 1; i >= 0; i--) {
			int symb = a[i];
			aux[symb] += prev;
			if (aux[symb] >= P) {
				aux[symb] -= P;
			}
			
			prev = aux[symb];
		}
		
		out.println(prev);
	}
	
	static final int P = 1_000_000_007;

	void test() {

	}

	void stress() {
		for (int tst = 0;; tst++) {
			if (false) {
				throw new AssertionError();
			}
			System.err.println(tst);
		}
	}

	Main() throws IOException {
		is = System.in;
		out = new PrintWriter(System.out);
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	private InputStream is;
	PrintWriter out;

	private byte[] buf = new byte[1 << 14];
	private int bufSz = 0, bufPtr = 0;

	private int readByte() {
		if (bufSz == -1)
			throw new RuntimeException("Reading past EOF");
		if (bufPtr >= bufSz) {
			bufPtr = 0;
			try {
				bufSz = is.read(buf);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			if (bufSz <= 0)
				return -1;
		}
		return buf[bufPtr++];
	}

	private boolean isTrash(int c) {
		return c < 33 || c > 126;
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isTrash(b))
			;
		return b;
	}

	String nextToken() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	String nextString() {
		int b = readByte();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b) || b == ' ') {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	char nextChar() {
		return (char) skip();
	}

	int nextInt() {
		int ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}

	long nextLong() {
		long ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}
}


Measured memory_bytes: 25556
#include <iostream>

int main() {
    int n;
    std::cin >> n;
    if (n < 105) std::cout << 0;
    else if (n < 135) std::cout << 1;
    else if (n < 165) std::cout << 2;
    else if (n < 189) std::cout << 3;
    else if (n < 195) std::cout << 4;
    else std::cout << 5;
    std::cout << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

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

    int m[N];
    int mi = 1000;
    REP(0, i, N) {
        scanf("%d", &m[i]);
        X -= m[i];
        if (m[i] < mi) {
            mi = m[i];
        }
    }

    int ans = N;
    while (true) {
        if (mi <= X) {
            X -= mi;
            ans++;
        } else {
            break;
        }
    }

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

    return 0;
}


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
)

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	ans := 0.0
	for i := 0; i < n; i++ {
		tmp := 1 / float64(sc.NextInt())
		ans += tmp
	}
	fmt.Printf("%v\n", 1/ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
def main():
    h, n = map(int, input().split())
    magic_list = []

    for _ in range(n):
        a, b = map(int, input().split())
        magic_list.append((a, b))

    ans = solve(h, magic_list)
    print(ans)


def solve(h, magic_list):
    # 1-origin
    max_attack = max(magic_list)[0]
    dp = [0] * (h + max_attack)

    # time O(HN)
    for hp in range(1, h + 1):
        dp[hp] = min(dp[hp - attack] + mp for attack, mp in magic_list)

    return dp[h]


main()


Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define nl          '\n'
#if     DEBUG
#define trace(var)  {cerr << "Line " << __LINE__ << ": " << #var << "=" << var << nl;}
#else
#define trace(var)	{}
#endif
#define fori(n)			for(int i = 0; i < n; ++i)
#define forj(n)			for(int j = 0; j < n; ++j)
#define fork(n)			for(int k = 0; k < n; ++k)
#define forl(n)			for(int l = 0; l < n; ++l)

typedef long long ll;typedef pair<int,int> pii;typedef vector<bool> vbool;typedef vector<int> vint;typedef vector<ll> vll;typedef long double ld;typedef vector<vector<int>> vvi;

const ll V = 100000;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;

ll n, W; 
struct item {
	ll w,v;
};

void dodp(vector<item> &bag) {
	//do dp	
	vector<vector<ll>> dp(V+1, vll(n+1,W+1));
	fori(n+1) 
		dp[0][i] = 0;
	for(int i = 1; i <= n; ++i) {
		for(ll j = 1; j <= V; ++j) {
			dp[j][i] = dp[j][i-1];
			if (j >= bag[i-1].v)
				dp[j][i] = min(dp[j-bag[i-1].v][i-1]+bag[i-1].w, dp[j][i]);
		}
	}
	for(int j = V; j >= 0; --j) {
		if (dp[j][n] <= W) {
			cout << j << nl;
			return;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> W;
	vector<item> bag(n);
	fori(n) {
		cin >> bag[i].w >> bag[i].v;
	}

	dodp(bag);
	
#if DEBUG
	cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << " s" << nl;
	#endif
	return 0;
}


Measured memory_bytes: 84352
N = int(input())
A = [int(i) for i in input().split()]
ans = []
num = 0
for i,x in enumerate(A):
    if x < 0:
        ans.append(-x)
        num += 1
    else:
        ans.append(x)
if num%2 == 0:
    print(sum(ans))
else:
    print(sum(ans)-2*min(ans))

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<int> x;
    rep(i, n){
        int num;
        cin >> num;
        x.push_back(num);
    }
    int minim=INT32_MAX;
    rep2(i, 1, 100){
        int sum=0;
        rep(j, n){
            sum += pow(x[j] - i, 2);
        }
        minim = min(sum, minim);
    }
    cout << minim << endl;
    return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        try(Scanner cs = new Scanner(System.in)){
            String line = cs.nextLine();
            String answer = "";
            int length = line.length();
            for(int i =0;i<length;i++){
                char ch = line.charAt(i);
                if(Character.isLowerCase(ch)){
                    System.out.print(Character.toUpperCase(ch));
                }else{
                    System.out.print(Character.toLowerCase(ch));
                }
            }
            System.out.printf("\n");
        }
    }

}


Measured memory_bytes: 26740
///////////////////////////////////////////////////
/* __                                       __   */
/*|  |--.-----.---.-.----.----.-----.-----.|  |_ */
/*|  _  |  -__|  _  |  __|  __|  -__|  _  ||   _|*/
/*|_____|_____|___._|____|____|_____|   __||____|*/
/*                                  |__|         */
///////////////////////////////////////////////////
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long lint; using namespace std;
#define rep(counter, limit) for (int counter = 0; counter < (limit); counter++)
#define INF 1000000000000
#define MOD 10000007
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){cin.tie(0);ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}setupios;
int main() {

  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n);
  rep(i,n){
    if(s[i] == 'R') a[i] = 0;
    if(s[i] == 'G') a[i] = 1;
    if(s[i] == 'B') a[i] = 2;
  }
  vector<int> cnt(3);
  rep(i,n) cnt[a[i]]++;
  lint ans = 1;
  rep(i,3) ans *= cnt[i];
  rep(j,n)rep(i,j){
    int k = j + (j - i);
    if(k < n){
      if(a[i] == a[j]) continue;
      if(a[i] == a[k]) continue;
      if(a[j] == a[k]) continue;
      ans--;
    }
  }
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 3664
# NOTE : 勉強になる初期化の仕方
# dict(zip('abc',(input() for _ in range(3)))))

dic = dict()
k='a'

for name in list('abc'):
    dic[name] = input()

while dic[k]:
    dic[k],k=dic[k][1:],dic[k][0]
print(k.upper())



Measured memory_bytes: 3064
from collections import defaultdict, Counter
import sys
n=int(input())
#d=defautldict(int)
l=[]
for _ in range(n):
  s=input()
  l.append(s)
c = Counter(l).most_common()
max_ = c[0][1]
ans=[]
for tup in c:
  p,q = tup
  if q != max_:
    break
  else:
    ans.append(p)
ans.sort()
for a in ans:
  print(a)

Measured memory_bytes: 121680
#include <cstdio>

int main(void){
    // Here your code !
    int x, y, t;
   while (1){
       scanf("%d %d", &x, &y);
       if (x == 0 && y == 0) break;
       if (x > y){
           t = x;
           x = y;
           y = t;
       }
       printf("%d %d\n", x, y);
   }
    return 0;
}

Measured memory_bytes: 2588
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    m = 10 ** 9 + 7
    tmp_sum = 0
    for i in range(n - 1):
        tmp_sum += a[i]
        tmp_sum %= m
        ans += tmp_sum * a[i+1]
        ans %= m
    
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 94428
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int N, M, Q;
int a[55], b[55], c[55], d[55];
int arr[15]={};

int solve(int key, int now){
    int res=0;
    for(int i=now; i<=M; ++i){
        arr[key]=i;
        if(key<N) res=max(res, solve(key+1, i));
        else{
            int shu=0;
            for(int j=0; j<Q; ++j){
                if(arr[b[j]]-arr[a[j]]==c[j]) shu += d[j];
            }
            res=max(res, shu);
        }
    }
    return res;
}

int main(void){
    cin >> N >> M >> Q;
    for(int i=0; i<Q; ++i) cin >> a[i] >> b[i] >> c[i] >> d[i];
    cout << solve(1, 1) << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;

int n,w,h;
int par[40001],rank[40001];
int x[40001],y[40001];
int ux[2][40001],uy[2][40001];
vector<int> xid[100001],yid[100001];

void init(){
	for(int i=0;i<n;i++){
		par[i]=i;
		rank[i]=0;
	}
}

int find(int x){
	if(par[x]==x)return x;
	return par[x]=find(par[x]);
}

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(rank[x]>rank[y]){
		par[y]=x;
	}else{
		if(rank[x]==rank[y]){
			rank[y]++;
		}
		par[x]=y;
	}
}

bool same(int x,int y){
	return find(x)==find(y);
}

int main(void){
	scanf("%d %d %d",&n,&w,&h);
	bool flag=false;
	for(int i=0;i<n;i++){
		scanf("%d %d",&x[i],&y[i]);
		xid[x[i]].push_back(i);
		yid[y[i]].push_back(i);
		if(x[i]==w || x[i]==1 || y[i]==1 || y[i]==h)flag=true;
	}
	init();
	int cnt=0;
	for(int i=1;i<=w;i++){
		for(int j=0;j<(int)xid[i].size()-1;j++){
			if(same(xid[i][j],xid[i][j+1]))continue;
			cnt++;
			unite(xid[i][j],xid[i][j+1]);
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=0;j<(int)yid[i].size()-1;j++){
			if(same(yid[i][j],yid[i][j+1]))continue;
			cnt++;
			unite(yid[i][j],yid[i][j+1]);
		}
	}
	for(int i=1;i<n;i++){
		if(!same(0,i)){
			if(flag){
				cnt+=2;
			}
			if(!flag){
				cnt+=3;
				flag=true;
			}
			unite(0,i);
		}
	}
	printf("%d\n",cnt);
	return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
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;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int N; cin >> N;
    vector<ll> A(N),B(N);
    REP(i,N){
        cin >> A[i] >> B[i];
    }
    bool lhalf = false;
    bool rhalf = false;
    sort(ALL(A));
    sort(B.rbegin(),B.rend());

    if (N % 2 == 1){    
        cout << B[N / 2] - A[N / 2] + 1 << endl;
    }else{
        if ((B[N / 2] + B[N / 2 - 1] ) % 2 == 1) rhalf = true;
        if ((A[N / 2] + A[N / 2 - 1] ) % 2 == 1) lhalf = true;
        ll Bh = (B[N / 2] + B[N / 2 - 1]) / 2;
        ll Ah = (A[N / 2] + A[N / 2 - 1]) / 2;
        ll ans = 2 * (Bh - Ah) + 1;
        if (lhalf) ans--;
        if (rhalf) ans++;
        //DB2(lhalf,rhalf);
        //DB2(Ah,Bh);
        cout << ans << endl;
    }
}

Measured memory_bytes: 6376
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
x = list(map(int, input().split()))
x.sort()
d = []
for i in range(m - 1):
    x_d = x[i + 1] - x[i]
    d.append(x_d)
d.sort()
if n > m:
    n = m
ans = sum(d[:m - n])
print(ans)


Measured memory_bytes: 13968
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(int i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
ll LCM(ll x, ll y) { 
  return x / GCD(x, y) * y;
}

int main() {
    int n, r; cin >> n >> r;
    if(n >= 10) cout << r << endl;
    else cout << 100 * (10 - n) + r << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	string a[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
	int i,j;
	if(s==a[0])
	cout<<7;
	for(i=1;i<4;i++)
	{
		if(s==a[i])
		cout<<7-i;
	
    }
    for(j=6;j>3;j--)
    {
    	if(s==a[j])
		cout<<7-j;
	}
return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //a
  int h, a;
  cin >> h >> a;
  cout << (h + a - 1) / a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD=1e9+7;
ll inv(ll a, ll b = MOD){
    ll x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b != 0) {
        const ll q = a / b;
        ll tmp = a % b;
        a = b;
        b = tmp;
        tmp = x0 - q * x1;
        x0 = x1;
        x1 = tmp;
        tmp = y0 - q * y1;
        y0 = y1;
        y1 = tmp;
    }
    return (x0 + MOD) % MOD;
}
ll fact(ll x){
    // 再帰だとスタックオーバーフローするので
    ll ret = 1;
    for(ll a=2; a<=x; ++a){
        ret = (ret * a) % MOD;
    }
    return ret;
}
/*
【解法】
A = [1, 2, ..., n] と固定する（求める場合の数は、固定した場合の数の mPn 倍）。B を長さ n の数列とする

ある集合 S \subset {1, ..., n} の上で値が一致する（そのほかにも一致する値のある可能性がある）ような B の場合の数は g(S) = (m-|S|)P(n-|S|) 通り
（まだ決まっていない n-|S| 箇所の値を、使っていない m-|S| 個の値から重複しないように決める）

ある集合 S \subset {1, ..., n} の上でちょうど値が一致する（ S に属さない点 i ではA[i] != B[i] となる）ような
B の場合の数を f(S) 通りとすると、g(S) = \sum_{S\subset T} f(T) となる。

F(S) = f({1, ..., n} \setminus S), G(S) = g({1, ..., n} \setminus S) とおくと、
G(S) = \sum_{T\subset S} F(S) なので、包除原理から F(S) = \sum_{T\subset S} (-1)^|S\setminus T| G(T) が成り立つ。

求めるのは f(\emptyset)
= F({1, ..., n})
= \sum_{T\subset {1, ..., n}} (-1)^|{1, ..., n}\setminus T| G(T)
= \sum_{T\subset {1, ..., n}} (-1)^|{1, ..., n}\setminus T| g({1, ..., n} \setminus T)
= \sum_{T\subset {1, ..., n}} (-1)^|T| g(T)
（ T -> T\setminus {1, ..., n} で置換）
ここで g は size の関数なので g(T) = g(|T|) とおくと、 k 元集合の選び方が nCk 通りなので 
= \sum_{k=0}^n (-1)^k nCk g(k)
= \sum_{k=0}^n (-1)^k n! / (n-k)! / k! * (m-k)! / (m-n)!
となる。

これを高速に計算する。 k == 0 のとき m! / (m-n)! で、

    n! (m-k)!             n! (m-(k-1))!          n-k+1
---------------- == ------------------------ * ---------
(n-k)! k! (m-n)!    (n-(k-1))! (k-1)! (m-n)!   (m-k+1) k

なので、 k がふえるたびに (n-k+1) / (m-k+1) / k 倍すればよい
*/
ll inv_table[500001] = {};
void make_inv_table(int n){
    inv_table[1] = 1;
    for (int i=2; i<=n; ++i){
        // (MOD / i) * i + MOD % i = 0 なので
        // (MOD / i) * i = - (MOD % i)
        // - (MOD / i) * (MOD % i)^(-1) = i^(-1)
        inv_table[i] = inv_table[MOD%i] * (MOD - MOD / i) % MOD;
    }
}

pair<ll, ll> get_fact(ll a, ll b){
    if (a>b){
        auto p = get_fact(b, a);
        return pair<ll, ll>(p.second, p.first);
    }
    ll tmp = 1;
    for(ll i=2; i<=a; ++i)tmp = (tmp * i) % MOD;
    ll fact_a = tmp;
    for(ll i=a+1; i<=b; ++i)tmp = (tmp * i) % MOD;
    ll fact_b = tmp;
    return pair<ll, ll>(fact_a, fact_b);
}

int main()
{
    ll n, m;
    cin >> n >> m;

    auto p = get_fact(m-n, m);
    const ll mpn = p.second * inv(p.first) % MOD;
    ll tmp = mpn;
    ll sum = tmp;
    const ll sign[2] = {1, MOD-1};
    make_inv_table(m);
    for(int k=1; k<=n; ++k){
        tmp = (tmp * inv_table[m-k+1]) % MOD * (inv_table[k] * (n-k+1) % MOD) % MOD;
        sum = (sum + sign[k%2] * tmp) % MOD;
    }
    cout << (sum * mpn) % MOD;
    return 0;
}


Measured memory_bytes: 7420
#include <bits/stdc++.h>
using namespace std;
#define M 100010
#define LL long long
#define rep(i, x, y) for(int i = (x); i <= (y); ++ i)
inline int read() {
	char ch = getchar(); int x = 0, f = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while('0' <= ch && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}
inline int solve(int n, int m){
	if(n < m) return 0;
	if(n % m == 0) return n / m;
	return solve(n - ((n % m - 1) / (n / m + 1) + 1) * (n / m + 1), m);
}
int main() {
	//freopen("in.txt", "r", stdin);
	int n = read();
	int res = 0;
	rep(i, 1, n) {
		int A = read(), K = read();
		res ^= solve(A, K);
	}
	if(res) puts("Takahashi");
	else puts("Aoki");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
char s[N];
 
int main()
{
	scanf("%s",s);
	int len = strlen(s);
	int cnt = len - 2;
	if (s[0] == s[len - 1])
	{
		if (cnt % 2) puts("Second");
		else puts("First");
	}
	else
	{
		if (cnt % 2 == 0) puts("Second");
		else puts("First");
	}
	return 0;
} 

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;
int ar[N + 5], L[N + 5], R[N + 5];
int main(){
  FASTER;
  int n;
  cin >> n;
  int gg = 0;
  for (int i = 1; i <= n; i++){
    cin >> ar[i];
    gg = __gcd(ar[i], gg);
    L[i] = gg;
  }
  gg = 0;
  for (int i = n; i > 0; i--){
    gg = __gcd(gg, ar[i]);
    R[i] = gg;
  }
  int mx = 1;
  for (int i = 1; i <= n; i++){
    mx = max(mx, __gcd(L[i - 1], R[i + 1]));
  }
  cout << mx << '\n';
  return 0;
}


Measured memory_bytes: 1408
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit

MOD = 10**9 + 7

N = int(readline())
S = np.array(list(read().rstrip()), np.int8)

R = np.sum(S == ord('R'))
B = np.sum(S == ord('B'))
G = np.sum(S == ord('G'))
 
@njit
def f(S):
    N = len(S)
    ret = 0
    for i in range(N):
        for j in range(i + 1, N):
          k = j + j - i
          if k >= N:
            break
          if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ret += 1
    return ret
  
answer = R * B * G - f(S)
print(answer)

Measured memory_bytes: 109708
n,k=gets.split(' ').map(&:to_i)
#h=gets.split(' ').map(&:to_i)
#tajigen = Array.new(4) { Array.new(2,0) }
#maze = h.times.map { gets.chomp }
wari = Array.new(k+1)
kkk=10**9+7
=begin
for i in 1..k
  #puts i
  wari[i] = (k/i)**n
end
#puts wari
=end
ans=0
=begin
def power2(a, n)
  p = 1
  n.to_s(2).split('').each{|i|
    p *= p

    if i == '1'
      p *= a
    end
  }
  p
end
=end

def pow(x, n, mod)
  return 1 if n == 0
  return pow(x**2 % mod, n / 2, mod) if (n % 2) == 0
  return pow(x**2 % mod, n / 2, mod) * x  if (n % 2) == 1
end
#puts power2(a,n)
k.downto(1) do |soto|
  wari[soto] = pow(k/soto,n,kkk)  #((k/soto)**n)
  count=2
  while soto * count <= k
    wari[soto]-=wari[soto * count]
    count+=1
  end
  ans += (wari[soto]*soto)
  #puts wari[soto]
end
puts ans%kkk
=begin
puts "iii"
wari[0] = 0
for i in 0..(k/2-1)
  put = k/2-i
  count=2
  #puts i
  while put * count <= k
    wari[put]=wari[put] - wari[put * count]
    count+=1
  end
end
=end
#puts wari
=begin
ans=0
for i in 1..k
  ans += (i * wari[i]) % kkk
  ans %= kkk
#  ans = ans%kkk
end
=end
#puts ans


Measured memory_bytes: 23216
package main

import "fmt"

func main() {
	var num1, num2, num3, num4 int
	var ans string
	fmt.Scanf("%d %d %d %d\n", &num1, &num2, &num3, &num4)

	if num1 == 1 || num2 == 1 || num3 == 1 || num4 == 1 {
		if num1 == 9 || num2 == 9 || num3 == 9 || num4 == 9 {
			if num1 == 7 || num2 == 7 || num3 == 7 || num4 == 7 {
				if num1 == 4 || num2 == 4 || num3 == 4 || num4 == 4 {
					ans = "YES"
				} else {
					ans = "NO"
				}
			} else {
				ans = "NO"
			}
		} else {
			ans = "NO"
		}

	} else {

		ans = "NO"
	}

	fmt.Println(ans)

}

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

int main(){
	int n;
	cin >> n;
	vector<int> ar(n),br(n);
	for(int i=0;i<n;i++){
		cin >> ar[i] >> br[i];
	}
	bool val = false;
	for(int i=0;i<n-2;i++){
		bool same = true;
		for(int j=i;j<i+3;j++){
			if(ar[j] != br[j]){
				same = false;
			}
		}
		val |= same;
	}
	cout << (val ? "Yes\n" : "No\n");
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(200000)

def solve(N: int, M: int, X: "List[int]", Y: "List[int]", Z: "List[int]"):
    conn = [[] for _ in range(N)]
    for i in range(M):
        conn[X[i] - 1].append(Y[i] - 1)
        conn[Y[i] - 1].append(X[i] - 1)

    def dfs(idx, conn, visited):
        visited[idx] = True
        for c in conn[idx]:
            if not visited[c]:
                dfs(c, conn, visited)
        return visited

    visited = [False] * N
    ret = 0
    for i in range(N):
        if not visited[i]:
            visited = dfs(i, conn, visited)
            ret += 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = [int()] * (M)  # type: "List[int]" 
    Y = [int()] * (M)  # type: "List[int]" 
    Z = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        X[i] = int(next(tokens))
        Y[i] = int(next(tokens))
        Z[i] = int(next(tokens))
    solve(N, M, X, Y, Z)

if __name__ == '__main__':
    main()


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

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

  string s;
  cin >> s;
  vector<string> t = {"eraser", "erase", "dreamer", "dream"};
  for (string &x : t) {
    while (true) {
      size_t i = s.find(x);
      if (i == -1) break;
      s.replace(i, x.size(), "");
    }
  }
  string ans = (s.empty()) ? "YES" : "NO";
  cout << ans << '\n';
  return 0;
}

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

int main(){
	int a,b,c,d; cin>>a>>b>>c>>d;
	if(abs(a-b)<=d&&abs(b-c)<=d||abs(a-c)<=d) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(){
    int a,h,m,m1,s;
    scanf("%d",&a);
    h=a/3600;
    m=a%3600;
    m1=m/60;
    s=m%60;
    printf("%d:%d:%d\n",h,m1,s);
    return 0;
}



Measured memory_bytes: 2100
n = int(input())

mod = 10**9 + 7

dict = dict()
list = []
res = 1
for i in range(n):
  x = input()
  list.append(x)
  if x in dict and list[i - 1] != x:
    res += dict[x]
    dict[x] = res
  elif x not in dict:
    dict[x] = res

print(res % mod)

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector <long long> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  for (int i = K; i < N; ++i) {
    if (A[i - K] < A[i]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4824