akhauriyash/Code-Regression huggingface dataset:
#! env/bin/local python3
# -*- coding:utf-8 -*-

# -- submit ----

# --- fetch input ---

inputs: list = []
while True:
    try:
        inputs.append(input().strip('\n'))
    except EOFError:
        break

# --- write code below ---
n: int = int(inputs[0])
workers: list = [int(w) for w in inputs[1].split(' ')]

w_list: dict = {n: 0 for n in range(1, n+1)}

for worker in workers:
    w_list[worker] += 1

print(*w_list.values(), sep='\n')


Measured memory_bytes: 40024
N, M, X, Y = map(int,input().split())

x = list(map(int,input().split()))
y = list(map(int,input().split()))

x.append(X)
y.append(Y)

if max(x)<min(y):
    ans = 'No War'
else:
    ans = 'War'

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;

int n;
vector<string> alp={"a","b","c","d","e","f","g","h","i","j"};

int dfs(int m,int d,string s){
  if(d==n-1){
    cout << s << endl;
  }else{
    for(int i=0;i<m+1;i++){
      dfs(m,d+1,s+alp[i]);
    }
    if(m+1<n) dfs(m+1,d+1,s+alp[m+1]);
  }
  return 0;
}

int main(){

  cin >> n;

  dfs(0,0,"a");
    
  return 0;
}


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

int comp(const void *p1,const void *p2);

typedef struct{
	int ti;
	int tj;
} observatories;

int main(void){
	int n,m,i,now,flg,ans;
	int *h;
	observatories*obs;
	scanf("%d%d",&n,&m);
	h=(int *)calloc(n,sizeof(int));
	obs=(observatories *)calloc(2*m,sizeof(observatories));
	for(i=0;i<n;i++) scanf("%d",&h[i]);
	for(i=0;i<m;i++){
		scanf("%d%d",&obs[i].ti,&obs[i].tj);
		obs[m+i].ti=obs[i].tj;
		obs[m+i].tj=obs[i].ti;
	}
	
	qsort(obs,2*m,sizeof(observatories),comp);
	/*
	putchar('\n');
	for(i=0;i<2*m;i++){
		printf("%d %d\n",obs[i].ti,obs[i].tj);
	}*/
	flg=0;
	ans=0;
	i=0;
	
	for(now=1;now<=n;now++){
		//printf("now: %d,ans: %d\n",now,ans);
		for(;obs[i].ti==now && i<2*m;i++){
			//printf("now-1: %d, obs.ti: %d, obs.tj: %d\n",now, obs[i].ti,obs[i].tj);
			if(h[now-1]<=h[obs[i].tj-1]){
				flg=1;
			}
		}
		if(flg==0){
				ans++;
		}
		flg=0;
	}
	printf("%d\n",ans);
	free(obs);
	free(h);
	return 0;
}

int comp(const void *p1,const void *p2){
	const observatories *n1, *n2;
	n1=(const observatories *)p1;
	n2=(const observatories *)p2;
	if(n1->ti==n2->ti){
		return n1->tj-n2->tj;
	}else{
		return n1->ti-n2->ti;
	}
}


Measured memory_bytes: 4952
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
typedef long long int ll;
using namespace std;
int main(){
	int N;
	cin >> N;
	for(int i=1;i<=9;i++){
		if(N<=i*111){
			cout << i*111 << endl;
			return 0;
		}
	}
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int
#define P pair<int, int>

vector<int> bit;
void bitinit(int n){
	bit=vector<int>(n);
}
int bitget(int i){
	if(i== -1) return 0;
	int ii=i+1, j=0;
	while((ii>>j&1)==0)j++;
	return bit[i]+bitget((ii& ~(1<<j))-1);
}
void bitadd(int i, int x){
	if(i>=bit.size()) return ;
	bit[i]+=x;
	int ii=i+1, j=0;
	while((ii>>j&1)==0)j++;
	ii+=(1<<j);
	bitadd(ii-1, x);
}

int main(){
	int n, q;
	cin>>n>>q;
	vector<int> c(n);
	rep(i, n) cin>>c[i];
	vector<vector<P>> qs(n);
	rep(i, q){
		int l, r;
		cin>>l>>r; l--; r--;
		qs[l].push_back(make_pair(r, i)); 
	}

	vector<int> pi(n+1, -1);
	vector<vector<int>> rs(n);
	rep(i, n){
		int p=pi[c[i]];
		if(p!= -1)
			rs[p].push_back(i);
		pi[c[i]]=i;
	}

	vector<int> ans(q);
	bitinit(n);
	for(int l=n-1; l>=0; l--){
		for(int s : rs[l]) bitadd(s, 1);
		for(P p : qs[l]){
			int r=p.first, qi=p.second;
			ans[qi]=(r-l+1)-bitget(r);
		}
	}

	rep(i, q) cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 59884
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N;
    cin >> N;
    char a;
    REP(i,N){
        cin >> a;
        if(a == 'Y'){
            cout << "Four" << "\n";
            return 0;
        }
    }
    cout << "Three" << "\n";
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair


using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

struct uf_tree {
	std::vector<int> parent;
	int __size;
	uf_tree(int size_) : parent(size_, -1), __size(size_) {}
	void unite(int x, int y) {
		if ((x = find(x)) != (y = find(y))) {
			if (parent[y] < parent[x]) std::swap(x, y);
			parent[x] += parent[y];
			parent[y] = x;
			__size--;
		}
	}
	bool is_same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
	int size(int x) { return -parent[find(x)]; }
	int size() { return __size; }
};



//!!!問題をちゃんと読む!!!
//!!!問題をちゃんと読め!!!
//!!!問題は読みましたか？!!!


signed main() {
	int N, K;
	cin >> N >> K;
	double ans = 0.0;

	for (int i = 1; i <= N; i++) {
		//最初にiがでたとすると、
		//logなので全探索OK
		double win = 1;
		int first = i;
		while (first < K) {
			win *= 0.5;
			first *= 2;
		}
		win /= N;
		ans += win;
	}
	cout << setprecision(11) << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  ll h,n,w;
    for(h=1;h<=3500;h++){
      for(n=1;n<=3500;n++){
        if(-N*(h+n)+4*h*n<=0) continue;
        if((h*n*N)%(4*h*n-N*h-N*n)==0){
          cout << h << " " << n << " " << (h*n*N)/(4*h*n-N*h-N*n) << endl;
          return 0;
        }
      }
    }
}

Measured memory_bytes: 256
// by tmt514
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define SZ(x) ((int)(x).size())
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
using namespace std;
typedef long long LL;

const int N = 200005;
LL dp[N][4][2], a[N];
LL rsum[N], lsum[N];
int main(void) {
  int n;
  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  for(int i=n;i>=0;i--) rsum[i] = rsum[i+1] + a[i];
  for(int i=1;i<=n;i++) lsum[i] = lsum[i-1] + a[i];
  const LL INF = (1LL<<50);
  dp[0][0][0] = 0;
  dp[0][1][0] = INF;
  dp[0][2][0] = INF;
  dp[0][0][1] = INF;
  dp[0][1][1] = INF;
  dp[0][2][1] = INF;

  LL ans = rsum[0];
  for(int i=1;i<=n;i++) {
    for(int o=0;o<=2;o++)
      for(int v=0;v<2;v++) dp[i][o][v] = INF;
    for(int o=0;o<=2;o++) {
      for(int v=0;v<2;v++) {
        if(o==0 && v==0) dp[i][0][0] = lsum[i];


        for(int w=0;w<2;w++) {
          int mo = ((a[i]+w)%2!=0);
          if(a[i]==0 && mo==0) mo+=2;
          LL &t = dp[i][o+((w+v)%2)][w];
          t = min(t, dp[i-1][o][v] + mo);
        }
      }
    }
    ans = min(ans, dp[i][0][0]+rsum[i+1]);
    ans = min(ans, dp[i][1][1]+rsum[i+1]);
    ans = min(ans, dp[i][2][0]+rsum[i+1]);
  }

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


Measured memory_bytes: 17408
import Text.Regex
import Data.Array

main :: IO ()
main= do
  cn<-getLine
  let n = read cn::Int
  dat<-getLine
  let listeddat = map read (words dat)::[Int]
  let arr       = listArray (1,n) listeddat
  print (solve arr n)

solve:: Array Int Int -> Int -> Int
solve arr n = div (sum [if x == arr ! (arr ! x) then 1 else 0 | x <- [1..n]]) 2


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



Measured memory_bytes: 2148
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
a=list(map(int,input().split()))
i=0
m=1000
f=True
k=0
M=[1000]
res=[0]*(n-1)
for i in range(1,n):
    if a[i]<a[i-1]:
        res[i-1]=-1
    else:
        res[i-1]=1

for i in range(n):

    if f:
        if i==n-1:
          break
        if res[i]==1:
            f=False 
            k=m//a[i]
            m=m%a[i]
        else:
          continue
    else:
        if i==n-1 or res[i]==-1:
            m=k*a[i]+m
            M.append(m)
            f=True 
        else:
            continue
print(max(M))
        

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#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(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF (INT_MAX/3)

int main() {
    int town_n, road_n, start, goal1, goal2;
    while (cin >> town_n >> road_n >> start >> goal1 >> goal2, town_n) {
        start--;
        goal1--;
        goal2--;

        vvi E(town_n, vi(town_n, INF));
        REP(i, town_n) E[i][i] = 0;
        REP(i, road_n) {
            int a, b, c;
            cin >> a >> b >> c;
            a--;
            b--;
            E[a][b] = c;
        }
        REP(i, town_n) REP(j, town_n) REP(k, town_n) E[j][k] = min(E[j][k], E[j][i] + E[i][k]);

        int mi = INF;
        REP(i, town_n) {
            mi = min(mi, E[start][i] + E[i][goal1] + E[i][goal2]);
        }
        cout << mi << endl;
    }
}

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

using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

template<typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; 
    return x *= f;
}

int n;
double d, x, ans = 0.0;

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif

    read(n); n <<= 1;
    scanf("%lf%lf", &d, &x);

    while(n > 0) {
        ans += ((n-1) * x + 2 * d) * 0.5;

        double td, tx;
        td = ((n + 2) * d + 5 * x) / n;
        tx = (n + 4) * x / n;

        d = td;
        x = tx;
        n -= 2;
    }
    printf("%.8lf\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    if(N==2){
        cout << 1 << "\n";
        return 0;
    }
    set<ll> s;
    for(ll i=1;i*i<=N-1;i++) if((N-1)%i==0){
        if(i!=1) s.insert(i);
        s.insert((N-1)/i);
    }

    auto check = [&](ll x){
        ll n = N;
        while(n%x==0) n /= x;
        return n%x==1;
    };

    for(ll i=1;i*i<=N;i++) if(N%i==0){
        if(i!=1 && check(i)) s.insert(i);
        if(check(N/i)) s.insert(N/i);
    }
    cout << s.size() << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100
#define INF 100000000

int n, M[N][N];
int d[N];
int Q[N];
int head, tail;

void enqueue(int x){

  Q[tail] = x;

  if(tail+1 == N){
    tail = 0;
  } else {
    tail++;
  }
}

int dequeue(){
  int x;

  x = Q[head];
  if(head+1 == N){
    head = 0;
  } else {
    head++;
  }
  return x;
}

void bfs(int s){
  int u, i, v, check=0;

  enqueue(s);

  for(i=0; i<n; i++) d[i] = INF;
  d[s] = 0;

  while(head != tail){
    u = Q[head];
    dequeue();
    for(v=0; v<n; v++){
      if(M[u][v] == 0) continue;
      if(d[v] != INF) continue;
      d[v] = d[u]+1;
      enqueue(v);
    }
  }

  for(i=0; i<n; i++){
    check = (d[i]==INF) ? (-1) : d[i];
    printf("%d %d\n", i+1, check);
  }

}

int main(){
  int i, j, u, k, v;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      M[i][j] = 0;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d %d", &u, &k);
    u--;
    for(j=0; j<k; j++){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }

  bfs(0);

  return 0;
}

Measured memory_bytes: 636
S = input()
N = len(S)

# 1,3,...文字目が'R'でも'U'でも'D'でもない、または、2,4,...文字目が'L'でも'U'でも'D'でもないとき、'No'を出力する
ans = 'Yes'
for i in range(N):
  if (i % 2 == 0 and S[i] != 'R' and S[i] != 'U' and S[i] != 'D') or (i % 2 == 1 and S[i] != 'L' and S[i] != 'U' and S[i] != 'D'):
    ans = 'No'
    break
    
print(ans)

Measured memory_bytes: 9052
import scala.io.StdIn.{readLine, readInt}

object Main extends App {
  var str = readLine()
  val m = readInt()
  for (_ <- 1 to m) {
    val line = readLine().split(" ")
    val cmd = line(0)
    val start = line(1).toInt
    val end = line(2).toInt + 1
    val Array(p1, p2, p3) = splitStr(str, start, end)
    cmd match {
      case "replace" => str = s"$p1${line(3)}$p3"
      case "reverse" => str = s"$p1${p2.reverse}$p3"
      case "print" => println(p2)
    }
  }

  def splitStr(str: String, start: Int, end: Int): Array[String] = {
    val arr = Array[String]("", "", str.substring(end))
    if (start == 0) {
      arr(1) = str.substring(0, end)
    } else {
      arr(0) = str.substring(0, start)
      arr(1) = str.substring(start, end)
    }
    arr
  }
}



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

int main(){
    int N;
    string S;
    cin >> N >> S;
    string good_string = "";
    int open_bracket = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == '('){
            open_bracket++;
            good_string.push_back(S[i]);
        }else if(S[i] == ')' && open_bracket){
            open_bracket--;
            good_string.push_back(S[i]);
        }else{
            good_string.insert(good_string.begin(), '(');
            good_string.push_back(S[i]);
        }
    }
    cout << good_string;
    for(int i = 0; i < open_bracket; i++){
        cout << ")";
    }
    cout << endl;
}


Measured memory_bytes: 256
use std::collections::VecDeque;

const MAX_BIT: usize = 32;

fn main() {
    let mut sc = Scanner::new();
    let n = sc.read();
    let x: Vec<usize> = sc.read_vec(n);
    let l = sc.usize_read();
    let mut go = vec![vec![0; n]; MAX_BIT];
    let mut q = VecDeque::new();
    q.push_back(0);

    for i in 1..n {
        while !q.is_empty() {
            let head = q.pop_front().unwrap();
            let dx = x[i] - x[head];
            if dx > l {
                go[0][head] = i - 1;
            } else {
                q.push_front(head);
                break;
            }
        }
        q.push_back(i);
    }
    while let Some(head) = q.pop_front() {
        go[0][head] = n - 1;
    }

    for b in 1..MAX_BIT {
        for i in 0..n {
            go[b][i] = go[b - 1][go[b - 1][i]];
        }
    }

    let q = sc.read();
    for _ in 0..q {
        let a = sc.usize_read() - 1;
        let b = sc.usize_read() - 1;
        let (a, b) = if a > b { (b, a) } else { (a, b) };
        let mut cur = a;
        let mut ng = 0;
        for bit in (0..MAX_BIT).rev() {
            if go[bit][cur] < b {
                ng += (1 << bit);
                cur = go[bit][cur];
            }
        }
        println!("{}", ng + 1);
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 39292
def solve():
  N, W = map(int, input().split())
  INF = 1e9 + 5
  dp = [INF]  * (100001)
  dp[0] = 0
  items = []
  for i in range(N):
    w, v = map(int, input().split())
    items.append((w, v))

  sum_v = 0
  for w, v in items:
    sum_v += v
    temp_dp = list(dp) 
    for i in range(v, sum_v + 1):
      if temp_dp[i - v] != INF:
        dp[i] = min(temp_dp[i], temp_dp[i - v] + w)

  for i in range(100000, -1, -1):
    if dp[i] != INF and dp[i] <= W:
      print(i)
      break
      

if __name__ == "__main__":
  solve()


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

int main()
{
    string S;
    cin >> S;
    int A[4];
    for (int i = 0; i < 4; ++i) {
        A[i] = stoi(S.substr(i, 1));
    }

    int i = 0;
    for (i = 0; i < 1<<3; ++i) {
        int tmp = A[0];
        for (int k = 0; k < 3; ++k) {
            if (i>>k & 1) {
                tmp += A[k+1];
            } else {
                tmp -= A[k+1];
            }
        }
        if (tmp == 7) {
            break;
        }
    }

    cout << A[0];
    for (int k = 0; k <3; ++k) {
        cout << ((i>>k & 1) ? "+" : "-") << A[k+1];
    }
    cout << "=7" << endl;

    return 0;
}

Measured memory_bytes: 256
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1 << 28;
const ll MOD = 1000000007LL;

char board[1010][1010];

int rec[1010][1010][5];
int H, W;

struct Elem {
    int x, y, bit;
};
 
signed main() {
    while(cin >> W >> H, W || H) {
        int sx, sy, gx, gy;
        for(int i=0; i<H; i++) {
            for(int j=0; j<W; j++) {
                cin >> board[i][j];

                if(board[i][j] == 'S') sx = i, sy = j;
                if(board[i][j] == 'G') gx = i, gy = j;
                if('0' <= board[i][j] and board[i][j] <= '9') {
                    int c = board[i][j] - '0';
                    board[i][j] = (char)(c - 1 + '0');
                }
            }
        }

        const pair<int, int> NIL(INF, INF);
        pair<int, int> ans = NIL;

        for(int p=0; p<5; p++) {
            fill(rec[0][0], rec[H][0], INF);
            rec[sx][sy][0] = 0;

            queue<Elem> que;
            que.push(Elem{sx, sy, 0});

            while(que.size()) {
                Elem cur = que.front(); que.pop();
                int x = cur.x, y = cur.y, bit = cur.bit;
                if(x == gx and y == gy and bit == 4) break;

                for(int k=0; k<4; k++) {
                    int nx = x + dx[k], ny = y + dy[k];
                    if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
                    
                    int nbit = bit;
                    if('0' <= board[nx][ny] and board[nx][ny] <= '9') {
                        int c = (board[nx][ny] - '0' - p + 15) % 5;
                        bool ok = (bit + 1 >= c);
                        
                        nbit = ok ? max(bit, c) : bit;
                    }
                
                    if(rec[nx][ny][nbit] > rec[x][y][bit] + 1) {
                        rec[nx][ny][nbit] = rec[x][y][bit] + 1;
                        que.push(Elem{nx, ny, nbit});
                    }
                }
            }

            ans = min(ans, make_pair(rec[gx][gy][4], p+1));
        }
        if(ans.first == INF) cout << "NA" << endl;
        else cout << ans.second << " " << ans.first << endl;
    }
    return 0;
}


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

#define X first
#define Y second

using namespace std;

const int MAXN = 1e5 + 1;

vector<pair<int,int>> nxt[MAXN];
bool vis[MAXN];
bool col[MAXN];

void paint(int v) {
	vis[v] = 1;
	for(auto e : nxt[v]) {
		if(vis[e.X]) continue;
		col[e.X] = col[v] ^ (e.Y & 1);
		paint(e.X);
	}
}


int main() {
	ios_base::sync_with_stdio(0);
	
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		nxt[x].push_back({y,w});
		nxt[y].push_back({x,w});
	}
	
	paint(1);
	
	for(int v = 1; v <= n; v++) {
		cout << col[v] << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

// UnionFind
struct UnionFind{
  VI par,sizes; // par[i]:iの親の番号
  UnionFind(int n) : par(n), sizes(n,1){ // 最初は全てが根であるとして初期化
    rep(i,n) par[i] = i;
  }
  int root(int x){
    if(par[x]==x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y){
    int rx = root(x); int ry = root(y);
    if(rx==ry) return;
    if(sizes[rx]<sizes[ry]) swap(rx,ry);
    par[ry] = rx;
    sizes[rx] += sizes[ry];
  }
  bool same(int x, int y){
    return root(x)==root(y);
  }
  int size(int x){
    return sizes[root(x)];
  }
};


signed main(){
  int n; cin>>n;
  VVI x, y;
  rep(i,n){
    int a,b; cin>>a>>b;
    VI x0, y0; x0.PB(a); x0.PB(i); y0.PB(b); y0.PB(i);
    x.PB(x0); y.PB(y0);
  }
  sort(ALL(x)), sort(ALL(y));

  using edge = pair<int, PII>;
  vector<edge> edges;
  rep(i,n-1){
    int s = x[i][1], t = x[i+1][1];
    edges.PB(edge(x[i+1][0]-x[i][0], PII(s,t)));
    int u = y[i][1], v = y[i+1][1];
    edges.PB(edge(y[i+1][0]-y[i][0], PII(u,v)));
  }
  sort(ALL(edges));
  // cerr << edges[0].first SP edges[0].second.first SP edges[0].second.second << endl;
  // ここまでは動作確認済み

  UnionFind uf(n);
  ll ans = 0;
  for(auto e : edges){
    int u = e.second.first, v = e.second.second;
    ll cost = e.first;
    if(uf.same(u,v)) continue;
    uf.unite(u,v);
    ans += cost;
  }
  cout << ans << endl;



  return 0;
}


Measured memory_bytes: 17888
#include <iostream>
using namespace std;
int main() {
	int a, b, c, x, i;
	cin >> a >> b >> c;
	for(i=a;i<b+1;i++) {
		if(c%i==0){
			x = x + 1;
			
		}
	}
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>
main(){
  int a,b,sum;
  char op;
  while(1){
    scanf("%d %c %d",&a,&op,&b);
    if(op=='?')break;
    if(op=='+'){
      sum=a+b;
    }
    else if(op=='-'){
      sum=a-b;
    }
    else if(op=='*'){
      sum=a*b;
    }
    else if(op=='/'){
      sum=a/b;
    }
    printf("%d\n",sum);
  } 
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef double ll;
typedef pair<double,int> P;
int n;
ll G[101][101];

void dijkstra(int s,int g){
  ll D[101];
  int from[101];
  for(int i=0;i<101;i++) D[i]=INF;
  priority_queue<P,vector<P>,greater<P> > Q;
  D[s]=0;
  Q.push(P(0,s));

  while(!Q.empty()){
    P t=Q.top(); Q.pop();
    int pos=t.second;
    ll cost=t.first;
    if(pos==g) break;
    if(D[pos]<cost) continue;
    
    for(int i=0;i<n;i++){
      if(G[pos][i]==-1||i==pos)continue;
      if(cost+G[pos][i]<D[i]){
	Q.push(P(cost+G[pos][i],i));
	D[i]=cost+G[pos][i];
	from[i]=pos;
      }
    }
  }

  if(D[g]==INF){cout<<"NA"<<endl;return;}
    
  vector<int> res;
  res.push_back(g);
  int pos=g;
  while(pos!=s){
    pos=from[pos];
    res.push_back(pos);
  }

  for(int i=0;i<res.size();i++){
    if(i) cout<<" ";
    cout<<res[res.size()-1-i]+1;
  }
  cout<<endl;
}


int main(){
  while(cin>>n,n){
    ll x[101],y[101];
    for(int i=0;i<n;i++){
      int b;
      cin>>b;
      cin>>x[b-1]>>y[b-1];
    }
    
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++){
	ll X=(x[i]-x[j]);
	ll Y=(y[i]-y[j]);
	ll dis=sqrt(X*X+Y*Y);
	if(dis>50) G[i][j]=G[j][i]=-1;
	else G[i][j]=G[j][i]=dis;
    }

  int m;
  cin>>m;
  while(m--){
    int s,g;
    cin>>s>>g;
    dijkstra(s-1,g-1);
  }
  }
  return 0;
}

Measured memory_bytes: 3280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    ll n, period;
    cin >> n >> period;
    vector<ll> t(n);
    for (int i = 0; i < n; ++i) cin >> t[i];
    ll ans = 0;
    for (int i = 1; i < n; ++i)
    {
        if (period > t[i] - t[i - 1])
        {
            ans += t[i] - t[i - 1];
        }
        else
        {
            ans += period;
        }
    }
    ans += period;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4796
h, w = map(int, input().split())

num2alpha = lambda c: chr(c+64)

for i in range(h):
  l = list(map(str, input().split()))
  for j in range(w):
    if l[j] == 'snuke':
      y = i+1
      x = num2alpha(j+1)
      print(str(x)+str(y))
      exit()

Measured memory_bytes: 38384
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
//#include<unordered_map>
//#include<unordered_set>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define RREP(i,n) for(int i=1; i<=(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> P; 
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 100005;
//////////////////////////////

const int mx = 300 * 300;
Int dp[330][mx + 330], dp2[330][mx + 330];

void add(Int& a, Int b) {
	a = (a + b) % MOD2;
}

void mul(Int& a, Int b) {
	a = (a*b) % MOD2;
}

void solve()
{
	int n, a[330];
	cin >> n;
	int sum = 0;
	REP(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	
	dp[0][0] = 1;
	dp2[0][0] = 1;
	REP(i, n) REP(j, mx + 1) {
		add(dp[i + 1][j + a[i]], dp[i][j]);
		add(dp[i + 1][j], 2 * dp[i][j]);
		add(dp2[i + 1][j + a[i]], dp2[i][j]);
		add(dp2[i + 1][j], dp2[i][j]);
	}

	Int sub = 0;
	for (int j = (sum + 1) / 2; j <= mx; j++) add(sub, dp[n][j]);
	if (sum % 2 == 0) add(sub, MOD2 - dp2[n][sum / 2]);
	mul(sub, 3);

	Int ans = 1;
	REP(i, n) mul(ans, 3);
	add(ans, MOD2 - sub);
	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}



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

#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0);
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(x) x.begin(),x.end()
#define V(x) vector<x>
#define P(x,y) pair<x,y>
#define UMP(x,y) unordered_map<x,y>
#define MP(x,y) map<x,y>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define inf 1e18
#define endl "\n"
#define coutd(n) cout << fixed << setprecision(n)
#define watch(x) cout<<#x<<" = "<<x<<endl;
typedef double db;
typedef long double ld;	
const int mod = 1000000007;

using namespace std;

int32_t main(){
    fast
    	
    //int t;
	//cin>>t;
	//rep(_,0,t){	
		
	//}
	int n;
	cin>>n;
	n = n%10;
	if(n == 3)
		cout<<"bon";
	else if(n== 0 || n== 1 || n==6 || n==8)
		cout<<"pon";
	else
		cout<<"hon";
    return 0;
}


Measured memory_bytes: 3652
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]
v = 0
last = [0 for _ in range(len(c))]

for day in range(D):
    v += s[day][t[day]-1] 
    last[t[day]-1] = day + 1
    for j in range(len(c)):
        v -= c[j]*(day + 1 - last[j])
    print(v)

Measured memory_bytes: 9084
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;


int main()
{
   FAST/**/
   
   ll n,k;
   cin>>n>>k;
   
   ll r,s,p;
   cin>>r>>s>>p;
   
   string t;
   cin>>t;
   bool mark[n];
   memset(mark,0,sizeof(mark));
   vector<ll> v[3];
   rep(n)
   {
       if(t[i] == 'r')
            v[0].pb(i);
       else if(t[i] == 'p')
            v[1].pb(i);
       else v[2].pb(i);        
   }
   
   bool tak = 0;
   ll ans = 0;
   for(ll i=0;i<v[0].size();i++)
   {
       if(v[0][i]<k)
       {
           ans+=p;
           mark[v[0][i]] = 1;
           continue;
       }
       
       if(mark[v[0][i]-k])
            continue;
       ans+=p;
       mark[v[0][i]] = 1;        
   }
   
   tak = 0;
   memset(mark,0,sizeof(mark));
   
   for(ll i=0;i<v[1].size();i++)
   {
       if(v[1][i]<k)
       {
           ans+=s;
           mark[v[1][i]] = 1;
           continue;
       }
       
       if(mark[v[1][i]-k])
            continue;
       ans+=s;
       mark[v[1][i]] = 1;        
   }
   
   tak = 0;
   memset(mark,0,sizeof(mark));
   
   for(ll i=0;i<v[2].size();i++)
   {
       if(v[2][i]<k)
       {
           ans+=r;
           mark[v[2][i]] = 1;
           continue;
       }
       
       if(mark[v[2][i]-k])
            continue;
       ans+=r;
       mark[v[2][i]] = 1;        
   }
   
   cout<<ans;
   
   
   return 0;        
}  
   

Measured memory_bytes: 1736
#include<stdio.h>
#include<string.h>

#define LEN 100000

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b){return a < b ? a : b ;}

int main(){
  
  int elaps = 0, c;
  int i, q;
  P u;
  
  scanf("%d%d",&n,&q);

  for(i = 1 ; i <= n ; i++)
    {
      scanf("%s",Q[i].name);
      scanf("%d",&Q[i].t);
    }

  head = 1 ; tail = n + 1;

  while(head != tail)
    {
      u = dequeue();
      c = min(q, u.t);
      u.t -= c;
      elaps += c;
      if(u.t > 0)
	{
	  enqueue(u);
	}
      else
	{
	  printf("%s %d\n",u.name, elaps);
	}
    }
  return 0;
}


Measured memory_bytes: 11884
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll a,b,n;
    cin >> a >> b >> n;
    ll ans = 0;
    if(n<b-1){
        ans = a*n/b - a*(n/b);
    }else{
        ans = a*(b-1)/b - a*((b-1)/b);
        debug(b-1/b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3652
//2004 366 1/1 Thursday

#include <cstdio>

using namespace std;

void today(int mon, int day);

int main()
{
	int mon, day;
	
	while (1){
		scanf("%d %d", &mon, &day);
		
		if (mon == 0){
			break;
		}
		
		today(mon, day);
	}
	
	return (0);
}

void today(int mon, int day)
{
	int tmp = 0;
	
	for (int i = 1; i < mon; i++){
		if (i == 4 || i == 6 || i == 9 || i == 11){
			tmp += 30;
		}
		else if (i == 2){
			tmp += 29;
		}
		else {
			tmp += 31;
		}
	}
	
	switch ((tmp + day) % 7){
	  case 0:
	    puts("Wednesday");
		break;
		
	  case 1:
	    puts("Thursday");
		break;
		
	  case 2:
	    puts("Friday");
		break;
		
	  case 3:
	    puts("Saturday");
		break;
		
	  case 4:
	    puts("Sunday");
		break;
		
	  case 5:
	    puts("Monday");
		break;
		
	  case 6:
	    puts("Tuesday");
		break;
	}
}

Measured memory_bytes: 1012
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
 
const ll INF=1e9+7;

ll dp[5005][5005];

int main(){
    ll n;
    cin >> n;
    string s;
    cin>> s;
    for(ll i=n-1;i>=0;i--){
        for(ll j=n-1;j>=0;j--){
            if(s[i]!=s[j]) dp[i][j]=0;
            else dp[i][j]=dp[i+1][j+1]+1;
        }
    }
    ll ans=0;
    rep(i,n){
        rep(j,n){
            if(j<=i) continue;
            ll now=min(dp[i][j],j-i);
            ans=max(ans,now);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 199108
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int result = 0;
		for (int i = 0; i < 2; i++ ) {
			if (A > B) {
				result += A;
				A--;
			} else {
				result += B;
				B--;
			}
		}

		System.out.println(result);
	}

}


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

const int MAXN = 200005;
const int M = 2019;

 
char s[MAXN];
int cnt[M + 3];
 
int main() {
  ll res = 0;
  string s;
  cin>>s;
  int len = s.size(), t = 0, p = 1;
  for (int i = len - 1; i >= 0; --i) {
    ++cnt[t];
    t += (s[i] - 48) * p;
    t %= M;
    res += cnt[t];
    p = p * 10 % M;
  }
  cout<<res;
  return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	auto a = vector<vector<int>>(3, vector<int>(n + 1));
	for(auto i = 1; i <= 2; ++i){
		for(auto j = 1; j <= n; ++j){
			cin >> a[i][j];
		}
	}
	for(auto i = 1; i <= 2; ++i){
		for(auto j = 1; j <= n; ++j){
			a[i][j] += max(a[i - 1][j], a[i][j - 1]);
		}
	}
	cout << a[2][n] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n,sum=0,ma=0,hoge;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>hoge;
        sum+=hoge;
        ma=max(hoge,ma);
    }
    sum-=ma/2;
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    int n;
    cin >> n;
    vector<int> e(n-1);
    const int N = 100000;
    int color[N];
    rep(i,N) color[i] = i+1;
    // 辺の番号と次のノード
    vector<vector<P>> to(n);
    // ノードを訪れたか
    vector<bool> visited(n, false);
    int a, b;
    rep(i,n-1) {
        cin >> a >> b;
        a--; b--;
        to[a].emplace_back(i,b);
        to[b].emplace_back(i,a);
    }
    // ノードと前の辺の色
    queue<P> q;
    q.emplace(0, 0);
    int c_n, f_c, n_n, n_c;
    visited[0] = true;
    while (!q.empty()) {
        c_n = q.front().first;
        f_c = q.front().second;
        q.pop();
        int j = 0;
        rep(i,to[c_n].size()) {
            n_n = to[c_n][i].second;
            // 訪れとことがある場合はとばす
            if (visited[n_n]) {j--; continue;}
            // 色がかぶる場合は一つ色を増やす
            if (color[i+j] == f_c) j++;
            n_c = color[i+j];
            visited[n_n] = true;
            e[to[c_n][i].first] = n_c;
            q.emplace(n_n, n_c);
        }
    }
    int max_c = 0;
    rep(i,n-1) {
        max_c = max(max_c, e[i]);
    }
    cout << max_c << endl;
    rep(i,n-1) cout << e[i] << endl;
    
    return 0;
}

Measured memory_bytes: 7424
import sys
input = sys.stdin.readline

n,k = map(int, input().split())
As = [int(input()) for i in range(n)]

# N: 処理する区間の長さ

INF = 0

mx = 300001
LV = (mx-1).bit_length()
N0 = 2**LV
data = [INF]*(2*N0)
lazy = [None]*(2*N0)

# 伝搬対象の区間を求める
def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
        lazy[i-1] = None

# 区間[l, r)をxで更新
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = x
        if L & 1:
            lazy[L-1] = data[L-1] = x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = max(data[2*i-1], data[2*i])

# 区間[l, r)内の最小値を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])
        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

ans = 0
update(As[0],As[0]+1,1)
for i, a in enumerate(As[1:]):
    l = max(0,a-k)
    r = min(mx,a+k)
    upd = query(l,r+1)
    if upd == -1:continue
    # print("i",i,"a",a,"upd",upd,"l",l,"r",r)
    update(a, a+1, upd+1)
    ans = max(ans, upd+1)
print(ans)



Measured memory_bytes: 111052
#include<bits/stdc++.h>
using namespace std;
int n,a[100010],Q,L,f[100010][31];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	scanf("%d",&L);
	for(int i=1,pos=2;i<=n;i++){
		while(pos<=n&&a[pos]-a[i]<=L) pos++;
		f[i][0]=pos-1;
	}
	for(int i=1;i<=30;i++)
		for(int j=1;j<=n;j++)
			f[j][i]=f[f[j][i-1]][i-1];
	scanf("%d",&Q);
	while(Q--){
		int x,y,num=0;
		scanf("%d%d",&x,&y);
		if(x>y) swap(x,y);
		for(int i=30;i>=0;i--){
			if(f[x][i]>=y) continue;
			num+=(1<<i); x=f[x][i];
		}
		printf("%d\n",num+1);
	}
	return 0;
}

Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef long double ld;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; };
int main(){
  string s; cin>>s;
  reverse(all(s));
  string t="";
  for(int i=0 ; i<s.size() ; ){
    if(s[i]=='B'){
      int j=i;
      while(s[j]=='B'&&j<s.size()) j++;
      i += 2*(j-i);
    }else{
      t += s[i++];
    }
  }
  reverse(all(t));
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

int t[505][505];

void check(int p,int q,int v){
	int i,j,k;
	int a,b,c;
	if(q-p<=2){
		for(i=p;i<q;i++){
			for(j=i+1;j<q;j++){
				t[i][j]=v;
			}
		}
		return;
	}
	a=(q+p)/2;
	for(i=p;i<a;i++){
		for(j=a;j<q;j++){
			t[i][j]=v;
		}
	}
	check(p,a,v+1);
	check(a,q,v+1);
}

int main(){
	int n;
	int i,j,k;
	int a,b,c;
	cin>>n;
	check(0,n,1);
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++)printf("%d%c",t[i][j],(j!=n-1?' ':'\n'));
	}
}
	
	


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,W; cin>>n>>W;
	int V=0;
	vector<int>w(n),v(n);
	for(int i=0;i<n;++i){
		cin>>w.at(i)>>v.at(i);
		V+=v.at(i);
	}
	vector<int64_t>dp(V+1,1e9);
	dp.front()=0;
	for(int i=0;i<n;++i){
		for(int j=V;j>=v.at(i);--j){
			dp.at(j)=min(dp.at(j),dp.at(j-v.at(i))+w.at(i));
		}
	}
	int ans=0;
	for(int i=V;i>=0;--i){
		if(dp.at(i)<=W){
			ans=i;
			break;
		}
	}
	cout<<ans<<"\n"s;
}


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

int main(void){
    int a,b;
    cin>>a>>b;
    if(a%2==1){
        if(b%2==1){
            cout<<"Yes"<<endl;
        
        }else{
            cout<<"No"<<endl;
        }
    }else {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256