akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from itertools import product
    n,k=map(int,input().split())
    cnt=[0]*40
    for a in map(int,input().split()):
        for d in range(40):
            cnt[d]+=(a>>d)&1
    dp=[0,-INF]
    for d in range(39,-1,-1):
        kb=(k>>d)&1
        newdp=[0,-INF]
        for lt,x in product(range(2),repeat=2):
            nlt=lt
            if(lt==0 and x>kb): continue
            if(x<kb): nlt=1
            newdp[nlt]=max(newdp[nlt],dp[lt]+(n-cnt[d] if(x) else cnt[d])*(1<<d))
        dp=newdp
    print(max(dp))
resolve()

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

int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    vector<char> res, tmp;
    bool reverse = false;
    for(int i = 0; i < s.size(); i++){
        res.push_back(s[i]);
    }
    for (int i = 0; i < q; i++){
        int t;
        cin >> t;
        if(t == 1){
            reverse ^= true;
        } 
        if(t == 2){
            int f;
            cin >> f;
            char c;
            cin >> c;
            if((f == 1 && reverse == true) || (f == 2 && reverse == false)){
                res.push_back(c);
            } else if((f == 1 && reverse == false) || (f == 2 && reverse == true)){
                tmp.push_back(c);
            }
        }
    }
    if(reverse == false){
        for(int i = tmp.size() - 1; i >= 0; i--){
            cout << tmp[i];
        }
        for(int i = 0; i < res.size(); i++){
            cout << res[i];
        }
    }else if(reverse == true){
        for(int i = res.size() - 1; i >= 0; i--){
            cout << res[i];
        }
        for(int i = 0; i < tmp.size(); i++){
            cout << tmp[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1148
import sys
input = sys.stdin.readline
N = int(input())
F = []
for _ in range(N):
    F.append([int(x) for x in input().split()])
P = []
for _ in range(N):
    P.append([int(x) for x in input().split()])
ans = -10 ** 10
import numpy as np
for i in range(1, 2 ** 10):
    bini = format(i, 'b').zfill(10)
    bini = np.array([int(x) for x in list(bini)])
    ans_ = 0
    for j in range(N):
        shop = np.array(F[j])
        cnt = np.count_nonzero(shop * bini)
        ans_ += P[j][cnt]
    ans = max(ans, ans_)
print(ans)



Measured memory_bytes: 12304
#include <iostream>

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

	int sum = 0;
	for( int i = 0; i < n; i++ ) {
		int l, r;
		std::cin >> l >> r;
		sum = sum + ( r - l + 1 );
	}

	std::cout << sum << std::endl;
	return 0;
}



Measured memory_bytes: 256
def main():

    N = int(input())

    d = dict()
    for i in range(1, N+1):
        u = int(str(i)[0])
        v = int(str(i)[-1])
        d[(u, v)] = d.get((u, v), 0) + 1

    ans = 0
    for u, v in d:
        if (v, u) in d:
            ans += d[(u, v)] * d[(v, u)]
    return ans


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


Measured memory_bytes: 67888
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    double n,m,var,count=0.0,total=0.0;
    long long int i;
    cin>>n>>m;
    vector<double> a;
    for(i=0;i<n;i++)
    {
        cin>>var;
        a.push_back(var);
        total+=var;
    }
    double temp=total/(4*m);
    for(i=0;i<n;i++)
    {
        if(a[i]>=temp)
        count++;
    }
    if(count>=m)
    cout<<"Yes";
    else
    cout<<"No";
	return 0;
}

Measured memory_bytes: 256
// #include <stdio.h>
// #include <string.h>
//#include <iostream>
#include <utility>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>
#include <string>
#include <set>

using namespace std;
typedef pair<int, int> XY;// Pair型変数の宣言
    
int main()
{
  	int Nmax = 100000;
    char String[Nmax];
    int N;
    int i,j,k;
    int len;   // 文字列の長さ
    int flag=0;

    

        
    
    // 入力読込

    
    // 数列
   scanf("%d", &N);
//    for(i=1;i<=N;i++){
//        scanf("%d %d %d",&t[i],&x[i],&y[i]);
//    }
    
        // 文字列
   scanf("%s", String);   
    
    
    // 文字列の長さをチェック
    // 文字列は配列の0からlen-1に格納されてる
//    len = strlen( String );
//  	printf("%d\n",len);
    
    if(N>=3200) 
        printf("%s\n",String);
    else
        printf("red\n");
    
  
        
  
  return 0;
   
}

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

signed main() {
  int subs[200000];
  int n;
  cin >> n;
  subs[0] = 0;
  for(int i = 1; i < n; i++){
    subs[i] = 0;
    int no;
    cin >> no;
    subs[no - 1]++;
  }
  for(int i = 0; i < n; i++){
    cout << subs[i] << endl;
  }
}

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

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  cout << n / max(h, w) + (n % max(h, w) != 0) << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}

use std::cmp::{max, min};

// watch
// ref https://www.youtube.com/watch?v=JQmQjJd-sLA&feature=youtu.be

fn main() {
    let s: String = read();
    let sv: Vec<char> = s.chars().collect();
    let K: usize = read();
    let n: usize = s.len();

    let mut dp: Vec<Vec<Vec<usize>>> = vec![vec![vec![0; 2]; K + 1]; n + 1];

    dp[0][0][0] = 1;

    for i in 0..n {
        for j in 0..K + 1 {
            // println!("j: {}", j);
            for k in 0..2 {
                let nd = sv[i] as u32 - '0' as u32;
                // println!("nd: {}", nd);
                for d in 0..10 {
                    let mut ni = i + 1;
                    let mut nj = j;
                    let mut nk = k;
                    if d != 0 {
                        nj += 1;
                    }

                    if nj > K {
                        continue;
                    }

                    if nk == 0 {
                        if d > nd {
                            continue;
                        }
                        if d < nd {
                            nk = 1
                        }
                    }
                    // println!(
                    //     "ni:{} nj:{} nk:{} d:{} i:{} j{} k{} v:{}",
                    //     ni, nj, nk, d, i, j, k, dp[i][j][k]
                    // );
                    dp[ni][nj][nk] += dp[i][j][k];
                }
            }
        }
    }

    let ans = dp[n][K][1] + dp[n][K][0];
    println!("{}", ans);
}


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

int main()
{
  int k,n;
  cin >> k >> n;
  int a[n], b[n];
  rep(i, n) cin >> a[i];
  for(int i = 0; i < n - 1; i++){
    b[i] = a[i+1] - a[i];
  }
  b[n - 1] = k - a[n - 1] + a[0];
  int max=0;
  rep(i, n){
  	if(max <= b[i]) max = b[i];
  }
  cout << k - max << endl;
  return 0;
}

Measured memory_bytes: 1792
n,m = map(int, input().split())
l = [0] * m
r = [0] * m
for i in range(m):
  a,b = map(int, input().split())
  l[i] = a
  r[i] = b

if min(r) - max(l) < 0:
  print(0)
else:
  print(min(r) - max(l) + 1)

Measured memory_bytes: 10868
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
int c[101];
int m, d;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> m >> d;
  FOR(i, 1, d+1){
    int d1 = i/10, d2 = i%10;
    if(d1>1 && d2>1) c[d1*d2]++;
  }
  int ans = 0;
  FOR(i, 1, m+1) ans += c[i];
  cout << ans << endl;
}

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

  int m, n, r;

  while(1)
    {
      scanf("%d %d %d", &m, &n, &r);
      if ( m == -1 && n == -1 && r == -1) break;

      if ( m == -1 || n == -1 ) { printf("F\n");}
      else if ( m + n >= 80 ) { printf("A\n");}
      else if ( m + n >= 65 ) { printf("B\n");}
      else if ( m + n >= 50 || r >= 50) { printf("C\n");}
      else if ( m + n >= 30 ){ printf("D\n");}
      else { printf("F\n");}

    }
  return 0;
}

Measured memory_bytes: 584
import heapq
h = []

n,m=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
for i in a:
    heapq.heappush(h, [(-1)*i,1])

for i in range(m):
    b,c=(int(i) for i in input().split())
    heapq.heappush(h, [(-1)*c,b])

num=0
data=0
while num <= n:
    v=heapq.heappop(h)
    data+=v[0]*v[1]
    num+=v[1]

print((-1)*(data-v[0]*(num-n)))


Measured memory_bytes: 95128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;

const ll INF = 0x3f3f3f3f3f3f3f3f;
ll dis[150][150];

int main()
{
    int n,m;
    while(cin>>n>>m){
        for(int i = 0;i < n;i++)
            for(int j = 0;j < n;j++)
                if(i == j) dis[i][j] = 0;
                else dis[i][j] = INF;
        int a,b,c;
        while(m--){
            cin>>a>>b>>c;
            dis[a][b] = c;
        }
        for(int k = 0;k < n;k++)
            for(int i = 0;i < n;i++){
                if(dis[i][k] == INF) continue;
                for(int j = 0;j < n;j++){
                    if(dis[k][j] == INF) continue;
                    dis[i][j] = min(dis[i][k] + dis[k][j],dis[i][j]);
                }
            }
        int flag = 0;
        for(int i = 0;i < n;i++)
            if(dis[i][i]<0){
                flag = 1;
                break;
            }
        if(flag) cout<<"NEGATIVE CYCLE"<<endl;
        else{
            for(int i = 0;i < n;i++){
                for(int j = 0;j < n;j++){
                    if(dis[i][j] == INF) cout<<"INF"<<(j==n-1?'\n':' ');
                    else cout<<dis[i][j] <<(j==n-1?'\n':' ');
                }
            }

        }
    }
    return 0;
}



Measured memory_bytes: 3168
n = int(input())
ans = 0
lst = []
for i in range(1,n+1):
  ans += i
  lst.append(i)
  if ans>=n:
    break
  
num = ans-n
if num != 0:
  lst.remove(num)

L =len(lst)
for i in range(L):
  print(lst[i])

Measured memory_bytes: 3572
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
 int main(){
     CIN(A);CIN(B);CIN(C);
     int M = max({A,B,C});
     if((M*3)%2==(A+B+C)%2){
         COUT(((M*3)-A-B-C)/2);
     }else{
         M++;
         COUT(((M*3)-A-B-C)/2);
     }
  return 0;
 }


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

int main(){
  
  int a;
  cin >> a;
  
  if( a%10 == 9 ){
    
    cout << "Yes" << endl;
    
  }
  
  else if( 90 <= a && a <= 99 ){
    
    cout << "Yes" << endl;
    
  }
  
  else{
    
    cout << "No" << endl;
    
  }
  
}


Measured memory_bytes: 3612
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iterator>
#include <map>
#include <unordered_map>
#define ll long long int
#define vi vector<long long int>
#define vvi vector<vi >
#define vs vector<string>
#define vsf v.begin(),v.end()
#define pb push_back
#define mp make_pair
using namespace std;
int main(){
	ll i,j,n,m;
	string a,b,c;
	cin>>a>>b;
	n=a.size();m=b.size();
	vvi v(n+1);
	for(i=0;i<=n;i++) v[i]=vi(m+1,0);
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			v[i][j]=max(v[i-1][j],v[i][j-1]);
			if(a[i-1]==b[j-1]) v[i][j]=max(v[i][j],v[i-1][j-1]+1);
		}
	}
	i=n;j=m;
	while(i&&j){
		if(a[i-1]==b[j-1]){
			c.pb(a[i-1]);
			i--;j--;
		}
		else if(v[i-1][j]>v[i][j-1]) i--;
		else j--;
	}
	reverse(c.begin(),c.end());
	cout<<c<<endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<bool> checked(N,false);
  int m = 0;
  for (int i = 0; i < N; i++) {
    if (checked[i]) continue;
    int c = 0;
    queue<int> Q;
    Q.push(i);
    while (!Q.empty()) {
      int v = Q.front();
      Q.pop();
      c += 1;
      checked[v] = true;
      for (auto p : G[v]) {
        if (checked[p]) continue;
        checked[p] = true;
        Q.push(p);
      }
    }
    m = max(m,c);
  }
  cout << m << endl;
}

Measured memory_bytes: 14880
#include <bits/stdc++.h>
#define INF 1023456789
#define sacnf scanf
#define scnf scanf
#define scnaf scanf
#define CRLF <<'\n';
#define ALL(v) v.begin,v.end()
#define SIZE(v) (int)v.size()
#define PRPAIR(x) x.first << x.second
#define DEBUG(x) do { std::cerr <<(x)<<'\n'; } while (0)
#define rep(i,a,b) for(int i=(a);i!=(int)b-((a)>(b));(a)>(b)?--i:++i)
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> pip;
typedef vector<int> vi;
typedef long long ll;

int main(){
    ll n,d,k;
    scanf("%lld%lld%lld",&n,&k,&d);
    n = abs(n);
    ll num = (n%d==0? n/d : n/d+1);
    if (num > k){
        cout << n-k*d;
    }else{
        ll num = n/d;
        n-= (n/d)*d;
        k-=num;
        if (k %2==0){
            cout << n;
        }else{
            cout << abs(n-d);
        }
    }

}


Measured memory_bytes: 3720
h,w=map(int,input().split())
s=[]
s.append(['.']*(w+2))
for _ in range(h):
    s.append(['.']+list(input())+['.'])
s.append(['.']*(w+2))

flag=True
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=='#' and s[i-1][j]=='.' and s[i][j-1]=='.' and s[i+1][j]=='.' and s[i][j+1]=='.':
            flag=False
print('Yes' if flag else 'No')


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[M];
		for(int i = 0; i < M; i++) {
			A[i] = sc.nextInt();
		}
		sc.close();
		int[] c = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
		String[] dp = new String[10000 + 10];
		Arrays.fill(dp, "0");
		for(int i = 0; i < M; i++) {
			if(dp[c[A[i]]].equals("0")) {
				dp[c[A[i]]] = Integer.toString(A[i]);
			}else {
				String t = dp[c[A[i]]];
				if(t.compareTo(Integer.toString(A[i])) < 0) {
					dp[c[A[i]]] = Integer.toString(A[i]);
				}
			}
		}

		for(int i = 0; i < N; i++) {
			String t = dp[i];
			if(!t.equals("0")) {
				for(int j = 0; j < M; j++) {
					String k = dp[i + c[A[j]]];
					String k1 = t + Integer.toString(A[j]);
					if(k.equals("0")) {
						dp[i + c[A[j]]] = k1;
					}else {
						if(k.length() < k1.length()) {
							dp[i + c[A[j]]] = k1;
						}else {
							if(k.compareTo(k1) < 0) {
								dp[i + c[A[j]]] = k1;
							}
						}
					}
				}
			}
		}
		//System.out.println(dp[N]);
		String[] t = new String[dp[N].length()];
		for(int i = 0; i < t.length; i++) {
			t[i] = dp[N].substring(i, i + 1);
		}
		Arrays.sort(t, Collections.reverseOrder());
		StringBuilder sb = new StringBuilder();
		for(String i : t) {
			sb.append(i);
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 379472
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,m,d[200010],t[200010];
	cin>>n;
	for (int i=0;i<n;i++) cin>>d[i];
	cin>>m;
	for (int i=0;i<m;i++) cin>>t[i];
	sort(d,d+n);sort(t,t+m);
	//for (int i=0;i<n;i++) cout<<d[i];
	int p=0,q=0;
	while (q<m && p<n) 
	{
		if (d[p]==t[q]) {p++;q++;} else p++;
		//cout<<p<<' '<<q;
	}
	if (q>=m) cout<<"YES"; else cout<<"NO";
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main () {
    int N,M,C, ans = 0;;
    cin >> N >> M >> C;
    vector<int> bbb(M);
   vector<vector<int>> vec(N,vector<int>(M));
   for(int a = 0; a < M; a++){
       cin >> bbb.at(a);
   }
   for(int i = 0; i<N; i++){
       for(int j = 0; j<M; j++){
           cin >> vec.at(i).at(j);
       }
   }
       for(int i= 0; i<N; i++){
           int equ = 0;
           for(int j = 0; j < M; j++){
               
               equ += vec.at(i).at(j)*bbb.at(j);
           }
        if(equ + C > 0){
            ans++;
        }
       }
   cout << ans << endl;
}

Measured memory_bytes: 256
import math
a = []
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
t = []
b = []
u = []
for i in a:
	if(i%10 == 0):
		b.append(i)
	else:
		t.append(i)
		u.append(i%10)
if(sum(u) != 0):
	min_t = u.index(min(u))
	ss = t.pop(min_t)
	u.pop(min_t)

	for i in range(len(t)): 
		u[i] = 10 - u[i]
		t[i] = t[i] + u[i]
	print(sum(b) + sum(t) + ss)

else:
	print(sum(b))

Measured memory_bytes: 3064
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun main() {

    fun PrintWriter.solve() {
        var s = next()
        var rev = false

        var q = ArrayDeque<Char>()
        q.addAll(s.toList())
        repeat(nextInt()){
            var line = nextLine().split(" ")
            if (line.size == 1){
                rev = !rev
            }
            else{
                var addToFront = if ((line[1].equals("1") and !rev )|| (line[1].equals("2") and rev) ) true else false

                if (addToFront)q.addFirst(line[2][0])
                else q.addLast(line[2][0])
            }

        }

        var sb = StringBuilder(q.joinToString(""))
        if (rev)sb.reverse()

        println(sb.toString())


    }

    writer.solve()
    writer.flush()


}


private val reader = System.`in`.bufferedReader()
private val writer = PrintWriter(System.out, false)

private var tokenizer: StringTokenizer = StringTokenizer("")

private fun next(): String {
    while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine())
    return tokenizer.nextToken()
}

private fun nextInt() = next().toInt()
private fun nextLong() = next().toLong()
private fun nextDouble() = next().toDouble()
private fun nextLine() = reader.readLine()



Measured memory_bytes: 59720
# coding: utf-8
# N : 県の数, M: 市の数
import bisect

N, M = map(int, input().split())
ps, ys = [], []

v = [ [] for _ in range(N+1) ]

for i in range(M):
    p, y = map(int, input().split())
    ps += [p]; ys += [y];
    v[p].append(y)

for i in range(N):
    v[i+1].sort()


for i in range(M):
    print("{:06d}".format(ps[i]), end="")
    print("{:06d}".format(bisect.bisect_left(v[ps[i]], ys[i])+1))


Measured memory_bytes: 24168
#include<stdio.h>
int main(){
	int n[1006]={0},m[1006]={0},k=0,i,N,M;
	for(;;k=0){
		scanf("%d%d",&N,&M);
		if(M==0&&M==0)break;
		for(i=0;i<N;i++)scanf("%d",&n[i]);
		for(i=0;i<M;i++)scanf("%d",&m[i]);
		for(i=0;;i++){
			k+=m[i];
			k+=n[k];
			if(k>=N-1)break;
		}	
		printf("%d\n",i+1);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), x(n, -1), org(n, 0);
    bool ok = true;
    map<int,int>islast;
    rep(i, n)
    {
        cin >> a[i];

        if (a[i] > i or a[i]-a[i-1]>1)
        {
            ok = false;
        }
        else
        {
            org[i] = i - a[i];
        }
       // cout<<org[i]<<endl;
    }
    ll cnt=0;
    if (ok)
    {

        for(int i=n-1; i>0; i--){
           if(islast[org[i]]==0){
               islast[org[i]]++;
               cnt+=a[i];
           }
        }
        cout<<cnt<<endl;
    }else{
        cout<<-1<<endl;
    }
}


Measured memory_bytes: 12032
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(),(x).end()

void solve(){

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

    string w[n];
    for (int i = 0; i < n; i++){
        cin >> w[i];
    }

    string before = w[0];
    for (int i = 0; i < n; i++){
        for (int k = i+1; k < n; k++){
            if (w[i] == w[k]){
                cout << "No" << endl;
                exit(0);
            }
        }
    }

    for (int i = 1; i < n; i++){
        if (before.back() != w[i].front()){
            cout << "No" << endl;
            exit(0);
        }
        before = w[i];
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var ps = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var k = 0;
        for (int i = 0; i < ps.Length; ++i)
        {
            if (k > 1 && ps[i] != i + 1)
            {
                Console.WriteLine("NO");
                return;
            }
            
            if (ps[i] == i + 1)
            {
                continue;
            }

            ++k;
        }

        Console.WriteLine("YES");
    }
}


Measured memory_bytes: 13268
#!/usr/bin/env python3

import collections
N = int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

lis = prime_factorize(N)
c = collections.Counter(lis)
ans =0
for i in c.values():
    cnt = 0
    for j in range(1,i+1):
        cnt += j
        if cnt <= i:
            ans +=1
print(ans) 

Measured memory_bytes: 9468
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define allr(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

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

const int maxn = 1e5+4;
int dp[maxn];

void solve(){
    
   int n,k,sum = 0;
   cin >> n >> k;

   for(int i = k;i>=1;i--){
        int x = k/i;
        dp[i] = powm(x,n);

        for(int j = 2*i;j<=k;j+=i){
            dp[i] = (dp[i] -dp[j] + mod)%mod;
        }

        sum = (sum+ i*dp[i])%mod;
   }

   cout << sum << endl;
}

signed main() 
{   
    IOS;
    int t = 1;
    // cin >> t;
    
    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 4420
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b){
        cout<<c<<"\n";
    }
    else if(a==c){
        cout<<b<<"\n";
    }
    else cout<<a<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 10005
#define pb push_back
#define int long long
#define vi vector<int>
#define len(x) (x.size())
#define f(i,a,b) for(int i=a;i<b;i++)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define T int tc;cin>>tc;for(int t=1;t<=tc;t++)
#define set_arr(arr,i) memset(arr,i,sizeof(arr))
using namespace std;

double distance(int points[][100],int x, int y,int d){
	double ans = 0;
	for(int i=0;i<d;i++){
		ans += pow((points[x][i] - points[y][i]),2);
	}
	return sqrt(ans);
}

signed main(){
	ios_base::sync_with_stdio(false);	
	cin.tie(0);
	cout.tie(0);
	
 	int n,d;
 	cin>>n>>d;
 	int points[100][100] ;
 	for(int i=0;i<n;i++){
 		for(int j=0;j<d;j++){
 			cin>>points[i][j];
 		}
 	}
 	int count = 0;
 	for(int i=0;i<n;i++){
 		for(int j=i+1;j<n;j++){
 			double dist = distance(points,i,j,d);
 			if(dist - (int)(dist)==0)count++;
 		}
 	}
 	cout<<count;

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

#define MAX 10000


int solve(int i, int A[], int m, int n )
{
	int res;
	
	if (m == 0) {
		return 1;
	}
	if (i >= n) {
		return 0;
	}
	
	res = solve(i + 1, A, m, n) || solve(i + 1, A, m - A[i], n);
	return res;
}
		

int main()
{
	int n, q, i,j;
	int A[MAX], m[MAX];
	
	scanf("%d",&n);
	for (j = 0; j < n; j++) {
		scanf("%d",&A[j]);
		
	}
	
	scanf("%d",&q);
	for (j = 0; j < q; j++) {
		scanf("%d",&m[j]);
		
	}
	
	for (i = 0; i < q; i++) {
		if (solve(0, A, m[i], n) == 1) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}
return 0;
}


Measured memory_bytes: 2108
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
//const double PI = 3.141592653589793238462643383279;
const double PI = acos(-1);
int main(){
    int a,b,x;
    scanf("%d%d%d", &a, &b, &x);
    double o;
    if(x*2 <= a*a*b) {
        o = atan2(b*b*a, 2*x);
    }else {
        o = atan2(2*(a*a*b-x), a*a*a);
    }
    printf("%.10lf\n", o/PI*180);
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

   class Main{
     public static void main(String[] args){
       Scanner stdIn = new Scanner(System.in);
       int A = stdIn.nextInt();
       String S = stdIn.next();
       if(A >= 3200){
         System.out.println(S);
       }else {
         System.out.println("red");
       }
     }
   }

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<long int> num(n);
  long int answer = 0;
  for(int i = 0;i < n;i++){
    cin >> num.at(i);
    for(int j = 0;;j++){
      if(num.at(i) % 2 == 0){
        num.at(i) /= 2;
      }else{
        answer += j;
        break;
      }
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
	int[][] land,looked;
	int sx,sy,w,h,count;
	int[] dx={-1,1,0,0},dy={0,0,-1,1};
	
	Scanner stdin =new Scanner(System.in);
	Queue qx=new LinkedList();Queue qy=new LinkedList();
	
	
	void Solve(){
		
		while(true){
			w=stdin.nextInt();
			h=stdin.nextInt();
			if(w==0&&h==0) break;
			land=new int[h][w];
			looked=new int[h][w];
			count=1;
			
			for(int i=0;i<h;i++){
				String s=stdin.next();
				for(int j=0;j<w;j++){
					if(s.charAt(j)=='.') land[i][j]=1;
					else if(s.charAt(j)=='@'){
						land[i][j]=0;
						sx=i;
						sy=j;
					}else land[i][j]=0;
				}
			}
			looked=land.clone();
			//System.out.println(land[5][8]);
			bfs(sx,sy);
			System.out.println(count);
			
			
		}
		
		
		
		
		
	}
	
	void bfs(int sx,int sy){
		//System.out.println(sx+" "+sy);
		looked[sx][sy]=0;
		for(int i=0;i<4;i++){
			int xx=sx+dx[i];
			int yy=sy+dy[i];
			if(0<=xx&&xx<h&&0<=yy&&yy<w){
				if(land[xx][yy]==1){
					if(looked[xx][yy]==1)count++;
					bfs(xx,yy);
				}
			}
		}
	}
	
	public static void main(String args[]){
		Main m=new Main();
		m.Solve();
	}
}

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

struct Card{char suit, value; };

void bubble(struct Card A[], int N)
{
int i=0;
int j=0;
for(i =0;i<N;i++)
{
for(j=N-1;j>=i;j--)
{
if(A[j].value<A[j-1].value)
{
Card t =A[j]; A[j]=A[j-1]; A[j-1]=t;
}
}
}
}

void selection(struct Card A[], int N)
{
int i=0;
int j=0;
for(i=0; i<N; i++)
{
int minj=i;
for(j=i; j<N; j++)
{
if(A[j].value<A[minj].value)minj = j;
}
Card t=A[i]; A[i]=A[minj];A[minj] = t;
}
}

void print(struct Card A[], int N)
{
int i=0;
for(i = 0;i<N ; i++)
{
if(i>0)cout<<" ";
cout<<A[i].suit<<A[i].value;
}
cout<< endl;
}

bool isStable(struct Card C1[], struct Card C2[],int N)
{
int i=0;
for(i=0;i<N;i++)
{
if( C1[i].suit !=C2[i].suit )return false;
}
return true;
}

int main()
{
int i=0;

Card C1[100],C2[200];
int N;
char ch;

cin >> N;
for(i=0; i<N; i++)
{
cin >> C1[i].suit >> C1[i].value;
}

for(i=0;i<N; i++)
{
C2[i]= C1[i];
}
bubble(C1,N);
selection(C2,N);
print(C1,N);
cout<<"Stable"<<endl;
print(C2,N);
if(isStable(C1,C2,N))
{
cout << "Stable"<<endl;
}
else
{
cout<<"Not stable"<<endl;
}

return 0;
}



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

int main() {
  int N; cin >> N; // 問題数
  int M; cin >> M; // 提出数

  int A_AC = 0;     // 正答数
  int A_WA = 0;     // ペナルティ

  map<int,pair<string,int>> mapA; // 問題番号,状態,誤答数

  int P;  // 問題番号
  string S;  // 評価

  // 回答を読取ながら、回答状態・誤答数を加算
  rep(i,M){
    cin >> P >> S;
    auto tmp_P = mapA[P];
    if ( tmp_P.first != "AC" ) {
      if ( S =="AC" ) {
        tmp_P.first = "AC";
        A_AC++;
        A_WA += tmp_P.second;
      }
      else if ( S=="WA" ) {
        tmp_P.second++;
  //      A_WA++;
      }
      mapA[P] = tmp_P;
    }
  }

  cout << A_AC << " " << A_WA << endl;
}


Measured memory_bytes: 11136
import itertools,math
n = int(input())
word = [input() for _ in range(n)]
count = 0

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(n):
    word[i] = sorted(word[i])

new_word = list(sorted(word))

x = 1

for i in range(n-1):
    if new_word[i] == new_word[i+1]:
        x += 1
    elif x >= 2:
        count += combinations_count(x,2)
        x = 1
if x >= 2:
    count +=  combinations_count(x,2)

print(count)

Measured memory_bytes: 32216
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
string s,t;
int main()
{
    cin>>s>>t;
    for(int i=0;i<3;i++)
    if(s[i]!=t[2-i]) return printf("NO\n"),0;
    printf("YES\n");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int N, D;
    cin >> N >> D;
    int X[N][D];
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < D; ++j)
        {
            cin >> X[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        for (int j = i+1; j < N; ++j)
        {
            int norm = 0;
            for (int k = 0; k < D; ++k)
            {
                int diff = abs(X[i][k] - X[j][k]);
                norm += diff * diff;
            }
            bool flag = false;
            for (int k = 0; k <= norm; ++k)
            {
                if (k * k == norm)
                {
                    flag = true;
                }
            }
            if (flag)
                ++ans;
        }
    }
    cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    int check = n % 10;
    if (check == 3) cout << "bon" << endl;
    else if (check == 0 || check == 1 || check == 6 || check == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}


Measured memory_bytes: 3600
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let n: usize = read();
    let a: Vec<usize> = read_n(n);
    let mut b: Vec<bool> = vec![false; 1_000_000_000];
    let mut ans: String = "YES".to_string();

    for i in 0..a.len() {
        let ai = a[i];
        if b[ai] == false {
            b[ai] = true;
        } else {
            ans = "NO".to_string();
            break;
        }
    }

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


Measured memory_bytes: 1001980
#include <stdio.h>
#include <stdlib.h>

int main(){
  int S[100], num;
  char s[200];

  while(scanf("%s", s) != EOF){
    if(s[0] == '+'){
      S[num-1] = S[num-1] + S[num];
      num--;
    }
    else if(s[0] == '-'){
      S[num-1] = S[num-1] - S[num];
      num--;
    }
    else if(s[0] == '*'){
      S[num-1] = S[num-1] * S[num];
      num--;
    }
    else{
      num++;
      S[num] = atoi(s);
    }
  }
  printf("%d\n", S[num]);
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ull d[100000],dp[100][100];

int main(){
  cin >> n >> m;
  if(abs(n - m) <= 1)puts("Brown");
  else puts("Alice");
  return 0;
}

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

#define ll long long
#define pb push_back
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define inf 0x3f3f3f3f

int n;
int g[21];
int c[21];

int solve(int i, int v, int cost){
    if(i == n) return v-cost;
    return max(solve(i + 1, v, cost), solve(i + 1, v + g[i], cost + c[i]));
}

int main(){
    fcin;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> g[i];
    for(int i = 0; i < n; i++) cin >> c[i];
    cout << solve(0, 0, 0);
    
    return 0;
}




Measured memory_bytes: 256
#pragma region

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (register int i = (begin); i < (end); i++)
#define IFOR(i, begin, end) for (register int i = (end)-1; i >= (begin); i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define MOD 1000000007
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  REP(i, vec.size())
  i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &deq) {
  os << "deq[ ";
  REP(i, deq.size())
  i == 0 ? os << deq[i] : os << ", " << deq[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}

#pragma endregion
#pragma region

#define out(x) cout << (x) << '\n';

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

bool isPrime(ll a) {
  if (a == 2) return true;
  if (a < 2 || a % 2 == 0) return false;
  int b = sqrt(a);
  for (register int i = 3; i <= b; i += 2)
    if (b % i == 0) return false;
  return true;
}

#pragma endregion
#define INF 2147483647

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);

  int A, B;
  cin >> A >> B;
  out(A == B ? A * 2 : max(A, B) * 2 - 1);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
//construct SA by SA-IS O(N)
#include<string>
#include<vector>
struct SA{
	string s;
	vector<int>sa;
	SA(const string&s_):s(s_)
	{
		sa=build(vector<int>(s.begin(),s.end()),256);
	}
	vector<int>induced_sort(const vector<int>&S,const vector<int>&id,const vector<bool>&SL,vector<int>last)
	{
		vector<int>first(last);
		vector<int>ret(id.size());
		ret[0]=id[0];
		for(int i=0;i<id.size();i++)
		{
			if(id[i]>=1&&!SL[id[i]-1])
			{
				ret[first[S[id[i]-1]-1]++]=id[i]-1;
			}
			else if(ret[i]>=1&&!SL[ret[i]-1])
			{
				ret[first[S[ret[i]-1]-1]++]=ret[i]-1;
			}
		}
		for(int i=id.size();i--;)
		{
			if(ret[i]>=1&&SL[ret[i]-1])
			{
				ret[--last[S[ret[i]-1]]]=ret[i]-1;
			}
		}
		return ret;
	}
	vector<int>build(vector<int>S,int maxval)
	{
		if(S.size()==1)
		{
			return(vector<int>){1,0};
		}
		S.push_back(0);
		vector<int>cnt(maxval,0);
		vector<bool>SL(S.size());//S=>true,L=>false
		for(int i=S.size();i--;)
		{
			cnt[S[i]]+=1;
			SL[i]=i+1==S.size()||S[i]<S[i+1]||S[i]==S[i+1]&&SL[i+1];
		}
		for(int i=1;i<maxval;i++)cnt[i]+=cnt[i-1];
		vector<int>last(cnt);
		vector<int>id(S.size());
		vector<int>is_LMS(S.size());
		int LMScnt=0;
		for(int i=1;i<S.size();i++)
		{
			if(!SL[i-1]&&SL[i])
			{
				is_LMS[i]=1;
				id[--cnt[S[i]]]=i;
				LMScnt+=1;
			}
		}
		id=induced_sort(S,id,SL,last);
		int LMSsub=1;
		int pre=-1;
		is_LMS[id[0]]=LMSsub++;
		for(int i=1;i<id.size();i++)
		{
			if(is_LMS[id[i]])
			{
				if(pre>=0&&S[pre]==S[id[i]])
				{
					int k;
					for(k=1;S[pre+k]==S[id[i]+k]&&!is_LMS[pre+k]&&!is_LMS[id[i]+k];k++);
					LMSsub-=S[pre+k]==S[id[i]+k]&&is_LMS[pre+k]&&is_LMS[id[i]+k];
				}
				pre=id[i];
				is_LMS[id[i]]=LMSsub++;
			}
		}
		vector<int>newstr(LMScnt);
		vector<int>rev(LMScnt);
		int counter=0;
		for(int i=0;i<S.size();i++)
		{
			if(is_LMS[i])
			{
				newstr[counter]=is_LMS[i];
				rev[counter]=i;
				counter+=1;
			}
		}
		vector<int>sortedLMS=build(newstr,LMSsub);
		id.assign(S.size(),0);
		for(int i=1;i<sortedLMS.size();i++)
		{
			int I=rev[sortedLMS[i]];
			id[cnt[S[I]]++]=I;
		}
		return induced_sort(S,id,SL,last);
	}
	int operator[](int i){return sa[i];}
	int lower_bound(const string&t)
	{
		int L=-1,R=sa.size();
		while(R-L>1)
		{
			int M=L+R>>1;
			if(s.compare(sa[M],t.size(),t)>=0)R=M;
			else L=M;
		}
		return R;
	}
	int upper_bound(const string&t)
	{
		int L=-1,R=sa.size();
		while(R-L>1)
		{
			int M=L+R>>1;
			if(s.compare(sa[M],t.size(),t)<=0)L=M;
			else R=M;
		}
		return R;
	}
	bool contain(const string&t)
	{
		int id=lower_bound(t);
		return id<sa.size()&&s.compare(sa[id],t.size(),t)==0;
	}
	int size(){return sa.size();}
};
main()
{
	string T,P;
	cin>>T>>P;
	SA X(T);
	int L=X.lower_bound(P);
	int R=X.upper_bound(P);
	vector<int>A;
	for(int i=L;i<R;i++)
	{
		A.push_back(X[i]);
	}
	sort(A.begin(),A.end());
	for(int a:A)printf("%d\n",a);
}



Measured memory_bytes: 27816
#include "bits/stdc++.h"
#define int long long
#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 ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define sqr(x) (x) * (x)
#define cube(x) (z) * (z) * (x)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define itn int

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

template <class T = int>
int in() {
  T x;
  cin >> x;
  return x;
}

signed main() {
  int N, M;
  cin >> N >> M;
  int ans    = 0;
  int fact_N = 1;
  int fact_M = 1;
  rep(i, N) {
    fact_N *= (i + 1);
    fact_N %= MOD;
  }
  rep(i, M) {
    fact_M *= (i + 1);
    fact_M %= MOD;
  }
  if (abs(N - M) >= 2) {
    cout << 0 << endl;
    return 0;
  }
  if (abs(N - M) == 1) {
    cout << (fact_M * fact_N) % MOD << endl;
  } else {
    cout << (fact_M * fact_N * 2) % MOD << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int n; cin >> n;
    ves S(n); rep(i,n) cin >> S[i];
    ve_vei check(n, vei(26,0));

    rep(i,n){
        rep(j,S[i].size()) {
            check[i][ S[i][j] - 'a' ]++;
        }
    }

    vei final_check(26);

   

    vei ans(26,100);
    if(n == 1) {
        rep(i,26) ans[i] = check[0][i];
        rep(i,26) {
            rep(j,ans[i]){
                cout << (char)(i + 'a') ;
            }
        }
        cout << endl;
        return 0;
    }

    rep(i,26) {
        int temp;
        rep(j,n-1) {
            temp = min(check[j][i], check[j+1][i]);
            ans[i] = min(ans[i], temp);
        }
    }
    rep(i,26) {
        rep(j,ans[i]){
            cout << (char)(i + 'a') ;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256