akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main() 
{
    int H, W;           //Hight, Width

    while( cin >> H >> W )
    {
        if( H == 0 && W == 0 )
            break;
        for( int i = 0; i < H; i++ )
        {
            for( int j = 0; j < W; j++ )
            {
                if( ( i + j ) % 2 == 0 )            //チェック柄の条件
                    cout << '#';
                else
                    cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a1 = sc.nextInt()
    val b1 = sc.nextInt()
    val a2 = sc.nextInt()
    val b2 = sc.nextInt()
    val a3 = sc.nextInt()
    val b3 = sc.nextInt()

    // 同じ数字が3つか、出てきてない数字があったらアウト
    val list = listOf(a1, a2, a3, b1, b2, b3)
    val result = list.groupBy { it }
    if (existUnreachableCity(result)) {
        println("NO")
        return
    }
    if (existHubCity(result)) {
        println("NO")
        return
    }
    println("YES")
}

private fun existUnreachableCity(result: Map<Int, List<Int>>): Boolean {
    if (result.size != 4) {
        return true
    }
    return false
}

private fun existHubCity(result: Map<Int, List<Int>>): Boolean {
    val has = result.any { it.value.size == 3 }
    return has
}

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

using namespace std;

int main(void)
{
	bool cards[4][13] = {false};
	int n, num;
	char tx;
	
	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> tx >> num;
		switch (tx){
			case 'S' : cards[0][num - 1] = true; break;
			case 'H' : cards[1][num - 1] = true; break;
			case 'C' : cards[2][num - 1] = true; break;
			case 'D' : cards[3][num - 1] = true; break;
		}
	}
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 13; j++){
			if(cards[i][j] == false){
				switch (i){
				case 0: cout << 'S' << ' ' << j + 1 << endl; break;
				case 1: cout << 'H' << ' ' << j + 1 << endl; break;
				case 2: cout << 'C' << ' ' << j + 1 << endl; break;
				case 3: cout << 'D' << ' ' << j + 1 << endl; break;
					
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long
const int MOD = 1e6 + 3;

int add(int a, int b) {
	return (a + b) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int divv(int a, int b) {
	return mul(a, binpow(b, MOD - 2));
}

int f[MOD];

void init() {
	f[0] = 1;
	for (int i = 1; i < MOD; i++) {
		f[i] = mul(f[i - 1], i);
	}
}

void solve() {
	int x, d, n;
	cin >> x >> d >> n;
	if (d == 0) {
		cout << binpow(x, n) << '\n';
	} else {
		x = divv(x, d);
		if (x + n - 1 >= MOD) {
			cout << 0 << '\n';
		} else {
			int ans = divv(f[x + n - 1], f[x - 1]);
			ans = mul(ans, binpow(d, n));
			cout << ans << '\n';
		}
	}
}

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

	init();

	int q;
	cin >> q;
	while (q--) {
		solve();
	}
}


Measured memory_bytes: 8704
ls = list(map(int, input().split()))
nokori = ls[-1]
nokori_ = ls[-1]
sum_max = 0
for i, j in zip(ls[:-1], [1, 0, -1]):
    nokori -= i
    if nokori > 0:
        sum_max += i*j
    elif nokori == 0:
        sum_max += i*j
        break
    else:
        sum_max += nokori_*j
        break
    nokori_ = nokori
print(sum_max)


Measured memory_bytes: 9124
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
bool sosu(int a){
  if(a > 1000000){
	FOR(i,2,a/1000){
	  if(a%i==0) return false;
	}
  }else  if(a > 10000){
	FOR(i,2,a/100){
	  if(a%i==0) return false;
	}
  }else if(a > 100){
	FOR(i,2,a/10){
	  if(a%i==0) return false;
	}
  }else{
	if(a==1) return false;
	if(a==2) return true;
	FOR(i,2,a/2+1){
	  if(a%i==0) return false;
	}
  }
  return true;
}

int main(){

  while(1){
	int a,d,n;
	cin >> a >> d >> n;
	if(a==0&&d==0&&n==0) break;

	int c = 0;
	int now;
	now = a;

	while(1){
	  if(sosu(now)) c++;
	  if(c==n) break;
	  now += d;
	}

	cout << now << endl;

  }
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

template<typename T>
void trace(T *a, int s, int n) {
    for (int i=s; i<n; i++) {
	cout<<a[i]<<" ";
    }
    cout<<endl;
}



typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



vector<int> v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

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

    int k; cin>>k;
    out(v[k-1]);
  

    return 0;
}


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

int main()
{
  string s;
  int k;
  cin >> s >> k;

  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'a') continue;
    int x = 'z'-s[i]+1;
    if(k >= x){
      k -= x;
      s[i] = 'a';
    }
  }

  if(k){
    s[s.size()-1] = 'a' + (s[s.size()-1] - 'a' + k) % 26;
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
using namespace std;
int n, m;
inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return x * f;
}
int main()
{
    n = read();
    m = read();
    int las = n - (n / 500) * 500;
    if (m < las)
        printf("No");
    else
    {
        printf("Yes");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
using namespace std;

struct NODE{
	int x1,y1,x2,y2,c;
	NODE(int x1,int y1,int x2,int y2,int c) : x1(x1) , y1(y1) , x2(x2) , y2(y2) , c(c) {}
	
};

bool memo[52][52][52][52];

int main(){
	int n;
	int W,H;
	while(cin >> W >> H && W){
		int sx,sy,gx,gy;
		cin >> sx >> sy >> gx >> gy;
		int t[52][52];
		for(int i = 0 ; i < 52 ; i++)
			for(int j = 0 ; j < 52 ; j++)
				t[i][j] = 1;
			
		for(int i = 1 ; i <= H ; i++)
			for(int j = 1 ; j <= W ; j++)
				cin >> t[i][j];
		queue<NODE> Q;
		Q.push(NODE(sx,sy,gx,gy,0));
		memset(memo,0,sizeof(memo));
		int dx[] = {-1,0,1,0};
		int dy[] = {0,1,0,-1};
		while(Q.size()){
			NODE q = Q.front(); Q.pop();
			if( q.c > 100 ) break;
			if( q.x1 == q.x2 && q.y1 == q.y2 ) {
				cout << q.c << endl;
				goto exit;
			}
			if( memo[q.x1][q.y1][q.x2][q.y2] ) continue;
			else memo[q.x1][q.y1][q.x2][q.y2] = true;
			for(int i = 0 ; i < 4 ; i++){
				int x1 = q.x1 + dx[i] , y1 = q.y1 + dy[i];
				int x2 = q.x2 - dx[i] , y2 = q.y2 - dy[i];
				if( t[y1][x1] ) x1 = q.x1 , y1 = q.y1;
				if( t[y2][x2] ) x2 = q.x2 , y2 = q.y2;
				Q.push(NODE(x1,y1,x2,y2,q.c+1));
			}
		}
		cout << "NA" << endl;
		exit:;
		
	}
}

Measured memory_bytes: 9548
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int a,b;

int main(){
	while(cin>>a>>b) cout<<a+b<<endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MD = 1e9 + 7;
map<pair<ll, ll>, ll> ma;
ll quick_pow(ll a, ll b) {
    ll res=1;
    for(;b;b>>=1){
        if(b&1) res=res*a%MD;
        a=a*a%MD;
    }
    return res;
}
int main() {
    int n, s = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        ll a, b;
        scanf("%lld%lld", &a, &b);
        ll d = __gcd(a, b);
        if(d == 0) {
            s++;
            continue;
        }
        a /= d, b /= d;
        if(a < 0) a = -a, b = -b;
        ma[{a, b}]++;
    }
    ll ans = 1;
    for(auto it : ma) {
        if(it.second == 0) continue;
        ll a = it.first.first, b = it.first.second;
        ll d = quick_pow(2, ma[{a, b}]);
        b = -b;
        if(b < 0) a = -a, b = -b;
        if(ma.count({b, a})) {
            d = (d + quick_pow(2, ma[{b, a}]) - 1) % MD;
            ma[{b, a}] = 0;
        }
        //printf("d:%lld\n\n",d);
        ans = ans * d % MD;
    }
    ans = (ans - 1 + s + MD) % MD;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 16184
import math

A,B,H,M = list(map(int,input().split()))
H_deg = 30*H+0.5*M
M_deg = 6*M
x1 = A*math.cos(math.radians(H_deg))
y1 = A*math.sin(math.radians(H_deg))
x2 = B*math.cos(math.radians(M_deg))
y2 = B*math.sin(math.radians(M_deg))
print(math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2))

Measured memory_bytes: 9456
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m,x,ans=1000000000000000;
vector<ll>c;
vector<vector<ll>>vect;
vector<ll>path;
vector<ll>sum;
void dfs(ll itr)
{
    if(itr==n)
    {
        sum.clear();
        sum.resize(m);
        ll money=0;
        for(ll i=0;i<path.size();i++)
        {
            money+=c[path[i]];
            for(ll j=0;j<m;j++)
            {
                sum[j]=sum[j]+vect[path[i]][j];
            }
        }
        for(ll i=0;i<m;i++)
        {
            if(sum[i]<x)
            return;
        }
        ans=min(ans,money);
        return;
    }
    dfs(itr+1);
    path.push_back(itr);
    dfs(itr+1);
    path.pop_back();
}
int main()
{
    cin>>n>>m>>x;
    c.clear();
    c.resize(n);
    vect.clear();
    vect.resize(n);
    for(ll i=0;i<n;i++)
    {
        cin>>c[i];
        for(ll j=0;j<m;j++)
        {
            ll x;
            cin>>x;
            vect[i].push_back(x);
        }
    }
    dfs(0);
    if(ans==1000000000000000)
    cout<<-1;
    else
    cout<<ans;
    return 0;
}
//Author: master_sam

Measured memory_bytes: 3632
N,M=map(int,input().split())
LR=list(list(map(int,input().split())) for _ in range(M))
L=1
R=N
for i in range(M):
    L=max(L,LR[i][0])
    R=min(R,LR[i][1])
print(R-L+1 if L<=R else 0)

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

int	main()
{
	int	n, k, i, res;
	cin >> n >> k;

	res = 0;
	for (i = 0; i < n; i++)
	{
		int	x;
		cin >> x;
		if (x < k - x)
			res += x * 2;
		else
			res += (k - x) * 2;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<iostream>
#define pb push_back
#define fi first
#define se second
#define sz(x)  x.size()
#define cl(x)  x.clear()
#define all(x)  x.begin() , x.end()
#define r(x)  scanf("%d", &x)
#define rr(x , y)  scanf("%d%d" , &x , &y)
#define rst(s)  scanf("%s" , s)
#define rl(x)  scanf("%lld" , &x)
#define rrl(x , y)  scanf("%lld%lld" , &x , &y)
#define w(x)  printf("%d" , x)
#define ww(x , y)  printf("%d %d" , x , y)
#define wl(x)  printf("%lld" , x)
#define wwl(x , y)  printf("%lld %lld" , x , y)
#define sp()  printf(" ")
#define en()  puts("")
#define rep(i , x , n)  for(int i = x ; i <= n ; i ++)
#define per(i , n , x)  for(int i = n ; i >= x ; i --)
#define mem0(x)  memset(x , 0 , sizeof(x))
#define mem_1(x)  memset(x , -1 , sizeof(x))
#define mem_inf(x)  memset(x , inf , sizeof(x))
#define mem__inf(x)  memset(x , -inf , sizeof(x))
#define p_queue priority_queue
#define debug(x)  cout << '*' << x << '\n'
#define ddebug(x , y)  cout << '*' << x << ' ' << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
using namespace std ;
//mt19937  rnd(chrono::high_resolution_clock::now().time_since_epoch().count()) ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef pair<int , ll> pil ;
typedef pair<ll , int> pli ;
const int inf = 0x3f3f3f3f ;
const int maxn = 2005 ;
const int maxm = 30 ;
const double eps = 1e-6 ;
int main()
{
	int a , b ;
	rr(a , b) ;
	if(a > b)  puts("safe") ;
	else  puts("unsafe") ;
	return 0 ;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if (a==b)
		if (a!=c)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
			
		else
		{
			cout<<"No"<<endl;
			return 0;
		}	
	
	else if (b==c)
		if (a!=b)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
			
		else
		{
			cout<<"No"<<endl;
			return 0;
		}
			
	else if (a==c)
		if (b!=a)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
			
		else
		{
			cout<<"No"<<endl;
			return 0;
		}
		
	else
		cout<<"No"<<endl;
		return 0;		
 } 

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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const ll maxn = 2e8 + 5;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;
//iostream::sync_with_stdio(false);

ll gcd(ll a, ll b)
{
	while (b != 0)
	{
		int t = b;
		b = a % b;
		a = t;
	}
	return a;
}

int main()
{
    ll n;
    cin >> n;
    ll sum = 0;
    for(ll i = 1; i <= n; i++)
    {
        for(ll j = 1; j <= n; j++)
        {
            for(ll k = 1; k <= n; k++)
            {
                sum += gcd(i, gcd(j,k));
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3596
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,min,k:Integer;
  l:array of char;
  s,s123,s1,s2,s3:string;
  tf:Boolean;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(n);
    Readln(x);

    count:=0;
    min:=99999999999;
    for i := 0 to n - 1 do begin
      Readln(m);
      x:=x-m;
      inc(count);
      min:=(m+min-abs(m-min))div 2;
    end;

    count:=count+ x div min;

    Writeln(count);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

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

//when weight -->10^9
//cannot implement normal dp knapsach=k cause O(W*N) in that will be too large
long long knapsackdplargeW(long long N,long long W, long long *w, long long *v)
{
    if(N==1)
        return ((w[0]<=W)?v[0]:0);
    long long V=accumulate(v,v+N,0);
    long long dp[N+1][V+1];
    for(long long i=1;i<=V;i++)
    {
        dp[1][i]=1e9;
    }
    dp[1][0]=0;
    dp[1][v[0]]=w[0];
    for(long long i=2;i<=N;i++)
    {
        for(long long j=0;j<=V;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j-v[i-1]>=0)
                dp[i][j]=min(dp[i][j],w[i-1]+dp[i-1][j-v[i-1]]);
            //dp[i][j]=min(dp[i-1][j],((j-v[i-1]>=0)?(w[i-1]+dp[i-1][j-v[i-1]]):dp[i-1][j]));
        }
    }
    long long ansv=0;
        for(long long j=0;j<=V;j++)
        {
            if(dp[N][j]<=W)
            {
                if(ansv<j)
                    ansv=j;
            }
        }
    // for(long long i=0;i<=N;i++)
    // {
    //     for(long long j=0;j<=V;j++)
    //         cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    return ansv;
}

int main() 
{
    long long N,W;
    cin>>N>>W;
    long long w[N];
    long long v[N];
    for(long long i=0;i<N;i++)
        cin>>w[i]>>v[i];
    cout<<knapsackdplargeW(N,W,w,v);

}


Measured memory_bytes: 81544
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int key;
  node *left,*right,*p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
signed main(){
  int n;
  cin>>n;
  root=NULL;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    //cout<<(root==NULL?-1:root->key)<<endl;
    if(s=="print"){
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
      continue;
    }
    int x;
    cin>>x;
    insert(node(x));
  }
  return 0;
}


Measured memory_bytes: 26592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long K, long long Q, std::vector<long long> A){
    vector<ll> notReduce(N,0);
    for(int i=0;i<Q;i++){
        notReduce[A[i]]++;
    }
    for(int i=0;i<N;i++){
        if(K-Q+notReduce[i] <=0){
            cout <<NO<<endl;
        }else{
            cout <<YES << endl;
        }
    }

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> A(Q);
    for(int i = 0 ; i < Q ; i++){
        ll a;
        cin >> a;
        --a;
        A[i] = a;
    }
    solve(N, K, Q, std::move(A));
    return 0;
}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
ll A[2000];
int main() {
	ll N, K, Q;
	cin >> N >> K >> Q;
	ll ma = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		ma = max(ma, A[i]);
	}
	ll ans = 1 << 30;
	for (int i = 0; i < N; i++) {
		ll l = A[i] - 1, r = ma + 1;
		bool ok = 0;
		while (r - l > 1) {
			ll m = (l + r) / 2;
			ll cnt = 0;
			ll len = 0;
			ll sum = 0;
			for (int j = 0; j < N; j++) {
				if (A[j] < A[i]) {
					sum += min(cnt, max(len - K + 1, 0LL));
					len = 0;
					cnt = 0;
				}
				else {
					len++;
					if (A[j] <= m) cnt++;
				}
			}
			sum += min(cnt, max(len - K + 1, 0LL));
			if (sum >= Q) r = m, ok = 1;
			else l = m;
		}
		if (ok) ans = min(ans, r - A[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
ans=0
for i in range(n):
    ans+=(i+1)*(n-i)
for _ in range(n-1):
    a=list(map(int,input().split()))
    u=max(a)-1
    v=min(a)-1
    ans-=(v+1)*(n-u)
print(ans)

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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int x, y, z, k;
    ll a[1100], b[1100], c[1100];

    cin >> x >> y >> z >> k;
    REP(i, x)
    cin >> a[i];
    REP(i, y)
    cin >> b[i];
    REP(i, z)
    cin >> c[i];

    vector<ll> v;
    REP(i, x)
    REP(j, y)
    v.push_back(a[i] + b[j]);

    SORT(v);
    reverse(v.begin(), v.end());

    vector<ll> w;

    REP(i, min(k, x * y))
    REP(j, z)
    w.push_back(v[i] + c[j]);

    SORT(w);
    reverse(w.begin(), w.end());

    REP(i, k)
    cout << w[i] << endl;

    return 0;
}

Measured memory_bytes: 43364
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    vi poker={2,3,4,5,6,7,8,9,10,11,12,13,1};
    int A,B; cin>>A>>B;
    int CA,CB;
    rep(i,13) {
        if(poker[i]==A) CA=i;
    }
    rep(i,13) {
        if(poker[i]==B) CB=i;
    }
    if(CA>CB) printf("Alice");
    else if(CA<CB) printf("Bob");
    else printf("Draw");
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
double x[110];
double y[110];
vector<double>v;
double PI=acos(-1.0);
double EPS=1e-12;
int n;
int bk[110];
double calc(double a){
	for(int i=0;i<n;i++)bk[i]=0;
	vector<pair<double,pair<int,int> > >ev;
	for(int i=0;i<n;i++){
		double ty=x[i]*sin(a)+y[i]*cos(a);
		ev.push_back(make_pair(ty-1,make_pair(1,i)));
		ev.push_back(make_pair(ty+1,make_pair(-1,i)));
	}
	std::sort(ev.begin(),ev.end());
	double ret=0;
	int now=0;
	for(int i=0;i<ev.size();i++){
		if(now)ret+=ev[i].first-ev[i-1].first;
		now+=ev[i].second.first;
	//	if(i<ev.size()-1&&ev[i+1].first-ev[i].first>EPS){
			if(ev[i].second.first==-1&&now==0){
				bk[ev[i].second.second]--;
			}
			if(ev[i].second.first==1&&now==1){
				bk[ev[i].second.second]++;
			}
		//}
	}
	//printf("%f: %f\n",a,ret);
	return ret;
}
double bf(double t){
	double ret=0;
	for(int i=0;i<n;i++){
		ret+=(x[i]*cos(t)-y[i]*sin(t))*bk[i];
	}
	return ret;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%lf%lf",x+i,y+i);
		n=a;
		v.clear();
		v.push_back(0);
		v.push_back(PI);
		for(int i=0;i<a;i++)for(int j=i+1;j<a;j++){
			double th=atan2(y[j]-y[i],x[j]-x[i]);
			double th2;
			if(th>0){
				v.push_back(PI-th);
				th2=PI-th+PI/2;
			}else{
				v.push_back(-th);
				th2=-th+PI/2;
			}
			double d=sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
			d=max(d,2.0);
			double tt=acos(2.0/d);
			double t1=th2-tt;
			if(t1>PI)t1-=PI;
			if(t1<0)t1+=PI;
			v.push_back(t1);
			double t2=th2+tt;
			while(t2>PI)t2-=PI;
			v.push_back(t2);
		}
		std::sort(v.begin(),v.end());
		double tl=0;
		double tr=0;
		double vl=9999999;
		double vr=0;
		for(int i=0;i<v.size();i++){
			double val=calc(v[i]);
			if(vl>val){
				vl=val;tl=v[i];
			}
			if(vr<val){
				vr=val;tr=v[i];
			}
		}
		for(int i=0;i<v.size()-1;i++){
			if(v[i+1]-v[i]<EPS)continue;
	//		double p=(double)(rand()%100000)/100000;
			double M=(v[i]+v[i+1])/2;
			calc(M);
			double T=0;
			if(bf(v[i])<bf(v[i+1])){
				double L=v[i];
				double R=v[i+1];
				for(int j=0;j<100;j++){
					double m=(L+R)/2;
					double val=bf(m);
					if(val<0)L=m;
					else R=m;
				}
				T=L;
			}else{
				double L=v[i];
				double R=v[i+1];
				for(int j=0;j<100;j++){
					double m=(L+R)/2;
					double val=bf(m);
					if(val<0)R=m;
					else L=m;
				}
				T=L;
			}
	//		for(int j=0;j<a;j++)printf("%d ",bk[j]);
			
			double tmp=calc(T);
		//	printf("%f %f %f -> %f %f %f: %f\n",v[i],T,v[i+1],bf(v[i]),bf(T),bf(v[i+1]),tmp);
			if(vl>tmp){
				vl=tmp;tl=T;
			}
			if(vr<tmp){
				vr=tmp;tr=T;
			}
		}
	//	printf("%f %f\n",vl,vr);
		printf("%.15f\n%.15f\n",tl,tr);
	}
}

Measured memory_bytes: 1348
n, a, b =map(int, input().split())
p = 10**9 + 7
frac1 = [1]
frac2 = []
for i in range(max(a, b)):
  frac1.append(frac1[i] * (i + 1) % p)
  if i == 0:
    frac2.append(n)
  else:
    frac2.append(frac2[i-1] * (n-i) % p)

def comb(n, k, mod):
    x=frac2[k-1]
    y=frac1[k]
    return (x * pow(y, mod-2, mod)) % mod

print( (pow(2, n, p)-1 - comb(n, a, p)- comb(n, b, p))% p)

Measured memory_bytes: 18944
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<i64>();
    let nm1 = n - 1;
    let mut i = 1;
    let mut mn_factors = vec![];
    while i * i <= nm1 {
        if nm1 % i == 0 {
            mn_factors.push(i);
            mn_factors.push(nm1 / i);
        }
        i += 1;
    }
    debug!(mn_factors);
    mn_factors.sort();
    mn_factors.dedup();
    let mut ans = mn_factors.len() - 1;

    let mut n_factors = vec![];
    let mut i = 1;
    while i * i <= n {
        if n % i == 0 {
            n_factors.push(i);
            n_factors.push(n / i);
        }
        i += 1;
    }
    n_factors.sort();
    n_factors.dedup();

    debug!(n_factors);
    for factor in n_factors {
        if factor == 1 {
            continue;
        }
        let mut n = n;
        while n % factor == 0 {
            n /= factor;
        }
        if n % factor == 1 {
            ans += 1;
        }
    }

    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4476
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));
		String str;
		int count = 0;
		double mv,v;
		List<Integer> result = new ArrayList<>();
		while(true){
			str = br.readLine();
			if(str == null) break;
			mv = (double)Double.parseDouble(str);
			for(int N = 1;; N++){
				v = 1.4*Math.sqrt(10*(5*N-5));
				if(v > mv){
					result.add((Integer)N);
					count++;
					break;
				}
			}
		}
		for(int i = 0; i < count; i++){
			System.out.println(result.get(i));
		}
	}
}

Measured memory_bytes: 24136
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int a[N],b[N],c[N],n,cnt=0,ans=0;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1); int sum=1;
	for (int i=2;i<=n;i++){
		if (a[i]==a[i-1]) sum++;
		else b[++cnt]=sum,c[cnt]=a[i-1],sum=1;
	}
	b[++cnt]=sum; c[cnt]=a[n];
	for (int i=1;i<=cnt;i++){
		if (b[i]<c[i]) ans=ans+b[i];
		else ans=ans+b[i]-c[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3072
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def generate_adj_matrix(v_info):
    for v_detail in v_info:
        v_adj_list = v_detail[2:]
        # assert len(v_adj_list) == int(v_detail[1])
        for each in v_adj_list:
            init_adj_matrix[int(v_detail[0]) - 1][int(each) - 1] = 1
    return init_adj_matrix


def graph_dfs(v_init):
    global time

    # init the first node of overall graph iterations(times >= 1)
    vertices_visit_stack.append(v_init)
    vertices_status_list[v_init] = VISITED_IN_STACK
    vertices_d_time[v_init] += time
    # init end

    while len(vertices_visit_stack) > 1:
        current_vertex = vertices_visit_stack[-1]
        next_vertex = get_adj_vertices(vertex=current_vertex)

        if next_vertex:
            if vertices_status_list[next_vertex] is UNVISITED:
                vertices_status_list[next_vertex] = VISITED_IN_STACK
                time += 1
                vertices_d_time[next_vertex] += time
                vertices_visit_stack.append(next_vertex)
        else:
            vertices_visit_stack.pop()
            vertices_status_list[current_vertex] = POPPED_OUT
            time += 1
            vertices_f_time[current_vertex] += time

    return None


def get_adj_vertices(vertex):
    index = int(vertex) - 1
    for j in range(vertices_num):
        if adj_matrix[index][j]:
            adj_matrix[index][j] = 0
            return j + 1
    return None


def dfs_start():
    global time
    for i in range(vertices_num):
        if vertices_status_list[i + 1] == UNVISITED:
            # print('round: ', i + 1)
            graph_dfs(v_init=i + 1)
            time += 1


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices_num = int(_input[0])
    vertices_info = list(map(lambda x: x.split(), _input[1:]))
    init_adj_matrix = [[0] * vertices_num for _ in range(vertices_num)]
    # assert len(vertex_info) == vertex_num

    # config length = (vertex_num + 1)
    vertices_visit_stack = [-1]
    vertices_status_list = [UNVISITED] * vertices_num
    vertices_status_list.insert(0, -1)
    vertices_d_time, vertices_f_time = ([0] * (vertices_num + 1) for _ in range(2))

    adj_matrix = generate_adj_matrix(vertices_info)
    # timing start from 1
    time = 1
    dfs_start()
    for k in range(vertices_num):
        print(k + 1, vertices_d_time[k + 1], vertices_f_time[k + 1])

Measured memory_bytes: 7924
#include "bits/stdc++.h"

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

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

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while (1) {
		cin >> n;
		int maxx = 0, minx = 0, maxy = 0, miny = 0;
		if (!n)break;
		vector<pair<int, int> > v;
		v.push_back({ 0, 0 });
		FOR(i,1, n) {
			int a, b;
			cin >> a >> b;
			int nx, ny;
			if (b == 0) nx = -1, ny = 0,minx=min(minx,v[a].first-1);
			else if (b == 1) nx = 0, ny = -1,miny = min(miny, v[a].second - 1);
			else if (b == 2) nx = 1, ny = 0,maxx=max(maxx,v[a].first+1);
			else nx = 0, ny = 1,maxy=max(maxy,v[a].second+1);
			v.push_back({ v[a].first + nx,v[a].second + ny });
		}
		cout << maxx - minx+1 << " " << maxy - miny+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <set>
#include <queue>

using ll = long long int;
using namespace std;

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

    set<ll> st;
    queue<string> q;
    for (int i=1; i<=9; ++i) {
        st.insert(i);
        q.push(string(1, '0'+i));
    }

    while(q.size()) {
        string str = q.front();
        q.pop();

        char ch = str.back();

        if (ch - 1 >= '0') {
            string s = str+string(1, ch-1);
            q.push(s);
            st.insert(stol(s));
        }

        {
            string s = str+string(1, ch);
            q.push(s);
            st.insert(stol(s));            
        }

        if (ch + 1 <= '9') {
            string s = str+string(1, ch+1);
            q.push(s);
            st.insert(stol(s));
        }

        if (st.size() > 200000) break;
    }

    int cnt = 0;
    for (const auto& elm: st) {
        cnt++;
        if (cnt == n){
            cout << elm << endl;
            break;
        }
    }
}

Measured memory_bytes: 16896
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=0
y=0
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]>a[j]:
      x+=1
for l in range(n):
  for m in range(n):
    if a[l]>a[m]:
      y+=1
ans=((k*(k-1)*y)//2)%(1000000007)+(k*x)%1000000007
print(ans%1000000007)


Measured memory_bytes: 3188
"use strict";

const main = arg => {

    const input = arg.trim().split("\n");
    const n = parseInt(input[0]);

    let sum = 0;
    for (let i = 0; i < n; i++) {
        const left = input[i + 1].split(" ")[0].trim();
        const right = input[i + 1].split(" ")[1].trim();
        sum += right - left + 1;
    }
    console.log(sum);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29904
package main
 
import (
	"fmt"
)
 
func main() {
  var s string
  fmt.Scanf("%s", &s)
 
  ans := "No"
  if s[0:1] != s[1:2] {
    ans = "Yes"
  }
  if s[1:2] != s[2:3] {
    ans = "Yes"
  }
  fmt.Printf("%s\n", ans)
}

Measured memory_bytes: 1832
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
  int N,counter=0,ni=0,normal=0;
  scanf("%d",&N);
  unsigned int A;
  for (int i = 0; i < N; i++) {
    scanf("%d",&A);
    if(A%4==0){
      ++counter;
    }else if(A%2==0){
      ++ni;
    }else{
      ++normal;
    }
  }
  //以上入力と4の倍数、2の検出終了
  if((ni==0 && counter+1>=normal) || (ni>0 && counter>=normal)){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


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

int main() {
    string s;
    cin >> s;
    vector<string> week = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};

    int ans = 0;
    rep(i, 7) {
        if (s == week[i]) ans = i + 1;
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;

const int N = 3e3 + 3 , MOD = 998244353;
int a[N] , memo[N][N];
int n , s;

int mul (int a , int b) {
    return a * 1ll * b % MOD;
}

int add (int a , int b) {
    a += b;
    while (a >= MOD) a -= MOD;
    while (a < 0) a += MOD;
    return a;
}

int solve (int i , int rem) {
    if (i == n)
        return rem == 0;

    int &ret = memo[i][rem];
    if (~ret)
        return ret;

    ret = mul(2 , solve(i + 1 , rem));
    if (a[i] <= rem)
        ret = add(ret , solve(i + 1 , rem - a[i]));

    return ret;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    cin >> n >> s;
    for (int i = 0 ;i < n ;i++)
        cin >> a[i];

    memset(memo , -1 , sizeof memo);
    cout << solve(0 , s);
}


Measured memory_bytes: 38988
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int H, W, D, N, T;
    cin >> H >> W >> D;
    N = H * W;
    T = sqrt(N);
    vector<pair<int, int>> A(N);
    auto f = [&](int from, int to) -> i64 {
        return abs(A[from].first - A[to].first) + abs(A[from].second - A[to].second);
    };
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            int a;
            cin >> a;
            A[a - 1] = {i, j};
        }
    }
    vector<i64> memo(N);

    for(int i = 0; i < N; i++) {
        if(i < D) {
            memo[i] = 0;
        } else {
            memo[i] = memo[i - D] + f(i - D, i);
        }
    }

    int Q;
    cin >> Q;

    for(int q = 0; q < Q; q++) {
        int l, r;
        cin >> l >> r;
        cout << (memo[r - 1] - memo[l - 1]) << endl;
    }

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int f(int k){
  int cnt =0;
  rep(i,1,k){
    if(k % i == 0) cnt++;
  }
  return cnt == 8 && k % 2 == 1;
}

int main(){
  int N;
  cin >> N;
  int ans = 0;
  rep(i,1,N){
    ans += f(i);
  }
  cout << ans << endl;
}


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

using namespace std;
using llint = long long;
using pint = pair<int,int>;

#define LOG(x) cout << "# " << #x <<" => "<< (x) <<endl

const int INF = 1<<28;
const llint LLINF = 1LL<<60;

// Functions
vector<int> cumulativeSum(vector<int> &a, int reverse){
    int n = a.size();
    vector<int> res(n);

    if (reverse == 0)
    {
        res.at(0) = a.at(0);

        for (int i = 1; i < n; ++i) {
            if (a.at(i) == 0) continue;
            res.at(i) = a.at(i) + res.at(i-1);
        }
    } else {
        res.at(n-1) = a.at(n-1);

        for (int i = n-2; i >= 0; --i) {
            if (a.at(i) == 0) continue;
            res.at(i) = a.at(i) + res.at(i+1);
        }
    }
    
    return res;
}

vector<vector<int> > transpose(vector<vector<int> > &a){
    int h = a.size(); int w = a.at(0).size();
    vector<vector<int> > res(w);

    for (int x = 0; x < w; ++x) {
        res.at(x).resize(h);

        for (int y = 0; y < h; ++y) {
            res.at(x).at(y) = a.at(y).at(x);
        }
    }
    return res;
}


int main() {
    // Input
    int h, w, ans = 0;

    cin >> h >> w;
    vector<vector<int> > s(h);
    
    for (int i = 0; i < h; ++i) {
        s.at(i).resize(w);

        string str;
        cin >> str;
        for (int j = 0; j < w; ++j) {
            s.at(i).at(j) = (str.at(j)=='#') ? 0 : 1;
        }
    }

    // Solve
    vector<vector<int> > r(h, vector<int>(w));
    vector<vector<int> > l(h, vector<int>(w));
    vector<vector<int> > d(h, vector<int>(w));
    vector<vector<int> > u(h, vector<int>(w));

    for (int x = 0; x < h; ++x) {
        r.at(x) = cumulativeSum(s.at(x), 0);
        l.at(x) = cumulativeSum(s.at(x), 1);
    }

    vector<vector<int> > st = transpose(s);
    vector<vector<int> > dt(w, vector<int>(h));
    vector<vector<int> > ut(w, vector<int>(h));


    for (int x = 0; x < w; ++x) {
        dt.at(x) = cumulativeSum(st.at(x), 0);
        ut.at(x) = cumulativeSum(st.at(x), 1);
    }

    d = transpose(dt);
    u = transpose(ut);

    for (int x = 0; x < h; ++x)
    {
        for (int y = 0; y < w; ++y)
        {
            ans = max(ans, r.at(x).at(y) + l.at(x).at(y) + d.at(x).at(y) + u.at(x).at(y) - 3);
        }
    }

    // Output
    cout << ans << endl;
    return 0;
}

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

bool check(){
  int cal=0;
  for(int i=1;i<s.size();i++){
    int x;
    if(1<=i&&i<=6)x=i+1;
    else x=i-5;
    cal+=(s[i]-'0')*x;
  }
  

  cal%=11;
  
  int checkd;
  if(cal<=1)checkd=0;
  else{  
    checkd=11-cal;
  }
  
  
  
  
  return checkd==(int)(s[0]-'0');
}

int main(){
  cin>>s;
  reverse(s.begin(),s.end());
  int cnt=0,ans;
  for(int i=0;i<s.size();i++){
    if(s[i]=='?'){
      for(int j=0;j<10;j++){
	s[i]=j+'0';
	if(check())cnt++,ans=j;
      }
    }
  }
  if(cnt>1)cout<<"MULTIPLE"<<endl;
  else cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3212
//
//  main.cpp
//  Ice_Tea_Store
//
//  Created by Uttam Datta on 02/06/19.
//  Copyright © 2019 Uttam Datta. All rights reserved.
//

#include <iostream>
using namespace std;

long long int fourth,half,one,two;
long long int k;
long long int ans(){
    if(fourth*2 < half){
        half = fourth*2;
    }
    
    if(half*2 < one){
        one = half*2;
    }
    if(two > one*2){
        two = one*2;
    }
    
    long long int res = 0;
    
    res += (k/2)*two;
    k = k% 2;
    res += k*one;
    
    return res;
    
    
}

int main(){
    cin >> fourth >> half >> one >> two >> k;
    cout << ans() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
void solve(){
  string s;
  int res=0;
  cin>>s;
  for (int i=0;i<s.length();i++){
  	int count=0, j=i;
  	while (j<s.length()&&s[j]=='R'){
  		j++;count++;
	  }
	  if (count>res) res=count;
  }
  cout<<res;
}

int main(){
  solve();
}


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

double PI = 3.14159265358979323846264;

int main() {
	double A, B, H, M;
	cin >> A >> B >> H >> M;
	double DH, DM;
	DH = (H * 60 + M) / 720 * (PI * 2);
	DM = M / 60 * (PI * 2);
	double D = abs(DH - DM);
	if (D > PI) D = PI * 2 - D;
	double ANS = sqrt(A * A + B * B - 2 * A * B * cos(D));
	printf("%.12lf\n", ANS);
}

Measured memory_bytes: 4100
h, w, n = map(int, input().split())
y, x = map(int, input().split())
s = input().rstrip()
t = input().rstrip()


def check(pos_dir, neg_dir, minlim, maxlim, start):
    lim = maxlim
    count = 0
    for sc, tc in zip(s[::-1], t[::-1]):
        if tc == pos_dir:
            minlim = max(minlim - 1, 0)
        elif tc == neg_dir:
            maxlim = min(maxlim + 1, lim)
        if sc == pos_dir:
            maxlim -= 1
        elif sc == neg_dir:
            minlim += 1
        count += 1
        if minlim > maxlim:
            return False
    return minlim <= start <= maxlim


for elem in [
    ('R', 'L', 0, w - 1, x - 1),
    ('D', 'U', 0, h - 1, y - 1),
]:
    if not check(*elem):
        print('NO')
        break
else:
    print('YES')

Measured memory_bytes: 4024
import heapq
from collections import defaultdict
def gijkstra(n,E,s=1):
    d = [float('inf')]*(n+1)
    p = [-1]*(n+1)
    hq = [(0,s)]
    d[s] = 0
    while hq:
        u = heapq.heappop(hq)[1]
        for v, c in E[u]:
            if d[v] > d[u] + c:
                d[v], p[v] = d[u]+c, u
                heapq.heappush(hq, (d[u]+c, v))
    return d, p

n, m, s, t =  map(int,input().split())
E1 = defaultdict(set)
E2 = defaultdict(set)

for i in range(m):
    u,v,a,b = tuple(map(int,input().split()))
    E1[u].add((v,a))
    E1[v].add((u,a))
    E2[u].add((v,b))
    E2[v].add((u,b))
d1, _ = gijkstra(n,E1,s=s)
d2, _ = gijkstra(n,E2,s=t)
d = [d1[-1] + d2[-1],]
for i in range(n-1,0,-1):
    d.append(min(d[-1],d1[i]+d2[i]))
[print(10**15-c) for c in reversed(d)]

Measured memory_bytes: 116424
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
const int mod=1e9+7;
using namespace std;
int x1,x2,x3,x4,x5,x6;
int y1,y2,y3,y4,y5,y6;
ll zl[1000005];
ll yl[1000005];
ll sl[1000005];
ll xl[1000005];
ll zr[1000005];
ll yr[1000005];
ll sr[1000005];
ll xr[1000005];

namespace combinatorics
{
	int *fac;
	int *ifac;
	int __Tmod;
	inline int add(int a,int b)
	{
		return (a+b)%__Tmod;
	}
	inline int sub(int a,int b)
	{
		return (a-b+__Tmod)%__Tmod;
	}
	inline int mult(int a,int b)
	{
		return (1LL*a*b)%__Tmod;
	}
	inline int fastpow(int basic,int x)
	{
		int res=1;
		while(x)
		{
			if(x&1)	res=mult(res,basic);
			basic=mult(basic,basic);
			x>>=1;
		}
		return res;
	}
	inline int inv(int x)
	{
		return fastpow(x,__Tmod-2);
	}
	void init(int n,int tmod)
	{
		__Tmod=tmod;
		fac=new int[n+5];
		ifac=new int[n+5];
		fac[0]=1;
		for(int i=1;i<=n;i++)
		{
			fac[i]=mult(fac[i-1],i);
		}
		ifac[n]=inv(fac[n]);
		for(int i=n-1;i>=0;i--)
		{
			ifac[i]=mult(ifac[i+1],i+1);
		}
	}
	inline int C(int n,int m)
	{
		return mult(mult(fac[n],ifac[m]),ifac[n-m]);
	}
	inline int Cat(int x)
	{
		return mult(C(x*2,x),inv(x+1));
	}
};
using namespace combinatorics;

ll calc(int sx,int sy,int ex,int ey)
{
	if(sx>ex) return 0;
	if(sy>ey) return 0;
	return C(ex-sx+ey-sy,ex-sx);
}

ll lenof(int sx,int sy,int ex,int ey)
{
	return abs(sx-ex)+abs(sy-ey);
}

ll solve(int sx,int sy,int ex,int ey)
{
	ll res=0;
	for(int i=x3;i<=x4;i++)
	{
		res=add(res,mult(mult(calc(sx,sy,i,y4),calc(i,y4+1,ex,ey)),i+y4+1));
		res=sub(res,mult(mult(calc(sx,sy,i,y3-1),calc(i,y3,ex,ey)),i+y3));
	}
	for(int j=y3;j<=y4;j++)
	{
		res=add(res,mult(mult(calc(sx,sy,x4,j),calc(x4+1,j,ex,ey)),x4+j+1));
		res=sub(res,mult(mult(calc(sx,sy,x3-1,j),calc(x3,j,ex,ey)),j+x3));
	}
	return res;
}

int main()
{
//	freopen("input.txt","r",stdin);
	init(4e6,mod);
	cin>>x1>>x2>>x3>>x4>>x5>>x6>>y1>>y2>>y3>>y4>>y5>>y6;
	ll res=0;
	res+=solve(x1-1,y1-1,x5,y5);
	res+=solve(x1-1,y1-1,x6+1,y6+1);
	res+=solve(x2,y2,x5,y5);
	res+=solve(x2,y2,x6+1,y6+1);
	res+=solve(x1-1,y2,x6+1,y5);
	res+=solve(x1-1,y2,x5,y6+1);
	res+=solve(x2,y1-1,x5,y6+1);
	res+=solve(x2,y1-1,x6+1,y5);
	
	res-=solve(x1-1,y1-1,x6+1,y5);
	res-=solve(x1-1,y1-1,x5,y6+1);
	res-=solve(x2,y2,x5,y6+1);
	res-=solve(x2,y2,x6+1,y5);
	res-=solve(x1-1,y2,x5,y5);
	res-=solve(x1-1,y2,x6+1,y6+1);
	res-=solve(x2,y1-1,x5,y5);
	res-=solve(x2,y1-1,x6+1,y6+1);
	res%=mod;
	if(res<0) res+=mod;
	
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 31488
import heapq
import bisect

k,t=map(int,input().split())
a=sorted([-int(i) for i in input().split()],reverse=True)

heapq.heapify(a)
while len(a)>=2:
 max=heapq.heappop(a)
 min=a.pop(-1)
 if max+1<=-1:
  bisect.insort(a,max+1)
 if min+1<=-1:
  heapq.heappush(a,min+1)
if a:
 print(abs(a[0]+1))
else:
 print(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a,b;
	cin>>a>>b;
	if(a>b)
	  cout<<a-1<<endl;
	else
      cout<<a<<endl;
}

Measured memory_bytes: 256