akhauriyash/Code-Regression huggingface dataset:
from random import randint
import sys
input = sys.stdin.readline
INF = 9223372036854775808


def calc_score(D, C, S, T):
    """
    開催日程Tを受け取ってそこまでのスコアを返す
    コンテストi 0-indexed
    d 0-indexed
    """
    score = 0
    last = [0]*26  # コンテストiを前回開催した日
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]
    return score


def update_score(D, C, S, T, score, ct, ci):
    """
    ct日目のコンテストをコンテストciに変更する
    スコアを差分更新する

    ct: change t 変更日 0-indexed
    ci: change i 変更コンテスト 0-indexed
    """
    last = [0]*26  # コンテストiを前回開催した日
    for d in range(ct):
        last[T[d]] = d + 1
    prei = T[ct]  # 変更前に開催する予定だったコンテストi
    score -= S[ct][prei]
    score += S[ct][ci]
    for d in range(ct, D):
        if d != ct and T[d] == prei:
            break
        score += C[prei]*(d + 1 - ct - 1)
        score -= C[prei]*(d + 1 - last[prei])
    for d in range(ct, D):
        if d != ct and T[d] == ci:
            break
        score += C[ci]*(d + 1 - last[ci])
        score -= C[ci]*(d + 1 - ct - 1)
    T[ct] = ci
    return score, T


def local_search(D, C, S, T, today_score, d):
    pass


def evaluate(D, C, S, T, k):
    """
    d日目終了時点での満足度を計算し，
    d + k日目終了時点での満足度の減少も考慮する
    """
    score = 0
    last = [0]*26
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]

    for d in range(len(T), min(len(T) + k, D)):
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
    return score


def greedy(D, C, S, k):
    T = []  # 0-indexed
    for d in range(D):
        # d日目終了時点で満足度が一番高くなるようなコンテストiを開催する
        max_score = -INF
        best_i = 0
        for i in range(26):
            T.append(i)
            score = evaluate(D, C, S, T, k)
            if max_score < score:
                max_score = score
                best_i = i
            T.pop()
        T.append(best_i)
    return T


if __name__ == '__main__':
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    T = greedy(D, C, S, 10)
    for t in T:
        print(t+1)


Measured memory_bytes: 83944
# include <stdio.h>

int min(int a,int b){
  int m=a;
  if (m>b) m=b;
  return m;
}

int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  printf("%d\n",min(a,b)+min(c,d));
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,M;cin >> N >> M;
  int N_ = 1;
  rep(i,N-1) N_*=10;
  vector<PII> v(M);
  rep(i,M){
    cin >> v[i].first >> v[i].second;
    v[i].first = N - v[i].first;
  }
  rep(x,1000){
    if(N==1 && x==0){
      bool sat = true;
      rep(i,M){
        if(v[i].second != 0) sat = false;
      }
      if(sat){
        cout << x << endl;
        return 0;
      }
    }

    if(x<N_ || x>=10*N_)continue;
    bool sat = true;
    rep(i,M){
      int s_ = 1;
      rep(j,v[i].first) s_*=10;
      if((x/s_)%10 != v[i].second) sat = false;
    }
    if(sat){
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
use v5.18;
use warnings;
sub read_line { chomp(my $str = <STDIN>); $str }
sub splited_read_line { split / /, read_line }

my $n = read_line;
my @nums = sort { $a <=> $b } splited_read_line;
say( abs($nums[-1] - $nums[0]) );


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define nl cout<<"\n"
#define endl "\n"
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c.size())
#define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++)
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define f first
#define s second

inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a; a%=b;return gcd(b,a);}
ll power(ll x, ll y){if(y == 0) return 1; ll a = power(x,y/2);if (y % 2 == 0) return a * a; else return x * a * a; }
ll powermod(ll x, ll ex , ll md) {ll ans = 1ll;while (ex > 0) {if (ex & 1ll) ans = (ans * x) % md; ex >>= 1ll;x = (x * x) % md;}return ans;}

const ll inf = 1e18 + 9;
const ll mod = 1e9 + 7;
const ld PI = acos(-1);
const ld eps = 1e-9;

const ll N = 1e5 + 11;

void solve(){
    ll n;
    cin >> n;
    n %= 1000;
    n = 1000 - n;
    n %= 1000;
    cout << n << endl;
}
int main(){
    IOS;
    cout << fixed << setprecision(20);
    ll NTC = 1;
    // cin >> NTC;
    ll PTC = 0;
    while(PTC++ < NTC){
        // cout << "Case #" << PTC << ":" << ' ';
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 3800
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)

#define cio ios::sync_with_stdio(false); // Do not use it with "scanf" and other c input!
#define pb push_back
#define rep(i,a,b) for (int i = a;i <= b;i ++)
#define pre(i,a,b) for (int i = a;i >= b;i --)
#define REP(i,a,b) for (int i = a;i < b;i ++)

#define _read(a,s,n) rep(i,s,n) scanf("%d",a + i);
#define _READ(a,s,n) REP(i,s,n) scanf("%d",a + i);

#define _read_ll(a,s,n) rep(i,s,n) scanf("%lld",a + i);
#define _READ_ll(a,s,n) REP(i,s,n) scanf("%lld",a + i);

#define _T_(T) int T;scanf("%d",&T);while (T --)

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    int n;
    scanf("%d",&n);
    int a[200010];
    int b[200010];
    rep(i,1,n) scanf("%d%d",a + i,b + i);
    sort(a + 1,a + n + 1);
    sort(b + 1,b + n + 1);
    if (n % 2) {
        printf("%d\n",b[(n + 1) / 2] - a[(n + 1) / 2] + 1);
    } else {
        printf("%d\n",b[n / 2] + b[n / 2 + 1] - a[n / 2] - a[n / 2 + 1] + 1);
    }
    
}


Measured memory_bytes: 5324
#include <stdio.h>

int main (){
	int n; 
	scanf("%d", &n);

	if (n % 1000 == 0){
		puts ("0");
}
	else {
		printf("%d\n", ((n / 1000) + 1) * 1000 - n);
	}
	
	return 0;
}


Measured memory_bytes: 1732
void main()
{
    int[] tmp = readln.split.to!(int[]);
    int h = tmp[0], w = tmp[1];

    string result;
    foreach (i; 1 .. h+1)
    {
        string[] s = readln.split;
        foreach (j, u; uppercase)
        {
            if (s[j] == "snuke")
            {
                result = u ~ i.to!string;
            }

            if (j == w - 1) break;
        }
    }

    result.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
#define rep(i, n) for(int i = 0; i < n; i++)
#define ll long long
using namespace std;


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  rep(i, n) {
    int a, b, c;
    cin >> a >> b >> c;
    if ((a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)) {
      cout << "YES" << "\n";
    } else {
      cout << "NO" << "\n";
    }
  }
  return 0;
}



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

using namespace std;

const int INF = 1e9;
const int N = 1e5;
const int MOD = 1e9 + 7;

const double PI = acos(-1);



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, m;
    cin >> m >> n;
    pair<int, int> a[n];
    for (auto& x : a)
        cin >> x.first >> x.second;
    sort(a, a + n);
    int mn = INF, ans = 1;
    for (auto x : a) {
        mn = min(mn, x.second);
        if (x.first >= mn) {
            ans++;
            mn = x.second;
        }
    }
    cout << ans;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n;
  cin >> n;
  if(n==1){
    cout << 1;
    return 0;
  }
  long long b = 1LL << (64- __builtin_clzll(n));
  cout << b-1 << endl;
}

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


int n;
int h[100010];
int dp[100010];

int main(){

    cin >> n;
    for(int i = 1; i <= n; i++) cin >> h[i];

    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);

    for(int i = 3; i <= n; i++){
        dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1], abs(h[i] - h[i-2]) + dp[i-2]);
    }

    cout << dp[n] << endl;

    return 0;
}

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

int dp[5010][5010], mod = 1e9 + 7;
int main(int argc, char *argv[]){
  int n, l;
  cin >> n >> l;
  int x[n], a[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  memset(dp, 0, sizeof(dp));
  dp[0][x[0]] = 1;
  for (int i = x[0] + 1; i < l; i++) {
    if(a[0] == 0){
      dp[0][i] = dp[0][i - 1];
      continue;
    }
    if((i - x[0])%a[0] == 0) dp[0][i] = (dp[0][i - 1] + 1)%mod;
    else dp[0][i] = dp[0][i - 1];
  }
  for (int i = 1; i < n; i++) {
    dp[i][x[i]] = dp[i - 1][x[i] - 1];
    if(a[i] == 0){
      for (int j = x[i] + 1; j < l; j++) {
        dp[i][j] = dp[i - 1][j];
      }
     continue; 
    }
    for (int j = x[i] + 1; j < l; j++) {
      if((j - x[i])%a[i] == 0){
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1])%mod;
      }else{
        dp[i][j] = dp[i][j - 1];
      }
    }
  }
  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < l; j++) {
  //     std::cout << dp[i][j] << " ";
  //   }
  //   std::cout << std::endl;
  // }
  std::cout << dp[n - 1][l - 1] << std::endl;
  return 0;
}

Measured memory_bytes: 99252
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=0
y=0
for i in range(n):
    v=max(0,a[i]-y)
    if v<=b[i]:
        s+=a[i]
        y=b[i]-v
    elif v>b[i]:
        s+=b[i]+y
        y=0
print(s+min(a[-1],y))

Measured memory_bytes: 18624
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int MOD = 998244353;
const int MXN = 2e5 + 10;

vector<int> fac(MXN);

int add(int x, int y) {
	return (x+y) % MOD;
}

int sub(int x, int y) {
	return add(x, MOD-y);
}

int mul(int x, int y) {
	return (x*1ll*y) % MOD;
}

int bp(int x, int y) {
	int ans = 1;
	while (y) {
		if (y&1) ans = mul(ans, x);
		x = mul(x, x);
		y/=2;
	}
	return ans;
}

int inv(int x) {return bp(x, MOD-2);}

int com(int n, int k) {
	return mul(fac[n], inv(mul(fac[k], fac[n-k])));
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	fac[0] = fac[1] = 1;
	for (int i=2; i<=n; i++) {
		fac[i] = mul(fac[i-1], i);
	}
	
	int ans = 0;
	for (int i=0; i<=k; i++) {
		ans = add(ans, mul(mul(com(n-1, i), m), bp(m-1, n-i-1)));
	}
	cout << ans;
}

Measured memory_bytes: 3880
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int N, K;
    cin >> N >> K;
    int M = N / 2 + N % 2;
    cout << ((M >= K) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=5005;
string ch[maxn*6];
char s[maxn];
int n,k,cnt;
int main()
{
    scanf("%s%d",s,&k),n=strlen(s);
    for(int i=0,T;i<n;i++)
    {
        ch[++cnt]=s[i];T=min(k,n-i);
        for(int j=1;j<T;j++,cnt++) ch[cnt+1]=ch[cnt]+s[i+j];
    }
    sort(ch+1,ch+cnt+1);unique(ch+1,ch+cnt+1);
    cout<<ch[k]<<endl;
    return 0;
}

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

using namespace std;

#define rep(i, a, b) for(auto (i)=a;i<b;i++)
#define list(i, N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

template<class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n; cin >> n;
    int a[n]; list(i,n) cin >> a[i];
    int sum = 0; list(i,n) sum += a[i];
    list(i,n) a[i] *= 2;
    int m[n];
    //Find m[n-1] first and then find the other values
    //subtract a[0] and a[evenNum] from this
    for(int i=0;i+2<n;i+=2) sum -= a[i];
    m[n-1] = sum; m[0] = a[n-1] - sum;
   rep(i,1,n-1){
        m[i] = a[i-1] - m[i-1];
    }

    list(i,n) cout << m[i] << " ";
    cout << "\n";
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;


int V;
vector<int> G[201];
int match[201];
bool used[201];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v){
  used[v] = true;
  for (int i=0;i<G[v].size();i++) {
    int u = G[v][i];
    int w = match[u];
    if (w < 0 || (!used[w] && dfs(w))) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int main(){
  int rx[101], ry[101], bx[101], by[101];
  cin >> V;
  for (int i=0;i<V;i++) {
    cin >> rx[i] >> ry[i];
  }
  for (int i=0;i<V;i++) {
    cin >> bx[i] >> by[i];    
  }
  for (int i=0;i<V;i++) {
    for (int j=0;j<V;j++) {
      if (rx[i] < bx[j] && ry[i] < by[j]) {
	add_edge(i, V+j);
      }
    }
  }
  
  int res = 0;
  memset(match, -1, sizeof(match));
  for (int v=0;v<(2*V);v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) {
	res++;
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] Args) throws IOException{
		final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		final byte[] gameBoard = new byte[16];
		StringTokenizer st = null;
		for (int i = 0; i<16; i++) {
			if (i%4 == 0) {
				st = new StringTokenizer(br.readLine(), " ");
			}
			gameBoard[i] = (byte)Integer.parseInt(st.nextToken());
		}
		
		final PQ puzzleQueue = new PQ();
		final Set<Long> cl = new HashSet<Long>();
		
		puzzleQueue.add(new state(gameBoard, 0), md(gameBoard));
		int minmove = 45;
		final int dx[] = {1, 0, -1, 0};
		final int dy[] = {0, 1, 0, -1};
		
		while (!puzzleQueue.isEmpty()) {
			final state s = puzzleQueue.remove();
			final long nh = hashBoard(s.gameBoard);
			if(nh == 1401602636313L){
				minmove = s.move;
				break;
			}
			if(cl.contains(nh)) continue;
			cl.add(nh);
			int f;
			for (f = 0; f<16 && s.gameBoard[f]!=0; f++);
			for (int i = 0; i < 4; i++) {
				final int fx = f%4+dx[i];
				final int fy = f/4+dy[i];
				if(fx<0 || fx>3 || fy<0 || fy>3) continue;
				final byte[] next = Arrays.copyOf(s.gameBoard, s.gameBoard.length);
				next[f] = next[fy*4+fx];
				next[fy*4+fx] = 0;
				final long h = hashBoard(next);
				if(!cl.contains(h)){
					puzzleQueue.add(new state(next, s.move+1), s.move+1+md(next));
				}
			}
		}
		System.out.println(minmove);	
	}
	
	private static long hashBoard(byte[] b){
		long head = b[0];
		for (int i = 1; i < 15; i++) {
			head *= 16-i;
			head += b[i];
			for (int j = 0; j < i; j++) {
				if(b[j]<b[i]) --head;
			}
		}
		return head;
	}
	
	private static int md(byte[] b){
		int md = 0;
		for (int i = 0; i < 16; i++) {
			if(b[i] == 0) continue;
			final int num = b[i] - 1;
			md += Math.abs(num/4-i/4);
			md += Math.abs(num%4-i%4);
		}
		return md;
	}
	
}



class state{
	final byte[] gameBoard;
	final int move;
	state(byte[] gameBoard, int move){
		this.gameBoard = gameBoard;
		this.move = move;
	}
}

class PQ{
	int length;
	int head;
	ArrayDeque<state>[] data;
	@SuppressWarnings("unchecked")
	
	PQ(){
		length = 0;
		head = Integer.MAX_VALUE;
		data = new ArrayDeque[45];
		for(int i = 0; i<45; i++){
			data[i] = new ArrayDeque<state>();
		}
	}
	boolean isEmpty(){
		return length == 0;
	}
	boolean add(state e, int minmove){
		if(minmove>=45){
			return false;
		}
		if(minmove<head){
			head = minmove;
		}
		++length;
		return data[minmove].add(e);
	}
	state remove(){
		final state toRemove = data[head].remove();
		--length;
		for( ; head<45 && data[head].isEmpty(); ++head);
		return toRemove;
	}
}


Measured memory_bytes: 184860
import sys
from collections import defaultdict as dd

N, K = map(int,input().split())
R, S, P = map(int,input().split())
rsp = [R,S,P]
T = input()
res = 0
tb = dd(list)
for i in range(N):
    tb[i%K].append(T[i])
for key in tb.keys():
    dic = tb[key]
    lg = len(dic)+1
    dp = [[0,0,0] for _ in range(lg)]
    for i in range(1,lg):
        for j in range(3):
            rsp2 = [0,0,0]
            if dic[i-1] == 'r':
                rsp2[2] = P
            elif dic[i-1] == 's':
                rsp2[0] = R
            else:
                rsp2[1] = S
            dp[i][j] = max([dp[i-1][(j+1)%3]+rsp2[(j+1)%3],dp[i-1][(j+2)%3]+rsp2[(j+2)%3]])
    res += max(dp[lg-1])
print(res)


Measured memory_bytes: 24992
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int n = stdIn.nextInt(); 
		
		int x = stdIn.nextInt(); 
		
		int [] l = new int[n];
		
		for(int i = 0; i < n; i++) {
			l[i] = stdIn.nextInt();
		}
		
		int[] d = new int[n+1];
		d[0] = 0;
		
		int cnt = 1;
		
		for(int i = 1; i < n+1; i++) {
			
			d[i] = d[i-1] + l[i-1];
			
			if(d[i] <= x) {
				cnt++;
			}
			
			
		}
		System.out.println(cnt);

	}

}


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

int main(){
  int n;
  string s;
  int k;
  cin >> n >> s >> k;
  char x = s[k - 1];
  for (int i = 0; i < n; i++){
    if (s[i] != x){
      s[i] = '*';
    }
  }

  for (int i = 0; i < n; i++){
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}

int a[maxn];
int main(){
    int n,m,T;
    rep(i,0,3){
        cin>>n>>m;
        a[n]++;
        a[m]++;
    }
    rep(i,1,5){
        if(a[i]>2){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;

    return 0;
}



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

int main() {
  string S;
  cin >> S;

  for (char c = 'a'; c <= 'z'; c++) {
    if (count(S.begin(), S.end(), c) % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

struct T {
	T* oya = NULL;
	vector<T*> children;
	int count = 0;
	int number = 0;
	unsigned long long counter = 0;
	void addChildren(T* t) {
		children.push_back(t);
		count++;
		//children[count++] = t;
		t->oya = this;
	}
	void Counter(const vector<unsigned long long>& p, unsigned long long tmp = 0) {
		unsigned long long t = p[number] + tmp;
		counter = t;
		rep(i, count) {
			if (children[i]) children[i]->Counter(p, t);
		}
	}
};

void addT(T* s, const vector<unsigned long long>& p, unsigned long long tmp = 0) {
	if (!s) return;
	unsigned long long t = p[s->number];
	s->counter += t + tmp;
	rep(i, s->count) {
		addT(s->children[i], p, t + tmp);
	}
}


int main() {
	int n, q; cin >> n >> q;
	vector<T*> t(n + 1);
	rep(i, n + 1) {
		//nodeの生成
		t[i] = new T;
		t[i]->number = i;
	}

	T* s = t[1];//暫定として

	rep(i, n - 1) {
		int a = 1, b = i + 2;
		cin >> a >> b;
		t[a]->addChildren(t[b]);
	}

	//根に移動
	while (s->oya) s = s->oya;

	vector<unsigned long long> ps(n + 1);

	//0で初期化
	rep(i, n + 1) ps[i] = 0;


	rep(i, q) {
		int p = i, x = 10;
		cin >> p >> x;
		ps[p] += x;
	}


	s->Counter(ps, 0);

	rep(i, n) {
		cout << t[i + 1]->counter << " ";
	}

}

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

#define MAX 100000
#define WHITE 0
#define GRAY 1
#define BLACK 2

// プロトタイプ宣言
void tSort();
void dfs(int s);
// ここまでプロトタイプ宣言


int v,e;
vector<int> Graph[MAX];
int color[MAX];
list<int> out;

int main(){

	for(int i=0;i<MAX;i++){
		color[i]=WHITE;
	}

	cin>>v>>e;
	int from,to;
	for(int i=0;i<e;i++){
		cin>>from>>to;
		Graph[from].push_back(to);
	}

	tSort();

	for(list<int>::iterator it=out.begin();	it!=out.end();	it++){
		cout<< *it <<endl;
	}

	return 0;
}

void dfs(int s){
	color[s]=GRAY;

	for(int next: Graph[s]){
		if(color[next]==WHITE) dfs(next);
	}
	out.push_front(s);
}

void tSort(){
	for(int s=0;s<v;s++){
		if(color[s]==WHITE){
			dfs(s);
		}
	}
}



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

const long long int INF = 1LL << 50;
const int nmax = 1001;
const int mmax = 2001;

struct edge {
    int from,to;
    long long int cost;
};

edge es[2010];

int a[mmax],b[mmax];
long long int c[mmax];

long long int d[nmax];
int n,m;

int main(){

    int s,t;
    long long int dd;

    cin >> n >> m;

    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i] >> c[i];
        c[i] = -c[i];
    }

    for(int i=0; i<=n; i++){
        d[i] = INF;
    }

    d[1] = 0;

    for(int loop=0; loop<n-1; loop++){
        for(int i=0; i<m; i++){
            if(d[a[i]] == INF){
                continue;
            }
            if(d[b[i]] > d[a[i]] + c[i]){
                d[b[i]] = d[a[i]] + c[i];
            }
        }
    }

    long long int ans = d[n];

    bool negative[nmax];

    for (int i = 0; i <= n; ++i) {
        negative[i] = false;
    }

    for (int loop = 0; loop < n ; ++ loop) {
        for (int i = 0; i < m; ++i) {
            if (d[a[i]] == INF) continue;
            if (d[b[i]] > d[a[i]] + c[i]) {
                d[b[i]] = d[a[i]] + c[i];
                negative[b[i] ] = true;
            }

            if (negative[a[i]]) {
                negative[b[i]] = true;
            }
        }
    }

    if(negative[n]){
        cout << "inf" << endl;
    }
    else{
        cout << -ans << endl;
    }

    return 0;
}

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


int main()
{

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
  string s;
  string t;
  cin>>s;
  cin>>t;
  ll m=s.length();
  ll n=t.length();

  ll dp[m+1][n+1];

  for(ll i=0;i<=m;i++)
  {
for(ll j=0;j<=n;j++)
{

  if(i==0 || j==0)
  {
    dp[i][j]=0;
    continue;
  }

  if(s[i-1]==t[j-1])
  {
    
    dp[i][j]=dp[i-1][j-1]+1;
  }
  else
  {
    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
  }


}

  }
// cout<<dp[m][n];
  vector<char> ans;
   ll i=m;
   ll j=n;
  ll tp=dp[m][n];

  while(tp>0)
  {


    if(dp[i][j]>dp[i-1][j] && dp[i][j]>dp[i][j-1])
    {
      ans.push_back(s[i-1]);
      // cout<<s[i-1]<<" ";
      i=i-1;
      j=j-1;
      tp=dp[i][j];
      continue;
    }
    else
    {
      if(dp[i-1][j]>dp[i][j-1])
      {
        i=i-1;
        tp=dp[i][j];
      }
      else
      {
        j=j-1;
        tp=dp[i][j];
      }

    }

  }

  for(ll i=ans.size()-1;i>=0;i--)
  {
    cout<<ans[i];
  }

}

Measured memory_bytes: 70656
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

#define N 500000

int n;
int A[N+1];

int parent(int i){
	return i/2;
}
int left(int i){
	return 2*i;
}
int right(int i){
	return 2*i+1;
}
int inside(int i){
	if(i>=1&&i<=n) return 1;
	else return 0;
}

void max_heapify(int x){
	int l = left(x);
	int r = right(x);
	int largest = x;
	if(inside(l)&&A[l]>A[largest]) largest = l;
	if(inside(r)&&A[r]>A[largest]) largest = r;
	if(largest!=x){
		int tmp = A[largest];
		A[largest] = A[x];
		A[x] = tmp;
		max_heapify(largest);
	}
}

int main(){
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> A[i];
	}
	/*
	for(int i=1; i<=n; i++){
		printf("node %d: ", i);
		printf("key = %d, ", A[i]);
		if(inside(parent(i))) printf("parent key = %d, ", A[parent(i)]);
		if(inside(left(i))) printf("left key = %d, ", A[left(i)]);
		if(inside(right(i))) printf("right key = %d, ", A[right(i)]);
		printf("\n");
	}
	*/

	for(int i=n; i>=1; i--){
		max_heapify(i);
	}
	for(int i=1; i<=n; i++){
		cout << " " << A[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3112
$edges = []
$pathhash = {}

### subroutines

def check_path(src, bits, strs, w)
  #p "check_path(#{src}, #{strs})"

  return $pathhash[src][bits] if ! $pathhash[src][bits].nil?

  n = strs.length
  stsrc = strs[src]

  bits0 = (bits | (1 << src))
  w0 = w + stsrc[2]

  min_time = Float::INFINITY
  min_ids = []

  for nxt in (0...n)
    next if ((bits0 >> nxt) & 1) != 0

    #p "(#{stsrc[0]})src=#{src}, stsrc[3]=#{stsrc[3]}"
    #p "(#{strs[nxt][0]})nxt=#{nxt}, strs[nxt][3]=#{strs[nxt][3]}"

    ntime, nids = check_path(nxt, bits0, strs, w0)
    time = ntime + $edges[src][nxt] * (70 + w0) / 2000

    if min_time > time
      min_time = time
      min_ids = [stsrc[0]] + nids
    end
  end

  $pathhash[src][bits] = [min_time, min_ids]
end

### main

n = gets.strip.to_i
strs = (0...n).map{gets.strip.split(' ').map{|s| s.to_i}}
strs.each{|st| st[2] *= 20}

$edges = (0...n).map{(0...n).map{nil}}
for i in (0...n)
  for j in ((i + 1)...n)
    $edges[i][j] = $edges[j][i] = (strs[i][1] - strs[j][1]).abs.to_f
  end
end

$pathhash = (0...n).map{[]}
nbits = (1 << n) - 1

for i in (0...n)
  $pathhash[i][nbits ^ (1 << i)] = [0.0, [strs[i][0]]]
end

min_time = Float::INFINITY
min_ids = []

for src in (0...n)
  time, ids = check_path(src, 0, strs, 0)
  if min_time > time
    min_time = time
    min_ids = ids
  end
end

puts min_ids.join(' ')

Measured memory_bytes: 76168
import fractions
import sys
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
  
N,M = (int(x) for x in input().split())
a = list(map(int,input().split()))
a = [a_i//2 for a_i in a]
lcm = lcm_list(a)
for a_i in a:
  if (lcm // a_i) %2 == 0:
    print(0)
    sys.exit()
  
print((M//lcm)//2 + ((M//lcm)%2==1))

Measured memory_bytes: 16232
# 入力の取得
# 数値:1行1件
n = int(input())
# 数値:1行_N件_件数指定有
input_data = list(map(int, input().split()))[0:n]

# 処理
isApproved = True

# ループ_INDEX必要
for index, item in enumerate(input_data):
    # print("インデックス：" + str(index) + ", 値：" + item)
    if item % 2 == 0 and item % 3 != 0 and item % 5 != 0:
        isApproved = False

# 結果出力
if isApproved:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 38384
# N//m=N%m
# (N-N%m)/m=N%m
# N=(N%m)(m+1)

n=int(input())

def make_divisor(x):
    ret=[]
    for i in range(1,int(x**.5)+1):
        q,m=divmod(x,i)
        if m==0:
            ret.append(i)
            if i==q:continue
            ret.append(q)
    return ret

ans=[]
d=make_divisor(n)

for e in d:
    if e==1:continue
    m=e-1
    k=n%m
    if k*e==n:
        ans.append(m)
print(sum(ans))

Measured memory_bytes: 39152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int nagasa = sc.nextInt();
		int count1 = 0;
		int count2 = 0;
		for(int i=0;i<nagasa;i++) {
			if(i%2 == 0) {
				count1++;
			}else {
				count2++;
			}
		}
		System.out.println(count1*count2);

	}
}

Measured memory_bytes: 21332
#include<iostream>
#include<string>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
#include<iomanip>

typedef long long ll;
//#include"gap.h"

using namespace std;


const int MOD = 1e9 + 7;

int N;
string s, t;
ll dp[30] = {};
int main() {
	cin >> N >> s >> t;

	dp[s[0]-'a'] = 1;
	for (int i = 1; i < N-1; i++) {
		dp[s[i] - 'a'] += dp[t[i] - 'a'];
		dp[s[i] - 'a'] %= MOD;
	}

	cout << dp[t[N - 1] - 'a'] << endl;

	return 0;
}



Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const int MOD = 1000000007;

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

    ll N;
    cin >> N;
    vec A(N);
    Rep (i, N) {
        cin >> A[i];
    }

    ll ans = 0;
    Rep (i, 60) {
        ll ones = 0;
        Rep (j, N) {
            if ((ll)1 << i & A[j]) {
                ones++;
            }
        }
        ans += ((ll)1 << i) % MOD * ones % MOD * (N-ones) % MOD;
        ans %= MOD;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 2560
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
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; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
int n;
vector<int> a;
map<int,int> m;
vector<int> va(24,false);//確定の点
int count(){
    int mi=25;
    for(int i=0;i<24;i++){
        for(int j=0;j<24;j++){
            if(va[i]&&va[j]&&i!=j){
                int d=min(abs(i-j),24-abs(i-j));
                chmin(mi,d);
            }
        }
    }
    return mi;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        a.push_back(temp);
        m[temp]++;
    }
    m[0]++;
    if(m[0]>=2) return cout<<0<<"\n",0;
    va[0]=true;
    vector<int> v;//2択の点
    for(int i=1;i<12;i++){
        if(m[i]==1)v.push_back(i);
        else if(m[i]==2) va[i]=true,va[24-i]=true;
        else if(m[i]>=3)return cout<<0<<"\n",0;
    }
    int ans=0;
    if(m[12])va[12]=true;
    if(m[12]>=2)return cout<<0<<"\n",0;
    for(int i=0;i<(1<<v.size());i++){
        for(int j=0;j<v.size();j++){
            if(i&(1<<j))va[v[j]]=true,va[24-v[j]]=false;
            else{
                va[v[j]]=false,va[24-v[j]]=true;
            }
        }
        chmax(ans,count());
    }
    chmax(ans,count());
    cout << ans << "\n";
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	N := readInt()
	count := 0
	for i := 0; i < N; i++ {
		a := readInt()
		if a%2 == 1 {
			count++
		}
	}
	if count%2 == 1 {
		println("NO")
	} else {
		println("YES")
	}
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A=sc.nextInt();
    int B=sc.nextInt();
    int C=sc.nextInt();
    int D=sc.nextInt();
    int K=sc.nextInt();
    int X=(C-A)*60;
    int Y;
    if(B-D>0) {
    	Y=(60-B)+D;
    	System.out.println(X+Y-K-60);
    }else {
    	Y=D-B;
    	System.out.println(X+Y-K);
    	
    }

  }
}

Measured memory_bytes: 35824
// First Grader
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] number = new int[n];
		for (int i = 0; i < n; i++)
			number[i] = sc.nextInt();
		long[][] dp = new long[n][21];
		dp[0][0] = 1;
		for (int i = 0; i < n - 1; i++) {
			for (int j = 0; j < 21; j++) {
				if (dp[i][j] > 0) {
					if (j + number[i] < 21)
						dp[i + 1][j + number[i]] += dp[i][j];
					if ((i > 0 || number[i] > 0) && j - number[i] >= 0)
						dp[i + 1][j - number[i]] += dp[i][j];
				}
			}
		}
		System.out.println(dp[n - 1][number[n - 1]]);
		sc.close();
	}
}

Measured memory_bytes: 18132
#include<iostream>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  int H[N]={0};
  for(int i=1;i<=N;i++){
    cin>>H[i];
  }
  int High[N+1]={};
  int a,b;
   for(int i=1;i<=M;i++){
    cin>>a>>b;
    if(H[a]>=H[b])High[b]=1;
    if(H[a]<=H[b])High[a]=1;
  }
  int ans=0;
  for(int i=1;i<=N;i++){
    if(High[i]==0)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4412
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<50
#define fst first
#define sec second
#define pb push_back
#define int long long
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(int itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(int itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<ll,ll> P;

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

  int n;
  cin >> n;
  
  cout << n*(1+n)/2 << endl;

  return 0;
}

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

using namespace std;

string s;

void Process()
{
    int i = 0, cou = 0, state = 0;

    while (i <= s.length()-1)
    {
        if (s[i] == s[i+1])
        {
            if (state == 0)
            {
                i += 2;     state = 1;
            }
                else
                {
                    state = 0;      i++;
                }
        }
            else
            {
                i++;    state = 0;
            }

        //cout << i << " ";

        cou++;
    }
    //cout << endl;

    cout << cou;
}

void Input()
{
    ios_base::sync_with_stdio(0);   cin.tie(0);

    //freopen("abc.txt", "r", stdin);

    cin >> s;
}

int main()
{
    Input();
    Process();
    return 0;
}


Measured memory_bytes: 720
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
a, b = ri_()
print(a - 1 if b < a else a)

Measured memory_bytes: 62956
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

	if (s.length() == 1) {
		cout << 0 << endl;

		return 0;
	}

	int ans = 0;
	for (int i = 0; i < s.length() - 1; i++) {
		if (s[i] == s[i + 1]) {
			s[i + 1] = s[i + 1] == '0' ? '1' : '0';
			ans++;
		}
	}
	cout << min(ans, (int)s.length() - ans) << endl;

	return 0;
}

Measured memory_bytes: 512
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, Y = nl()
for x in range(N+1):
    left = Y - x*10000
    if left < 0:
        continue
    for y in range(N - x + 1):
        if left == y*5000 + (N - x - y)*1000:
            print(x, y, N - x - y)
            import sys
            sys.exit()

print('-1 -1 -1')


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

struct UnionFind{
    vector<int> p;
    vector<int> r;

    UnionFind(int n){
        p.resize(n, -1);
        r.resize(n, 1);
    }

    int find(int x){
        if(p[x] == -1) return x;
        else return p[x] = find(p[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);

        if(x == y) return;
        if(r[x] > r[y]) swap(x, y);
        if(r[x] == r[y]) ++r[y];

        p[x] = y;
    }
};

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

    int n, m;
    cin >> n >> m;

    vector<int> a(m), b(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
    }

    int res = 0;
    rep(i, m){
        UnionFind uf(n);

        rep(j, m){
            if(j == i) continue;

            uf.unite(a[j], b[j]);
        }

        set<int> grs;
        rep(j, n){
            grs.insert(uf.find(j));
        }

        if(grs.size() > 1) ++res;
    }

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
     
    int m[2][100];
    int ans[2][100];
    int main()
    {
    	int n;
    	cin >> n;
    	for (int i = 0; i < 2; i++)
    		for (int j = 0; j < n; j++)
    		{
    			cin >> m[i][j];
    		}
    	for (int i = 0; i < 2; i++)
    	{
    		for (int j = 0; j < n; j++)
    		{
    			if (i > 0) ans[i][j] = max(ans[i][j], ans[i - 1][j]);
    			if (j > 0) ans[i][j] = max(ans[i][j], ans[i][j - 1]);
    			ans[i][j] += m[i][j];
    		}
    	}
    	cout << ans[1][n - 1];
    	//system("pause");
    }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int n,m,c;
    cin >> n >> m >> c;
    int b[m]; for(int i=0; i<m; i++) cin >> b[i];
    int a[n][m];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> a[i][j];
        }
    }
    int ans=0;
    for(int i=0; i<n; i++){
        int karians=0;
        for(int j=0; j<m; j++){
            karians += a[i][j] * b[j];
        }
        karians += c;
        if(karians>0) ans++;
    }
    cout << ans << endl;

    return 0;
}

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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 101;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,m,sx,sy;

char st[maxn][maxn];

short line[maxn][maxn],row[maxn][maxn];

short dp[maxn][maxn][maxn];

void Work(){
	memset(dp,-1,sizeof(dp));dp[0][0][0]=0;
	REP(l,0,m-sy)
		REP(i,0,sx-1)
			REP(j,0,n-sx)
				REP(k,0,sy-1)if(dp[i][j][k]!=-1){
					int U=max(sx-i,j+1),D=min(sx+j,n-i),L=max(sy-k,l+1),R=min(sy+l,m-k);
					if(sx-i-1>=j+1)dp[i+1][j][k]=max((int)dp[i+1][j][k],dp[i][j][k]+line[sx-i-1][R]-line[sx-i-1][L-1]);
					if(sx+j+1<=n-i)dp[i][j+1][k]=max((int)dp[i][j+1][k],dp[i][j][k]+line[sx+j+1][R]-line[sx+j+1][L-1]);
					if(sy-k-1>=l+1)dp[i][j][k+1]=max((int)dp[i][j][k+1],dp[i][j][k]+row[D][sy-k-1]-row[U-1][sy-k-1]);
					if(sy+l+1<=m-k)dp[i][j][k]=max((int)dp[i][j][k],dp[i][j][k]+row[D][sy+l+1]-row[U-1][sy+l+1]);
				}
	int ans=0;
	REP(i,0,n)REP(j,0,n)REP(k,0,m)ans=max(ans,(int)dp[i][j][k]);
	iout(ans);
}

void Init(){
	read(n,m);
	REP(i,1,n)scanf("%s",st[i]+1);
	REP(i,1,n)REP(j,1,m){
		if(st[i][j]=='E')sx=i,sy=j;
		line[i][j]=line[i][j-1]+(st[i][j]=='o');
		row[i][j]=row[i-1][j]+(st[i][j]=='o');
	}
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main()
{
	
	int a,b,c; cin>>a>>b>>c;
	map<int,int>mp;
	mp[a]++;
	mp[b]++;
	mp[c]++;
	if(mp[a]==2 || mp[b]==2 || mp[c]==2)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}

int countBits(int in){
  int res=0;
  rep(i,10){
    int msk=1<<i;
    if((in&msk)!=0){
      res++;
    }
  }
  return res;
}

int main() {
  int n;cin>>n;
  vector<vector<int>> v(2,vector<int>(n/2,0));
  rep(i,n){
    cin>>v[i%2][i/2];
  }
  int ans=0;
  vector<vector<int>> val(2,vector<int>(1e5+1,0));
  int maxval[2]={0};
  rep(i,2){
    vector<int>& half=v[i%2];
    vector<int>& sum=val[i%2];
    int& m=maxval[i%2];
    rep(j,n/2){
      sum[half[j]]++;
    }
    int summax=0;
    rep(j,1e5+1){
      if(summax<sum[j]){
        m=j;
        summax=sum[j];
      }
    }
    sort(all(sum),greater<int>());
    rep(j,n/2){
      if(sum[j]==0){
        break;
      }
      ans+=sum[j];
    }
  }
  if((maxval[0]==maxval[1])){
    ans-=max(val[0][0]+val[1][1],val[0][1]+val[1][0]);
  }else if(val[0][1]==0&&val[1][1]==0){
    ans=0;
  }else{
    ans-=val[0][0]+val[1][0];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1852