akhauriyash/Code-Regression huggingface dataset:
import sys
import math
input = sys.stdin.readline

A, B, H, M = map(int, input().rstrip().split())


H_theta = 30 *( H + M * (1/60))
M_theta = M * 6
theta = min(abs(H_theta - M_theta), 360 - abs(H_theta - M_theta))
ans = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(math.radians(theta)))
print(ans)


Measured memory_bytes: 9352
#include <stdio.h>

int main(void){
	int n[4]={0,0,0,0}; char a;
	
	while(scanf("%*d,%c",&a)==1){
		switch(a){
			case 'A':
				if((a=getchar())=='B') n[2]++;
				else n[0]++;
				break;
			case 'B':
				n[1]++; break;
			case 'O':
				n[3]++; break;
		}
	}
	
	for(a=0; a<4; a++) printf("%d\n",n[a]);
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main()
{
	int w,h,x,y,r;
	
	scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
	if(x+r > w || x-r < 0) printf("No\n");
	else if(y+r > h || y-r < 0) printf("No\n");
	else printf("Yes\n");
	
	return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	bool edge[n][n];
	memset(&edge,0,sizeof(edge));
	for(int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		edge[a][b] = edge[b][a] = true;
	}
	vector<int> path;
	for(int i = 0; i < n; i ++)
	{
		path.push_back(i);
		//cout << path[i] << " ";
	}
	//cout << endl;
	int total = 0;
	do
	{
		if(path[0] == 0)
		{
			int edges = 0;
			for(int i = 0; i < n-1; i ++)
			{
				if(edge[path[i]][path[i+1]])
				{
					edges++;
				}
			}
			if(edges == n-1)
			{
				total++;
			}
		}
		else
		{
			continue;
		}
	}
	while(next_permutation(path.begin(),path.end()));
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
h = list(map(int,input().split()))
ab = [list(map(int,input().split())) for _ in range(m)]
result = {i + 1 for i in range(n)}

for a, b in ab:
    if h[a-1] < h[b-1]:
        result.discard(a)
    elif h[a-1] > h[b-1]:
        result.discard(b)
    else:
        result.discard(a)
        result.discard(b)

print(len(result))


Measured memory_bytes: 40472
/*
@samaranand
*/
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define sz(v) (int)(v).size()
using vi = vector < int >;
using vvi = vector < vi >;
using pii = pair < int , int >;
using vpii = vector < pii >;
using int64 = long long;
//const int64 biGinf = 9e+18;
//const string yo = "YES", no = "NO";
const int inf = 2e9 + 7;
const char nwl = '\n';

// [0, 1, 1, #, 0, 0, , 0, 0,]
// [1, 2, 3, 3, 0, 0, , 0, 0,]
// [1, 3, #, 3, 0, 0, , 0, 0,]
// [#, 3, 3, 3, 0, 0, , 0, 0,]
// [0, 0, 0, 0, 0, 0, , 0, 0,]
// [0, 0, 0, 0, 0, 0, , 0, 0,]
// [0, 0, 0, 0, 0, 0, , 0, 0,]
const int mod = 1e9 + 7;

int calc(int res[][1010], char input[][1010], int h, int w) {
	for1(i, w) {
		if (input[0][i] == '#') break;
		res[0][i] = 1;
	}
	for1(i, h) {
		if (input[i][0] == '#') break;
		res[i][0] = 1;
	}
	for (int i = 1; i < h; i++) {
		for (int j = 1; j < w; j++) {
			if (input[i][j] == '#') res[i][j] = 0;
			else res[i][j] = (res[i - 1][j] % mod + res[i][j - 1] % mod) % mod;
		}
	}
	return res[h - 1][w - 1];
}



int main() {
	int h, w;
	cin >> h >> w;
	char input[1010][1010];
	for0(i, h) {
		for0(j, w) {
			cin >> input[i][j];
		}
	}
	int res[1010][1010] = {0};

	int ans = calc(res, input, h, w);
	cout << ans;

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiil;
typedef pair<pll, ll> pplll;
typedef pair<pli, int> pplii;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<pll>> vvpll;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define rrep(i, a, b) for (ll i=(a); i>(b); i--)
#define pb push_back
#define tostr to_string
#define mkp make_pair
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

void print(ld out) { cout << fixed << setprecision(15) << out << '\n'; }
template<typename T> void print(T out) { cout << out << '\n'; }
template<typename T1, typename T2> void print(pair<T1, T2> out) { cout << out.first << ' ' << out.second << '\n'; }
template<typename T> void print(vector<T> A) { rep(i, 0, A.size()) { cout << A[i]; cout << (i == A.size()-1 ? '\n' : ' '); } }
template<typename T> void print(set<T> S) { vector<T> A(S.begin(), S.end()); print(A); }

template<typename T> inline bool chmax(T &x, T y) { return (y > x) ? x = y, true : false; }
template<typename T> inline bool chmin(T &x, T y) { return (y < x) ? x = y, true : false; }

ll sum(vector<ll> A) { ll res = 0; for (ll a: A) res += a; return res; }
ll max(vector<ll> A) { ll res = -INF; for (ll a: A) chmax(res, a); return res; }
ll min(vector<ll> A) { ll res = INF; for (ll a: A) chmin(res, a); return res; }

ll toint(string s) { ll res = 0; for (char c : s) { res *= 10; res += (c - '0'); } return res; }
int toint(char c) { return c - '0'; }
char tochar(int i) { return '0' + i; }

inline ll pow(int x, ll n) { ll res = 1; rep(_, 0, n) res *= x; return res; }
inline ll pow(ll x, ll n, int mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; }

inline ll floor(ll a, ll b) { if (a < 0) { return (a-b+1) / b; } else { return a / b; } }
inline ll ceil(ll a, ll b) { if (a >= 0) { return (a+b-1) / b; } else { return a / b; } }

int popcount(ll S) { return __builtin_popcountll(S); }
ll gcd(ll a, ll b) { return __gcd(a, b); }

ll N, Q, q;
string S;

ll f(ll x) {
    vector<ll> DM(N);
    ll mcnt = 0;
    rrep(i, N-1, -1) {
        if (i+x < N) {
            if (S[i+x] == 'M') {
                mcnt--;
            }
        }
        if (S[i] == 'M') {
            mcnt++;
        } else if (S[i] == 'D') {
            DM[i] = mcnt;
        }
    }

    ll res = 0, dcnt = 0, dmcnt = 0;
    rep(i, 0, N) {
        if (i-x >= 0) {
            if (S[i-x] == 'D') {
                dcnt--;
                dmcnt -= DM[i-x];
            }
        }
        if (S[i] == 'D') {
            dcnt++;
        } else if (S[i] == 'M') {
            dmcnt += dcnt;
        } else if (S[i] == 'C') {
            res += dmcnt;
        }
    }
    return res;
}

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

    cin >> N;
    cin >> S;
    cin >> Q;
    rep(_, 0, Q) {
        cin >> q;
        ll ans = f(q);
        print(ans);
    }
    return 0;
}


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

int N;
int cnt = 0;
bool flg[10];//多めに取る

int main() {
   fill(flg, flg+10, false);//fill・・・配列やコンテナに対して、レンジ指定をして、すべて同じ値を代入
   cin >> N;
   for (int i = 0; i < N; i++) {
      int a;
      cin >> a;
      bool ok = false;
      for (int i = 1; i <= 8; i++) {
         if (a < 400 * i) {
            ok = true;
            flg[i-1] = true;
            break;
         }
      }
      if (!ok) cnt++;//3200以上の人がいたらcnt++
   }

   int num = count(flg, flg+8, true);//count・・・配列やコンテナの特定の要素がいくつ含まれているか返すテンプレート関数
   cout << max(1, num) << " ";
   cout << num + cnt << endl;

   return 0;
}
//boolで解く方法

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String b=sc.next();
      	char tmp='\0',tmp1='\0';

		int total=1;
		for(int i=0;i<a;i++)
        {  
          tmp1=tmp;
          tmp=b.charAt(i);          
          if(i>0)
          {
            if(tmp1!=tmp)
            {
            	total+=1;
            }
          }          
        }
		System.out.println(total);
	}
}

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

/******************** START OF CRAPS ********************/

#define fin             freopen("input/in.txt","r",stdin);
#define fout            freopen("input/out.txt","w",stdout);
#define ri(x)           scanf("%d", &x)
#define r3i(x,y,z)      scanf("%d %d %d", &x, &y, &z)
#define rll(x)          scanf("%lld", &x)
#define r2ll(x,y)       scanf("%lld %lld", &x, &y)
#define imax            INT_MAX
#define imin            INT_MIN
#define pb              push_back
#define mp              make_pair
#define pi              acos(-1.0)
#define newl            "\n"
#define newlChar        '\n'
#define spChar          ' '
#define max3(a,b,c)     max(a,max(b,c))
#define min3(a,b,c)     min(a,min(b,c))
#define pCase(cs,ch)    printf("Case %d:%c", cs,ch)
#define iterAll(x)      x.begin(),x.end()
#define rIterAll(x)     x.rbegin(),x.rend()
#define fastreader      ios_base::sync_with_stdio(false); cin.tie(0)

typedef long long               ll;
typedef unsigned long long      ull;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef vector<double>          vd;
typedef vector<string>          vs;
typedef vector<char>            vc;
typedef pair<int,int>           pii;
typedef map<int,int>            mapii;
typedef map<char,int>           mapci;
typedef map<string,int>         mapsi;

/******************** END OF CRAPS ********************/

int main()
{
    //fin; fout;

    int n,a,b,c;

    while(r3i(n,a,b) != EOF)
    {
        int cnt = 0;
        for(int i=1; i<=n; i++)
        {
            ri(c);
            if(c<a || c>=b) cnt++;
        }
        cout << cnt << endl;
    }

    return 0;
}


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

int main() {
  int N,K,x=1,y,z;
  cin >> N>>K;
  for(int i=0;i<N;i++){
    y=2*x;
      z=x+K;
      if (y>z)
        x=z;
    else
      x=y;
}
  cout<< x<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define I 10000000

int h = 0, a[2000000000];

void makekey(int i, int k)
{
  int x;
  
  if (k < a[i])
    return;
  a[i] = k;
  while (i > 1 && a[i/2] < a[i]){
    x = a[i];
    a[i] = a[i/2];
    a[i/2] = x;
    i = i/2;
  }
}

void insert(int k)
{ 
  h++;
  a[h] = -I;
  makekey(h,k);
}

void maxheapify(int i)
{
  int l, r, largest, x;

  l = 2*i;
  r = 2*i+1;
  if (l <= h && a[l] > a[i])
    largest = l;
  else
    largest = i;
  if (r <= h && a[r] > a[largest])
    largest = r;
  if (largest != i){
    x = a[i];
    a[i] = a[largest];
    a[largest] = x;
    maxheapify(largest);
  }
}

int extract()
{
  int max;

  if (h < 1)
    return -I;
  max = a[1];
  a[1] = a[h--];
  maxheapify(1);
  return max;
}

int main()
{
  int k;
  char c[8];

  while (1){
    scanf("%s",c);
    if (c[0] == 'i'){
      scanf("%d",&k);
      insert(k);
    }
    else if (c[1] == 'n')
      break;
    else
      printf("%d\n",extract());
  }

  return 0;
}



Measured memory_bytes: 5608
#include <iostream>
#include <iomanip>
 
using namespace std;
 
int main() {
    int n, k;
    cin >> n >> k;
    double sum =.0;
    for(int i = 1; i<=n; i++) {
        double tempProb ,tempScore;
        tempProb = 1.0/n;
        tempScore = i;
        while(tempScore < k) {
            tempScore *= 2;
            tempProb *= 1.0/2;
        }
        sum += tempProb;
    }
    cout << fixed;
    cout << setprecision(12);
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'

int main() {
  string x;
  while(cin >> x){
    string rta = "No";
    for(int i = 0; i<x.size(); i++){
      if(x[i] == '7'){
        rta = "Yes";
        break;
      }
    }
    cout << rta << endl;
  }
	return 0;
}

Measured memory_bytes: 3620
def comb(n,k,mod):
    x = y = 1
    for i in range(min(k,n-k)):
        x = x*(n-i)%mod
        y = y*(i+1)%mod
    return x * pow(y, mod-2, mod) % mod

x,y = map(int,input().split())
ans = 0
mod = 10**9+7
if (x+y)%3 == 0:
    a = (-x+2*y)//3
    b = (2*x-y)//3
    if a >= 0 and b >= 0: ans = comb(a+b,a,mod)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    ll ans=1LL;
    for(int i=0; i<n; i++){
        if(a[i]==0){
            cout<<0<<endl;
            return 0;
        }
    }
    for(int i=0; i<n; i++){
        if(1000000000000000000/a[i]<ans){
            cout<<-1<<endl;
            return 0;
        }
        ans*=a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4000
l, r = (int(i) for i in input().split())
ans = float('inf')
for i in range(l,min(l+2019,r)):
    for j in range(i+1,min(i+1+2019,r+1)):
        val = i*j % 2019
        if val < ans:
            ans = val
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

int main(){
  int T, p, q;
  cin >> T;
  while(T--){
    cin >> p >> q;
    int pq = p * p + q * q;
    int count = 0;
    
    REP2(xy, 1, 20010){
      
      if(pq % xy == 0){
        int nm = pq / xy;
        
        REP2(n, -200, 200)REP2(m, -200, 200){
          if(n * n + m * m == nm){
            int a = m * p + n * q;
            int b = m * q - n * p;
            if(a % nm == 0 && b % nm == 0) count++;
          }
        }
      }
    }
    cout << (count > 8 ? "C" : "P") << endl;
    
  }
  return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
#include<vector>
using lint=int64_t;
using namespace std;

int N;
int a[10010]={};
int b[10010]={};
int c[10010]={};
vector<vector<int>> edge;
vector<int> in;
int num[10010];
int cindex;

void dfs(int cur,int prev)
{
	num[cur]=c[cindex];
	
	cindex++;
	for(auto&& i:edge[cur])
	{
		if(i==prev)
			continue;

		dfs(i,cur);
	}
	return;
}

int main()
{
	cin >> N;
	edge.resize(N);
	in.resize(N);
	for(int i=0;i<N-1;i++)
	{
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		edge[a[i]].push_back(b[i]);
		edge[b[i]].push_back(a[i]);
		in[a[i]]++;
		in[b[i]]++;
	}
	for(int i=0;i<N;i++)
		cin >> c[i];
	sort(c,c+N,greater<int>());
	
	
		int maxi=0;
		int maxin=0;
		for(int i=0;i<N;i++)
		{
			if(in[i]>maxin)
			{
				maxin=in[i];
				maxi=i;
			}
		}
	
	dfs(maxi,-1);

	lint M=0;
	for(int i=0;i<N-1;i++)
	{
		M+=min(num[a[i]],num[b[i]]);
	}
	cout << M << endl;
	for(int i=0;i<N;i++)
	{
		cout << num[i];
		if(i==N-1)cout << endl;
		else cout << " ";
	}
	return 0;
}



Measured memory_bytes: 1280
def main():
    from sys import stdin
    n = stdin.readline().rstrip()
    h = [2,4,5,7,9]
    p = [0,1,6,8]
    s = int(n[-1])
    if s in h:
        print("hon")
    elif s in p:
        print("pon")
    else:
        print("bon")
main()

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s;
  cin >> s;
  vector<string> t = {"Sunny", "Cloudy", "Rainy"};
  rep(i, 3) {
    if (s == t[i]) {
      cout << t[(i+1)%3] << endl;
    }
  }
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b,a%b);
}

int main(){
  ll n;
  cin >> n;
  ll GCD;
  if(n==2){
    ll a,b;
    cin >> a >> b;
    GCD = gcd(a,b);
  }else{
    ll a,b,c;
    cin >> a >> b >> c;
    GCD = gcd(gcd(a,b),c);
  }
  REP(i,GCD){
    if(GCD%(i+1)==0) cout << (i+1) << endl;
  }
  return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

int main(){
   string s;
   cin >> s;
   int ans = 0;
   rep(i, s.size()){
        int tmp = 0;
        for(int j = i; j<=s.size(); j++){
             if(s[j]=='A'||s[j]=='C'||s[j]=='G'||s[j]=='T') tmp++;
             else break;
        }
        if(tmp>=ans) ans = tmp;
   }
   cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 10000001
#define infpos 10e5
#define infneg -10e5
int a[100000]={0};
int main(){
ll ans,a,b,total;
cin>>a>>b;
ans=0;
total=1;
while(total<b)
{
    total+=a-1;ans++;
}
cout<<ans<<endl;
return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long H = scan.nextLong();
    long monster = 1;
    long count = 0;
    while(H > 0){
    count += monster;
    monster = 2 * monster;
    H = H / 2;
    }
    System.out.println(count);
  }
}



Measured memory_bytes: 23764
object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)

    while(true) {
      val n, x = scanner.nextInt
      if(n == 0 && x == 0) System.exit(0)
      println(search(n, x).filter(t => t._1.length == 3 && t._2 == x).length)
    }
  }

  def search(n: Int, x: Int): List[(List[Int], Int)] = {
    if(n == 1) {
      List((List(1), 1), (Nil, 0))
    } else {
      val l = search(n - 1, x)
      l.filter(_._1.length <= 3) ++ l.filter(t => t._1.length <= 2 && t._2 + n <= x).map(t => (n :: t._1, n + t._2))
    }
  }
}


Measured memory_bytes: 451736
/*input
2020 2040
*/
/**
    Author: Kristopher Paul
    Date Created: 07-07-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define pb push_back
#define INF 0x3f3f3f3f //0x3f3f3f3f = 63
#define MOD 1000000007
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int l,r;
    cin >> l >> r;
    if((r-l+1) >= 5000){
        cout << "0" << endl;
    }else{
        vector<int> arr;
        FOR(i,l,r+1){
            FOR(j,i+1,r+1){
                arr.pb((i*j)%2019);
            }
        }
        sort(arr.begin(),arr.end());
        cout << arr[0] << endl;
    }
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 17128
/* 
* ID: juryc
* PROG: Comparing Strings
* LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b; cin>>a>>b;
if(a<b){ for(int i=0;i<b;i++) cout<<a;  cout<<endl; }
else { for(int i=0;i<a;i++) cout<<b;  cout<<endl; }
return 0;
}

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

int main() {
  string S;
  cin >> S;
  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0) {
      if (S.at(i) == 'L') {
        cout << "No" << endl;
        break;
      }
    }
    if (i % 2 == 1) {
      if (S.at(i) == 'R') {
        cout << "No" << endl;
        break;
      }
    }
    if (i == S.size() - 1) {
      cout << "Yes" << endl;
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		long sum = 0;
		int j = Integer.valueOf(s);
		for (int i = 1; i <= j; i++) {
			if((i % 3 != 0 && i % 5 != 0)) {
				sum += i;
			}
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 35760
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{
int n,W; 
cin>>n>>W;
vector<int>v(n),w(n);
vector<int> dp(1e5+1,1e9+1);
dp[0]=0;
for(int i=0; i<n; i++) cin>>w[i]>>v[i];
for(int i=0; i<n; i++)for(int value=1e5; value>=v[i]; value--) dp[value]=min(dp[value-v[i]]+w[i],dp[value]); 
for(int value=1e5; value>=0; value--)
if (dp[value]<=W){
cout<<value; break;}
return 0; 
} 


Measured memory_bytes: 640
use std::str::FromStr;

fn read_str() -> String {
    let mut l = String::new();
    std::io::stdin().read_line(&mut l).unwrap();
    l
}

fn read_vec_i32() -> Vec<i32> {
    let mut l = String::new();
    std::io::stdin().read_line(&mut l).unwrap();
    l.trim()
        .split(' ')
        .map(|str| i32::from_str(str).unwrap())
        .collect()
}

fn main() {
    let n = read_vec_i32()[0];
    let mut s: Vec<String> = (0..n).map(|_| read_str().trim().to_owned()).collect();
    s.sort();
    println!("{}", s.concat());
}

Measured memory_bytes: 4352
N = int(input())
A = []
for x in range(N):
    A.append([y for y in input()])
    A[-1].sort()
A.sort()
count = 0
l = 1
r = 0
for i in range(1,N):
    if A[r] == A[i]:
        l += 1
    else:
        count += l * (l - 1) / 2
        l = 1
        r = i
count += l * (l - 1) / 2
print(int(count))

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

int n, a[100005];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i);
    sort(a + 1, a + 1 + n);
    if (a[1] <= 0) {
        if (a[n] >= 0) {
            int ans = 0;
            for (int i = 1; i <= n; ++i) ans += abs(a[i]);
            printf("%d\n", ans);
            int now = a[1];
            for (int i = 2; i < n; ++i)
                if (a[i] >= 0)
                    printf("%d %d\n", now, a[i]), now -= a[i];
            printf("%d %d\n", a[n], now), now = a[n] - now;
            for (int i = 2; i < n; ++i)
                if (a[i] < 0)
                    printf("%d %d\n", now, a[i]), now -= a[i];
        } else {
            int ans = 0;
            for (int i = 1; i < n; ++i) ans += -a[i];
            ans += a[n];
            printf("%d\n", ans);
            int now = a[n];
            for (int i = 1; i < n; ++i)
                printf("%d %d\n", now, a[i]), now -= a[i];
        }
    } else {
        int ans = 0;
        for (int i = 2; i <= n; ++i)
            ans += a[i];
        ans -= a[1];
        printf("%d\n", ans);
        int now = a[1];
        for (int i = 2; i < n; ++i)
            printf("%d %d\n", now, a[i]), now -= a[i];
        printf("%d %d\n", a[n], now);
    }
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1<<(i))))
#define setbit1(n,i) ((n)|(1<<(i)))
#define togglebit(n,i) ((n)^(1<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll fre[500005];
ll a[500005];
int main(){
    fastread;
    ll n,i,j,k,l,m;
    cin>>n>>m;
    ll sum=((n)*(n-1))/2+((m)*(m-1))/2;
    cout<<sum;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N;
  int l[11];
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&l[i]);
  } 
  int a,b;
  for(int j=0;j<N-1;j++){
    if(l[j]>=l[j+1]){
      a= l[j];
      b =l[j+1];
      l[j+1]=a;
      l[j]=b;
    }
  }
  /* for(int i=0;i<N;i++){
    printf("%d ",l[i]);
    }*/
  int sum=0;
  for(int k=0;k<N-1;k++){
    sum +=l[k];
      }
  // printf("最大値は%d\n",l[N-1]);
   //  printf("合計値は%d\n",sum);
  if(l[N-1]<sum)
    printf("Yes\n");
  else
    printf("No\n");
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <tuple>
#include <iomanip>


using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}



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

	long double ans = 0;

	for (int i = 1; i <= n; i++){
		int times = 0;
		int tmp = i;
		while (tmp < k){
			tmp *= 2;
			times++;
		}

		long double probabilityCoin = 1.0;
		for (int j = 0; j < times; j++){
			probabilityCoin /= 2.0;
		}

		ans += 1.0 / n * probabilityCoin;
	}

	cout << fixed << setprecision(10) << ans << endl;


}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;

public class AOJ1
{
    static int Comp(KeyValuePair<long, long> a, KeyValuePair<long, long> b)
    {
        return a.Key.CompareTo(b.Key);
    }
    static void Main()
    {
        long[] tmp = new long[9];
        while (true)
        {
            long n = long.Parse(Console.ReadLine());
            if (n == 0) break;
            List<KeyValuePair<long, long>> TimeTeam = new List<KeyValuePair<long, long>>();
            for (long i = 0; i < n; i++)
            {
                string[] Input = Console.ReadLine().Split(' ');
                for (int j = 0; j < Input.Length; j++) tmp[j] = long.Parse(Input[j]);
                long Sum=0;
                for (int j = 1; j <= 8; j += 2) Sum += 60 * tmp[j] + tmp[j + 1];
                TimeTeam.Add(new KeyValuePair<long, long>(Sum, tmp[0]));
            }
            TimeTeam.Sort(Comp);
            Console.WriteLine(TimeTeam[0].Value);
            Console.WriteLine(TimeTeam[1].Value);
            Console.WriteLine(TimeTeam[TimeTeam.Count-2].Value);
        }
    }
}

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

int main(void){
  int sum = 0;
  vector<int> data(5);
  vector<int> manu(5);
  for(int i = 0; i < 5 ; i++){
    cin >> data.at(i);
  }

  for(int i = 0; i < 5; i++){
    int x;
    x = data.at(i);
    sum += x;
    while(x >= 10){
      x %= 10;
    }
    if(x == 0){
      manu.at(i) = 0;
    }else{
      manu.at(i) = 10 - x;
    }
  }
  sort(manu.begin(), manu.end());
  for(int i = 0; i < 4; i++){
    sum += manu.at(i);
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> inline bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,x;
    cin>>n;
    vector<int> c(n);
    fr(i,n-1){
        cin>>x;
        --x;
        c[x]++;
    }
    fr(i,n) cout<<c[i]<<'\n';
}

Measured memory_bytes: 3936
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <cmath>

using namespace std;

int main() {
	int n,d;
	int count=0;
	cin >> n >> d;
	vector< vector<int> > x (n+10, vector<int>(d+10));

	for(int i=0; i<n; i++) {
		for(int j=0; j<d; j++) {
			cin >> x[i][j];
		}
	}

	for(int i=0; i<n; i++) {
		for(int j=i+1; j<n; j++) {
			double sum = 0.0;
			for(int k=0; k<d; k++) {
				sum += pow((abs(x[i][k] - x[j][k])), 2);
			}
			sum = sqrt(sum);
			//cout << "sum : " << sum << endl;
			if ( ceil(sum) == floor(sum) ) {
				count++;
			}
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))
#define ANS(x) cout << ((x)?"YES":"NO") << endl;

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 1010;

int N, M;
vi A, B;
int H[MAX], W[MAX]; // 縦横それぞれに置いている個数

int main() {

    cin >> N >> M;
    A = vi(N); B = vi(M);
    REP (i, N) cin >> A[i];
    REP (i, M) cin >> B[i];
    sort(ALL(A));
    sort(ALL(B));

    ll ans = 1;
    int idxA = N-1, idxB = M-1;
    FORR (x, 1, N*M+1) {
        if (A[idxA] == x && B[idxB] == x) { // 数字の場所は決定
            H[idxA]++; W[idxB]++;
            idxA--; idxB--;
        } else if (A[idxA] == x) { // 横にidxBの範囲まで移動可能
            (ans *= (max((M-idxB-1), 0) % MOD)) %= MOD;
            H[idxA]++;
            idxA--;
        } else if (B[idxB] == x) { // 縦にidxAの範囲まで移動可能
            (ans *= (max((N-idxA-1), 0) % MOD)) %= MOD;
            W[idxB]++;
            idxB--;
        } else {
            (ans *= (max((N-idxA-1)*(M-idxB-1) - (N*M-x), 0ll)) % MOD) %= MOD;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

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

 ll n,k;
  cin >> n >> k;
 ll x=0;
 while(n>0) n/=k,x++;
  

 cout << x << endl;
  
  
  
}


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

using namespace std;

typedef long long int ll;

ll M = 1e9 + 7;

int main()
{
    ll n;
    cin >> n;
    ll dp[2005] = {0};

    dp[0] = 1;
    dp[1] = 1;
    dp[2] = 1;
    dp[3] = 1;
    if(n<3)
        cout << 0 <<"\n";
    else
    {
        for(int i=4 ; i<=n ; i++)
        {
            dp[i] = dp[i-3];
            dp[i-2] += dp[i-3];
            dp[i-2] %= M;
        }
        cout << dp[n-1];
    }
    return 0;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int a, b, c, max_listen_music_times, real_listen_music_times;

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

  max_listen_music_times = b / a;

  real_listen_music_times = (max_listen_music_times < c) ? max_listen_music_times : c;

  cout << real_listen_music_times << endl;

  return 0;
}


Measured memory_bytes: 256
from sys import stdin


def main():
    n, k = map(int, stdin.readline().split())
    mod = 10 ** 9 + 7

    ans = 0

    for i in range(k, n + 2):
        ans += ((n + 1 - i) * i + 1) % mod

    print(ans % mod)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62856
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    s = []   
    for i in range(n):
        t = int(input())
        ans += t
        s.append(t)
    s.sort()
    
    if ans%10 == 0:
        for i in range(n):
            if s[i]%10 != 0:
                ans -= s[i]
                break
    if ans%10 == 0:
      ans = 0
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9180
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
#sort = sorted(a)[::-1] 降順
#if l[i] == l[j]: continue
a, b, c, d = map(int, input().split())

print(max(a*c, a*d, b*c, b*d))


Measured memory_bytes: 9144
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int N;
string A, B, C;

int main(void){

  cin >> N >> A >> B >> C;
  
  int ans = 0;
  for(int i = 0; i < N; i++){
    if(A[i] == B[i] && A[i]== C[i] && B[i] == C[i]){
      ans += 0; 
    } else if(A[i] != B[i] && A[i] != C[i] && B[i] != C[i]){
      ans += 2;
    }
    else{
      ans += 1;
    }
  }

  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 256
import sys
n,m=map(int,input().split())
l=[-1]*n
b=[sys.stdin.readline().split() for _ in range(m)]
c=[0]*m+[n*(n-1)//2]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  s,t=0,0
  if x!=y:
    s,t=l[x],l[y]
    if s>t:
      l[x]=y
      l[y]+=s
    else:
      l[y]=x
      l[x]+=t
  c[i]=c[i+1]-s*t
for x in c[1:]:
  print(x)

Measured memory_bytes: 40268
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long LL;

int main()
{
	char s[100];
	while (~scanf("%s", s)) {
		if (strlen(s) < 4) printf("No\n");
		else {
			if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') printf("Yes\n");
			else printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

// 1 way is to find compute all the sorted permutations and find the 
// positions of the current permutation.


bool _find(string &str){
    set<char> s;
    for(char ch:str){
        if(s.count(ch)>0){
            return false;
        }
        s.insert(ch);
    }
    return 1;
}
void solve(){
    string str;
    cin>>str;
    if(_find(str)){
        cout<<"yes";
    }
    else{
        cout<<"no";
    }
}

int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    cout.precision(10);
    int N;
    long double ans = 0.0;
    cin >> N;
    for(int i = 1; i <= N; i++) {
        long double x;
        string u;
        cin >> x >> u;
        if(u == "JPY") ans += x;
        else ans += x * 380000;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination1(int, int);
};
int Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_9x9(void) {

	int A, B; cin >> A >> B;
	
	if (A > 9 || B > 9) cout << -1 << flush;
	else				cout << A * B << flush;
	return;
}

int main(void) {

	A_9x9();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <sstream>
#include <cstdlib>
#include <iterator>
#include <algorithm>
using namespace std;
vector<string> split(const string &str, char sep = ' ') {
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

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

    string input;
    getline( cin, input);
    vector<string> splited = split(input);
    vector<int> casted;
    for(int i = 0; i < end(splited) - begin(splited); i++) {
        casted.push_back(atoi(splited[i].c_str()));
    }

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

    cout << casted[0] << ' ' << casted[1] << ' ' << casted[2] << endl;
    return 0;
}

Measured memory_bytes: 3224
#include<stdio.h>

typedef struct{
	int U,W,E,S,N,D;
}dice_t;

int t;

void shoki(dice_t* dice){//ダイスの初期位置
	dice->U=1;
	dice->W=4;
	dice->E=3;
	dice->S=2;
	dice->N=5;
	dice->D=6;
}

void N(dice_t* dice){
	t=dice->U;
	dice->U=dice->S;
	dice->S=dice->D;
	dice->D=dice->N;
	dice->N=t;
}

void E(dice_t* dice){
	t=dice->U;
	dice->U=dice->W;
	dice->W=dice->D;
	dice->D=dice->E;
	dice->E=t;
}

void W(dice_t* dice){
	t=dice->U;
	dice->U=dice->E;
	dice->E=dice->D;
	dice->D=dice->W;
	dice->W=t;
}

void S(dice_t* dice){
	t=dice->U;
	dice->U=dice->N;
	dice->N=dice->D;
	dice->D=dice->S;
	dice->S=t;
}

void R(dice_t* dice){
	t=dice->S;
	dice->S=dice->E;
	dice->E=dice->N;
	dice->N=dice->W;
	dice->W=t;
}

void L(dice_t* dice){
	t=dice->S;
	dice->S=dice->W;
	dice->W=dice->N;
	dice->N=dice->E;
	dice->E=t;
}

int main(void){
	char sousa[10];
	int i,n,s;
	dice_t dice;
	while(0==0){
		scanf("%d",&n);
		if(n==0) break;
		shoki(&dice);
		s=1;
		for(i=0;i<n;i++){
			scanf("%s",sousa);
			switch(sousa[0]){
			    case 'N':
				  N(&dice);
				  break;
				case 'E':
				  E(&dice);
				  break;
				case 'W':
				  W(&dice);
				  break;
				case 'S':
				  S(&dice);
				  break;
				case 'R':
				  R(&dice);
				  break;
				case 'L':
				  L(&dice);
				  break;
			}
			s+=dice.U;
		}
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 1032
def main():

    N = int(input())
    if N == 1: return 1
    if N == 2: return 1

    ball = []
    for _ in range(N):
        x, y = map(int, input().split())
        ball.append((x, y))
    ball.sort()
    

    pq = []
    for i in range(N-1):
        x0, y0 = ball[i]
        for j in range(i+1, N):
            x1, y1 = ball[j]
            pq.append([x1-x0, y1-y0])
    # print(pq)

    min_count = N
    for p, q in pq:
        count = 0
        visited = set()
        for b in ball:
            if b not in visited:
                count += 1
                z, w = b[0], b[1]
                while (z, w) in ball:
                    visited.add((z, w))
                    z += p
                    w += q
            # print(visited, count)
        min_count = min(min_count, count)

    return min_count

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 43244
n,l = map(int,input().split())
total = 0
if l < 0 and (l + n - 1) > 0:
        for i in range(n):
                total += l + i
elif l < 0 and (l + n - 1) <= 0:
        for i in range(n):
                total += l + i
        total -= l + n - 1
elif l >= 0:
        for i in range(n):
                total += l + i
        total -= l
print(total)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n,k;
  cin>>n>>k;
  vector<long long int> a(n);
  for(long long int i=0; i<n; i++){
    cin>>a.at(i);
  }

  for(long long int j=0; j<k; j++){
    vector<long long int> ruiseki(n,0);
    for(long long int i=0; i<n; i++){
        long long int l,r;
        l=max((long long int)0,i-a.at(i));
        r=min(n-1,i+a.at(i));
        ruiseki.at(l)++;
        if(r+1>n-1) continue;
        ruiseki.at(r+1)--;
    }
    vector<long long int> pre(n,0);
    bool all=true;
    pre.at(0)=ruiseki.at(0);
    if(pre.at(0)!=n) all=false;
    //cout<<ruiseki.at(0)<<" ";
    for(long long int i=1; i<n; i++){
        pre.at(i)=pre.at(i-1)+ruiseki.at(i);
        if(pre.at(i)!=n) all=false;
        //cout<<ruiseki.at(i)<<" ";
    }
    //cout<<endl;
    a=pre;
    if(all) break;
  }

    for(long long int i=0; i<n; i++){
        cout<<a.at(i);
        if(i!=n-1){
            cout<<" ";
        }else{
            cout<<endl;
        }
    }
}

Measured memory_bytes: 7932
#include <iostream>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	int a, b, c,ans;
	cin >> a >> b >> c;
	if (a != b) {
		ans = 2;
		if (a != c && b != c) {
			ans = 3;
		}
	}
	
	else{
		ans = 1;
		if (a != c) {
			ans = 2;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}



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

long long INF = (1 << 31) - 1;

class LazySegmentTree {
private:
	long long Size;
	vector<long long> Node, Lazy;
	vector<bool> Flag;
public:
	LazySegmentTree(long long N) {
		Size = 1;
		while (Size < N) Size <<= 1;
		Node.assign(Size * 2, 0);
		Lazy.assign(Size * 2, 0);
		Flag.assign(Size * 2, false);
	}
	void Eval(long long K, long long L, long long R) {
		if (Flag[K]) {
			Node[K] = Lazy[K] * (R - L);
			if (R - L > 1) {
				Lazy[K * 2] = Lazy[K];
				Flag[K * 2] = true;
				Lazy[K * 2 + 1] = Lazy[K];
				Flag[K * 2 + 1] = true;
			}
			Flag[K] = false;
		}
	}
	void Update(long long A, long long B, long long X, long long K, long long L, long long R) {
		Eval(K, L, R);
		if (B <= L || R <= A) return;
		if (A <= L && R <= B) {
			Lazy[K] = X;
			Flag[K] = true;
			Eval(K, L, R);
			return;
		}
		Update(A, B, X, K * 2, L, (L + R) / 2);
		Update(A, B, X, K * 2 + 1, (L + R) / 2, R);
		Node[K] = Node[K * 2] + Node[K * 2 + 1];
	}
	void Update(long long A, long long B, long long X) {
		Update(A, B, X, 1, 0, Size);
		return;
	}
	long long Query(long long A, long long B, long long K, long long L, long long R) {
		Eval(K, L, R);
		if (B <= L || R <= A) return 0;
		if (A <= L && R <= B) return Node[K];
		return Query(A, B, K * 2, L, (L + R) / 2) + Query(A, B, K * 2 + 1, (L + R) / 2, R);
	}
	long long Query(long long A, long long B) {
		return Query(A, B, 1, 0, Size);
	}
};

int main() {
	long long N, Q;
	cin >> N >> Q;
	LazySegmentTree Seg(N);
	for (int i = 0; i < Q; i++) {
		long long Mode;
		cin >> Mode;
		if (Mode == 0) {
			long long A, B, X;
			cin >> A >> B >> X;
			Seg.Update(A, B + 1, X);
		}
		else {
			long long A, B;
			cin >> A >> B;
			cout << Seg.Query(A, B + 1) << endl;
		}
	}
}


Measured memory_bytes: 7080
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define PI 3.1415926535897932384626433832795
using namespace std;

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll sum=n/(a+b);
    ll rem = n%(a+b);
    if(rem > a ){
        cout<< a * sum + a;
    }
    else{
        cout<<a * sum + rem;
    }
    return 0;
}



Measured memory_bytes: 256
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N;
    cin >> N;

    string S;
    cin >> S;

    ll R = 0, W = 0;
    REP(i, N)
    if (S[i] == 'R')
    {
        R++;
    }
    else
    {
        W++;
    }

    ll former = 0;
    REP(i, R)
    {
        if (S[i] == 'R')
            former++;
    }

    cout << R - former << endl;

    return 0;
}


Measured memory_bytes: 3424
from functools import lru_cache
import sys
mod=1000000007

n,k=[int(i) for i in input().split(" ")]

facts=[1 for i in range(n+k+1)]

for i in range(1,n+k+1):
    facts[i]=i*facts[i-1]

@lru_cache()
def combination(i,j):
    return facts[i]//(facts[j]*facts[i-j])


print(combination(n+k-1,n)%mod)



Measured memory_bytes: 8532