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

#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384


int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}    //最大公約数
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}     //最小公倍数
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} //コンビネーション
int nHr(int a,int b){return nCr(a+b-1,b);}       // 重複組み合わせ
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}  //階乗
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} // a~bまでの階乗
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}   //数字の各位の和
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}  // b進数の各位の和？
int sankaku(int x){return ((1+x)*x)/2;} //三角数 xまでの和

//以下long long ver
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}

//double
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}


typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) ; for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
bool is_prime (int x){
  if (x<=1) return false ;
  for (int i=2 ; i*i<=x ; i++){
    if (x%i==0) return false ;
  }
   return true;
}
string alpha = "abcdefghijklmnopqrstuvwxyz" ;
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
 
/*CODE START HERE*/
int main() {
  string s , l;
  cin >> s >> l;
  string a = s;
  forn(i,s.size()){
    if ( a == l){
      cout << "Yes" << endl;
      return 0;
    }
    string b = a.substr(s.size()-1) ;
    string c = a.erase(s.size()-1) ;
    a =  b + c ;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3640
import math
xs,ys,xt,yt=map(int,input().split())
N=int(input())

xyrlist=[]
for _ in range(N):
  x,y,r=map(int,input().split())
  xyrlist.append((x,y,r))
  
graph=[[] for _ in range(N+2)]
#s->t
graph[0].append((N+1,math.sqrt((xt-xs)**2+(yt-ys)**2)))

#s->xi
for i in range(N):
  xi,yi,ri=xyrlist[i]
  if (xs-xi)**2+(ys-yi)**2<=ri**2:
    graph[0].append((i+1,0))
  else:
    graph[0].append((i+1,math.sqrt((xs-xi)**2+(ys-yi)**2)-ri))

#xi<->xj
for i in range(N):
  xi,yi,ri=xyrlist[i]
  for j in range(i+1,N):
    xj,yj,rj=xyrlist[j]
    if (xj-xi)**2+(yj-yi)**2<=(ri+rj)**2:
      graph[i+1].append((j+1,0))
      graph[j+1].append((i+1,0))
    else:
      graph[i+1].append((j+1,math.sqrt((xj-xi)**2+(yj-yi)**2)-ri-rj))
      graph[j+1].append((i+1,math.sqrt((xj-xi)**2+(yj-yi)**2)-ri-rj))

#xi->t
for i in range(N):
  xi,yi,ri=xyrlist[i]
  if (xt-xi)**2+(yt-yi)**2<=ri**2:
    graph[i+1].append((N+1,0))
  else:
    graph[i+1].append((N+1,math.sqrt((xt-xi)**2+(yt-yi)**2)-ri))
#print(graph)
    
import heapq
def dijkstra_heap(s):
  #始点sから各頂点への最短距離
  dist=[float("inf")]*size_v
  used=[False]*size_v
  dist[s]=0
  used[s]=True

  hq_edge=[]
  for v,w in graph[s]:
    heapq.heappush(hq_edge,(w,v))

  while hq_edge:
    min_w,min_v=heapq.heappop(hq_edge)
    #まだ使われてない頂点の中から最小の距離のものを探す
    if used[min_v]:
      continue

    dist[min_v]=min_w
    used[min_v]=True
    #prev[min_v]=ei #第3引数
    for v,w in graph[min_v]:
      if not used[v]:
        heapq.heappush(hq_edge,(min_w+w,v))

  return dist

size_v=N+2
dist=dijkstra_heap(0)
#print(dist)
print(dist[N+1])

Measured memory_bytes: 155900
#include<stdio.h>

int main(void){

int i,n;

int number;

long long int sum=0;

int min=0;

int max=0;

scanf("%d",&n);

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

scanf("%d",&number);

if(i==0){

min=number;

max=number;

}

if(number<min)min=number;

if(number>max)max=number;

sum+=number;

}

printf("%d %d %lld\n",min,max,sum);

return 0 ; 

}

Measured memory_bytes: 600
import java.io.*;

public class Main{

    public static void main(String[] args) throws IOException{
        String str = getLine();
        double r = Double.parseDouble(str);
        double s = r * r * Math.PI;
        double l = (r * 2)  * Math.PI;
        System.out.printf("%.6f %.6f\n",s,l);
    }

    public static String getLine() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        return str;
    }
}





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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}

int main(){
	startTime=clock();
	int n;
	cin >> n;
	int a;
	std::vector<int> even;
	std::vector<int> odd;
	FOR(i,n) {
		cin >> a;
		if(i%2) odd.eb(a);
		else even.eb(a);
	}
	sort(odd.begin(),odd.end());
	sort(even.begin(),even.end());
	int maxe=0; int me=-1;
	int maxo=0; int mo=-1;
	int i=0;
	while(i < n/2){
		int j=i;
		while(j < n/2 &&even[j]==even[i]) j++;
		if(j-i > maxe){
			maxe=j-i;
			me=even[i];
		}
		i=j;
	}
	i=0;
	int maxe2=0; int me2=-1;
	int maxo2=0; int mo2=-1;
	while(i < n/2){
		int j=i;
		while(j < n/2 && even[j]==even[i])j++;
		if(j-i > maxe2 && even[i]!=me){
			maxe2=j-i;
			me2=even[i];
		}
		i=j; 
	}
	int k=0;
	while(k < n/2){
		int j=k;
		while(j < n/2 && odd[j]==odd[k]) j++;
		if(j-k > maxo){
			maxo=j-k;
			mo=odd[k];
		}
		k=j;
	}
	k=0;
	while(k < n/2){
		int j=k;
		while(j < n/2 && odd[j]==odd[k]) j++;
		if(j-k > maxo2 && odd[k]!=mo){
			maxo2=j-k;
			mo2=odd[k];
		}
		k=j;
	}
	
	if(me!=mo){
		cout << n- maxe  -maxo;
	}
	else{
		cout << min(n-maxe-maxo2, n-maxe2-maxo);
	}
	return 0;
}

Measured memory_bytes: 3868
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX 100
using namespace std;
string s,t;
int dp[MAX][MAX];

bool check(char a,char b)
{
  return (a == '(' && b == ')') || (a == ')' && b == '(') || (a == '{' && b == '}') || (a == '}' && b == '{') || (a == '[' && b == ']') || (a == ']' && b == '[');
}

int main()
{
  string line;
  while(getline(cin,line))
    {
      if(line.empty())assert(false);
	
      rep(i,line.size())
	if(line[i] == 'i' || line[i] == 'w')line[i] = ' ';
      stringstream ss;
      ss << line;
      s = t = "";
      while(!(ss >> line).fail())
	if(s.empty())s = line;
	else t = line;
     
      rep(i,MAX)rep(j,MAX)dp[i][j] = 0;
      reverse(t.begin(),t.end());
      rep(i,s.size())
	{
	  rep(j,t.size())
	    {
	      if(check(s[i],t[j]))dp[i+1][j+1] = dp[i][j]+1;
	      else dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
	    }
	}
      
      cout << 3 + 2*dp[s.size()][t.size()] << endl;
    }
  return 0;
}

Measured memory_bytes: 1248
def MaxDigits(A, B):
    Adig = 0
    while A > 0:
        A //= 10
        Adig += 1
    Bdig = 0
    while B > 0:
        B //= 10
        Bdig += 1
    return max(Adig, Bdig)

N = int(input())
infinity = float('inf')
ans = infinity

for i in range(1, int(N**0.5) + 1):
    if N%i == 0:
        if ans > MaxDigits(i, N/i):
            ans = MaxDigits(i, N/i)
print(ans)


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

int main()
{

        int K, N;
        cin >> K >> N;
        int A[N];
        for (int i = 0; i < N; ++i) {
                cin >> A[i];
        }
        int sa[N];
        for (int i = 0; i < N; ++i) {
                if (i == N - 1) {
                        sa[i] = K + A[0] - A[N-1];
                }
                else {
                        sa[i] = A[i+1] - A[i];
                }
        }

        long long ans = 0;
        int max = -1;
        for (int i = 0; i < N; ++i) {
                ans += sa[i];
                if (max == -1) max = sa[i];
                else if (max < sa[i]) max = sa[i];
        }
        cout << ans - max << endl;


}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

int main() {
  ll h;
  cin >> h;
  ll ans=0;
  int i=0;
  while(h>0){
    h/=2;
    ans+=(ll)pow(2,i);
    i++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
a,b,c = map(int, input().split())
l = [a,b,c]



count = 0
for i in l:
	if i == 5:
		count += 1
		
		if count == 2:
			break

if any([i == 7 for i in l]) and count == 2:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 2940
def GCD(a, b):
    return a if b == 0 else GCD(b, a % b)

a, b, k = map(int, input().split())

n = 0

for i in reversed(range(1, GCD(a, b)+1)):
    if a % i == 0 and b % i == 0:
        n += 1

    if n == k:
        print(i)
        break


Measured memory_bytes: 2940
fun main(args: Array<String>) = println(run {
    val n = readLine()!!.split(" ").map { it.toInt() }
    val v = readLine()!!.split(" ").map { it.toInt() }.sorted()

    var avg = v[0].toDouble()
    v.reduce { a, b -> avg = (avg+b)/2; b }
    avg
})

Measured memory_bytes: 37928
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

class Dice{
public:
  int t, s, e, n, w, b; //上,南,東,北,西,下
  Dice(){}
  Dice(int t, int s, int e, int n, int w, int b) :
    t(t), s(s), e(e), n(n), w(w), b(b) {}

  // 上の面が東の面に来るように回転
  Dice moveEast()  { return Dice(w, s, t, n, b, e); }
  // 上の面が北の面に来るように回転
  Dice moveNorth() { return Dice(s, b, e, t, w, n); }
  // 南の面が西の面に来るように回転
  Dice moveRight() { return Dice(t, e, n, w, s, b); }

  bool operator==(const Dice &d)const{
    return
      t == d.t && s == d.s && e == d.e &&
      n == d.n && w == d.w && b == d.b;
  }
};

void solve(){
}

int main(){
  int n;

  while(cin>>n,n){
    Dice d(1,2,3,5,4,6);
    int cnt = 1;

    rep(i,n){
      string s;
      cin>>s;
      if(s == "North"){
        d = d.moveNorth();
      }
      else if(s == "East"){
        d = d.moveEast();
      }
      else if(s == "West"){
        d = d.moveEast();
        d = d.moveEast();
        d = d.moveEast();
      }
      else if(s == "South"){
        d = d.moveNorth();
        d = d.moveNorth();
        d = d.moveNorth();
      }
      else if(s == "Right"){
        d = d.moveRight();
      }
      else{
        d = d.moveRight();
        d = d.moveRight();
        d = d.moveRight();
      }

      cnt += d.t;
    }

    cout<<cnt<<endl;
  }
}

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

using namespace std;

bool check(int n, int a, int b);

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (check(i, a, b)) {
			ans += i;
		}
	}
	cout << ans << endl;
	
	return 0;
}

bool check(int n, int a, int b)
{
	int t = 0;
	while (n != 0) {
		t += n % 10;
		n /= 10;
	}

	if (a <= t && t <= b) {
		return true;
	}
	else {
		return false;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define N 200005
#define M 524289
#define LL long long
#define oo (1<<30)
#define V 32768
#define LD long double
using namespace std;
const int mo=924844033;
const LD Pi=acos(-1.0);
int n,m,head[N],num[2*N],nxt[2*N],ans[N],fc[N],xf[N],sz[N],a[N],b[N],e,ep;
void inc(int &x,int y){ x+=y; if(x>=mo) x-=mo;}
LL fpm(LL x,LL y)
{
	LL s=1;
	while(y){
		if(y&1) s=(s*x)%mo;
		y>>=1 , x=(x*x)%mo;
	  }
	return s;
}
void dfs(int t,int fa)
{
	int i; sz[t]=1;
	for(i=head[t];i;i=nxt[i])
		if(num[i]!=fa){
			dfs(num[i],t);
			sz[t]+=sz[num[i]];
		  }
}
struct cp{
	LD x,y;
	cp(LD _x=0,LD _y=0){ x=_x,y=_y;}
}A[M],B[M],C[M],D[M],tmp[M],F[M];
cp operator +(cp p,cp q){ return cp(p.x+q.x,p.y+q.y);}
cp operator -(cp p,cp q){ return cp(p.x-q.x,p.y-q.y);}
cp operator *(cp p,double r){ return cp(p.x*r,p.y*r);}
cp operator *(double r,cp p){ return cp(p.x*r,p.y*r);}
cp operator *(cp p,cp q){ return cp(p.x*q.x-p.y*q.y,p.x*q.y+p.y*q.x);}
int rev(int x)
{
	int i,y=0;
	for(i=0;i<ep;i++)
		y+=((x>>i)&1)*(1<<(ep-i-1));
	return y;
}
void FFT(cp *x,int op)
{
	int i,j,k; cp p,q,w,wn;
	for(i=0;i<e;i++) tmp[i]=x[i];
	for(i=0;i<e;i++) x[i]=tmp[rev(i)];
	for(i=1;i<=e;i<<=1){
		wn=cp(cos(2*Pi*op/i),sin(2*Pi*op/i));
		for(j=0;j<e;j+=i){
			w=cp(1,0);
			for(k=0;k<i/2;k++){
				p=x[j+k],q=x[j+k+i/2]*w;
				x[j+k]=p+q,x[j+k+i/2]=p-q;
				w=w*wn;
			  }
		  }
	  }
}
LL com(int n,int m)
{
	return 1LL*fc[n]*xf[m]%mo*xf[n-m]%mo;
}
int main()
{
	int i,x,y;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d %d",&x,&y);
		num[++m]=y,nxt[m]=head[x],head[x]=m;
		num[++m]=x,nxt[m]=head[y],head[y]=m;
	  }
	dfs(1,0),fc[0]=xf[0]=1;
	for(i=1;i<=n;i++){
		fc[i]=(1LL*fc[i-1]*i)%mo;
		xf[i]=fpm(fc[i],mo-2);
	  }
	for(i=1;i<=n;i++){
		(a[sz[i]]+=fc[sz[i]])%=mo;
		(a[n-sz[i]]+=fc[n-sz[i]])%=mo;
	  }
	for(i=0;i<=n;i++) b[i]=xf[n-i];
	a[0]=b[0]=0;
	for(e=1,ep=0;e<=2*n;e<<=1,ep++);
	for(i=0;i<=n;i++){
		A[i].x=a[i]/V,B[i].x=a[i]%V;
		C[i].x=b[i]/V,D[i].x=b[i]%V;
	  }
	FFT(A,1),FFT(B,1);
	FFT(C,1),FFT(D,1);
	for(i=0;i<e;i++) F[i]=A[i]*C[i];
	FFT(F,-1);
	for(i=n+1;i<=2*n;i++)
		ans[i-n]=(ans[i-n]+(LL)(F[i].x/e+0.5)%mo*V%mo*V)%mo;
	for(i=0;i<e;i++) F[i]=B[i]*D[i];
	FFT(F,-1);
	for(i=n+1;i<=2*n;i++)
		ans[i-n]=(ans[i-n]+(LL)(F[i].x/e+0.5))%mo;
	for(i=0;i<e;i++) F[i]=A[i]*D[i];
	FFT(F,-1);
	for(i=n+1;i<=2*n;i++)
		ans[i-n]=(ans[i-n]+(LL)(F[i].x/e+0.5)%mo*V)%mo;
	for(i=0;i<e;i++) F[i]=B[i]*C[i];
	FFT(F,-1);
	for(i=n+1;i<=2*n;i++)
		ans[i-n]=(ans[i-n]+(LL)(F[i].x/e+0.5)%mo*V)%mo;
	for(i=1;i<=n;i++){
		ans[i]=(1LL*ans[i]*xf[i])%mo;
		ans[i]=(1LL*(n+1)*com(n,i)-ans[i]+mo)%mo;
	  }
	for(i=1;i<=n;i++)
		printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 116992
#include <bits/stdc++.h>
int main() {
	int N, M;
	std::cin >> N>> M;
	std::vector<double> A(N),B(N),C(N);
	for(int i = 0; i < N; i++){std::cin >> A[i]>>B[i]>>C[i];}
	auto dist = [&](const int i, const int j){
		return (A[i]-A[j])*(A[i]-A[j])+(B[i]-B[j])*(B[i]-B[j])+(C[i]-C[j])*(C[i]-C[j]);
	};
	std::vector<int> o(N, 0);
	std::fill(o.begin(),o.begin()+M, 1);
	double ans = 0;
	do{
		std::vector<int> ind;
		for(int i = 0;i < N; i++){
			if(o[i]){ind.push_back(i);}
		}
		double sum = 0;
		for(int i = 0;i < M-1; i++){
			for(int j = i+1; j < M; j++){sum += dist(ind[i],ind[j]);}
		}
		ans = std::max(ans, sum);
	}while(std::prev_permutation(o.begin(),o.end()));
	std::cout << std::fixed << std::setprecision(15)<<ans << std::endl;
	return 0;
}


Measured memory_bytes: 3280
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,g,h,i,j,z;
	scanf("%d %d %d %d %d %d %d %d %d %d\n",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
	z=a+b+c+d+e+f+g+h+i+j;
	printf("%d\n",z);
	return 0;
}

Measured memory_bytes: 1028
def sk(k):
  tk = k
  ret = 0
  while tk!=0:
    ret+=tk%10
    tk//=10
  return ret

ans = []
for i in range(1,100):
  tmp = i/sk(i)
  if len(ans)==0:
    ans.append((i,tmp))
  else:
    l=ans[-1]
    if l[1]>tmp:
      ans[-1]=(i,tmp)
    else:
      ans.append((i,tmp))

for j in range(15):
  for i in range(100,1000):
    n=int(str(i)+''.join(['9']*j))
    tmp=n/sk(n)
    if ans[-1][1] > tmp:
      while ans[-1][1]>tmp:
        ans.pop()
    ans.append((n,tmp))

for i in range(int(input())):
  print(ans[i][0])

Measured memory_bytes: 9112
#include <stdio.h>

int
get_right_surface(int *surfaces, int top, int front)
{
	if (top == surfaces[0] && front == surfaces[1]) return surfaces[2];
	if (top == surfaces[0] && front == surfaces[2]) return surfaces[4];
	if (top == surfaces[0] && front == surfaces[4]) return surfaces[3];
	if (top == surfaces[0] && front == surfaces[3]) return surfaces[1];
	if (top == surfaces[1] && front == surfaces[5]) return surfaces[2];
	if (top == surfaces[1] && front == surfaces[2]) return surfaces[0];
	if (top == surfaces[1] && front == surfaces[0]) return surfaces[3];
	if (top == surfaces[1] && front == surfaces[3]) return surfaces[5];
	if (top == surfaces[2] && front == surfaces[1]) return surfaces[5];
	if (top == surfaces[2] && front == surfaces[5]) return surfaces[4];
	if (top == surfaces[2] && front == surfaces[4]) return surfaces[0];
	if (top == surfaces[2] && front == surfaces[0]) return surfaces[1];
	if (top == surfaces[3] && front == surfaces[1]) return surfaces[0];
	if (top == surfaces[3] && front == surfaces[0]) return surfaces[4];
	if (top == surfaces[3] && front == surfaces[4]) return surfaces[5];
	if (top == surfaces[3] && front == surfaces[5]) return surfaces[1];
	if (top == surfaces[4] && front == surfaces[2]) return surfaces[5];
	if (top == surfaces[4] && front == surfaces[5]) return surfaces[3];
	if (top == surfaces[4] && front == surfaces[3]) return surfaces[0];
	if (top == surfaces[4] && front == surfaces[0]) return surfaces[2];
	if (top == surfaces[5] && front == surfaces[1]) return surfaces[3];
	if (top == surfaces[5] && front == surfaces[3]) return surfaces[4];
	if (top == surfaces[5] && front == surfaces[4]) return surfaces[2];
	if (top == surfaces[5] && front == surfaces[2]) return surfaces[1];
	return 0;
}

int
main()
{
	int i;
	int top, front;
	int n_questions;
	int surfaces[6];

	for (i = 0; i < 6; i++)
	{
		scanf("%d", &surfaces[i]);
	}
	scanf("%d", &n_questions);
	for (i = 0; i < n_questions; i++)
	{
		scanf("%d %d", &top, &front);
		printf("%d\n", get_right_surface(surfaces, top, front));
	}

	return 0;
}

Measured memory_bytes: 596
n, a, b = gets.split(' ').map{|i| i.to_i}
ans = 0

(0..n).each do |i|
  x = i.to_s.split('')
  s = x.map{|m| m.to_i}.inject(&:+)
  if a <= s && s <= b
    ans += i
  end
end

puts ans

Measured memory_bytes: 2300
a, b, x = map(int, input().split(' '))

if a % x == 0:
    y1 = a
elif a < x:
    y1 = x
else:
    y1 = a + (x - a % x)

y2 = b - b % x

ans = (y2 - y1) // x + 1
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

object Main extends App {

  val sc = new Scanner(System.in);

  val len = sc.nextInt();
  val str = sc.next();
  val str2 = str.toArray;

  @scala.annotation.tailrec
  def sub(answer: Int, wi: Int, ri: Int): Int = {
    val wi2 = str2.indexOf('W', wi);
    val ri2 = str2.lastIndexOf('R', ri);
    if (ri2 < 0) {
      answer;
    } else if (wi2 < 0) {
      answer;
    } else if (wi2 > ri2) {
      answer;
    } else {
      str2(wi2) = 'R';
      str2(ri2) = 'W';
      sub(answer + 1, wi2 + 1, ri2 - 1);
    }
  }

  val answer = sub(0, 0, len - 1);
  println(answer);
}

Measured memory_bytes: 55692
#include<stdio.h>

int main()
{
    int n, i;
    scanf("%d", &n);
    double arr[n+5], sum=0, dif;
    arr[0]=0;
    for(i=1; i<=n; i++)
    {
        scanf("%lf", &arr[i]);
        if(arr[i]<arr[i-1])
        {
            dif = arr[i-1]-arr[i];
            sum = sum + dif;
            arr[i] = arr[i-1];
        }
    }
    printf("%.0lf\n", sum);

    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int K = nextLong();
  vector<int> vis(K+1);
  int age = 1;
  ll x = 7 % K;
  for (;; age++) {
    if (x == 0) {
      cout << age << endl;
      return 0;
    }
    if (vis[x] != 0) {
      cout << -1 << endl;
      return 0;
    }
    vis[x] = age;
    x = (10 * x + 7) % K;
  }

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 7232
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,ssse3")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using ld = long double;
#include<bits/extc++.h>
using namespace __gnu_pbds;
using oset = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn = 1<<21, mod = 1e9 + 7;
__int128 absa(__int128 a) {
	return max(a, -a);}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	ll x = n/k;
	ll ans = 1ll<<60;
	for(__int128 i = -1000; i < 1000; i++) ans = min((__int128)ans,
	 absa(__int128(x+i)*k-__int128(n))
	 );
	cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <numeric>
#include <queue>
typedef long long int ll;
using namespace std;
int main(){
	vector<char> F;
	vector<char> C;
	string S;
	ll q;
	int m,s,k=0;
	char c;
	cin>>S>>q;
	for(ll i=0;i<q;i++){
		cin>>m;
		if(m==1){
			k=(k+1)%2;
		}else{
			cin>>s>>c;
			if(s==1){
				if(k==0){
					F.insert(F.begin(),c);
				}else{
					C.push_back(c);
				}
			}else{
				if(k==0){
					C.push_back(c);
				}else{
					F.insert(F.begin(),c);
				}
			}
		}
	}
	
	if(k==0){
		for(ll i=0;i<F.size();i++){
			cout<<F[i];
		}	
		cout<<S;
		for(ll i=0;i<C.size();i++){
			cout<<C[i];
		}
	}else{
		for(ll i=0;i<C.size();i++){
			cout<<C[C.size()-1-i];
		}
		for(ll i=0;i<S.size();i++){
			cout<<S[S.size()-1-i];
		}
		for(ll i=0;i<F.size();i++){
			cout<<F[F.size()-1-i];
		}
	}
	
	return 0;
}


Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

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

int main(){
    int h, w;
    cin >> h >> w;
    int sy, sx, ty,tx;
    cin >> sy >> sx >> ty >> tx;
    --sy;
    --sx;
    --ty;
    --tx;
    vector<string> s(h);
    rep(i, h) cin >> s[i];


    vector<vi> d(h, vi(w, 1e9));
    d[sy][sx] = 0;
    using P = tuple<int, int, int>;
    priority_queue<P, vector<P>, greater<P> > q;
    q.emplace(0, sy,sx);

    while(!q.empty()) {
        auto p = q.top(); q.pop();
        int c, x, y;
        tie(c, y, x) = p;
        if(d[y][x] != c) continue;

        rep(i, 4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
            if(s[ny][nx] == '#') continue;
            if(d[ny][nx] > c) {
                d[ny][nx] = c;
                q.emplace(c, ny, nx);
            }
        }

        REP(i, -2, 3) REP(j, -2, 3) {
            int nx = x + j;
            int ny = y + i;
            if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
            if(s[ny][nx] == '#') continue;
            if(d[ny][nx] > c+1) {
                d[ny][nx] = c+1;
                q.emplace(c+1, ny, nx);
            }
        }
    }
    if(d[ty][tx] == 1e9) cout << -1 << '\n';
    else cout << d[ty][tx] << '\n';
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

int f(int i)
{
        string s=to_string(i);
        return s.size()%2;
}

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

        int ans=0;

        FOR(i,1,n)ans+=f(i);

        cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
      signed int a,b,c;
      scanf("%d %d %d",&a,&b,&c);
      if(a==b)
      {
          printf("%d\n",c);
      }
      else if(b==c)
      {
          printf("%d\n",a);
      }
      else if(c==a)
      {
          printf("%d\n",b);
      }
      return 0;
}



Measured memory_bytes: 128
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))

satisfy = sum(B)
for i in range(N-1):
  if A[i+1]==A[i]+1:
    satisfy = satisfy + C[A[i]-1]
print(satisfy)

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

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)cin >> a[i];
    sort(a.begin(), a.end());

    ll sum = 0;
    ll ret = 0;
    for (int i = 0; i < n - 1; i++) {
        sum += a[i];
        if (a[i + 1] <= sum * 2)ret++;
        else ret = 0;
    }
    cout << ret + 1 << endl;
    return 0;
}

Measured memory_bytes: 1024
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
long long n,a[303030],dp[303030],dph[303030],ans=-1e18;
map<long long,long long>mp;
priority_queue<long long>pq;
int main()
{
	cin>>n;
	for(int i=1;i<=3*n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		mp[a[i]]++;
		dp[i]=dp[i-1]+a[i];
	}
	for(int i=n+1;i<=n*2;i++)
	{
		mp[a[i]]++;
		dp[i]=dp[i-1]+a[i]-mp.begin()->first;
		mp.begin()->second--;
		if(mp.begin()->second==0)
		{
			mp.erase(mp.begin());
		}
	}
	for(int i=3*n;i>2*n;i--)
	{
		pq.push(a[i]);
		dph[i]=dph[i+1]+a[i];
	}
	for(int i=2*n;i>n;i--)
	{
		pq.push(a[i]);
		dph[i]=dph[i+1]+a[i]-pq.top();
		pq.pop();
	}
	for(int i=n;i<=2*n;i++)
	{
		ans=max(ans,dp[i]-dph[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13688
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

const int INF{1001001001};
const lint LINF{1001001001001001001ll};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

signed main() {
  int a[4];
  rep(i, 4) cin >> a[i];

  print(max(a[0] * a[1], a[2] * a[3]));
}


Measured memory_bytes: 256
n=int(input())
List=list(map(int,input().split()))
newList =[0] * n
count = 0
min = List[0]
# print(List)
for i in List:
    # 最小値更新
    if i < min:
        min = i
    # カウントする
    if min >= i:
        count = count + 1

print(count)

Measured memory_bytes: 24744
#include<bits/stdc++.h>
#define ull unsigned long long
# define ll long long
# define mod 1000000007LL 
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int arr[n];
    int brr[n];
    int fre[1000001]={0};
    for(int i=0;i<n;i++)
    {
    cin>>arr[i];
    brr[i]=arr[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=2;j*j<=arr[i];j++)
        {
            if((arr[i]%j)==0)
            fre[j]++;
            while((arr[i]%j)==0)
            {
                arr[i]=arr[i]/j;
            }
        }
        if(arr[i]!=1)
        fre[arr[i]]++;
    }
    sort(fre,fre+500000,greater<int>());
    if(fre[0]==1 || fre[0]==0)
    {
        cout<<"pairwise coprime";
        return 0;
    }
    int ans=__gcd(brr[0],brr[1]);
    for(int i=2;i<n;i++)
    {
        ans=__gcd(ans,brr[i]);
    }
    if(ans==1)
    {
        cout<<"setwise coprime";
        return 0;
    }
    cout<<"not coprime";

    
    
    return 0;
}

Measured memory_bytes: 15344
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,y; cin>>n>>y;
    reps(i,0,n){
        reps(j,0,n){
            if(i+j>n) continue;
            if(10000*i+5000*j+1000*(n-i-j) == y){
                cout << i << " " << j << " " << n-i-j << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 <<endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
main(){
  vector<int>xs(3);
  for(auto&x:xs)cin>>x;
  auto it=max_element(xs.begin(), xs.end());
  int K;
  cin>>K;
  *it=*it*pow(2, K);
  for(int i=1;i<xs.size();++i)xs[i]+=xs[i-1];
  cout<<xs.back()<<endl;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
count = 0
flag = 1
while flag:
    flag = 0
    for i in range(n-1, 0, -1):
        if A[i] < A[i - 1]:
            A[i], A[i-1] = A[i-1], A[i]
            flag = 1
            count += 1
print(*A,sep=' ')
print(count)


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
typedef vector<vector<int>> Graph;
#define MOD 1000000007
#define INF 1000000000000
#define FOR(i,a,b) for(INT i=a;i<=INT(b);i++)
#define REP(i,n) for (INT i=0;i<(INT(N));i++)
#define all(x) (x).begin,(x).end()

int judge(int n)
{
    int cnt=0;
    FOR(i,1,n){
        if (n%i==0)cnt++;
    }
    return cnt;
}


int main()
{
    int n;
    cin>>n;
    int ans=0;
    FOR(i,1,n){
        if(i%2==1){
            int cnt=judge(i);
            if(cnt==8)ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <int, PII> PIP;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
typedef vector <int> vi;
const int mod = 1e9+7;
const int inf = 1e9+10;
const ll MOD = 1e9+696969;
const ll INF = 1e18;
const int W = 1e9;
#define maxn 1001009
int n, m, k, a, b, c;
int t[maxn];
char s[maxn];
bool ans[maxn];
inline int nt(int x) {
	if (x == n) return 1;
	return x + 1;
}
inline int lt(int x) {
	if (x == 1) return n;
	return x - 1;
}

void check(int st)
{
	t[1] = st & 1;
	if (st == 2 || st == 3) t[2] = 1;
	else t[2] = 0;
	FOR(i, 2, n-1)
	{
		if (t[i] == 0) {//sheep
			if (ans[i] == 1) t[i + 1] = t[i - 1];
			else t[i + 1] = 1 - t[i - 1];
		}
		else {//wolf
			if (ans[i] == 0) t[i + 1] = t[i - 1];
			else t[i + 1] = 1 - t[i - 1];
		}
	}

	FOR(i, 1, n)
	{
		bool diff = 0;
		if (t[nt(i)] != t[lt(i)]) diff = 1;
		if (t[i] == 0 && (diff == ans[i])) return;
		if (t[i] == 1 && (diff != ans[i])) return;
	}
	FOR(i, 1, n)
	if (t[i] == 0) cout << "S";
	else cout << "W";
	exit(0);
}

int main()
{
	scanf("%d%s", &n, s+1);
	FOR(i, 1, n)
	if (s[i] == 'o') ans[i] = 1;
	else ans[i] = 0;
	
	FOR(i, 0, 3) check(i);
	OUT(-1);
}


Measured memory_bytes: 2688
l1 = input().split()
l2 = input().split()
l3 = input().split()
l = [l1,l2,l3]
n = int(input())
b = [input() for i in range(n)]
for i in range(3):
    for j in range(3):
        if l[i][j] in b:
            l[i][j] = -1
if l[0] == [-1,-1,-1] or l[1] == [-1,-1,-1] or l[2] == [-1,-1,-1] or (l[0][0] == -1 and l[1][0] == -1 and l[2][0] == -1) or (l[0][1] == -1 and l[1][1] == -1 and l[2][1] == -1) or (l[0][2] == -1 and l[1][2] == -1 and l[2][2] == -1) or (l[0][0] == -1 and l[1][1] == -1 and l[2][2] == -1) or (l[2][0] == -1 and l[1][1] == -1 and l[0][2] == -1):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N,K = LI()
    f = [1]
    r = [1]

    s = 1
    for i in range(1,N+2):
        s = (s * i) % MOD
        f.append(s)
        r.append(pow(s,MOD-2,MOD))


    def comb(a,b):
        return f[a] * r[b] * r[a-b]

    ans = 0
    for k in range(min(K,N-1)+1):
        ans = (ans + comb(N,k) * comb(N-1,k)) % MOD
    print(ans)

if __name__ == '__main__':
    main()

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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const ll MOD = 1000000007;

ll fpow(ll a, ll b, ll p){
    ll res = 1;
    while(b > 0){
        if(b&1) res = (res * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return res;
}

ll inv(ll a, ll p){
    return fpow(a,p - 2, p);
}

ll nCk(ll n, ll k, ll p){
    vector<ll> fn(n + 1);
    fn[0] = 1;
    for(ll i = 1; i <= n; ++i){
        fn[i] = (fn[i - 1] * i) % p;
    }
    ll aux = (fn[k] * fn[n -k]) % p;
    ll pw = fpow(aux, p - 2, p) % p;
    ll ok = (pw * fn[n]) % p;
    return ok;
}

signed main(){
    io();
    ll x, y; cin >> x >> y;
    if((x + y) % 3){
        cout << 0 << '\n';
    }else{
        ll a = (x + x - y)/3;
        ll b = (y + y - x)/3;
        if(a < 0 || b < 0){
            cout << 0 << '\n';
        }else{
            cout << nCk(a+b, b, MOD) << '\n';
        }
    }
    return 0;
}

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

using ll = long long;

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

	ll i;
	if(n>=10){
		i = r;
	}	
	else{
		ll a = 100*(10-n);
		i = r+a;
	}

	cout << i << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {

    private static final int MOD = 1_000_000_007;
    private static final int MAX = 1000000;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();

        int A = -1, B = -1;
        for (int a = 0; a <= X; a++) {
            int b = X - 2*a;
            if (b >= 0 && a+2*b == Y) {
                A = a;
                B = b;
                break;
            }
        }
        if (A == -1) {
            System.out.println(0);
        } else {
            System.out.println(combMod(A+B, A));
        }
    }
  private static long combMod(int n, int k) {  
    long[] fac = new long[n+1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++) {
      fac[i] = fac[i-1]*i % MOD;
    }
    return ((fac[n]*power(fac[k], MOD-2))%MOD)*power(fac[n-k], MOD-2)%MOD;
  }
  private static long power(long a, int n) {
    if (n == 0) {
      return 1;
    }
    if (n%2 == 1) {
      return power(a, n-1)*a%MOD;
    }
    long half = power(a, n/2);
    return half*half%MOD;
  }
}


Measured memory_bytes: 27988
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

vector<int> TopologicalSort(vector<vector<int> > &G, vector<int> &indegree){
	vector<int> va;
	queue<int> qa;
	for(int i = 0; i < G.size(); i++){
		if(indegree[i] == 0) qa.push(i);
	}
	while(!qa.empty()){
		int u = qa.front(); qa.pop();
		va.push_back(u);
		for(int i = 0; i < G[u].size(); i++){
			int v = G[u][i];
			indegree[v]--;
			if(indegree[v] == 0) qa.push(v);
		}
	}
	return va;
}

int main(){
	int V, E;
	cin >> V >> E;
	vector<vector<int> > G(V, vector<int>());
	vector<int> indegree(V, 0);
	for(int i = 0; i < E; i++){
		int s, t;
		cin >> s >> t;
		G[s].push_back(t);
		indegree[t]++;
	}
	vector<int> res = TopologicalSort(G, indegree);
	if(res.size() != V) cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}



Measured memory_bytes: 3176
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}
#define ONE_CLOCK 0.000000425

inline unsigned long long get_cycle() {
  unsigned int low, high;
  __asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
  return ((unsigned long long int)low) | ((unsigned long long int)high << 32);
}

class Timer {
 public:
  unsigned long long start_time;
  Timer() { start_time = get_cycle(); }
  inline int get_time() {
    return get_cycle() * ONE_CLOCK - start_time * ONE_CLOCK;
  }
};
int main() {
  Timer timer;
  GI2(N, M);
  vector<vector<int>> G(N);
  FOR(i, M) {
    GI2(u, v);
    G[u - 1].push_back(v - 1);
  }
  GI2(S, T);
  vector<vector<int>> visit(N, vector<int>(3));
  queue<pair<int, int>> q;
  q.push(pair<int, int>(S - 1, 0));
  while (timer.get_time() < 1800) {
    if (!q.empty() && q.size() < 100000000) {
      pair<int, int> p = q.front();
      q.pop();
      int v = p.first;
      int d = p.second;
      if (v == T - 1 && d % 3 == 0) {
        print(d / 3);
        return 0;
      }
      if (!G[v].empty())
        for (int x : G[v]) {
          if (visit[x][(d + 1) % 3] == 0) {
            q.push(pair<int, int>(x, d + 1));
            visit[x][(d + 1) % 3] = 1;
          }
        }
    }
  }
  print(-1);
  return 0;
}

Measured memory_bytes: 11136
#include <stdio.h> 

int main(void)
{
	int a, b, c, tmp;

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

	if(a > b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}

	if(b > c)
	{
		tmp = b;
		b = c;
		c = tmp;
	}

	if(a > b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}

	printf("%d %d %d\n",a,b,c);

	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    vector<ll> P;
    vector<ll> minP;
    cin >> N;
    for (int i = 0; i < N; i++) {
        ll p; cin >> p;
        P.pb(p);
    }
    minP.pb(LINF);
    for (int i = 0; i < N; i++) {
        if(minP[i] > P[i]){
            minP.pb(P[i]);
        } else {
            minP.pb(minP[i]);
        }
    }
    ll cnt = 0;
    for (int i = 1; i <= N; i++) {
        if(minP[i] >= P[i-1]){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 7960
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;

int ac, wa, tle, re;

int main () {

    int n;
    cin >> n;

    for (int i = 1 ; i <= n ; ++ i) {
        string s;
        cin >> s;
        if (s == "AC") {
            ++ ac;
        }
        if (s == "WA")
            ++ wa;
        if (s == "TLE")
            ++ tle;
        if (s == "RE")
            ++ re;
    }

    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tle);
    printf("RE x %d\n", re);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 3712
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		int flag = 0;
      if(a%2==0||b%2==0){
        flag = 1;
      }
		// 出力
      if(flag==0){
		System.out.println("Odd");
	}else{
        System.out.println("Even");
      }
      }
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)

lli inv[200200];

lli mod_pow(lli a,lli b){
	a %= MOD;
	if(b==0)return 1;
	if(b==1)return a;
	lli res = mod_pow(a,b/2)%MOD;
	res *= res;
	res %= MOD;
	if(b%2)res *=a;
	return res%MOD;
}

signed main(){

	lli n;
	cin>>n;
	vector<lli> x(n);
	REP(i,0,n)cin>>x[i];

	//invMake;
	inv[0]=1;
	REP(i,1,150150)inv[i] = inv[i-1]*i%MOD;

	vector<lli> cnt(n+5,0);
	REP(i,1,n+4){
		cnt[i] = inv[n-1] * mod_pow(i,MOD-2)%MOD;
		cnt[i] += cnt[i-1];
		cnt[i] %= MOD;
	}

	lli ans = 0;
	REP(i,0,n-1){
		ans += (x[i+1]-x[i])*cnt[i+1]%MOD;
		ans %=MOD;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    vector<ll> p(n);
    For(i,0,n) cin>>p[i];
    vector<ll> q(n);
    For(i,0,n) cin>>q[i];
    ll P,Q;
    vector<ll> R(n);
    For(i,0,n) R[i]=i+1;
    ll count=0;
    do{
         bool flagp=true,flagq=true;
         For(i,0,n){
              flagp=flagp&&(p[i]==R[i]);
              flagq=flagq&&(q[i]==R[i]);
         }
         if(flagp) P=count;
         if(flagq) Q=count;
         count++;
    }while(next_permutation(R.begin(),R.end()));
    ans=abs(P-Q);
    cout<<ans<<endl;     
}
int main(){
     Main();
     return 0;
}

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

int main() {
    int n, l;
    cin >> n >> l;
    
    vector<string> s(n);
    for (int i = 0; i < n; i++) cin >> s.at(i);
    
    sort(s.begin(), s.end());
    for (string si : s) {
        cout << si;
    }
    cout << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# A

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

h1, m1, h2, m2, k = map(int, input().split())

val = 0
val += (h2 - h1) * 60
val += m2 - m1

print(val - k)




Measured memory_bytes: 65120